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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/streams/writable-streams/write.js

Issue 2668783003: Import wpt@767dc2a4f049c761bd146d61de2ea860a895a624 (Closed)
Patch Set: Update test expectations and baselines. Created 3 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
OLDNEW
1 'use strict'; 1 'use strict';
2 2
3 if (self.importScripts) { 3 if (self.importScripts) {
4 self.importScripts('/resources/testharness.js'); 4 self.importScripts('/resources/testharness.js');
5 self.importScripts('../resources/test-utils.js'); 5 self.importScripts('../resources/test-utils.js');
6 self.importScripts('../resources/recording-streams.js'); 6 self.importScripts('../resources/recording-streams.js');
7 } 7 }
8 8
9 const error1 = new Error('error1');
10 error1.name = 'error1';
11
12 const error2 = new Error('error2');
13 error2.name = 'error2';
14
9 function writeArrayToStream(array, writableStreamWriter) { 15 function writeArrayToStream(array, writableStreamWriter) {
10 array.forEach(chunk => writableStreamWriter.write(chunk)); 16 array.forEach(chunk => writableStreamWriter.write(chunk));
11 return writableStreamWriter.close(); 17 return writableStreamWriter.close();
12 } 18 }
13 19
14 promise_test(() => { 20 promise_test(() => {
15 let storage; 21 let storage;
16 const ws = new WritableStream({ 22 const ws = new WritableStream({
17 start() { 23 start() {
18 storage = []; 24 storage = [];
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 assert_equals(writer.desiredSize, 0, 'desiredSize should be 0'); 129 assert_equals(writer.desiredSize, 0, 'desiredSize should be 0');
124 130
125 const writePromise2 = writer.write('b'); 131 const writePromise2 = writer.write('b');
126 assert_equals(sinkWritePromiseRejectors.length, 1, 'there should be still 1 rejector'); 132 assert_equals(sinkWritePromiseRejectors.length, 1, 'there should be still 1 rejector');
127 assert_equals(writer.desiredSize, -1, 'desiredSize should be -1'); 133 assert_equals(writer.desiredSize, -1, 'desiredSize should be -1');
128 134
129 const closedPromise = writer.close(); 135 const closedPromise = writer.close();
130 136
131 assert_equals(writer.desiredSize, -1, 'desiredSize should still be -1'); 137 assert_equals(writer.desiredSize, -1, 'desiredSize should still be -1');
132 138
133 const passedError = new Error('horrible things');
134
135 return Promise.all([ 139 return Promise.all([
136 promise_rejects(t, passedError, closedPromise, 'closedPromise should rejec t with passedError') 140 promise_rejects(t, error1, closedPromise,
141 'closedPromise should reject with the error returned from the sink\'s write method')
137 .then(() => assert_equals(sinkWritePromiseRejectors.length, 0, 142 .then(() => assert_equals(sinkWritePromiseRejectors.length, 0,
138 'sinkWritePromise should reject before close dPromise')), 143 'sinkWritePromise should reject before close dPromise')),
139 promise_rejects(t, passedError, writePromise, 'writePromise should reject with passedError') 144 promise_rejects(t, error1, writePromise,
145 'writePromise should reject with the error returned from t he sink\'s write method')
140 .then(() => assert_equals(sinkWritePromiseRejectors.length, 0, 146 .then(() => assert_equals(sinkWritePromiseRejectors.length, 0,
141 'sinkWritePromise should reject before write Promise')), 147 'sinkWritePromise should reject before write Promise')),
142 promise_rejects(t, passedError, writePromise2, 'writePromise2 should rejec t with passedError') 148 promise_rejects(t, error1, writePromise2,
149 'writePromise2 should reject with the error returned from the sink\'s write method')
143 .then(() => assert_equals(sinkWritePromiseRejectors.length, 0, 150 .then(() => assert_equals(sinkWritePromiseRejectors.length, 0,
144 'sinkWritePromise should reject before write Promise2')), 151 'sinkWritePromise should reject before write Promise2')),
145 flushAsyncEvents().then(() => { 152 flushAsyncEvents().then(() => {
146 sinkWritePromiseRejectors[0](passedError); 153 sinkWritePromiseRejectors[0](error1);
147 sinkWritePromiseRejectors = []; 154 sinkWritePromiseRejectors = [];
148 }) 155 })
149 ]); 156 ]);
150 }); 157 });
151 }, 'when write returns a rejected promise, queued writes and close should be cle ared'); 158 }, 'when write returns a rejected promise, queued writes and close should be cle ared');
152 159
153 promise_test(t => { 160 promise_test(t => {
154 const thrownError = new Error('throw me');
155 const ws = new WritableStream({ 161 const ws = new WritableStream({
156 write() { 162 write() {
157 throw thrownError; 163 throw error1;
158 } 164 }
159 }); 165 });
160 166
161 const writer = ws.getWriter(); 167 const writer = ws.getWriter();
162 168
163 return promise_rejects(t, thrownError, writer.write('a'), 'write() should reje ct with thrownError') 169 return promise_rejects(t, error1, writer.write('a'),
170 'write() should reject with the error returned from the sink\'s write method')
164 .then(() => promise_rejects(t, new TypeError(), writer.close(), 'close() s hould be rejected')); 171 .then(() => promise_rejects(t, new TypeError(), writer.close(), 'close() s hould be rejected'));
165 }, 'when sink\'s write throws an error, the stream should become errored and the promise should reject'); 172 }, 'when sink\'s write throws an error, the stream should become errored and the promise should reject');
166 173
174 promise_test(t => {
175 const ws = new WritableStream({
176 write(chunk, controller) {
177 controller.error(error1);
178 throw error2;
179 }
180 });
181
182 const writer = ws.getWriter();
183
184 return promise_rejects(t, error2, writer.write('a'),
185 'write() should reject with the error returned from the sink\'s write method ')
186 .then(() => {
187 return Promise.all([
188 promise_rejects(t, error1, writer.ready,
189 'writer.ready must reject with the error passed to the con troller'),
190 promise_rejects(t, error1, writer.closed,
191 'writer.closed must reject with the error passed to the co ntroller')
192 ]);
193 });
194 }, 'writer.write(), ready and closed reject with the error passed to controller. error() made before sink.write'
195 + ' rejection');
196
167 promise_test(() => { 197 promise_test(() => {
168 const numberOfWrites = 1000; 198 const numberOfWrites = 1000;
169 199
170 let resolveFirstWritePromise; 200 let resolveFirstWritePromise;
171 let writeCount = 0; 201 let writeCount = 0;
172 const ws = new WritableStream({ 202 const ws = new WritableStream({
173 write() { 203 write() {
174 ++writeCount; 204 ++writeCount;
175 if (!resolveFirstWritePromise) { 205 if (!resolveFirstWritePromise) {
176 return new Promise(resolve => { 206 return new Promise(resolve => {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 thenCalled = true; 249 thenCalled = true;
220 onFulfilled(); 250 onFulfilled();
221 } 251 }
222 }; 252 };
223 } 253 }
224 }); 254 });
225 return ws.getWriter().write('a').then(() => assert_true(thenCalled, 'thenCalle d should be true')); 255 return ws.getWriter().write('a').then(() => assert_true(thenCalled, 'thenCalle d should be true'));
226 }, 'returning a thenable from write() should work'); 256 }, 'returning a thenable from write() should work');
227 257
228 done(); 258 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698