[Streams API] Update tests according to latest spec
[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
7 test(function() {
8     var input = {
9         readable: { },
10         writable: { }
11     };
12     var options = { };
13     assert_throws(new TypeError(), function() { ReadableStream.prototype.pipeThrough.call(undefined, input, options); });
14     assert_throws(new TypeError(), function() { ReadableStream.prototype.pipeThrough.call(null, input, options); });
15     assert_throws(new TypeError(), function() { ReadableStream.prototype.pipeThrough.call(1, input, options); });
16     assert_throws(new TypeError(), function() { ReadableStream.prototype.pipeThrough.call({ "pipeTo": "test" }, input, options); });
17 }, 'ReadableStream.prototype.pipeThrough should throw when "this" has no pipeTo method');
18
19 test(function() {
20     var options = { };
21     var thisValue = {
22         pipeTo: function() {
23             assert_unreached();
24         }
25     };
26
27     assert_throws(new TypeError(), function() { ReadableStream.prototype.pipeThrough.call(thisValue, null, options); });
28     assert_throws(new TypeError(), function() { ReadableStream.prototype.pipeThrough.call(thisValue, undefined, options); });
29 }, 'ReadableStream.prototype.pipeThrough should throw when passed argument is not an object');
30
31 test(function() {
32     var options = { };
33     var error = new TypeError("potato");
34
35     var thisWrongValue = {
36         get pipeTo() {
37             throw error;
38         }
39     };
40     assert_throws(error, function() { ReadableStream.prototype.pipeThrough.call(thisWrongValue, { readable: { }, writable: { } }, options); });
41
42     var thisValue = {
43         pipeTo: function() {
44             assert_unreached();
45         }
46     };
47     var wrongInput = {
48         readable: { },
49         get writable() {
50             throw error;
51         }
52     };
53     assert_throws(error, function() { ReadableStream.prototype.pipeThrough.call(thisValue, wrongInput, options); });
54
55     var wrongInput2 = {
56         get readable() {
57             throw error;
58         },
59         writable: { }
60     };
61     var thisValue2 = {
62         pipeTo: function() { }
63     };
64     assert_throws(error, function() { ReadableStream.prototype.pipeThrough.call(thisValue2, wrongInput2, options); });
65 }, 'ReadableStream.prototype.pipeThrough should throw when called getters are throwing');
66
67 test(function() {
68     var count = 0;
69     var thisValue = {
70         pipeTo: function() {
71             ++count;
72         }
73     };
74
75     ReadableStream.prototype.pipeThrough.call(thisValue, { readable: { }, writable: { } });
76     ReadableStream.prototype.pipeThrough.call(thisValue, { readable: { } }, { });
77     ReadableStream.prototype.pipeThrough.call(thisValue, { writable: { } }, { });
78
79     assert_equals(count, 3);
80 }, 'ReadableStream.prototype.pipeThrough should work with missing parameters');
81
82 </script>