Check that XMLHttpRequest.response returns null or a json object as specified in...
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Sep 2013 22:01:48 +0000 (22:01 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Sep 2013 22:01:48 +0000 (22:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=120690

Reviewed by Darin Adler.

Merge https://chromium.googlesource.com/chromium/blink/+/d667a115b0fd8f5e11a24d8db44388a990abf543

* http/tests/xmlhttprequest/resources/test.json: Added.
* http/tests/xmlhttprequest/response-json-and-readystate-expected.txt: Added.
* http/tests/xmlhttprequest/response-json-and-readystate.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/http/tests/xmlhttprequest/resources/test.json [new file with mode: 0644]
LayoutTests/http/tests/xmlhttprequest/response-json-and-readystate-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/xmlhttprequest/response-json-and-readystate.html [new file with mode: 0644]

index 0a14d3f54cab5c8d92eeb8cd50c0db100b879694..5136e537e0af5ea68c4783ce9c0a3460a3f0dea4 100644 (file)
@@ -1,3 +1,16 @@
+2013-09-04  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Check that XMLHttpRequest.response returns null or a json object as specified in the spec according to readyState value.
+        https://bugs.webkit.org/show_bug.cgi?id=120690
+
+        Reviewed by Darin Adler.
+
+        Merge https://chromium.googlesource.com/chromium/blink/+/d667a115b0fd8f5e11a24d8db44388a990abf543
+
+        * http/tests/xmlhttprequest/resources/test.json: Added.
+        * http/tests/xmlhttprequest/response-json-and-readystate-expected.txt: Added.
+        * http/tests/xmlhttprequest/response-json-and-readystate.html: Added.
+
 2013-09-04  Csaba Osztrogon√°c  <ossy@webkit.org>
 
         Remove HTMLDialogElement layout tests after r154835
diff --git a/LayoutTests/http/tests/xmlhttprequest/resources/test.json b/LayoutTests/http/tests/xmlhttprequest/resources/test.json
new file mode 100644 (file)
index 0000000..b711f08
--- /dev/null
@@ -0,0 +1 @@
+["a","b",2,{"3":3}]
diff --git a/LayoutTests/http/tests/xmlhttprequest/response-json-and-readystate-expected.txt b/LayoutTests/http/tests/xmlhttprequest/response-json-and-readystate-expected.txt
new file mode 100644 (file)
index 0000000..f3e5428
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Test response of XMLHttpRequest with responseType set to 'json' for various readyState. 
+
diff --git a/LayoutTests/http/tests/xmlhttprequest/response-json-and-readystate.html b/LayoutTests/http/tests/xmlhttprequest/response-json-and-readystate.html
new file mode 100644 (file)
index 0000000..1597a6d
--- /dev/null
@@ -0,0 +1,65 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src="../w3c/resources/testharness.js"></script>
+<script src="../w3c/resources/testharnessreport.js"></script>
+<script type="text/javascript">
+var test = async_test("Test response of XMLHttpRequest with responseType set to 'json' for various readyState.");
+
+test.step(function()
+{
+    var xhr = new XMLHttpRequest;
+
+    xhr.responseType = "json";
+    assert_equals(xhr.responseType, "json", "xhr.responseType");
+
+    assert_equals(xhr.readyState, xhr.UNSENT, "xhr.readyState");
+    assert_equals(xhr.response, null, "xhr.response");
+
+    var seenStates = [];
+
+    xhr.onreadystatechange = test.step_func(function() {
+        seenStates.push(xhr.readyState);
+
+        switch (xhr.readyState) {
+        case xhr.UNSENT:
+            assert_unreached('Unexpected readyState: UNSENT');
+            return;
+
+        case xhr.OPENED:
+            assert_equals(xhr.response, null, "xhr.response");
+            return;
+
+        case xhr.HEADERS_RECEIVED:
+            assert_equals(xhr.response, null, "xhr.response");
+            return;
+
+        case xhr.LOADING:
+            assert_equals(xhr.response, null, "xhr.response");
+            return;
+
+        case xhr.DONE:
+            assert_equals(xhr.status, 200, "xhr.status");
+            assert_equals(JSON.stringify(xhr.response),
+                          '["a","b",2,{"3":3}]',
+                          "Stringify result of xhr.response");
+
+            // Check that we saw all states.
+            assert_array_equals(seenStates,
+                                [xhr.OPENED, xhr.HEADERS_RECEIVED, xhr.LOADING, xhr.DONE]);
+
+            test.done();
+            return;
+
+        default:
+            assert_unreached('Unexpected readyState: ' + xhr.readyState)
+            return;
+        }
+    });
+
+    xhr.open('GET', 'resources/test.json', true);
+    xhr.send();
+});
+</script>
+</body>
+</html>