| OLD | NEW |
| (Empty) |
| 1 'use strict'; | |
| 2 | |
| 3 if (self.importScripts) { | |
| 4 self.importScripts('/resources/testharness.js'); | |
| 5 self.importScripts('../resources/test-utils.js'); | |
| 6 self.importScripts('../resources/recording-streams.js'); | |
| 7 } | |
| 8 | |
| 9 promise_test(() => { | |
| 10 let resolveStartPromise; | |
| 11 const ws = recordingWritableStream({ | |
| 12 start() { | |
| 13 return new Promise(resolve => { | |
| 14 resolveStartPromise = resolve; | |
| 15 }); | |
| 16 } | |
| 17 }); | |
| 18 | |
| 19 const writer = ws.getWriter(); | |
| 20 | |
| 21 assert_equals(writer.desiredSize, 1, 'desiredSize should be 1'); | |
| 22 writer.write('a'); | |
| 23 assert_equals(writer.desiredSize, 0, 'desiredSize should be 0 after writer.wri
te()'); | |
| 24 | |
| 25 // Wait and verify that write isn't called. | |
| 26 return flushAsyncEvents() | |
| 27 .then(() => { | |
| 28 assert_array_equals(ws.events, [], 'write should not be called until sta
rt promise resolves'); | |
| 29 resolveStartPromise(); | |
| 30 return writer.ready; | |
| 31 }) | |
| 32 .then(() => assert_array_equals(ws.events, ['write', 'a'], | |
| 33 'write should not be called until start pr
omise resolves')); | |
| 34 }, 'underlying sink\'s write should not be called until start finishes'); | |
| 35 | |
| 36 promise_test(() => { | |
| 37 let resolveStartPromise; | |
| 38 const ws = recordingWritableStream({ | |
| 39 start() { | |
| 40 return new Promise(resolve => { | |
| 41 resolveStartPromise = resolve; | |
| 42 }); | |
| 43 } | |
| 44 }); | |
| 45 | |
| 46 const writer = ws.getWriter(); | |
| 47 | |
| 48 writer.close(); | |
| 49 assert_equals(writer.desiredSize, 1, 'desiredSize should be 1'); | |
| 50 | |
| 51 // Wait and verify that write isn't called. | |
| 52 return flushAsyncEvents().then(() => { | |
| 53 assert_array_equals(ws.events, [], 'close should not be called until start p
romise resolves'); | |
| 54 resolveStartPromise(); | |
| 55 return writer.closed; | |
| 56 }); | |
| 57 }, 'underlying sink\'s close should not be called until start finishes'); | |
| 58 | |
| 59 test(() => { | |
| 60 const passedError = new Error('horrible things'); | |
| 61 | |
| 62 let writeCalled = false; | |
| 63 let closeCalled = false; | |
| 64 assert_throws(passedError, () => { | |
| 65 // recordingWritableStream cannot be used here because the exception in the | |
| 66 // constructor prevents assigning the object to a variable. | |
| 67 new WritableStream({ | |
| 68 start() { | |
| 69 throw passedError; | |
| 70 }, | |
| 71 write() { | |
| 72 writeCalled = true; | |
| 73 }, | |
| 74 close() { | |
| 75 closeCalled = true; | |
| 76 } | |
| 77 }); | |
| 78 }, 'constructor should throw passedError'); | |
| 79 assert_false(writeCalled, 'write should not be called'); | |
| 80 assert_false(closeCalled, 'close should not be called'); | |
| 81 }, 'underlying sink\'s write or close should not be called if start throws'); | |
| 82 | |
| 83 promise_test(() => { | |
| 84 const ws = recordingWritableStream({ | |
| 85 start() { | |
| 86 return Promise.reject(); | |
| 87 } | |
| 88 }); | |
| 89 | |
| 90 // Wait and verify that write or close aren't called. | |
| 91 return flushAsyncEvents() | |
| 92 .then(() => assert_array_equals(ws.events, [], 'write and close should not
be called')); | |
| 93 }, 'underlying sink\'s write or close should not be invoked if the promise retur
ned by start is rejected'); | |
| 94 | |
| 95 promise_test(t => { | |
| 96 const rejection = { name: 'this is checked' }; | |
| 97 const ws = new WritableStream({ | |
| 98 start() { | |
| 99 return { | |
| 100 then(onFulfilled, onRejected) { onRejected(rejection); } | |
| 101 }; | |
| 102 } | |
| 103 }); | |
| 104 return promise_rejects(t, rejection, ws.getWriter().closed, 'closed promise sh
ould be rejected'); | |
| 105 }, 'returning a thenable from start() should work'); | |
| 106 | |
| 107 done(); | |
| OLD | NEW |