Bug 1632044 [wpt PR 23164] - XHR: align with Fetch's Content-Type stripping, a=testonly
authorAnne van Kesteren <annevk@annevk.nl>
Tue, 28 Apr 2020 11:37:02 +0000
changeset 527569 3a312842c93cb4177df2d959979dff57a587043b
parent 527568 6639c02fb2c0552c5f82637e01d3db026e6deec9
child 527570 46ecf7e8fcfcfcd7073bdc2cf812fd10cf27fd86
push id37368
push userbtara@mozilla.com
push dateFri, 01 May 2020 21:45:51 +0000
treeherdermozilla-central@0f9c5a59e45d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1632044, 23164, 23156
milestone77.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1632044 [wpt PR 23164] - XHR: align with Fetch's Content-Type stripping, a=testonly Automatic update from web-platform-tests XHR: align with Fetch's Content-Type stripping Also modernize the code a tiny bit. Closes #23156. -- wpt-commits: 79311e3ce537612a80c21afc0013ee074d1fc5c1 wpt-pr: 23164
testing/web-platform/tests/xhr/send-redirect-to-cors.htm
--- a/testing/web-platform/tests/xhr/send-redirect-to-cors.htm
+++ b/testing/web-platform/tests/xhr/send-redirect-to-cors.htm
@@ -7,71 +7,75 @@
   </head>
   <body>
     <div id="log"></div>
     <script>
       function extractBody(body) {
         if (body === null) {
           return { body: "", type: "NO" };
         }
-        if (typeof body == "string") {
+        if (typeof body === "string") {
           return { body: body, type: "text/plain;charset=UTF-8" };
         }
         if (body instanceof Uint8Array) {
-          var arr = Array.prototype.slice.call(body);
+          const 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 (client.readyState === 4) {
               if (explicitType !== "application/x-pony" || safelistContentType) {
-                var { body: expectedBody, type: expectedType } = extractBody(body);
+                let { body: expectedBody, type: expectedType } = extractBody(body);
                 if (explicitType !== null) {
                   expectedType = explicitType
                 }
+                let expectedMethod = method;
                 if (((code === "301" || code === "302") && method === "POST") || code === "303") {
-                  method = "GET"
-                  expectedBody = ""
+                  expectedMethod = "GET";
+                  expectedBody = "";
+                  expectedType = "NO";
                 }
                 assert_equals(client.status, 200);
-                assert_equals(client.getResponseHeader("x-request-method"), method);
+                assert_equals(client.getResponseHeader("x-request-method"), expectedMethod);
                 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)
+                assert_equals(client.status, 0);
+                assert_equals(client.statusText, "");
+                assert_equals(client.responseText, "");
+                assert_equals(client.responseXML, null);
               }
               t.done();
             }
           })
-          let safelist = ""
+          let safelist = "";
           if (safelistContentType) {
-            safelist = "?safelist_content_type"
+            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)
+          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.setRequestHeader("Content-Type", explicitType);
           }
-          client.send(body)
-        }, document.title + " (" + name + ")")
+          client.send(body);
+        }, document.title + " (" + name + ")");
       }
+      // corsenabled.py safelists methods GET, POST, PUT, and FOO
       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("302", "302 FOO with string and explicit Content-Type safelisted", "FOO", "test", "application/x-pony", true)
+      redirect("303", "303 FOO with string and explicit Content-Type safelisted", "FOO", "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")