Revision b0f0ef9adb50765ea38be619015bb061d6a224b6 authored by Mustaq Ahmed on 27 June 2018, 15:33:46 UTC, committed by Blink WPT Bot on 27 June 2018, 15:42:47 UTC
With User Activation v2, activating a parent frame doesn't activate
its subframes.  We fixed these two tests by sending the click to
subframes.  This needed a workaround in auto-click.js because
the mutation observer there in doesn't seem to work when a button
element is added to a subframe.

Bug: 802371
Change-Id: I786668c87b802565e99ad16223cafc8ac1fd6296
Reviewed-on: https://chromium-review.googlesource.com/868323
Reviewed-by: Navid Zolghadr <nzolghadr@chromium.org>
Commit-Queue: Mustaq Ahmed <mustaq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570778}
1 parent b44c265
Raw File
send-redirect-to-cors.htm
<!doctype html>
<html>
  <head>
    <title>XMLHttpRequest: send() - Redirect to CORS-enabled resource</title>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
  </head>
  <body>
    <div id="log"></div>
    <script>
      function extractBody(body) {
        if (body === null) {
          return { body: "", type: "NO" };
        }
        if (typeof body == "string") {
          return { body: body, type: "text/plain;charset=UTF-8" };
        }
        if (body instanceof Uint8Array) {
          var arr = Array.prototype.slice.call(body);
          return { body: String.fromCharCode.apply(null, arr), type: "NO" }
        }
        return { body: "EXTRACT NOT IMPLEMENTED", type: "EXTRACT NOT IMPLEMENTED" }
      }

      function redirect(code, name = code, method = "GET", body = null, explicitType = null, safelistContentType = false) {
        async_test(t => {
          var client = new XMLHttpRequest()
          client.onreadystatechange = t.step_func(() => {
            if (client.readyState == 4) {
              if (explicitType !== "application/x-pony" || safelistContentType) {
                var { body: expectedBody, type: expectedType } = extractBody(body);
                if (explicitType !== null) {
                  expectedType = explicitType
                }
                if (((code === "301" || code === "302") && method === "POST") || code === "303") {
                  method = "GET"
                  expectedBody = ""
                }
                assert_equals(client.status, 200);
                assert_equals(client.getResponseHeader("x-request-method"), method);
                assert_equals(client.getResponseHeader("x-request-content-type"), expectedType);
                assert_equals(client.getResponseHeader("x-request-data"), expectedBody);
              } else {
                // "application/x-pony" is not safelisted by corsenabled.py -> network error
                assert_equals(client.status, 0)
                assert_equals(client.statusText, "")
                assert_equals(client.responseText, "")
                assert_equals(client.responseXML, null)
              }
              t.done();
            }
          })
          let safelist = ""
          if (safelistContentType) {
            safelist = "?safelist_content_type"
          }
          client.open(method, "resources/redirect.py?location="+encodeURIComponent("http://www2."+location.host+(location.pathname.replace(/[^\/]+$/, ''))+'resources/corsenabled.py')+safelist+"&code=" + code)
          if (explicitType !== null) {
            client.setRequestHeader("Content-Type", explicitType)
          }
          client.send(body)
        }, document.title + " (" + name + ")")
      }
      redirect("301")
      redirect("301", "301 GET with explicit Content-Type", "GET", null, "application/x-pony")
      redirect("301", "301 GET with explicit Content-Type safelisted", "GET", null, "application/x-pony", true)
      redirect("302")
      redirect("303")
      redirect("303", "303 LALA with string and explicit Content-Type safelisted", "LALA", "test", "application/x-pony", true)
      redirect("307")
      redirect("307", "307 post with null", "POST", null)
      redirect("307", "307 post with string", "POST", "hello")
      redirect("307", "307 post with typed array", "POST", new Uint8Array([65, 66, 67]))
      redirect("301", "301 POST with string and explicit Content-Type", "POST", "yoyo", "application/x-pony")
      redirect("301", "301 POST with string and explicit Content-Type safelisted", "POST", "yoyo", "application/x-pony", true)
      redirect("302", "302 POST with string and explicit Content-Type", "POST", "yoyo", "application/x-pony")
      redirect("307", "307 POST with string and explicit Content-Type", "POST", "yoyo", "application/x-pony")
      redirect("307", "307 FOO with string and explicit Content-Type", "FOO", "yoyo", "application/x-pony")
      redirect("308", "308 POST with string and explicit Content-Type", "POST", "yoyo", "application/x-pony")
      redirect("308", "308 FOO with string and explicit Content-Type", "FOO", "yoyo", "application/x-pony")
      redirect("308", "308 FOO with string and explicit Content-Type text/plain", "FOO", "yoyo", "text/plain")
      redirect("308", "308 FOO with string and explicit Content-Type multipart/form-data", "FOO", "yoyo", "multipart/form-data")
      redirect("308", "308 FOO with string and explicit Content-Type safelisted", "FOO", "yoyo", "application/thunderstorm", true)
      redirect("307", "307 POST with string and explicit Content-Type safelisted", "POST", "yoyo", "application/thunderstorm", true)
    </script>
  </body>
</html>
back to top