Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / xmlhttprequest / abort-on-changestate-headers-received.html
1 <!DOCTYPE html>
2 <script src="/js-test-resources/js-test.js"></script>
3 <script>
4 jsTestIsAsync = true;
5
6 var numberOfDocumentsBefore, numberOfDocumentsAfter;
7 function checkDocumentLeakAndFinishTest() {
8     numberOfDocumentsAfter = internals.numberOfLiveDocuments();
9     shouldBe("numberOfDocumentsAfter", "numberOfDocumentsBefore");
10     finishJSTest();
11 }
12
13 function runTest() {
14     numberOfDocumentsBefore = internals.numberOfLiveDocuments();
15
16     var xhr = new XMLHttpRequest();
17     xhr.responseType = 'document';
18     xhr.overrideMimeType("text/html");
19     xhr.onreadystatechange = function () {
20         if (this.readyState == XMLHttpRequest.HEADERS_RECEIVED) {
21             testPassed("this reached HEADERS_RECEIVED state.");
22             this.abort();
23             asyncGC(checkDocumentLeakAndFinishTest);
24         } else if (this.readyState == XMLHttpRequest.LOADING) {
25             testFailed("this reached LOADING state, but it should not reach here after abort().");
26         } else if (this.readyState == XMLHttpRequest.DONE) {
27             testPassed("this reached DONE state.");
28         }
29     }
30
31     xhr.open("GET", "resources/get.txt", true);
32     xhr.send(null);
33     xhr = null;
34 }
35
36 // run GC before test to avoid document count being flaky.
37 asyncGC(runTest);
38 </script>