Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Unified Diff: LayoutTests/http/tests/xmlhttprequest/response-stream.html

Issue 455303002: Add 'stream' to XMLHttpRequest response type. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@stream-promise-property-reset
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..a24b84532d3ac34cc290fd3028c5f920075318f1
--- /dev/null
+++ b/LayoutTests/http/tests/xmlhttprequest/response-stream.html
@@ -0,0 +1,96 @@
+<!DOCTYPE html>
+<html>
+<body>
tyoshino (SeeGerritForStatus) 2014/08/14 04:39:09 feel free to omit <html> and <body>
yhirano 2014/08/14 06:48:53 Done.
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+<script type="text/javascript">
+var test = async_test('Test response of XMLHttpRequest with responseType set to "stream" for various readyState.');
+
+test.step(function()
+{
+ var xhr = new XMLHttpRequest;
+
+ xhr.responseType = 'stream';
+ assert_equals(xhr.responseType, 'stream', 'xhr.responseType');
+
+ assert_equals(xhr.readyState, xhr.UNSENT, 'xhr.readyState');
+ assert_equals(xhr.response, null, 'xhr.response during UNSENT');
+
+ var seenStates = [];
+
+ function readStream(stream) {
+ var chunks = [];
+ function rec(resolve, reject) {
+ stream.wait().then(function() {
+ if (stream.state === 'closed') {
+ resolve(chunks);
+ return;
+ }
+ chunks.push(stream.read());
+ rec(resolve, reject);
tyoshino (SeeGerritForStatus) 2014/08/14 04:39:09 this works, but to follow the design philosophy of
yhirano 2014/08/14 06:48:53 Done. I'd leave the first stream.wait to avoid pla
yhirano 2014/08/14 06:49:39 Sorry, this comment was wrong.
+ }).catch(reject);
+ }
+ return new Promise(rec);
+ }
+ var streamPromise = undefined;
+
+ xhr.onreadystatechange = test.step_func(function() {
+ // onreadystatechange can be invoked multiple times in LOADING state.
+ if (seenStates.length == 0 || xhr.readyState != seenStates[seenStates.length - 1])
+ seenStates.push(xhr.readyState);
+
+ switch (xhr.readyState) {
+ case xhr.UNSENT:
+ assert_unreached('Unexpected readyState: UNSENT');
+ return;
+
+ case xhr.OPENED:
+ assert_equals(xhr.response, null, 'xhr.response during OPENED');
+ return;
+
+ case xhr.HEADERS_RECEIVED:
+ assert_equals(xhr.response, null, 'xhr.response during HEADERS_RECEIVED');
+ return;
+
+ case xhr.LOADING:
+ assert_not_equals(xhr.response, null, 'xhr.response during LOADING');
+ assert_true(xhr.response instanceof ReadableStream,
+ 'xhr.response should be ReadableStream during LOADING');
tyoshino (SeeGerritForStatus) 2014/08/14 04:39:09 be consistent about how you indent wrapped lines (
yhirano 2014/08/14 06:48:53 Done.
+ if (streamPromise === undefined) {
+ streamPromise = readStream(xhr.response);
+ }
+ return;
+
+ case xhr.DONE:
+ assert_equals(xhr.status, 200, 'xhr.status');
+
+ // Check that we saw all states.
+ assert_array_equals(seenStates,
+ [xhr.OPENED, xhr.HEADERS_RECEIVED, xhr.LOADING, xhr.DONE]);
+
+ assert_not_equals(streamPromise, undefined, 'streamPromise');
+ streamPromise.then(test.step_func(function(chunks) {
+ assert_equals(xhr.response.state, 'closed', 'stream status');
+ var size = 0;
+ for (var i = 0; i < chunks.length; ++i) {
+ size += chunks[i].byteLength;
+ }
+ assert_equals(size, 103746, 'response size');
+ test.done();
+ }), test.step_func(function(e) {
+ assert_unreached('failed to read the response stream: ' + e);
+ }));
+ return;
+
+ default:
+ assert_unreached('Unexpected readyState: ' + xhr.readyState)
+ return;
+ }
+ });
+
+ xhr.open('GET', '../resources/test.ogv', true);
+ xhr.send();
+});
+</script>
+</body>
+</html>
« no previous file with comments | « no previous file | LayoutTests/http/tests/xmlhttprequest/response-stream-abort.html » ('j') | Source/core/xml/XMLHttpRequest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698