| <!DOCTYPE html> |
| <html> |
| <body> |
| <script src="/resources/testharness.js"></script> |
| <script src="/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> |