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.");
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");
21 xhr
.onreadystatechange
= test
.step_func(function() {
22 seenStates
.push(xhr
.readyState
);
24 switch (xhr
.readyState
) {
26 assert_unreached('Unexpected readyState: UNSENT');
30 assert_equals(xhr
.response
, null, "xhr.response");
33 case xhr
.HEADERS_RECEIVED
:
34 assert_equals(xhr
.response
, null, "xhr.response");
38 assert_equals(xhr
.response
, null, "xhr.response");
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
]);
55 assert_unreached('Unexpected readyState: ' + xhr
.readyState
)
60 xhr
.open('GET', 'resources/test.json', true);