| 1 |
// META: global=window,worker,shadowrealm |
| 2 |
// META: script=../resources/test-utils.js |
| 3 |
// META: script=../resources/recording-streams.js |
| 4 |
'use strict'; |
| 5 |
|
| 6 |
function interceptThen() { |
| 7 |
const intercepted = []; |
| 8 |
let callCount = 0; |
| 9 |
Object.prototype.then = function(resolver) { |
| 10 |
if (!this.done) { |
| 11 |
intercepted.push(this.value); |
| 12 |
} |
| 13 |
const retval = Object.create(null); |
| 14 |
retval.done = ++callCount === 3; |
| 15 |
retval.value = callCount; |
| 16 |
resolver(retval); |
| 17 |
if (retval.done) { |
| 18 |
delete Object.prototype.then; |
| 19 |
} |
| 20 |
} |
| 21 |
return intercepted; |
| 22 |
} |
| 23 |
|
| 24 |
promise_test(async t => { |
| 25 |
const rs = new ReadableStream({ |
| 26 |
start(controller) { |
| 27 |
controller.enqueue('a'); |
| 28 |
controller.close(); |
| 29 |
} |
| 30 |
}); |
| 31 |
const ws = recordingWritableStream(); |
| 32 |
|
| 33 |
const intercepted = interceptThen(); |
| 34 |
t.add_cleanup(() => { |
| 35 |
delete Object.prototype.then; |
| 36 |
}); |
| 37 |
|
| 38 |
await rs.pipeTo(ws); |
| 39 |
delete Object.prototype.then; |
| 40 |
|
| 41 |
|
| 42 |
assert_array_equals(intercepted, [], 'nothing should have been intercepted'); |
| 43 |
assert_array_equals(ws.events, ['write', 'a', 'close'], 'written chunk should be "a"'); |
| 44 |
}, 'piping should not be observable'); |
| 45 |
|
| 46 |
promise_test(async t => { |
| 47 |
const rs = new ReadableStream({ |
| 48 |
start(controller) { |
| 49 |
controller.enqueue('a'); |
| 50 |
controller.close(); |
| 51 |
} |
| 52 |
}); |
| 53 |
const ws = recordingWritableStream(); |
| 54 |
|
| 55 |
const [ branch1, branch2 ] = rs.tee(); |
| 56 |
|
| 57 |
const intercepted = interceptThen(); |
| 58 |
t.add_cleanup(() => { |
| 59 |
delete Object.prototype.then; |
| 60 |
}); |
| 61 |
|
| 62 |
await branch1.pipeTo(ws); |
| 63 |
delete Object.prototype.then; |
| 64 |
branch2.cancel(); |
| 65 |
|
| 66 |
assert_array_equals(intercepted, [], 'nothing should have been intercepted'); |
| 67 |
assert_array_equals(ws.events, ['write', 'a', 'close'], 'written chunk should be "a"'); |
| 68 |
}, 'tee should not be observable'); |