Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 // FIXME: Check loading from Stream after abort once loading API is ready. | |
| 8 var testInLoadingState = async_test("Test aborting XMLHttpRequest with responseT ype set to 'stream' in LOADING state."); | |
| 9 | |
| 10 testInLoadingState.step(function() | |
| 11 { | |
| 12 var xhr = new XMLHttpRequest; | |
| 13 | |
| 14 xhr.responseType = "stream"; | |
| 15 | |
| 16 var seenStates = []; | |
| 17 | |
| 18 xhr.onreadystatechange = testInLoadingState.step_func(function() { | |
| 19 // onreadystatechange can be invoked multiple times in LOADING state. | |
| 20 if (seenStates.length == 0 || xhr.readyState != seenStates[seenStates.le ngth - 1]) | |
| 21 seenStates.push(xhr.readyState); | |
| 22 | |
| 23 switch (xhr.readyState) { | |
| 24 case xhr.UNSENT: | |
| 25 assert_unreached('Unexpected readyState: UNSENT'); | |
| 26 return; | |
| 27 | |
| 28 case xhr.OPENED: | |
| 29 case xhr.HEADERS_RECEIVED: | |
| 30 return; | |
| 31 | |
| 32 case xhr.LOADING: | |
| 33 xhr.abort(); | |
| 34 | |
| 35 assert_equals(xhr.readyState, xhr.DONE, "xhr.readyState after abort( ) call"); | |
| 36 assert_equals(xhr.response, null, "xhr.response after abort() call") ; | |
| 37 return; | |
| 38 | |
| 39 case xhr.DONE: | |
| 40 assert_array_equals(seenStates, [xhr.OPENED, xhr.HEADERS_RECEIVED, x hr.LOADING, xhr.DONE]); | |
| 41 testInLoadingState.done(); | |
| 42 return; | |
| 43 | |
| 44 default: | |
| 45 assert_unreached('Unexpected readyState: ' + xhr.readyState); | |
| 46 return; | |
| 47 } | |
| 48 }); | |
| 49 | |
| 50 xhr.open('GET', '../resources/test.ogv', true); | |
| 51 xhr.send(); | |
| 52 }); | |
| 53 | |
| 54 var testInDoneState = async_test("Test aborting XMLHttpRequest with responseType set to 'stream' in DONE state."); | |
| 55 | |
| 56 testInDoneState.step(function() | |
| 57 { | |
| 58 var xhr = new XMLHttpRequest; | |
| 59 | |
| 60 xhr.responseType = "stream"; | |
| 61 | |
| 62 var seenStates = []; | |
| 63 | |
| 64 xhr.onreadystatechange = testInDoneState.step_func(function() { | |
| 65 // onreadystatechange can be invoked multiple times in LOADING state. | |
| 66 if (seenStates.length == 0 || xhr.readyState != seenStates[seenStates.le ngth - 1]) | |
| 67 seenStates.push(xhr.readyState); | |
| 68 | |
| 69 switch (xhr.readyState) { | |
| 70 case xhr.UNSENT: | |
| 71 case xhr.OPENED: | |
| 72 case xhr.HEADERS_RECEIVED: | |
| 73 case xhr.LOADING: | |
| 74 return; | |
| 75 | |
| 76 case xhr.DONE: | |
| 77 assert_equals(xhr.status, 200, "xhr.status"); | |
| 78 | |
|
kinuko
2013/09/05 13:48:41
nit: maybe check xhr.response is not null before a
tyoshino (SeeGerritForStatus)
2013/09/06 04:24:55
Done.
| |
| 79 xhr.abort(); | |
| 80 | |
| 81 assert_equals(xhr.readyState, xhr.UNSENT, "xhr.readyState after abor t() call"); | |
| 82 assert_equals(xhr.response, null, "xhr.response after abort() call") ; | |
| 83 | |
| 84 assert_array_equals(seenStates, [xhr.OPENED, xhr.HEADERS_RECEIVED, x hr.LOADING, xhr.DONE]); | |
| 85 testInDoneState.done(); | |
| 86 return; | |
| 87 | |
| 88 default: | |
| 89 assert_unreached('Unexpected readyState: ' + xhr.readyState); | |
| 90 return; | |
| 91 } | |
| 92 }); | |
| 93 | |
| 94 xhr.open('GET', '../resources/test.ogv', true); | |
| 95 xhr.send(); | |
| 96 }); | |
| 97 </script> | |
| 98 </body> | |
| 99 </html> | |
| OLD | NEW |