summaryrefslogtreecommitdiffstats
path: root/dom/xhr/tests/test_bug1070763.html
blob: baf6ade4c1d46f88a4f9000c7cc225495d0f97f3 (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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1405571
-->
<head>
  <title>XMLHttpRequest send data and headers</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank"
   href="https://bugzilla.mozilla.org/show_bug.cgi?id=1405571">Mozilla Bug 1405571</a>
<p id="display">
</p>
<div id="content" style="display: none">

</div>
<pre id="test">
<script class="testbody" type="application/javascript">
SimpleTest.waitForExplicitFinish();

const url = "http://example.com/tests/dom/xhr/tests/file_XHRResponseURL.text";

function runTest(testName, testFn) {
  return new Promise(resolve => {
    const xhr = new XMLHttpRequest();
    xhr.onloadend = () => {
      xhr.onloadend = null;
      xhr.onreadystatechange = () => {
        if (xhr.readyState === 1) {
          testFn(xhr);
        } else if (xhr.readyState === 4) {
          ok(true, testName);
          resolve();
        }
      };
      xhr.open("GET", url);
      xhr.send(null);
    };
    xhr.open("GET", url);
    xhr.send(null);
  });
}

async function runTests() {
  await runTest("Abort #1", xhr => { xhr.abort() });
  await runTest("Abort #2", xhr => { setTimeout(() => xhr.abort(), 0) });
  await runTest("Timeout",  xhr => { xhr.timeout = 1 });
  SimpleTest.finish();
}

runTests();

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