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

Side by Side Diff: LayoutTests/http/tests/fetch/script-tests/stream-reader.js

Issue 899653002: Use ExclusiveStreamReader to lock Body. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@exclusive-reader
Patch Set: rebase Created 5 years, 10 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 unified diff | Download patch
« no previous file with comments | « no previous file | Source/core/streams/ReadableStream.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 if (self.importScripts) { 1 if (self.importScripts) {
2 importScripts('/fetch/resources/fetch-test-helpers.js'); 2 importScripts('/fetch/resources/fetch-test-helpers.js');
3 } 3 }
4 4
5 function read_until_end(reader) { 5 function read_until_end(reader) {
6 var chunks = []; 6 var chunks = [];
7 function rec(resolve, reject) { 7 function rec(resolve, reject) {
8 while (reader.state === 'readable') { 8 while (reader.state === 'readable') {
9 chunks.push(reader.read()); 9 chunks.push(reader.read());
10 } 10 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 for (var chunk of chunks) { 81 for (var chunk of chunks) {
82 buffer.set(new Uint8Array(chunk), offset); 82 buffer.set(new Uint8Array(chunk), offset);
83 offset += chunk.byteLength; 83 offset += chunk.byteLength;
84 } 84 }
85 return new TextDecoder().decode(buffer); 85 return new TextDecoder().decode(buffer);
86 }).then(function(string) { 86 }).then(function(string) {
87 assert_equals(string, '<!DOCTYPE html>\n'); 87 assert_equals(string, '<!DOCTYPE html>\n');
88 }); 88 });
89 }, 'read contents with ExclusiveStreamReader'); 89 }, 'read contents with ExclusiveStreamReader');
90 90
91 sequential_promise_test(function(t) {
92 return fetch('/fetch/resources/progressive.php').then(function(res) {
93 assert_false(res.bodyUsed);
94 var reader = res.body.getReader();
95 assert_true(res.bodyUsed);
96 return res;
97 }).then(function(res) {
98 return res.text();
99 }).then(unreached_rejection(t), function() {
100 // text() should fail because bodyUsed is set.
101 });
102 }, 'acquiring a reader should set bodyUsed.');
103
104 sequential_promise_test(function(t) {
105 return fetch('/fetch/resources/progressive.php').then(function(res) {
106 // We need to access body attribute to start the stream.
107 res.body;
108 assert_false(res.bodyUsed);
109 res.text();
110 assert_true(res.bodyUsed);
111 assert_throws({name: 'TypeError'}, function() { res.body.getReader() });
112 });
113 }, 'Setting bodyUsed means the body is locked.');
114
91 sequential_promise_test_done(); 115 sequential_promise_test_done();
92 done(); 116 done();
OLDNEW
« no previous file with comments | « no previous file | Source/core/streams/ReadableStream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698