Commit fce6d098 authored by Adam Rice's avatar Adam Rice Committed by Commit Bot

ReadableStream: test pipe options exceptions

Coverage indicated that the case where there is an exception looking up
a pipeTo or pipeThrough option was not actually tested. Add a web
platform test to verify that exceptions are thrown and that options are
accessed in the correct order.

Change-Id: I88d889a42853ee0625cc51fe30cd119b118289b8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1903169Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Commit-Queue: Adam Rice <ricea@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713362}
parent b642fd53
// META: global=worker,jsshell
class ThrowingOptions {
constructor(whatShouldThrow) {
this.whatShouldThrow = whatShouldThrow;
this.touched = [];
}
get preventClose() {
this.maybeThrow('preventClose');
return false;
}
get preventAbort() {
this.maybeThrow('preventAbort');
return false;
}
get preventCancel() {
this.maybeThrow('preventCancel');
return false;
}
get signal() {
this.maybeThrow('signal');
return undefined;
}
maybeThrow(forWhat) {
this.touched.push(forWhat);
if (this.whatShouldThrow === forWhat) {
throw new Error(this.whatShouldThrow);
}
}
}
const checkOrder = ['preventClose', 'preventAbort', 'preventCancel', 'signal'];
for (let i = 0; i < checkOrder.length; ++i) {
const whatShouldThrow = checkOrder[i];
const whatShouldBeTouched = checkOrder.slice(0, i + 1);
promise_test(t => {
const options = new ThrowingOptions(whatShouldThrow);
return promise_rejects(
t, new Error(),
new ReadableStream().pipeTo(new WritableStream(), options),
'pipeTo should reject')
.then(() => assert_array_equals(
options.touched, whatShouldBeTouched,
'options should be touched in the right order'));
}, `pipeTo should stop after getting ${whatShouldThrow} throws`);
test(() => {
const options = new ThrowingOptions(whatShouldThrow);
assert_throws(
new Error(),
() => new ReadableStream().pipeThrough(new TransformStream(), options),
'pipeThrough should throw');
assert_array_equals(
options.touched, whatShouldBeTouched,
'options should be touched in the right order');
}, `pipeThrough should stop after getting ${whatShouldThrow} throws`);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment