[Readable Streams API] Add ReadableByteStreamController byobRequest attribute
[WebKit-https.git] / LayoutTests / streams / readable-stream-pipeThrough.html
1 <!DOCTYPE html>
2 <script src='../resources/testharness.js'></script>
3 <script src='../resources/testharnessreport.js'></script>
4 <script src='../resources/gc.js'></script>
5 <script>
6 // This is updated till https://github.com/whatwg/streams/commit/4ba861e6f60c248060811830e11271c84b439cc3
7
8 test(function() {
9     var input = {
10         readable: { },
11         writable: { }
12     };
13     var options = { };
14     assert_throws(new TypeError(), function() { ReadableStream.prototype.pipeThrough.call(undefined, input, options); });
15     assert_throws(new TypeError(), function() { ReadableStream.prototype.pipeThrough.call(null, input, options); });
16     assert_throws(new TypeError(), function() { ReadableStream.prototype.pipeThrough.call(1, input, options); });
17     assert_throws(new TypeError(), function() { ReadableStream.prototype.pipeThrough.call({ "pipeTo": "test" }, input, options); });
18 }, 'ReadableStream.prototype.pipeThrough should throw when "this" has no pipeTo method');
19
20 test(function() {
21     var options = { };
22     var thisValue = {
23         pipeTo: function() {
24             assert_unreached();
25         }
26     };
27
28     assert_throws(new TypeError(), function() { ReadableStream.prototype.pipeThrough.call(thisValue, null, options); });
29     assert_throws(new TypeError(), function() { ReadableStream.prototype.pipeThrough.call(thisValue, undefined, options); });
30 }, 'ReadableStream.prototype.pipeThrough should throw when passed argument is not an object');
31
32 test(function() {
33     var options = { };
34     var error = new TypeError("potato");
35
36     var thisWrongValue = {
37         get pipeTo() {
38             throw error;
39         }
40     };
41     assert_throws(error, function() { ReadableStream.prototype.pipeThrough.call(thisWrongValue, { readable: { }, writable: { } }, options); });
42
43     var thisValue = {
44         pipeTo: function() {
45             assert_unreached();
46         }
47     };
48     var wrongInput = {
49         readable: { },
50         get writable() {
51             throw error;
52         }
53     };
54     assert_throws(error, function() { ReadableStream.prototype.pipeThrough.call(thisValue, wrongInput, options); });
55
56     var wrongInput2 = {
57         get readable() {
58             throw error;
59         },
60         writable: { }
61     };
62     var thisValue2 = {
63         pipeTo: function() { }
64     };
65     assert_throws(error, function() { ReadableStream.prototype.pipeThrough.call(thisValue2, wrongInput2, options); });
66 }, 'ReadableStream.prototype.pipeThrough should throw when called getters are throwing');
67
68 test(function() {
69     var count = 0;
70     var thisValue = {
71         pipeTo: function() {
72             ++count;
73         }
74     };
75
76     ReadableStream.prototype.pipeThrough.call(thisValue, { readable: { }, writable: { } });
77     ReadableStream.prototype.pipeThrough.call(thisValue, { readable: { } }, { });
78     ReadableStream.prototype.pipeThrough.call(thisValue, { writable: { } }, { });
79
80     assert_equals(count, 3);
81 }, 'ReadableStream.prototype.pipeThrough should work with missing parameters');
82 </script>