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