Skip to content

Commit

Permalink
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
calvaris committed Sep 14, 2015
1 parent b2b8b8c commit efd71ab
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
10 changes: 10 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,13 @@
2015-09-14 Xabier Rodriguez Calvar <calvaris@igalia.com>

[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.

2015-09-14 Xabier Rodriguez Calvar <calvaris@igalia.com>

[Streams API] Add tests about abort on writable streams
Expand Down
@@ -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 LayoutTests/streams/reference-implementation/pipe-to-options.html
@@ -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>

0 comments on commit efd71ab

Please sign in to comment.