OLD | NEW |
(Empty) | |
| 1 <html> |
| 2 <body> |
| 3 <script src="/js-test-resources/js-test-pre.js"></script> |
| 4 <script type="text/javascript"> |
| 5 description("Test partial data is readable from Stream returned by " + |
| 6 "XMLHttpRequest."); |
| 7 |
| 8 window.jsTestIsAsync = true; |
| 9 |
| 10 var xhr = new XMLHttpRequest(); |
| 11 var reader = null; |
| 12 |
| 13 function startReadingStream(stream) { |
| 14 reader = new FileReader(); |
| 15 reader.onloadstart = function() { |
| 16 testPassed("onloadstart invoked on reader"); |
| 17 }; |
| 18 reader.onabort = function() { |
| 19 testFailed("onabort invoked on reader"); |
| 20 finishJSTest(); |
| 21 }; |
| 22 reader.onerror = function() { |
| 23 testFailed("onerror invoked on reader"); |
| 24 finishJSTest(); |
| 25 }; |
| 26 reader.onprogress = function() { |
| 27 // Wait until we receive all data flushed by the server. |
| 28 shouldBeNonNull("reader.result"); |
| 29 if (reader.result == null) { |
| 30 finishJSTest(); |
| 31 return; |
| 32 } |
| 33 if (reader.result.byteLength != 5) { |
| 34 return; |
| 35 } |
| 36 |
| 37 shouldBe("reader.readyState", "reader.LOADING"); |
| 38 if (reader.readyState != this.LOADING) { |
| 39 finishJSTest(); |
| 40 return; |
| 41 } |
| 42 |
| 43 shouldBeNull("reader.error"); |
| 44 |
| 45 for (var i = 0; i < 5; ++i) { |
| 46 window.result = new Uint8Array(reader.result); |
| 47 shouldBe("result[" + i + "]", |
| 48 "'Hello'.charCodeAt(" + i + ")"); |
| 49 } |
| 50 |
| 51 finishJSTest(); |
| 52 } |
| 53 reader.onload = function() { |
| 54 testFailed("onload invoked on reader"); |
| 55 finishJSTest(); |
| 56 }; |
| 57 reader.onloadend = function() { |
| 58 testFailed("onloadend invoked on reader"); |
| 59 finishJSTest(); |
| 60 }; |
| 61 reader.readAsArrayBuffer(stream); |
| 62 } |
| 63 |
| 64 xhr.responseType = 'stream'; |
| 65 xhr.open('GET', 'resources/chunked-transfer-hang-after-partial-data.php', true); |
| 66 xhr.onreadystatechange = function() { |
| 67 if (this.readyState == this.HEADERS_RECEIVED) { |
| 68 shouldBeNull("xhr.response"); |
| 69 } else if (this.readyState == this.LOADING && reader == null) { |
| 70 shouldBe("xhr.status", "200"); |
| 71 if (this.status != 200) { |
| 72 finishJSTest(); |
| 73 return; |
| 74 } |
| 75 startReadingStream(xhr.response); |
| 76 } |
| 77 }; |
| 78 xhr.send(); |
| 79 </script> |
| 80 <script src="/js-test-resources/js-test-post.js"></script> |
| 81 </body> |
OLD | NEW |