| OLD | NEW |
| (Empty) | |
| 1 'use strict'; |
| 2 |
| 3 if (self.importScripts) { |
| 4 self.importScripts('/resources/testharness.js'); |
| 5 self.importScripts('../resources/recording-streams.js'); |
| 6 } |
| 7 |
| 8 const error1 = new Error('error1!'); |
| 9 error1.name = 'error1'; |
| 10 |
| 11 promise_test(() => { |
| 12 |
| 13 const rs = recordingReadableStream(); |
| 14 |
| 15 const ws = recordingWritableStream(); |
| 16 const writer = ws.getWriter(); |
| 17 writer.close(); |
| 18 writer.releaseLock(); |
| 19 |
| 20 return rs.pipeTo(ws).then( |
| 21 () => assert_unreached('the promise must not fulfill'), |
| 22 err => { |
| 23 assert_equals(err.name, 'TypeError', 'the promise must reject with a TypeE
rror'); |
| 24 |
| 25 assert_array_equals(rs.eventsWithoutPulls, ['cancel', err]); |
| 26 assert_array_equals(ws.events, ['close']); |
| 27 |
| 28 return Promise.all([ |
| 29 rs.getReader().closed, |
| 30 ws.getWriter().closed |
| 31 ]); |
| 32 } |
| 33 ); |
| 34 |
| 35 }, 'Closing must be propagated backward: starts closed; preventCancel omitted; f
ulfilled cancel promise'); |
| 36 |
| 37 promise_test(t => { |
| 38 |
| 39 // Our recording streams do not deal well with errors generated by the system,
so give them some help |
| 40 let recordedError; |
| 41 const rs = recordingReadableStream({ |
| 42 cancel(cancelErr) { |
| 43 recordedError = cancelErr; |
| 44 throw error1; |
| 45 } |
| 46 }); |
| 47 |
| 48 const ws = recordingWritableStream(); |
| 49 const writer = ws.getWriter(); |
| 50 writer.close(); |
| 51 writer.releaseLock(); |
| 52 |
| 53 return promise_rejects(t, error1, rs.pipeTo(ws), 'pipeTo must reject with the
same error').then(() => { |
| 54 assert_equals(recordedError.name, 'TypeError', 'the cancel reason must be a
TypeError'); |
| 55 |
| 56 assert_array_equals(rs.eventsWithoutPulls, ['cancel', recordedError]); |
| 57 assert_array_equals(ws.events, ['close']); |
| 58 |
| 59 return Promise.all([ |
| 60 rs.getReader().closed, |
| 61 ws.getWriter().closed |
| 62 ]); |
| 63 }); |
| 64 |
| 65 }, 'Closing must be propagated backward: starts closed; preventCancel omitted; r
ejected cancel promise'); |
| 66 |
| 67 for (const falsy of [undefined, null, false, +0, -0, NaN, '']) { |
| 68 const stringVersion = Object.is(falsy, -0) ? '-0' : String(falsy); |
| 69 |
| 70 promise_test(() => { |
| 71 |
| 72 const rs = recordingReadableStream(); |
| 73 |
| 74 const ws = recordingWritableStream(); |
| 75 const writer = ws.getWriter(); |
| 76 writer.close(); |
| 77 writer.releaseLock(); |
| 78 |
| 79 return rs.pipeTo(ws, { preventCancel: falsy }).then( |
| 80 () => assert_unreached('the promise must not fulfill'), |
| 81 err => { |
| 82 assert_equals(err.name, 'TypeError', 'the promise must reject with a Typ
eError'); |
| 83 |
| 84 assert_array_equals(rs.eventsWithoutPulls, ['cancel', err]); |
| 85 assert_array_equals(ws.events, ['close']); |
| 86 |
| 87 return Promise.all([ |
| 88 rs.getReader().closed, |
| 89 ws.getWriter().closed |
| 90 ]); |
| 91 } |
| 92 ); |
| 93 |
| 94 }, `Closing must be propagated backward: starts closed; preventCancel = ${stri
ngVersion} (falsy); fulfilled cancel ` + |
| 95 `promise`); |
| 96 } |
| 97 |
| 98 for (const truthy of [true, 'a', 1, Symbol(), { }]) { |
| 99 promise_test(t => { |
| 100 |
| 101 const rs = recordingReadableStream(); |
| 102 |
| 103 const ws = recordingWritableStream(); |
| 104 const writer = ws.getWriter(); |
| 105 writer.close(); |
| 106 writer.releaseLock(); |
| 107 |
| 108 return promise_rejects(t, new TypeError(), rs.pipeTo(ws, { preventCancel: tr
uthy })).then(() => { |
| 109 assert_array_equals(rs.eventsWithoutPulls, []); |
| 110 assert_array_equals(ws.events, ['close']); |
| 111 |
| 112 return ws.getWriter().closed; |
| 113 }); |
| 114 |
| 115 }, `Closing must be propagated backward: starts closed; preventCancel = ${Stri
ng(truthy)} (truthy)`); |
| 116 } |
| 117 |
| 118 promise_test(t => { |
| 119 |
| 120 const rs = recordingReadableStream(); |
| 121 |
| 122 const ws = recordingWritableStream(); |
| 123 const writer = ws.getWriter(); |
| 124 writer.close(); |
| 125 writer.releaseLock(); |
| 126 |
| 127 return promise_rejects(t, new TypeError(), rs.pipeTo(ws, { preventCancel: true
, preventAbort: true })) |
| 128 .then(() => { |
| 129 assert_array_equals(rs.eventsWithoutPulls, []); |
| 130 assert_array_equals(ws.events, ['close']); |
| 131 |
| 132 return ws.getWriter().closed; |
| 133 }); |
| 134 |
| 135 }, 'Closing must be propagated backward: starts closed; preventCancel = true, pr
eventAbort = true'); |
| 136 |
| 137 promise_test(t => { |
| 138 |
| 139 const rs = recordingReadableStream(); |
| 140 |
| 141 const ws = recordingWritableStream(); |
| 142 const writer = ws.getWriter(); |
| 143 writer.close(); |
| 144 writer.releaseLock(); |
| 145 |
| 146 return promise_rejects(t, new TypeError(), |
| 147 rs.pipeTo(ws, { preventCancel: true, preventAbort: true
, preventClose: true })) |
| 148 .then(() => { |
| 149 assert_array_equals(rs.eventsWithoutPulls, []); |
| 150 assert_array_equals(ws.events, ['close']); |
| 151 |
| 152 return ws.getWriter().closed; |
| 153 }); |
| 154 |
| 155 }, 'Closing must be propagated backward: starts closed; preventCancel = true, pr
eventAbort = true, preventClose ' + |
| 156 '= true'); |
| 157 |
| 158 done(); |
| OLD | NEW |