2 <script src='../../resources/testharness.js'></script>
3 <script src='../../resources/testharnessreport.js'></script>
4 <script src='resources/streams-utils.js'></script>
7 var theError = new Error('a unique string');
9 assert_throws(theError, function() {
15 }, 'constructing the stream should re-throw the error');
16 }, 'Underlying source start: throwing getter');
19 var theError = new Error('a unique string');
21 assert_throws(theError, function() {
27 }, 'constructing the stream should re-throw the error');
28 }, 'Underlying source start: throwing method');
30 var test1 = async_test('Underlying source: throwing pull getter (initial pull)');
31 test1.step(function() {
32 var theError = new Error('a unique string');
33 var rs = new ReadableStream({
39 rs.getReader().closed.then(
40 test1.step_func(function() { assert_unreached('closed should not fulfill'); }),
41 test1.step_func(function(r) {
42 assert_equals(r, theError, 'closed should reject with the thrown error');
47 var test2 = async_test('Underlying source: throwing pull method (initial pull)');
48 test2.step(function() {
49 var theError = new Error('a unique string');
50 var rs = new ReadableStream({
56 rs.getReader().closed.then(
57 test2.step_func(function() { assert_unreached('closed should not fulfill'); }),
58 test2.step_func(function(r) {
59 assert_equals(r, theError, 'closed should reject with the thrown error');
64 var test3 = async_test('Underlying source: throwing pull getter (second pull)');
65 test3.step(function() {
66 var theError = new Error('a unique string');
68 var rs = new ReadableStream({
72 return test3.step_func(function(c) { c.enqueue('a'); })
78 var reader = rs.getReader();
80 reader.read().then(test3.step_func(function(r) {
81 assert_object_equals(r, { value: 'a', done: false }, 'the chunk read should be correct');
85 test3.step_func(function() { assert_unreached('closed should not fulfill'); }),
86 test3.step_func(function(r) {
87 assert_equals(r, theError, 'closed should reject with the thrown error');
92 var test4 = async_test('Underlying source: throwing pull method (second pull)');
93 test4.step(function() {
94 var theError = new Error('a unique string');
96 var rs = new ReadableStream({
106 var reader = rs.getReader();
108 reader.read().then(test4.step_func(function(r) { assert_object_equals(r, { value: 'a', done: false }, 'the chunk read should be correct'); }));
111 test4.step_func(function() { assert_unreached('closed should not fulfill'); }),
112 test4.step_func(function(r) {
113 assert_equals(r, theError, 'closed should reject with the thrown error');
118 var test5 = async_test('Underlying source: throwing cancel getter');
119 test5.step(function() {
120 var theError = new Error('a unique string');
121 var rs = new ReadableStream({
128 test5.step_func(function() { assert_unreached('cancel should not fulfill'); }),
129 test5.step_func(function(r) {
130 assert_equals(r, theError, 'cancel should reject with the thrown error');
135 var test6 = async_test('Underlying source: throwing cancel method');
136 test6.step(function() {
137 var theError = new Error('a unique string');
138 var rs = new ReadableStream({
145 test6.step_func(function() { assert_unreached('cancel should not fulfill'); }),
146 test6.step_func(function(r) {
147 assert_equals(r, theError, 'cancel should reject with the thrown error');
152 var test7 = async_test('Underlying source: throwing strategy getter', { timeout: 50 });
153 test7.step(function() {
155 var theError = new Error('a unique string');
157 var rs = new ReadableStream({
160 assert_throws(theError, function() { c.enqueue('a'); }, 'enqueue should throw the error');
167 rs.getReader().closed.catch(test7.step_func(function(e) {
168 assert_true(started);
169 assert_equals(e, theError, 'closed should reject with the error');
174 var test8 = async_test('Underlying source: throwing strategy.size getter', { timeout: 50 });
175 test8.step(function() {
177 var theError = new Error('a unique string');
178 var rs = new ReadableStream({
181 assert_throws(theError, function() { c.enqueue('a'); }, 'enqueue should throw the error');
187 shouldApplyBackpressure: function() {
193 rs.getReader().closed.catch(test8.step_func(function(e) {
194 assert_true(started);
195 assert_equals(e, theError, 'closed should reject with the error');
200 var test9 = async_test('Underlying source: throwing strategy.size method', { timeout: 50 });
201 test9.step(function() {
203 var theError = new Error('a unique string');
204 var rs = new ReadableStream({
207 assert_throws(theError, function() { c.enqueue('a'); }, 'enqueue should throw the error');
213 shouldApplyBackpressure: function() {
219 rs.getReader().closed.catch(test9.step_func(function(e) {
220 assert_true(started);
221 assert_equals(e, theError, 'closed should reject with the error');
226 var test10 = async_test('Underlying source: throwing strategy.shouldApplyBackpressure getter', { timeout: 50 });
227 test10.step(function() {
229 var theError = new Error('a unique string');
230 var rs = new ReadableStream({
233 assert_throws(theError, function() { c.enqueue('a'); }, 'enqueue should throw the error');
239 get shouldApplyBackpressure() {
245 rs.getReader().closed.catch(test10.step_func(function(e) {
246 assert_true(started);
247 assert_equals(e, theError, 'closed should reject with the error');
252 var test11 = async_test('Underlying source: throwing strategy.shouldApplyBackpressure method', { timeout: 50 });
253 test11.step(function() {
255 var theError = new Error('a unique string');
256 var rs = new ReadableStream({
259 assert_throws(theError, function() { c.enqueue('a'); }, 'enqueue should throw the error');
265 shouldApplyBackpressure: function() {
271 rs.getReader().closed.catch(test11.step_func(function(e) {
272 assert_true(started);
273 assert_equals(e, theError, 'closed should reject with the error');
278 var test12 = async_test('Underlying source: strategy.size returning NaN', { timeout: 50 });
279 test12.step(function() {
280 var theError = undefined;
281 var rs = new ReadableStream({
285 assert_unreached('enqueue didn\'t throw');
288 assert_throws(new RangeError(), function() { throw error; }, 'enqueue should throw a RangeError');
295 shouldApplyBackpressure: function() {
301 rs.getReader().closed.catch(test12.step_func(function(e) {
302 assert_equals(e, theError, 'closed should reject with the error');
307 var test13 = async_test('Underlying source: strategy.size returning -Infinity', { timeout: 50 });
308 test13.step(function() {
309 var theError = undefined;
310 var rs = new ReadableStream({
314 assert_unreached('enqueue didn\'t throw');
317 assert_throws(new RangeError(), function() { throw error; }, 'enqueue should throw a RangeError');
324 shouldApplyBackpressure: function() {
330 rs.getReader().closed.catch(test13.step_func(function(e) {
331 assert_equals(e, theError, 'closed should reject with the error');
336 var test14 = async_test('Underlying source: strategy.size returning +Infinity', { timeout: 50 });
337 test14.step(function() {
338 var theError = undefined;
339 var rs = new ReadableStream({
343 assert_unreached('enqueue didn\'t throw');
346 assert_throws(new RangeError(), function() { throw error; }, 'enqueue should throw a RangeError');
353 shouldApplyBackpressure: function() {
359 rs.getReader().closed.catch(test14.step_func(function(e) {
360 assert_equals(e, theError, 'closed should reject with the error');
365 var test15 = async_test('Underlying source: calling close twice on an empty stream should throw the second time');
366 test15.step(function() {
370 assert_throws(new TypeError(), c.close, 'second call to close should throw a TypeError');
372 }).getReader().closed.then(test15.step_func(function() { test15.done('closed should fulfill'); }));
375 var test16 = async_test('Underlying source: calling close twice on a non-empty stream should throw the second time');
376 test16.step(function() {
377 var startCalled = false;
378 var readCalled = false;
379 var reader = new ReadableStream({
383 assert_throws(new TypeError(), c.close, 'second call to close should throw a TypeError');
388 reader.read().then(test16.step_func(function(r) {
389 assert_object_equals(r, { value: 'a', done: false }, 'read() should read the enqueued chunk');
392 reader.closed.then(test16.step_func(function() {
393 assert_true(startCalled);
394 assert_true(readCalled);
395 test16.done('closed should fulfill');
399 var test17 = async_test('Underlying source: calling close on an empty canceled stream should not throw');
400 test17.step(function() {
402 var startCalled = false;
403 var rs = new ReadableStream({
411 controller.close(); // Calling close after canceling should not throw anything.
413 rs.getReader().closed.then(test17.step_func(function() {
414 assert_true(startCalled);
415 test17.done('closed should fulfill');
419 var test18 = async_test('Underlying source: calling close on a non-empty canceled stream should not throw');
420 test18.step(function() {
422 var startCalled = false;
423 var rs = new ReadableStream({
432 controller.close(); // Calling close after canceling should not throw anything.
434 rs.getReader().closed.then(test18.step_func(function() {
435 assert_true(startCalled);
436 test18.done('closed should fulfill');
440 var test19 = async_test('Underlying source: calling close after error should throw');
441 test19.step(function() {
442 var theError = new Error('boo');
443 var startCalled = false;
447 assert_throws(new TypeError(), c.close, 'call to close should throw a TypeError');
450 }).getReader().closed.catch(test19.step_func(function(e) {
451 assert_true(startCalled);
452 assert_equals(e, theError, 'closed should reject with the error')
457 var test20 = async_test('Underlying source: calling error twice should throw the second time');
458 test20.step(function() {
459 var theError = new Error('boo');
460 var startCalled = false;
464 assert_throws(new TypeError(), c.error, 'second call to error should throw a TypeError');
467 }).getReader().closed.catch(test20.step_func(function(e) {
468 assert_true(startCalled);
469 assert_equals(e, theError, 'closed should reject with the error');
474 var test21 = async_test('Underlying source: calling error after close should throw');
475 test21.step(function() {
476 var startCalled = false;
480 assert_throws(new TypeError(), c.error, 'call to error should throw a TypeError');
483 }).getReader().closed.then(test21.step_func(function() {
484 assert_true(startCalled);
485 test21.done('closed should fulfill');