Index: LayoutTests/http/tests/xmlhttprequest/response-stream.html |
diff --git a/LayoutTests/http/tests/xmlhttprequest/response-stream.html b/LayoutTests/http/tests/xmlhttprequest/response-stream.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..82ec6916c3d26a76c1d1081ba2f8a92cc5c2b140 |
--- /dev/null |
+++ b/LayoutTests/http/tests/xmlhttprequest/response-stream.html |
@@ -0,0 +1,72 @@ |
+<html> |
+<body> |
+ <script src="/js-test-resources/js-test-pre.js"></script> |
+ <script type="text/javascript"> |
+description("Test receiving data as Stream by XMLHttpRequest."); |
+ |
+window.jsTestIsAsync = true; |
+ |
+var xhr = new XMLHttpRequest(); |
+var reader = null; |
+ |
+function tryReadingStreamAgain() { |
+ reader = new FileReader(); |
+ try { |
+ reader.readAsArrayBuffer(xhr.response); |
+ testFailed("reader didn't throw an exception for second read attempt"); |
+ } catch (e) { |
+ testPassed("reader threw an exception for second read attempt: " + e); |
+ } |
+ finishJSTest(); |
+} |
+ |
+function startReadingStream(stream) { |
+ reader = new FileReader(); |
+ reader.onloadstart = function() { |
+ testPassed("onloadstart invoked on reader"); |
+ shouldBe("reader.readyState", "reader.LOADING"); |
+ // Partial response should be available. |
+ shouldBeNonNull("reader.result"); |
+ }; |
+ reader.onabort = function() { |
+ testFailed("onabort invoked on reader"); |
+ finishJSTest(); |
+ }; |
+ reader.onerror = function() { |
+ testFailed("onerror invoked on reader"); |
+ finishJSTest(); |
+ }; |
+ reader.onload = function() { |
+ testPassed("onload invoked on reader"); |
+ }; |
+ reader.onloadend = function() { |
+ testPassed("onloadend invoked on reader"); |
+ shouldBe("reader.readyState", "reader.DONE"); |
+ shouldBeNonNull("reader.result"); |
+ shouldBe("reader.result.byteLength", "103746"); |
+ shouldBeNull("reader.error"); |
+ |
+ tryReadingStreamAgain(); |
+ }; |
+ reader.readAsArrayBuffer(stream); |
+} |
+ |
+xhr.responseType = 'stream'; |
+shouldBeNull("xhr.response"); |
+xhr.open('GET', '../resources/test.ogv', true); |
+shouldBeNull("xhr.response"); |
+xhr.onreadystatechange = function() { |
+ if (this.readyState == this.HEADERS_RECEIVED) { |
+ shouldBeNull("xhr.response"); |
+ } else if (this.readyState == this.LOADING && reader == null) { |
+ shouldBe("xhr.status", "200"); |
+ // readyState is not DONE. |
+ shouldBeNonNull("xhr.response"); |
+ |
+ startReadingStream(xhr.response); |
+ } |
+}; |
+xhr.send(); |
+ </script> |
+ <script src="/js-test-resources/js-test-post.js"></script> |
+</body> |