summaryrefslogtreecommitdiffstats
path: root/dom/xhr/tests/test_xhr_overridemimetype_throws_on_invalid_state.html
blob: 99e6bde004b04a954f6e6299eebd5f1442111ac0 (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
58
59
60
61
62
<!DOCTYPE HTML>
<html>
<head>
  <title>Test bug 482935</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="  /tests/SimpleTest/test.css" />
</head>
<body onload="onWindowLoad()">
<script class="testbody" type="text/javascript">"use strict";
SimpleTest.waitForExplicitFinish();

var url = "file_XHR_pass1.xml";

function onWindowLoad() {
  runTest();
}

function runTest() {
  var testFunctions = [
    function() { testOverMimeTypeThrowsDuringReadyState(3, "text/plain"); },
    function() { testOverMimeTypeThrowsDuringReadyState(3, "text/plain;charset=Shift-JIS"); },
    function() { testOverMimeTypeThrowsDuringReadyState(4, "text/plain"); },
    function() { testOverMimeTypeThrowsDuringReadyState(4, "text/plain;charset=Shift-JIS"); },
  ];

  function nextTest() {
    if (!testFunctions.length) {
      SimpleTest.finish();
      return;
    }
    (testFunctions.shift())();
  }

  nextTest();

  function testOverMimeTypeThrowsDuringReadyState(readyState, mimeType) {
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function() {
      if (xhr.readyState === readyState) {
        try {
          xhr.overrideMimeType(mimeType);
          ok(false, "No exception thrown, but expected InvalidStateError" +
                    " for readyState=" + readyState + ", mimeType=" + mimeType);
        } catch(exc) {
          is(exc.name, "InvalidStateError", "Expected InvalidStateError, got " + exc.name +
                       " for readyState=" + readyState + ", mimeType=" + mimeType);
        }
      }
      if (xhr.readyState === 4) {
        isnot(xhr.responseXML, null, "responseXML was null" +
                                     " for readyState=" + readyState +
                                     ", mimeType=" + mimeType);
        nextTest();
      }
    }
    xhr.open("GET", url);
    xhr.send();
  }
}
</script>
</body>
</html>