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 receiving data as Stream by XMLHttpRequest."); |
| 6 |
| 7 window.jsTestIsAsync = true; |
| 8 |
| 9 var xhr = new XMLHttpRequest(); |
| 10 var reader = null; |
| 11 |
| 12 function tryReadingStreamAgain() { |
| 13 reader = new FileReader(); |
| 14 try { |
| 15 reader.readAsArrayBuffer(xhr.response); |
| 16 testFailed("reader didn't throw an exception for second read attempt"); |
| 17 } catch (e) { |
| 18 testPassed("reader threw an exception for second read attempt: " + e); |
| 19 } |
| 20 finishJSTest(); |
| 21 } |
| 22 |
| 23 function startReadingStream(stream) { |
| 24 reader = new FileReader(); |
| 25 reader.onloadstart = function() { |
| 26 testPassed("onloadstart invoked on reader"); |
| 27 shouldBe("reader.readyState", "reader.LOADING"); |
| 28 // Partial response should be available. |
| 29 shouldBeNonNull("reader.result"); |
| 30 }; |
| 31 reader.onabort = function() { |
| 32 testFailed("onabort invoked on reader"); |
| 33 finishJSTest(); |
| 34 }; |
| 35 reader.onerror = function() { |
| 36 testFailed("onerror invoked on reader"); |
| 37 finishJSTest(); |
| 38 }; |
| 39 reader.onload = function() { |
| 40 testPassed("onload invoked on reader"); |
| 41 }; |
| 42 reader.onloadend = function() { |
| 43 testPassed("onloadend invoked on reader"); |
| 44 shouldBe("reader.readyState", "reader.DONE"); |
| 45 shouldBeNonNull("reader.result"); |
| 46 shouldBe("reader.result.byteLength", "103746"); |
| 47 shouldBeNull("reader.error"); |
| 48 |
| 49 tryReadingStreamAgain(); |
| 50 }; |
| 51 reader.readAsArrayBuffer(stream); |
| 52 } |
| 53 |
| 54 xhr.responseType = 'stream'; |
| 55 shouldBeNull("xhr.response"); |
| 56 xhr.open('GET', '../resources/test.ogv', true); |
| 57 shouldBeNull("xhr.response"); |
| 58 xhr.onreadystatechange = function() { |
| 59 if (this.readyState == this.HEADERS_RECEIVED) { |
| 60 shouldBeNull("xhr.response"); |
| 61 } else if (this.readyState == this.LOADING && reader == null) { |
| 62 shouldBe("xhr.status", "200"); |
| 63 // readyState is not DONE. |
| 64 shouldBeNonNull("xhr.response"); |
| 65 |
| 66 startReadingStream(xhr.response); |
| 67 } |
| 68 }; |
| 69 xhr.send(); |
| 70 </script> |
| 71 <script src="/js-test-resources/js-test-post.js"></script> |
| 72 </body> |
OLD | NEW |