OLD | NEW |
| (Empty) |
1 'use strict'; | |
2 | |
3 if (self.importScripts) { | |
4 self.importScripts('/resources/testharness.js'); | |
5 } | |
6 | |
7 | |
8 test(() => { | |
9 | |
10 const theError = new Error('a unique string'); | |
11 | |
12 assert_throws(theError, () => { | |
13 new ReadableStream({ | |
14 get start() { | |
15 throw theError; | |
16 } | |
17 }); | |
18 }, 'constructing the stream should re-throw the error'); | |
19 | |
20 }, 'Underlying source start: throwing getter'); | |
21 | |
22 | |
23 test(() => { | |
24 | |
25 const theError = new Error('a unique string'); | |
26 | |
27 assert_throws(theError, () => { | |
28 new ReadableStream({ | |
29 start() { | |
30 throw theError; | |
31 } | |
32 }); | |
33 }, 'constructing the stream should re-throw the error'); | |
34 | |
35 }, 'Underlying source start: throwing method'); | |
36 | |
37 | |
38 promise_test(t => { | |
39 | |
40 const theError = new Error('a unique string'); | |
41 const rs = new ReadableStream({ | |
42 get pull() { | |
43 throw theError; | |
44 } | |
45 }); | |
46 | |
47 return promise_rejects(t, theError, rs.getReader().closed); | |
48 | |
49 }, 'Underlying source: throwing pull getter (initial pull)'); | |
50 | |
51 | |
52 promise_test(t => { | |
53 | |
54 const theError = new Error('a unique string'); | |
55 const rs = new ReadableStream({ | |
56 pull() { | |
57 throw theError; | |
58 } | |
59 }); | |
60 | |
61 return promise_rejects(t, theError, rs.getReader().closed); | |
62 | |
63 }, 'Underlying source: throwing pull method (initial pull)'); | |
64 | |
65 | |
66 promise_test(t => { | |
67 | |
68 const theError = new Error('a unique string'); | |
69 | |
70 let counter = 0; | |
71 const rs = new ReadableStream({ | |
72 get pull() { | |
73 ++counter; | |
74 if (counter === 1) { | |
75 return c => c.enqueue('a'); | |
76 } | |
77 | |
78 throw theError; | |
79 } | |
80 }); | |
81 const reader = rs.getReader(); | |
82 | |
83 return Promise.all([ | |
84 reader.read().then(r => { | |
85 assert_object_equals(r, { value: 'a', done: false }, 'the chunk read shoul
d be correct'); | |
86 }), | |
87 promise_rejects(t, theError, reader.closed) | |
88 ]); | |
89 | |
90 }, 'Underlying source pull: throwing getter (second pull)'); | |
91 | |
92 | |
93 promise_test(t => { | |
94 | |
95 const theError = new Error('a unique string'); | |
96 | |
97 let counter = 0; | |
98 const rs = new ReadableStream({ | |
99 pull(c) { | |
100 ++counter; | |
101 if (counter === 1) { | |
102 c.enqueue('a'); | |
103 return; | |
104 } | |
105 | |
106 throw theError; | |
107 } | |
108 }); | |
109 const reader = rs.getReader(); | |
110 | |
111 return Promise.all([ | |
112 reader.read().then(r => { | |
113 assert_object_equals(r, { value: 'a', done: false }, 'the chunk read shoul
d be correct'); | |
114 }), | |
115 promise_rejects(t, theError, reader.closed) | |
116 ]); | |
117 | |
118 }, 'Underlying source pull: throwing method (second pull)'); | |
119 | |
120 promise_test(t => { | |
121 | |
122 const theError = new Error('a unique string'); | |
123 const rs = new ReadableStream({ | |
124 get cancel() { | |
125 throw theError; | |
126 } | |
127 }); | |
128 | |
129 return promise_rejects(t, theError, rs.cancel()); | |
130 | |
131 }, 'Underlying source cancel: throwing getter'); | |
132 | |
133 promise_test(t => { | |
134 | |
135 const theError = new Error('a unique string'); | |
136 const rs = new ReadableStream({ | |
137 cancel() { | |
138 throw theError; | |
139 } | |
140 }); | |
141 | |
142 return promise_rejects(t, theError, rs.cancel()); | |
143 | |
144 }, 'Underlying source cancel: throwing method'); | |
145 | |
146 promise_test(() => { | |
147 | |
148 let controller; | |
149 const rs = new ReadableStream({ | |
150 start(c) { | |
151 controller = c; | |
152 } | |
153 }); | |
154 | |
155 rs.cancel(); | |
156 assert_throws(new TypeError, () => controller.enqueue('a'), 'Calling enqueue a
fter canceling should throw'); | |
157 | |
158 return rs.getReader().closed; | |
159 | |
160 }, 'Underlying source: calling enqueue on an empty canceled stream should throw'
); | |
161 | |
162 promise_test(() => { | |
163 | |
164 let controller; | |
165 const rs = new ReadableStream({ | |
166 start(c) { | |
167 c.enqueue('a'); | |
168 c.enqueue('b'); | |
169 controller = c; | |
170 } | |
171 }); | |
172 | |
173 rs.cancel(); | |
174 assert_throws(new TypeError, () => controller.enqueue('c'), 'Calling enqueue a
fter canceling should throw'); | |
175 | |
176 return rs.getReader().closed; | |
177 | |
178 }, 'Underlying source: calling enqueue on a non-empty canceled stream should thr
ow'); | |
179 | |
180 promise_test(() => { | |
181 | |
182 return new ReadableStream({ | |
183 start(c) { | |
184 c.close(); | |
185 assert_throws(new TypeError(), () => c.enqueue('a'), 'call to enqueue shou
ld throw a TypeError'); | |
186 } | |
187 }).getReader().closed; | |
188 | |
189 }, 'Underlying source: calling enqueue on a closed stream should throw'); | |
190 | |
191 promise_test(t => { | |
192 | |
193 const theError = new Error('boo'); | |
194 const closed = new ReadableStream({ | |
195 start(c) { | |
196 c.error(theError); | |
197 assert_throws(new TypeError(), () => c.enqueue('a'), 'call to enqueue shou
ld throw the error'); | |
198 } | |
199 }).getReader().closed; | |
200 | |
201 return promise_rejects(t, theError, closed); | |
202 | |
203 }, 'Underlying source: calling enqueue on an errored stream should throw'); | |
204 | |
205 promise_test(() => { | |
206 | |
207 return new ReadableStream({ | |
208 start(c) { | |
209 c.close(); | |
210 assert_throws(new TypeError(), () => c.close(), 'second call to close shou
ld throw a TypeError'); | |
211 } | |
212 }).getReader().closed; | |
213 | |
214 }, 'Underlying source: calling close twice on an empty stream should throw the s
econd time'); | |
215 | |
216 promise_test(() => { | |
217 | |
218 let startCalled = false; | |
219 let readCalled = false; | |
220 const reader = new ReadableStream({ | |
221 start(c) { | |
222 c.enqueue('a'); | |
223 c.close(); | |
224 assert_throws(new TypeError(), () => c.close(), 'second call to close shou
ld throw a TypeError'); | |
225 startCalled = true; | |
226 } | |
227 }).getReader(); | |
228 | |
229 return Promise.all([ | |
230 reader.read().then(r => { | |
231 assert_object_equals(r, { value: 'a', done: false }, 'read() should read t
he enqueued chunk'); | |
232 readCalled = true; | |
233 }), | |
234 reader.closed.then(() => { | |
235 assert_true(startCalled); | |
236 assert_true(readCalled); | |
237 }) | |
238 ]); | |
239 | |
240 }, 'Underlying source: calling close twice on a non-empty stream should throw th
e second time'); | |
241 | |
242 promise_test(() => { | |
243 | |
244 let controller; | |
245 let startCalled = false; | |
246 const rs = new ReadableStream({ | |
247 start(c) { | |
248 controller = c; | |
249 startCalled = true; | |
250 } | |
251 }); | |
252 | |
253 rs.cancel(); | |
254 assert_throws(new TypeError(), () => controller.close(), 'Calling close after
canceling should throw'); | |
255 | |
256 return rs.getReader().closed.then(() => { | |
257 assert_true(startCalled); | |
258 }); | |
259 | |
260 }, 'Underlying source: calling close on an empty canceled stream should throw'); | |
261 | |
262 promise_test(() => { | |
263 | |
264 let controller; | |
265 let startCalled = false; | |
266 const rs = new ReadableStream({ | |
267 start(c) { | |
268 controller = c; | |
269 c.enqueue('a'); | |
270 startCalled = true; | |
271 } | |
272 }); | |
273 | |
274 rs.cancel(); | |
275 assert_throws(new TypeError(), () => controller.close(), 'Calling close after
canceling should throw'); | |
276 | |
277 return rs.getReader().closed.then(() => { | |
278 assert_true(startCalled); | |
279 }); | |
280 | |
281 }, 'Underlying source: calling close on a non-empty canceled stream should throw
'); | |
282 | |
283 promise_test(() => { | |
284 | |
285 const theError = new Error('boo'); | |
286 let startCalled = false; | |
287 | |
288 const closed = new ReadableStream({ | |
289 start(c) { | |
290 c.error(theError); | |
291 assert_throws(new TypeError(), () => c.close(), 'call to close should thro
w a TypeError'); | |
292 startCalled = true; | |
293 } | |
294 }).getReader().closed; | |
295 | |
296 return closed.catch(e => { | |
297 assert_true(startCalled); | |
298 assert_equals(e, theError, 'closed should reject with the error'); | |
299 }); | |
300 | |
301 }, 'Underlying source: calling close after error should throw'); | |
302 | |
303 promise_test(() => { | |
304 | |
305 const theError = new Error('boo'); | |
306 let startCalled = false; | |
307 | |
308 const closed = new ReadableStream({ | |
309 start(c) { | |
310 c.error(theError); | |
311 assert_throws(new TypeError(), () => c.error(), 'second call to error shou
ld throw a TypeError'); | |
312 startCalled = true; | |
313 } | |
314 }).getReader().closed; | |
315 | |
316 return closed.catch(e => { | |
317 assert_true(startCalled); | |
318 assert_equals(e, theError, 'closed should reject with the error'); | |
319 }); | |
320 | |
321 }, 'Underlying source: calling error twice should throw the second time'); | |
322 | |
323 promise_test(() => { | |
324 | |
325 let startCalled = false; | |
326 | |
327 const closed = new ReadableStream({ | |
328 start(c) { | |
329 c.close(); | |
330 assert_throws(new TypeError(), () => c.error(), 'second call to error shou
ld throw a TypeError'); | |
331 startCalled = true; | |
332 } | |
333 }).getReader().closed; | |
334 | |
335 return closed.then(() => assert_true(startCalled)); | |
336 | |
337 }, 'Underlying source: calling error after close should throw'); | |
338 | |
339 promise_test(() => { | |
340 | |
341 let startCalled = false; | |
342 const firstError = new Error('1'); | |
343 const secondError = new Error('2'); | |
344 | |
345 const closed = new ReadableStream({ | |
346 start(c) { | |
347 c.error(firstError); | |
348 startCalled = true; | |
349 return Promise.reject(secondError); | |
350 } | |
351 }).getReader().closed; | |
352 | |
353 return closed.catch(e => { | |
354 assert_true(startCalled); | |
355 assert_equals(e, firstError, 'closed should reject with the first error'); | |
356 }); | |
357 | |
358 }, 'Underlying source: calling error and returning a rejected promise from start
should cause the stream to error ' + | |
359 'with the first error'); | |
360 | |
361 promise_test(() => { | |
362 | |
363 let startCalled = false; | |
364 const firstError = new Error('1'); | |
365 const secondError = new Error('2'); | |
366 | |
367 const closed = new ReadableStream({ | |
368 pull(c) { | |
369 c.error(firstError); | |
370 startCalled = true; | |
371 return Promise.reject(secondError); | |
372 } | |
373 }).getReader().closed; | |
374 | |
375 return closed.catch(e => { | |
376 assert_true(startCalled); | |
377 assert_equals(e, firstError, 'closed should reject with the first error'); | |
378 }); | |
379 | |
380 }, 'Underlying source: calling error and returning a rejected promise from pull
should cause the stream to error ' + | |
381 'with the first error'); | |
382 | |
383 done(); | |
OLD | NEW |