| OLD | NEW |
| 1 'use strict'; | 1 'use strict'; |
| 2 | 2 |
| 3 if (self.importScripts) { | 3 if (self.importScripts) { |
| 4 self.importScripts('/resources/testharness.js'); | 4 self.importScripts('/resources/testharness.js'); |
| 5 self.importScripts('../resources/test-utils.js'); | 5 self.importScripts('../resources/test-utils.js'); |
| 6 self.importScripts('../resources/recording-streams.js'); | 6 self.importScripts('../resources/recording-streams.js'); |
| 7 } | 7 } |
| 8 | 8 |
| 9 const error1 = new Error('error1'); |
| 10 error1.name = 'error1'; |
| 11 |
| 12 const error2 = new Error('error2'); |
| 13 error2.name = 'error2'; |
| 14 |
| 9 promise_test(() => { | 15 promise_test(() => { |
| 10 const ws = new WritableStream({ | 16 const ws = new WritableStream({ |
| 11 close() { | 17 close() { |
| 12 return 'Hello'; | 18 return 'Hello'; |
| 13 } | 19 } |
| 14 }); | 20 }); |
| 15 | 21 |
| 16 const writer = ws.getWriter(); | 22 const writer = ws.getWriter(); |
| 17 | 23 |
| 18 const closePromise = writer.close(); | 24 const closePromise = writer.close(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 47 close(controller) { | 53 close(controller) { |
| 48 controller.error(passedError); | 54 controller.error(passedError); |
| 49 } | 55 } |
| 50 }); | 56 }); |
| 51 | 57 |
| 52 const writer = ws.getWriter(); | 58 const writer = ws.getWriter(); |
| 53 | 59 |
| 54 return writer.close().then(() => promise_rejects(t, passedError, writer.closed
, 'closed should stay rejected')); | 60 return writer.close().then(() => promise_rejects(t, passedError, writer.closed
, 'closed should stay rejected')); |
| 55 }, 'when sink calls error synchronously while closing, the stream should become
errored'); | 61 }, 'when sink calls error synchronously while closing, the stream should become
errored'); |
| 56 | 62 |
| 63 promise_test(t => { |
| 64 const ws = new WritableStream({ |
| 65 write(chunk, controller) { |
| 66 controller.error(error1); |
| 67 return new Promise(() => {}); |
| 68 } |
| 69 }); |
| 70 |
| 71 const writer = ws.getWriter(); |
| 72 writer.write('a'); |
| 73 |
| 74 return delay(0).then(() => { |
| 75 writer.releaseLock(); |
| 76 }); |
| 77 }, 'releaseLock on a stream with a pending write in which the stream has been er
rored'); |
| 78 |
| 79 promise_test(t => { |
| 80 const ws = new WritableStream({ |
| 81 close(controller) { |
| 82 controller.error(error1); |
| 83 return new Promise(() => {}); |
| 84 } |
| 85 }); |
| 86 |
| 87 const writer = ws.getWriter(); |
| 88 writer.close(); |
| 89 |
| 90 return delay(0).then(() => { |
| 91 writer.releaseLock(); |
| 92 }); |
| 93 }, 'releaseLock on a stream with a pending close in which the stream has been er
rored'); |
| 94 |
| 57 promise_test(() => { | 95 promise_test(() => { |
| 58 const ws = recordingWritableStream(); | 96 const ws = recordingWritableStream(); |
| 59 | 97 |
| 60 const writer = ws.getWriter(); | 98 const writer = ws.getWriter(); |
| 61 | 99 |
| 62 return writer.ready.then(() => { | 100 return writer.ready.then(() => { |
| 63 assert_equals(writer.desiredSize, 1, 'desiredSize should be 1'); | 101 assert_equals(writer.desiredSize, 1, 'desiredSize should be 1'); |
| 64 | 102 |
| 65 writer.close(); | 103 writer.close(); |
| 66 assert_equals(writer.desiredSize, 1, 'desiredSize should be still 1'); | 104 assert_equals(writer.desiredSize, 1, 'desiredSize should be still 1'); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 writer.releaseLock(); | 244 writer.releaseLock(); |
| 207 return delay(0).then(() => { | 245 return delay(0).then(() => { |
| 208 const abortingWriter = ws.getWriter(); | 246 const abortingWriter = ws.getWriter(); |
| 209 const abortPromise = abortingWriter.abort(); | 247 const abortPromise = abortingWriter.abort(); |
| 210 abortingWriter.releaseLock(); | 248 abortingWriter.releaseLock(); |
| 211 resolveClose(); | 249 resolveClose(); |
| 212 return abortPromise; | 250 return abortPromise; |
| 213 }); | 251 }); |
| 214 }, 'the promise returned by async abort during close should resolve'); | 252 }, 'the promise returned by async abort during close should resolve'); |
| 215 | 253 |
| 254 // Though the order in which the promises are fulfilled or rejected is arbitrary
, we're checking it for |
| 255 // interoperability. We can change the order as long as we file bugs on all impl
ementers to update to the latest tests |
| 256 // to keep them interoperable. |
| 257 |
| 258 promise_test(() => { |
| 259 const ws = new WritableStream({}); |
| 260 |
| 261 const writer = ws.getWriter(); |
| 262 |
| 263 const closePromise = writer.close(); |
| 264 |
| 265 const events = []; |
| 266 return Promise.all([ |
| 267 closePromise.then(() => { |
| 268 events.push('closePromise'); |
| 269 }), |
| 270 writer.closed.then(() => { |
| 271 events.push('closed'); |
| 272 }) |
| 273 ]).then(() => { |
| 274 assert_array_equals(events, ['closePromise', 'closed'], |
| 275 'promises must fulfill/reject in the expected order'); |
| 276 }); |
| 277 }, 'promises must fulfill/reject in the expected order on closure'); |
| 278 |
| 279 promise_test(t => { |
| 280 const ws = new WritableStream({}); |
| 281 |
| 282 // Wait until the WritableStream starts so that the close() call gets processe
d. Otherwise, abort() will be |
| 283 // processed without waiting for completion of the close(). |
| 284 return delay(0).then(() => { |
| 285 const writer = ws.getWriter(); |
| 286 |
| 287 const closePromise = writer.close(); |
| 288 const abortPromise = writer.abort(error1); |
| 289 |
| 290 const events = []; |
| 291 return Promise.all([ |
| 292 closePromise.then(() => { |
| 293 events.push('closePromise'); |
| 294 }), |
| 295 abortPromise.then(() => { |
| 296 events.push('abortPromise'); |
| 297 }), |
| 298 promise_rejects(t, new TypeError(), writer.closed, 'writer.closed must rej
ect with an error indicating abort') |
| 299 .then(() => { |
| 300 events.push('closed'); |
| 301 }) |
| 302 ]).then(() => { |
| 303 assert_array_equals(events, ['closePromise', 'abortPromise', 'closed'], |
| 304 'promises must fulfill/reject in the expected order'); |
| 305 }); |
| 306 }); |
| 307 }, 'promises must fulfill/reject in the expected order on aborted closure'); |
| 308 |
| 309 promise_test(t => { |
| 310 const ws = new WritableStream({ |
| 311 close() { |
| 312 return Promise.reject(error1); |
| 313 } |
| 314 }); |
| 315 |
| 316 // Wait until the WritableStream starts so that the close() call gets processe
d. |
| 317 return delay(0).then(() => { |
| 318 const writer = ws.getWriter(); |
| 319 |
| 320 const closePromise = writer.close(); |
| 321 const abortPromise = writer.abort(error2); |
| 322 |
| 323 const events = []; |
| 324 return Promise.all([ |
| 325 promise_rejects(t, error1, closePromise, |
| 326 'closePromise must reject with the error returned from the
sink\'s close method') |
| 327 .then(() => { |
| 328 events.push('closePromise'); |
| 329 }), |
| 330 promise_rejects(t, error1, abortPromise, |
| 331 'abortPromise must reject with the error returned from the
sink\'s close method') |
| 332 .then(() => { |
| 333 events.push('abortPromise'); |
| 334 }), |
| 335 promise_rejects(t, error1, writer.closed, |
| 336 'writer.closed must reject with the error returned from th
e sink\'s close method') |
| 337 .then(() => { |
| 338 events.push('closed'); |
| 339 }) |
| 340 ]).then(() => { |
| 341 assert_array_equals(events, ['closePromise', 'abortPromise', 'closed'], |
| 342 'promises must fulfill/reject in the expected order'); |
| 343 }); |
| 344 }); |
| 345 }, 'promises must fulfill/reject in the expected order on aborted and errored cl
osure'); |
| 346 |
| 216 done(); | 347 done(); |
| OLD | NEW |