Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / xmlhttprequest / xmlhttprequest-abort-readyState-shouldDispatchEvent.html
blobab9247eeb1d003a9ffa6eacb299098f793f98e3b
1 <html>
2 <head></head>
3 <body>
5 <p>Test bug 13141 : XMLHttpRequest should set readyState to 0 after abort() </p>
6 <p>Updated for bug 16989: Add send() flag checks in XmlHttpRequest </p>
7 <p>Should see "PASS (reasyState event send)" & "PASS" (in that order) three times:</p>
8 <div id="ans"></div>
10 <script type="text/javascript">
11 function log(message) {
12 document.getElementById("ans").appendChild(document.createTextNode(message));
13 document.getElementById("ans").appendChild(document.createElement("br"));
16 // Used to detect if a readystate event is dispatched
17 function catchReadystateEventAbort() {
18 log("PASS (readystate event send)");
21 // Called only for readyState == 1
22 function testAbortWithReadyStateEventLoading()
24 var xhr;
26 if (window.XMLHttpRequest) {
27 xhr = new XMLHttpRequest();
28 } else {
29 try {
30 xhr = new ActiveXObject("Msxml2.XMLHTTP");
31 } catch (ex) {
32 xhr = new ActiveXObject("Microsoft.XMLHTTP");
36 // We use a slow page to test the LOADING state with the send() flag
37 // and we do not catch readyState event before send has been called
38 xhr.open("GET", "resources/endlessxml.php", true);
39 xhr.send(null);
41 ++finishedTests;
42 xhr.onreadystatechange = catchReadystateEventAbort;
43 xhr.abort();
45 if (xhr.readyState == 0)
46 log("PASS");
47 else
48 log("FAILED");
50 if (finishedTests == abortToDo.length && window.testRunner)
51 testRunner.notifyDone();
54 // Called with num != 1
55 function testAbortWithReadyStateEvent(num)
57 var xhr;
59 if (window.XMLHttpRequest) {
60 xhr = new XMLHttpRequest();
61 } else {
62 try {
63 xhr = new ActiveXObject("Msxml2.XMLHTTP");
64 } catch (ex) {
65 xhr = new ActiveXObject("Microsoft.XMLHTTP");
69 xhr.onreadystatechange = function () {
70 if (this.readyState == num) {
71 ++finishedTests;
72 this.onreadystatechange = catchReadystateEventAbort;
73 this.abort();
74 if (this.readyState == 0)
75 log("PASS");
76 else
77 log("FAILED");
80 if (finishedTests == abortToDo.length && window.testRunner)
81 testRunner.notifyDone();
84 xhr.open("GET", "resources/1251.html", true);
85 xhr.send(null);
88 if (window.testRunner) {
89 testRunner.dumpAsText();
90 testRunner.waitUntilDone();
93 var finishedTests = 0;
95 var abortToDo = ['2', '3', '1'];
97 for (i = 0; i < abortToDo.length; i++)
98 if (abortToDo[i] == 1)
99 testAbortWithReadyStateEventLoading();
100 else
101 testAbortWithReadyStateEvent(abortToDo[i]);
103 </script>
104 </body>
105 </html>