| OLD | NEW |
| (Empty) | |
| 1 'use strict'; |
| 2 |
| 3 if (self.importScripts) { |
| 4 self.importScripts('/resources/testharness.js'); |
| 5 } |
| 6 |
| 7 promise_test(() => { |
| 8 let controller; |
| 9 const ws = new WritableStream({ |
| 10 start(c) { |
| 11 controller = c; |
| 12 } |
| 13 }); |
| 14 |
| 15 // Now error the stream after its construction. |
| 16 const passedError = new Error('horrible things'); |
| 17 controller.error(passedError); |
| 18 |
| 19 const writer = ws.getWriter(); |
| 20 |
| 21 assert_equals(writer.desiredSize, null, 'desiredSize should be null'); |
| 22 return writer.closed.catch(r => { |
| 23 assert_equals(r, passedError, 'ws should be errored by passedError'); |
| 24 }); |
| 25 }, 'controller argument should be passed to start method'); |
| 26 |
| 27 promise_test(t => { |
| 28 const ws = new WritableStream({ |
| 29 write(chunk, controller) { |
| 30 controller.error(new Error()); |
| 31 } |
| 32 }); |
| 33 |
| 34 const writer = ws.getWriter(); |
| 35 writer.write('a'); |
| 36 |
| 37 return promise_rejects(t, new Error(), writer.closed, 'controller.error() in w
rite() should errored the stream'); |
| 38 }, 'controller argument should be passed to write method'); |
| 39 |
| 40 promise_test(t => { |
| 41 const ws = new WritableStream({ |
| 42 close(controller) { |
| 43 controller.error(new Error()); |
| 44 } |
| 45 }); |
| 46 |
| 47 const writer = ws.getWriter(); |
| 48 writer.close(); |
| 49 |
| 50 return promise_rejects(t, new Error(), writer.closed, 'controller.error() in c
lose() should error the stream'); |
| 51 }, 'controller argument should be passed to close method'); |
| 52 |
| 53 promise_test(() => { |
| 54 const ws = new WritableStream({}, { |
| 55 highWaterMark: 1000, |
| 56 size() { return 1; } |
| 57 }); |
| 58 |
| 59 const writer = ws.getWriter(); |
| 60 |
| 61 assert_equals(writer.desiredSize, 1000, 'desiredSize should be 1000'); |
| 62 return writer.ready.then(v => { |
| 63 assert_equals(v, undefined, 'ready promise should fulfill with undefined'); |
| 64 }); |
| 65 }, 'highWaterMark should be reflected to desiredSize'); |
| 66 |
| 67 promise_test(() => { |
| 68 const ws = new WritableStream({}, { |
| 69 highWaterMark: Infinity, |
| 70 size() { return 0; } |
| 71 }); |
| 72 |
| 73 const writer = ws.getWriter(); |
| 74 |
| 75 assert_equals(writer.desiredSize, Infinity, 'desiredSize should be Infinity'); |
| 76 |
| 77 return writer.ready; |
| 78 }, 'WritableStream should be writable and ready should fulfill immediately if th
e strategy does not apply ' + |
| 79 'backpressure'); |
| 80 |
| 81 test(() => { |
| 82 new WritableStream(); |
| 83 }, 'WritableStream should be constructible with no arguments'); |
| 84 |
| 85 test(() => { |
| 86 const ws = new WritableStream({}); |
| 87 |
| 88 const writer = ws.getWriter(); |
| 89 |
| 90 assert_equals(typeof writer.write, 'function', 'writer should have a write met
hod'); |
| 91 assert_equals(typeof writer.abort, 'function', 'writer should have an abort me
thod'); |
| 92 assert_equals(typeof writer.close, 'function', 'writer should have a close met
hod'); |
| 93 |
| 94 assert_equals(writer.desiredSize, 1, 'desiredSize should start at 1'); |
| 95 |
| 96 assert_not_equals(typeof writer.ready, 'undefined', 'writer should have a read
y property'); |
| 97 assert_equals(typeof writer.ready.then, 'function', 'ready property should be
thenable'); |
| 98 assert_not_equals(typeof writer.closed, 'undefined', 'writer should have a clo
sed property'); |
| 99 assert_equals(typeof writer.closed.then, 'function', 'closed property should b
e thenable'); |
| 100 }, 'WritableStream instances should have standard methods and properties'); |
| 101 |
| 102 test(() => { |
| 103 ['WritableStreamDefaultWriter', 'WritableStreamDefaultController'].forEach(c =
> |
| 104 assert_equals(typeof self[c], 'undefined', `${c} should not be exported`))
; |
| 105 }, 'private constructors should not be exported'); |
| 106 |
| 107 test(() => { |
| 108 let WritableStreamDefaultController; |
| 109 new WritableStream({ |
| 110 start(c) { |
| 111 WritableStreamDefaultController = c.constructor; |
| 112 } |
| 113 }); |
| 114 |
| 115 assert_throws(new TypeError(), () => new WritableStreamDefaultController({}), |
| 116 'constructor should throw a TypeError exception'); |
| 117 }, 'WritableStreamDefaultController constructor should throw unless passed a Wri
tableStream'); |
| 118 |
| 119 test(() => { |
| 120 let WritableStreamDefaultController; |
| 121 const stream = new WritableStream({ |
| 122 start(c) { |
| 123 WritableStreamDefaultController = c.constructor; |
| 124 } |
| 125 }); |
| 126 |
| 127 assert_throws(new TypeError(), () => new WritableStreamDefaultController(strea
m), |
| 128 'constructor should throw a TypeError exception'); |
| 129 }, 'WritableStreamDefaultController constructor should throw when passed an init
alised WritableStream'); |
| 130 |
| 131 test(() => { |
| 132 const stream = new WritableStream(); |
| 133 const writer = stream.getWriter(); |
| 134 const WritableStreamDefaultWriter = writer.constructor; |
| 135 writer.releaseLock(); |
| 136 assert_throws(new TypeError(), () => new WritableStreamDefaultWriter({}), |
| 137 'constructor should throw a TypeError exception'); |
| 138 }, 'WritableStreamDefaultWriter should throw unless passed a WritableStream'); |
| 139 |
| 140 test(() => { |
| 141 const stream = new WritableStream(); |
| 142 const writer = stream.getWriter(); |
| 143 const WritableStreamDefaultWriter = writer.constructor; |
| 144 assert_throws(new TypeError(), () => new WritableStreamDefaultWriter(stream), |
| 145 'constructor should throw a TypeError exception'); |
| 146 }, 'WritableStreamDefaultWriter constructor should throw when stream argument is
locked'); |
| 147 |
| 148 done(); |
| OLD | NEW |