Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Streams API] Add pipe-to-options writable stream tests
https://bugs.webkit.org/show_bug.cgi?id=148297 Reviewed by Darin Adler. * streams/reference-implementation/pipe-to-options-expected.txt: Added. * streams/reference-implementation/pipe-to-options.html: Added. Canonical link: https://commits.webkit.org/167215@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@189689 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
3 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
LayoutTests/streams/reference-implementation/pipe-to-options-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
FAIL Piping with no options and a destination error Can't find variable: WritableStream | ||
FAIL Piping with { preventCancel: false } and a destination error Can't find variable: WritableStream | ||
FAIL Piping with { preventCancel: true } and a destination error Can't find variable: WritableStream | ||
|
105 changes: 105 additions & 0 deletions
105
LayoutTests/streams/reference-implementation/pipe-to-options.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<!DOCTYPE html> | ||
<script src='../../resources/testharness.js'></script> | ||
<script src='../../resources/testharnessreport.js'></script> | ||
<script src='resources/streams-utils.js'></script> | ||
<script> | ||
var test1 = async_test('Piping with no options and a destination error'); | ||
test1.step(function() { | ||
var cancelCalled = false; | ||
var theError = new Error('destination error'); | ||
var rs = new ReadableStream({ | ||
start: function(c) { | ||
c.enqueue('a'); | ||
setTimeout(test1.step_func(function() { c.enqueue('b'); }), 200); | ||
setTimeout(test1.step_func(function() { | ||
c.enqueue('c'); // Enqueue after cancel should not throw. | ||
assert_true(cancelCalled); | ||
test1.done(); | ||
}), 500); | ||
}, | ||
cancel: function(r) { | ||
assert_equals(r, theError, 'reason passed to cancel equals the source error'); | ||
cancelCalled = true; | ||
} | ||
}); | ||
|
||
var ws = new WritableStream({ | ||
write: function(chunk) { | ||
if (chunk === 'b') { | ||
throw theError; | ||
} | ||
} | ||
}); | ||
|
||
rs.pipeTo(ws); | ||
}); | ||
|
||
var test2 = async_test('Piping with { preventCancel: false } and a destination error'); | ||
test2.step(function() { | ||
var cancelCalled = false; | ||
var theError = new Error('destination error'); | ||
var rs = new ReadableStream({ | ||
start: function(c) { | ||
c.enqueue('a'); | ||
setTimeout(test2.step_func(function() { c.enqueue('b'); }), 200); | ||
setTimeout(test2.step_func(function() { | ||
c.enqueue('c'); // Enqueue after cancel should not throw. | ||
assert_true(cancelCalled); | ||
test2.done(); | ||
}), 500); | ||
}, | ||
cancel: function(r) { | ||
assert_equals(r, theError, 'reason passed to cancel equals the source error'); | ||
cancelCalled = true; | ||
} | ||
}); | ||
|
||
var ws = new WritableStream({ | ||
write: function(chunk) { | ||
if (chunk === 'b') { | ||
throw theError; | ||
} | ||
} | ||
}); | ||
|
||
rs.pipeTo(ws, { preventCancel: false }); | ||
}); | ||
|
||
var test3 = async_test('Piping with { preventCancel: true } and a destination error'); | ||
test3.step(function() { | ||
var theError = new Error('destination error'); | ||
var rs = new ReadableStream({ | ||
start: function(c) { | ||
c.enqueue('a'); | ||
setTimeout(test3.step_func(function() { c.enqueue('b'); }), 200); | ||
setTimeout(test3.step_func(function() { c.enqueue('c'); }), 400); | ||
setTimeout(test3.step_func(function() { c.enqueue('d'); }), 600); | ||
}, | ||
cancel: function(r) { | ||
assert_unreached('unexpected call to cancel'); | ||
} | ||
}); | ||
|
||
var ws = new WritableStream({ | ||
write: function(chunk) { | ||
if (chunk === 'b') { | ||
throw theError; | ||
} | ||
} | ||
}); | ||
|
||
rs.pipeTo(ws, { preventCancel: true }).catch(test3.step_func(function(e) { | ||
assert_equals(e, theError, 'rejection reason of pipeTo promise is the sink error'); | ||
|
||
var reader; | ||
reader = rs.getReader(); // Should be able to get a stream reader after pipeTo completes. | ||
|
||
// { value: 'c', done: false } gets consumed before we know that ws has errored, and so is lost. | ||
|
||
return reader.read().then(test3.step_func(function(result) { | ||
assert_object_equals(result, { value: 'd', done: false }, 'should be able to read the remaining chunk from the reader'); | ||
test3.done(); | ||
})); | ||
})).catch(test3.step_func(function(e) { assert_unreached(e); })); | ||
}); | ||
</script> |