summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/xhr/overridemimetype-blob.html
blob: fef0dfe816dcc008c9d54dc141358a8410a11c60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!doctype html>
<title>XMLHttpRequest: overrideMimeType() and responseType = "blob"</title>
<meta name="timeout" content="long">
<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();
  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");

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…");

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>