Bug 1452928 [wpt PR 8449] - Add more XMLHttpRequest overrideMimeType() tests, a=testonly
authorAnne van Kesteren <annevk@annevk.nl>
Wed, 25 Apr 2018 18:57:22 +0000
changeset 471891 a743786f569a9e77f8c86a2882abee702f58f981
parent 471890 04d6f363e6445f09fbd89aa6ec8923366a48b578
child 471892 dca90afc00ae4724896b7a4c36ec479aacec6462
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1452928
milestone61.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 1452928 [wpt PR 8449] - Add more XMLHttpRequest overrideMimeType() tests, a=testonly Automatic update from web-platform-testsAdd more XMLHttpRequest overrideMimeType() tests For https://github.com/whatwg/xhr/issues/157, https://github.com/whatwg/xhr/pull/174, and https://github.com/whatwg/mimesniff/issues/42. -- wpt-commits: ae41496630ba35cff974877498383f1280ca07c2 wpt-pr: 8449
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/mimesniff/mime-types/resources/mime-types.json
testing/web-platform/tests/xhr/overridemimetype-blob.html
testing/web-platform/tests/xhr/overridemimetype-edge-cases.window.js
testing/web-platform/tests/xhr/responsetext-decoding.htm
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -374466,16 +374466,22 @@
     ]
    ],
    "xhr/overridemimetype-done-state.htm": [
     [
      "/xhr/overridemimetype-done-state.htm",
      {}
     ]
    ],
+   "xhr/overridemimetype-edge-cases.window.js": [
+    [
+     "/xhr/overridemimetype-edge-cases.window.html",
+     {}
+    ]
+   ],
    "xhr/overridemimetype-headers-received-state-force-shiftjis.htm": [
     [
      "/xhr/overridemimetype-headers-received-state-force-shiftjis.htm",
      {}
     ]
    ],
    "xhr/overridemimetype-invalid-mime-type.htm": [
     [
@@ -579028,17 +579034,17 @@
    "1a3357e9bd14bc90cfa45f6844a270b7b3b93db4",
    "support"
   ],
   "mimesniff/mime-types/resources/mime-charset.py": [
    "635c7dd3564ddec8c7a18c9eb1dae4c01cab75c4",
    "support"
   ],
   "mimesniff/mime-types/resources/mime-types.json": [
-   "9271134541b22f4af44b6d179606c7a6cb8f3227",
+   "b214e6025adc09d310f47eea34f2ea316f6132ec",
    "support"
   ],
   "mixed-content/OWNERS": [
    "167112f19752c9c180831820b6e348427606b63b",
    "support"
   ],
   "mixed-content/audio-tag/http-csp/cross-origin-http/top-level/keep-scheme-redirect/optionally-blockable/opt-in-blocks.https.html": [
    "9219890ab0efa31e4f2db0646e12882da3a5443d",
@@ -614736,23 +614742,27 @@
    "224c1502970253197c670bfb04efa15708e034d5",
    "testharness"
   ],
   "xhr/open-user-password-non-same-origin.htm": [
    "9e28bf35af12bb962fdfd2213d7e20e031a29703",
    "testharness"
   ],
   "xhr/overridemimetype-blob.html": [
-   "462d95dec7146c2a7beba5d8b2285fd2b8460002",
+   "38a7f6e2871ac0def651e5b82bb8a43b061633bb",
    "testharness"
   ],
   "xhr/overridemimetype-done-state.htm": [
    "167f34f8dfc1312a9124c12ee4f8de808fa41680",
    "testharness"
   ],
+  "xhr/overridemimetype-edge-cases.window.js": [
+   "a76e1c81a86823765be280747d2fa6994395cc25",
+   "testharness"
+  ],
   "xhr/overridemimetype-headers-received-state-force-shiftjis.htm": [
    "92a00af686310d8b44fb5e4c70cc6fbea28e0a88",
    "testharness"
   ],
   "xhr/overridemimetype-invalid-mime-type.htm": [
    "1deea1bfa844816a404b90cf5650382383df5d57",
    "testharness"
   ],
@@ -615220,17 +615230,17 @@
    "6111310764e8aac694655f173aef9653325ef7e8",
    "testharness"
   ],
   "xhr/responsedocument-decoding.htm": [
    "ab52417826b3953b71b5f6037ebd616d4b862ad4",
    "testharness"
   ],
   "xhr/responsetext-decoding.htm": [
-   "538d6d5121157e04c44fd947140f2c913dc3b65e",
+   "d08dd5c1d0b21b639389dfc1deec65215b3334dc",
    "testharness"
   ],
   "xhr/responsetype.html": [
    "090ae5981aed9e0ed5e5f8a2f5615d57df0c366b",
    "testharness"
   ],
   "xhr/responseurl.html": [
    "b7ac10fed9c8a07afcd13f1d4906e10996ae56c6",
--- a/testing/web-platform/tests/mimesniff/mime-types/resources/mime-types.json
+++ b/testing/web-platform/tests/mimesniff/mime-types/resources/mime-types.json
@@ -267,16 +267,20 @@
     "input": "",
     "output": null
   },
   {
     "input": "\t",
     "output": null
   },
   {
+    "input": "/",
+    "output": null
+  },
+  {
     "input": "bogus",
     "output": null
   },
   {
     "input": "bogus/",
     "output": null
   },
   {
@@ -291,16 +295,20 @@
     "input": "</>",
     "output": null
   },
   {
     "input": "(/)",
     "output": null
   },
   {
+    "input": "ÿ/ÿ",
+    "output": null
+  },
+  {
     "input": "text/html(;doesnot=matter",
     "output": null
   },
   {
     "input": "{/}",
     "output": null
   },
   {
--- a/testing/web-platform/tests/xhr/overridemimetype-blob.html
+++ b/testing/web-platform/tests/xhr/overridemimetype-blob.html
@@ -1,65 +1,56 @@
 <!doctype html>
 <title>XMLHttpRequest: overrideMimeType() and responseType = "blob"</title>
 <meta charset="utf-8">
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <div id="log"></div>
 <script>
 async_test(t => {
-  const client = new XMLHttpRequest()
+  const client = new XMLHttpRequest();
   client.onload = t.step_func_done(() => {
-    assert_equals(client.getResponseHeader("Content-Type"), "")
-    assert_equals(client.response.type, "text/xml")
-  })
-  client.open("GET", "resources/status.py")
-  client.responseType = "blob"
-  client.send()
-}, "Use text/xml as fallback MIME type")
-
-async_test(t => {
-  const client = new XMLHttpRequest()
-  client.onload = t.step_func_done(() => {
-    assert_equals(client.getResponseHeader("Content-Type"), "")
-    assert_equals(client.response.type, "text/xml")
-  })
-  client.open("GET", "resources/status.py?content=thisshouldnotmakeadifferencebutdoes")
-  client.responseType = "blob"
-  client.send()
-}, "Use text/xml as fallback MIME type, 2")
+    assert_equals(client.getResponseHeader("Content-Type"), "");
+    assert_equals(client.response.type, "text/xml");
+  });
+  client.open("GET", "resources/status.py");
+  client.responseType = "blob";
+  client.send();
+}, "Use text/xml as fallback MIME type");
 
 async_test(t => {
-  const client = new XMLHttpRequest()
+  const client = new XMLHttpRequest();
   client.onload = t.step_func_done(() => {
-    assert_equals(client.getResponseHeader("Content-Type"), "")
-    assert_equals(client.response.type, "application/octet-stream")
-  })
-  client.open("GET", "resources/status.py")
-  client.responseType = "blob"
-  client.overrideMimeType("bogus")
-  client.send()
-}, "Bogus MIME type should end up as application/octet-stream")
-
-async_test(t => {
-  const client = new XMLHttpRequest()
-  client.onload = t.step_func_done(() => {
-    assert_equals(client.getResponseHeader("Content-Type"), "")
-    assert_equals(client.response.type, "application/octet-stream")
+    assert_equals(client.getResponseHeader("Content-Type"), "");
+    assert_equals(client.response.type, "text/xml");
   })
-  client.open("GET", "resources/status.py")
-  client.responseType = "blob"
-  client.overrideMimeType("text/xml;charset=†")
-  client.send()
-}, "Bogus MIME type should end up as application/octet-stream, 2")
+  client.open("GET", "resources/status.py?content=thisshouldnotmakeadifferencebutdoes");
+  client.responseType = "blob";
+  client.send();
+}, "Use text/xml as fallback MIME type, 2");
+
+promise_test(() => {
+  // Don't load generated-mime-types.json as sending them all over the network would be prohibitive
+  return fetch("../mimesniff/mime-types/resources/mime-types.json").then(res => res.json()).then(runTests);
+}, "Loading data…");
 
-async_test(t => {
-  const client = new XMLHttpRequest()
-  client.onload = t.step_func_done(() => {
-    assert_equals(client.getResponseHeader("Content-Type"), "")
-    assert_equals(client.response.type, "hi/x")
-  })
-  client.open("GET", "resources/status.py")
-  client.responseType = "blob"
-  client.overrideMimeType("HI/x;test=test")
-  client.send()
-}, "Valid MIME types need to be normalized")
+function runTests(tests) {
+  let index = 0;
+  tests.forEach((val) => {
+    if(typeof val === "string") {
+      return;
+    }
+    index++;
+    async_test(t => {
+      const client = new XMLHttpRequest(),
+            expectedOutput = val.output !== null ? val.output : "application/octet-stream";
+      client.onload = t.step_func_done(() => {
+        assert_equals(client.getResponseHeader("Content-Type"), "");
+        assert_equals(client.response.type, expectedOutput);
+      });
+      client.open("GET", "resources/status.py");
+      client.responseType = "blob";
+      client.overrideMimeType(val.input);
+      client.send();
+    }, index + ") MIME types need to be parsed and serialized: " + val.input);
+  });
+}
 </script>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/xhr/overridemimetype-edge-cases.window.js
@@ -0,0 +1,40 @@
+const testURL = "resources/status.py?type=" + encodeURIComponent("text/plain;charset=windows-1252") + "&content=%C2%F0";
+
+async_test(t => {
+  const client = new XMLHttpRequest();
+  let secondTime = false;
+  client.onload = t.step_func(() => {
+    if(!secondTime) {
+      assert_equals(client.responseText, "\uFFFD");
+      secondTime = true;
+      client.open("GET", testURL);
+      client.send();
+    } else {
+      assert_equals(client.responseText, "Âð");
+      t.done();
+    }
+  });
+  client.open("GET", testURL);
+  client.overrideMimeType("text/plain;charset=UTF-8")
+  client.send();
+}, "overrideMimeType() state needs to be reset across requests");
+
+async_test(t => {
+  const client = new XMLHttpRequest();
+  client.onload = t.step_func_done(() => {
+    assert_equals(client.responseText, "Âð")
+  });
+  client.open("GET", testURL);
+  client.overrideMimeType("text/xml");
+  client.send();
+}, "If charset is not overridden by overrideMimeType() the original continues to be used");
+
+async_test(t => {
+  const client = new XMLHttpRequest();
+  client.onload = t.step_func_done(() => {
+    assert_equals(client.responseText, "\uFFFD")
+  });
+  client.open("GET", testURL);
+  client.overrideMimeType("text/plain;charset=342");
+  client.send();
+}, "Charset can be overridden by overrideMimeType() with a bogus charset");
--- a/testing/web-platform/tests/xhr/responsetext-decoding.htm
+++ b/testing/web-platform/tests/xhr/responsetext-decoding.htm
@@ -77,16 +77,17 @@
       request("text/html;charset=windows-1252", encoded_html, html_decoded_as_windows_1252, "text");
       request("text/plain;charset=windows-1252", "%FF", "\u00FF", "text");
       request("text/plain", "%FF", "\uFFFD", "text");
       request("text/plain", "%FE%FF", "", "text");
       request("text/plain", "%FE%FF%FE%FF", "\uFEFF", "text");
       request("text/plain", "%EF%BB%BF", "", "text");
       request("text/plain", "%EF%BB%BF%EF%BB%BF", "\uFEFF", "text");
       request("text/plain", "%C2", "\uFFFD", "text");
+      request("text/plain;charset=bogus", "%C2", "\uFFFD", "text");
       request("text/xml", "%FE%FF", "", "text");
       request("text/xml", "%FE%FF%FE%FF", "\uFEFF", "text");
       request("text/xml", "%EF%BB%BF", "", "text");
       request("text/xml", "%EF%BB%BF%EF%BB%BF", "\uFEFF", "text");
       request("text/plain", "%E3%81%B2", "\u3072", "text");
     </script>
   </body>
 </html>