[Streams API] Add pipe-to-options writable stream tests
authorcalvaris@igalia.com <calvaris@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 14 Sep 2015 07:59:48 +0000 (07:59 +0000)
committercalvaris@igalia.com <calvaris@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 14 Sep 2015 07:59:48 +0000 (07:59 +0000)
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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@189689 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/streams/reference-implementation/pipe-to-options-expected.txt [new file with mode: 0644]
LayoutTests/streams/reference-implementation/pipe-to-options.html [new file with mode: 0644]

index b5e907b..ea28439 100644 (file)
@@ -1,5 +1,15 @@
 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
         https://bugs.webkit.org/show_bug.cgi?id=148298
 
diff --git a/LayoutTests/streams/reference-implementation/pipe-to-options-expected.txt b/LayoutTests/streams/reference-implementation/pipe-to-options-expected.txt
new file mode 100644 (file)
index 0000000..4c035f2
--- /dev/null
@@ -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
+
diff --git a/LayoutTests/streams/reference-implementation/pipe-to-options.html b/LayoutTests/streams/reference-implementation/pipe-to-options.html
new file mode 100644 (file)
index 0000000..2af547d
--- /dev/null
@@ -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>