Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / xmlhttprequest / response-json-and-readystate.html
blob2f97e3c3cc88c374bac0a7c8e29b79d783537c9e
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <script src="../resources/testharness.js"></script>
5 <script src="../resources/testharnessreport.js"></script>
6 <script type="text/javascript">
7 var test = async_test("Test response of XMLHttpRequest with responseType set to 'json' for various readyState.");
9 test.step(function()
11 var xhr = new XMLHttpRequest;
13 xhr.responseType = "json";
14 assert_equals(xhr.responseType, "json", "xhr.responseType");
16 assert_equals(xhr.readyState, xhr.UNSENT, "xhr.readyState");
17 assert_equals(xhr.response, null, "xhr.response");
19 var seenStates = [];
21 xhr.onreadystatechange = test.step_func(function() {
22 seenStates.push(xhr.readyState);
24 switch (xhr.readyState) {
25 case xhr.UNSENT:
26 assert_unreached('Unexpected readyState: UNSENT');
27 return;
29 case xhr.OPENED:
30 assert_equals(xhr.response, null, "xhr.response");
31 return;
33 case xhr.HEADERS_RECEIVED:
34 assert_equals(xhr.response, null, "xhr.response");
35 return;
37 case xhr.LOADING:
38 assert_equals(xhr.response, null, "xhr.response");
39 return;
41 case xhr.DONE:
42 assert_equals(xhr.status, 200, "xhr.status");
43 assert_equals(JSON.stringify(xhr.response),
44 '["a","b",2,{"3":3}]',
45 "Stringify result of xhr.response");
47 // Check that we saw all states.
48 assert_array_equals(seenStates,
49 [xhr.OPENED, xhr.HEADERS_RECEIVED, xhr.LOADING, xhr.DONE]);
51 test.done();
52 return;
54 default:
55 assert_unreached('Unexpected readyState: ' + xhr.readyState)
56 return;
58 });
60 xhr.open('GET', 'resources/test.json', true);
61 xhr.send();
62 });
63 </script>
64 </body>
65 </html>