summaryrefslogtreecommitdiffstats
path: root/dom/xhr/tests/test_xhr_abort_after_load.html
blob: 780c112539a8e791fe1b07a957fa29234ef1e2e3 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!DOCTYPE HTML>
<html>
<head>
  <title>Test bug 482935</title>
  <script type="text/javascript" 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 = [
    startTest1,
    startTest2,
    startTest3,
  ];

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

  nextTest();

  var xhr;
  function startTest1() {
    xhr = new XMLHttpRequest();
    xhr.onload = onLoad1;
    xhr.open("GET", url);
    xhr.send();
  }

  function onLoad1() {
    is(xhr.readyState, xhr.DONE, "readyState should be DONE");
    xhr.onabort = onAbort1;
    xhr.abort();

    function onAbort1(e) {
      ok(false, e.type + " event should not be fired!");
    }

    is(xhr.readyState, xhr.UNSENT, "readyState should be UNSENT");
    nextTest();
  }

  function startTest2() {
    xhr = new XMLHttpRequest();
    xhr.onloadstart = onAfterSend;
    xhr.open("GET", url);
    xhr.send();
  }

  function startTest3() {
    xhr = new XMLHttpRequest();
    xhr.open("GET", url);
    xhr.send();
    onAfterSend();
  }

  function onAfterSend() {
    is(xhr.readyState, xhr.OPENED, "readyState should be OPENED");
    var sent = false;
    try {
      xhr.send();
    } catch (e) {
      sent = true;
    }
    ok(sent, "send() flag should be set");
    var aborted = false;
    xhr.onabort = onAbort2;
    xhr.abort();

    function onAbort2() {
      is(xhr.readyState, xhr.DONE, "readyState should be DONE");
      aborted = true;
    }

    ok(aborted, "abort event should be fired");
    is(xhr.readyState, xhr.UNSENT, "readyState should be UNSENT");
    nextTest();
  }
}

</script>
</body>
</html>