|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <head> |
|
4 <title>Test bug 482935</title> |
|
5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
6 <link rel="stylesheet" type="text/css" href=" /tests/SimpleTest/test.css" /> |
|
7 </head> |
|
8 <body onload="onWindowLoad()"> |
|
9 <script class="testbody" type="text/javascript">"use strict"; |
|
10 SimpleTest.waitForExplicitFinish(); |
|
11 |
|
12 var url = "file_XHR_pass1.xml"; |
|
13 |
|
14 function onWindowLoad() { |
|
15 runTest(); |
|
16 } |
|
17 |
|
18 function runTest() { |
|
19 var testFunctions = [ |
|
20 startTest1, |
|
21 startTest2, |
|
22 startTest3, |
|
23 ]; |
|
24 |
|
25 function nextTest() { |
|
26 if (testFunctions.length == 0) { |
|
27 SimpleTest.finish(); |
|
28 return; |
|
29 } |
|
30 (testFunctions.shift())(); |
|
31 } |
|
32 |
|
33 nextTest(); |
|
34 |
|
35 var xhr; |
|
36 function startTest1() { |
|
37 xhr = new XMLHttpRequest(); |
|
38 xhr.onload = onLoad1; |
|
39 xhr.open("GET", url); |
|
40 xhr.send(); |
|
41 } |
|
42 |
|
43 function onLoad1() { |
|
44 is(xhr.readyState, xhr.DONE, "readyState should be DONE"); |
|
45 xhr.onabort = onAbort1; |
|
46 xhr.abort(); |
|
47 |
|
48 function onAbort1(e) { |
|
49 ok(false, e.type + " event should not be fired!"); |
|
50 } |
|
51 |
|
52 is(xhr.readyState, xhr.UNSENT, "readyState should be UNSENT"); |
|
53 nextTest(); |
|
54 } |
|
55 |
|
56 function startTest2() { |
|
57 xhr = new XMLHttpRequest(); |
|
58 xhr.onloadstart = onAfterSend; |
|
59 xhr.open("GET", url); |
|
60 xhr.send(); |
|
61 } |
|
62 |
|
63 function startTest3() { |
|
64 xhr = new XMLHttpRequest(); |
|
65 xhr.open("GET", url); |
|
66 xhr.send(); |
|
67 onAfterSend(); |
|
68 } |
|
69 |
|
70 function onAfterSend() { |
|
71 is(xhr.readyState, xhr.OPENED, "readyState should be OPENED"); |
|
72 var sent = false; |
|
73 try { |
|
74 xhr.send(); |
|
75 } catch (e) { |
|
76 sent = true; |
|
77 } |
|
78 ok(sent, "send() flag should be set"); |
|
79 var aborted = false; |
|
80 xhr.onabort = onAbort2; |
|
81 xhr.abort(); |
|
82 |
|
83 function onAbort2() { |
|
84 is(xhr.readyState, xhr.DONE, "readyState should be DONE"); |
|
85 aborted = true; |
|
86 } |
|
87 |
|
88 ok(aborted, "abort event should be fired"); |
|
89 is(xhr.readyState, xhr.UNSENT, "readyState should be UNSENT"); |
|
90 nextTest(); |
|
91 } |
|
92 } |
|
93 |
|
94 </script> |
|
95 </body> |
|
96 </html> |