Add XHR tests checking readyState transition when abort() is invoked in various states
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Sep 2013 17:57:24 +0000 (17:57 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Sep 2013 17:57:24 +0000 (17:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=121585

Reviewed by Alexey Proskuryakov.

Merge https://chromium.googlesource.com/chromium/blink/+/2d854757576db590745cfb78e11ca428a1aac342

* http/tests/xmlhttprequest/readystatechange-and-abort-expected.txt: Added.
* http/tests/xmlhttprequest/readystatechange-and-abort.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@156103 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/tests/xmlhttprequest/readystatechange-and-abort-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/xmlhttprequest/readystatechange-and-abort.html [new file with mode: 0644]

index a7f0620219e8eb32e44fcd11bb2c559b2f4f4724..19393c7af2804ea660390c92f570381cbd255a30 100644 (file)
@@ -1,3 +1,15 @@
+2013-09-19  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Add XHR tests checking readyState transition when abort() is invoked in various states
+        https://bugs.webkit.org/show_bug.cgi?id=121585
+
+        Reviewed by Alexey Proskuryakov.
+
+        Merge https://chromium.googlesource.com/chromium/blink/+/2d854757576db590745cfb78e11ca428a1aac342
+
+        * http/tests/xmlhttprequest/readystatechange-and-abort-expected.txt: Added.
+        * http/tests/xmlhttprequest/readystatechange-and-abort.html: Added.
+
 2013-09-19  Manuel Rego Casasnovas  <rego@igalia.com>
 
         Unreviewed. Fix typo in layout test description introduced in r155974.
diff --git a/LayoutTests/http/tests/xmlhttprequest/readystatechange-and-abort-expected.txt b/LayoutTests/http/tests/xmlhttprequest/readystatechange-and-abort-expected.txt
new file mode 100644 (file)
index 0000000..6069fbf
--- /dev/null
@@ -0,0 +1,8 @@
+
+PASS Test onreadystatechange invocation when abort()-ed in UNSENT state. 
+PASS Test onreadystatechange invocation when abort()-ed in OPENED state. 
+PASS Test onreadystatechange invocation when abort()-ed right after calling send(). 
+PASS Test onreadystatechange invocation when abort()-ed in HEADERS_RECEIVED state. 
+PASS Test onreadystatechange invocation when abort()-ed in LOADING state. 
+PASS Test onreadystatechange invocation when abort()-ed in DONE state. 
+
diff --git a/LayoutTests/http/tests/xmlhttprequest/readystatechange-and-abort.html b/LayoutTests/http/tests/xmlhttprequest/readystatechange-and-abort.html
new file mode 100644 (file)
index 0000000..509ab44
--- /dev/null
@@ -0,0 +1,164 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src="../w3c/resources/testharness.js"></script>
+<script src="../w3c/resources/testharnessreport.js"></script>
+<script type="text/javascript">
+test(function()
+{
+    var xhr = new XMLHttpRequest;
+    xhr.onreadystatechange = this.step_func(function() {
+        assert_unreached("Received readystatechange event unexpectedly: readyState=" + xhr.readyState)
+    });
+    xhr.abort();
+    assert_equals(xhr.readyState, xhr.UNSENT, "xhr.readyState after abort() call");
+}, "Test onreadystatechange invocation when abort()-ed in UNSENT state.");
+
+test(function()
+{
+    var xhr = new XMLHttpRequest;
+    var seenStates = [];
+    xhr.onreadystatechange = this.step_func(function() {
+        seenStates.push(xhr.readyState);
+
+        switch (xhr.readyState) {
+        case xhr.OPENED:
+            return;
+
+        case xhr.UNSENT:
+        case xhr.HEADERS_RECEIVED:
+        case xhr.LOADING:
+        case xhr.DONE:
+        default:
+            assert_unreached("Unexpected readyState: " + xhr.readyState);
+            return;
+        }
+    });
+    xhr.open("GET", "resources/test.ogv", true);
+    xhr.abort();
+    assert_equals(xhr.readyState, xhr.UNSENT, "xhr.readyState after abort() call");
+    assert_array_equals(seenStates, [xhr.OPENED]);
+}, "Test onreadystatechange invocation when abort()-ed in OPENED state.");
+
+test(function()
+{
+    var xhr = new XMLHttpRequest;
+    var seenStates = [];
+    xhr.onreadystatechange = this.step_func(function() {
+        seenStates.push(xhr.readyState);
+
+        switch (xhr.readyState) {
+        case xhr.OPENED:
+        case xhr.DONE:
+            return;
+
+        case xhr.UNSENT:
+        case xhr.HEADERS_RECEIVED:
+        case xhr.LOADING:
+        default:
+            assert_unreached("Unexpected readyState: " + xhr.readyState);
+            return;
+        }
+    });
+    xhr.open("GET", "resources/test.ogv", true);
+    xhr.send();
+    xhr.abort();
+    assert_equals(xhr.readyState, xhr.UNSENT, "xhr.readyState after abort() call");
+    assert_array_equals(seenStates, [xhr.OPENED, xhr.DONE]);
+}, "Test onreadystatechange invocation when abort()-ed right after calling send().");
+
+var abortInHeadersReceivedTest = async_test("Test onreadystatechange invocation when abort()-ed in HEADERS_RECEIVED state.");
+abortInHeadersReceivedTest.step(function()
+{
+    var xhr = new XMLHttpRequest;
+    var seenStates = [];
+    xhr.onreadystatechange = abortInHeadersReceivedTest.step_func(function() {
+        seenStates.push(xhr.readyState);
+
+        switch (xhr.readyState) {
+        case xhr.OPENED:
+        case xhr.DONE:
+            return;
+
+        case xhr.HEADERS_RECEIVED:
+            xhr.abort();
+            assert_equals(xhr.readyState, xhr.UNSENT, "xhr.readyState after abort() call");
+            assert_array_equals(seenStates, [xhr.OPENED, xhr.HEADERS_RECEIVED, xhr.DONE]);
+            abortInHeadersReceivedTest.done();
+            return;
+
+        case xhr.UNSENT:
+        case xhr.LOADING:
+        default:
+            assert_unreached("Unexpected readyState: " + xhr.readyState)
+            return;
+        }
+    });
+    xhr.open("GET", "resources/test.ogv", true);
+    xhr.send();
+});
+
+var abortInLoadingTest = async_test("Test onreadystatechange invocation when abort()-ed in LOADING state.");
+abortInLoadingTest.step(function()
+{
+    var xhr = new XMLHttpRequest;
+    var seenStates = [];
+    xhr.onreadystatechange = abortInLoadingTest.step_func(function() {
+        seenStates.push(xhr.readyState);
+
+        switch (xhr.readyState) {
+        case xhr.OPENED:
+        case xhr.HEADERS_RECEIVED:
+        case xhr.DONE:
+            return;
+
+        case xhr.LOADING:
+            xhr.abort();
+            assert_equals(xhr.readyState, xhr.UNSENT, "xhr.readyState after abort() call");
+            assert_array_equals(seenStates, [xhr.OPENED, xhr.HEADERS_RECEIVED, xhr.LOADING, xhr.DONE]);
+            abortInLoadingTest.done();
+            return;
+
+        case xhr.UNSENT:
+        default:
+            assert_unreached("Unexpected readyState: " + xhr.readyState)
+            return;
+        }
+    });
+    xhr.open("GET", "resources/test.ogv", true);
+    xhr.send();
+});
+
+var abortInDoneTest = async_test("Test onreadystatechange invocation when abort()-ed in DONE state.");
+abortInDoneTest.step(function()
+{
+    var xhr = new XMLHttpRequest;
+    var seenStates = [];
+    xhr.onreadystatechange = abortInDoneTest.step_func(function() {
+        seenStates.push(xhr.readyState);
+
+        switch (xhr.readyState) {
+        case xhr.OPENED:
+        case xhr.HEADERS_RECEIVED:
+        case xhr.LOADING:
+            return;
+
+        case xhr.DONE:
+            xhr.abort();
+            assert_equals(xhr.readyState, xhr.UNSENT, "xhr.readyState after abort() call");
+            assert_array_equals(seenStates, [xhr.OPENED, xhr.HEADERS_RECEIVED, xhr.LOADING, xhr.DONE]);
+            abortInDoneTest.done();
+            return;
+
+        case xhr.UNSENT:
+        default:
+            assert_unreached("Unexpected readyState: " + xhr.readyState)
+            return;
+        }
+    });
+    xhr.open("GET", "resources/test.ogv", true);
+    xhr.send();
+});
+</script>
+</body>
+</html>