[Streams API] Collecting a ReadableStreamReader should not unlock its stream
[WebKit-https.git] / LayoutTests / streams / readablestreamreader-constructor.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     assert_throws(new TypeError(), function() {
9         new ReadableStreamReader('potato');
10     });
11     assert_throws(new TypeError(), function() {
12         new ReadableStreamReader({});
13     });
14     assert_throws(new TypeError(), function() {
15         new ReadableStreamReader();
16     });
17 }, 'ReadableStreamReader constructor should get a ReadableStream object as argument');
18
19 test(function() {
20     var rsReader = new ReadableStreamReader(new ReadableStream());
21
22     assert_array_equals(Object.getOwnPropertyNames(rsReader), ['closed']);
23     assert_array_equals(Object.getOwnPropertyNames(Object.getPrototypeOf(rsReader)), ['constructor', 'read', 'cancel', 'releaseLock']);
24
25     assert_true(Object.getOwnPropertyDescriptor(rsReader, 'closed').enumerable);
26     assert_false(Object.getOwnPropertyDescriptor(rsReader, 'closed').configurable);
27     
28     assert_true(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(rsReader), 'cancel').enumerable);
29     assert_true(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(rsReader), 'cancel').configurable);
30     assert_true(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(rsReader), 'cancel').writable);
31
32     assert_true(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(rsReader), 'read').enumerable);
33     assert_true(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(rsReader), 'read').configurable);
34     assert_true(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(rsReader), 'read').writable);
35
36     assert_true(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(rsReader), 'releaseLock').enumerable);
37     assert_true(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(rsReader), 'releaseLock').configurable);
38     assert_true(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(rsReader), 'releaseLock').writable);
39
40     assert_exists(rsReader, 'closed', 'has a closed property');
41     assert_equals(typeof rsReader.closed.then, 'function', 'closed property is thenable');
42     assert_equals(typeof rsReader.cancel, 'function', 'has a cancel method');
43     assert_equals(rsReader.cancel.length, 1);
44     assert_equals(typeof rsReader.read, 'function', 'has a getReader method');
45     assert_equals(rsReader.read.length, 0);
46     assert_equals(typeof rsReader.releaseLock, 'function', 'has a releaseLock method');
47     assert_equals(rsReader.releaseLock.length, 0);
48
49 }, 'ReadableStream instances should have the correct list of properties');
50
51 test(function() {
52     rsReader = new ReadableStreamReader(new ReadableStream());
53
54     closedPromise = rsReader.closed;
55     assert_equals(closedPromise, rsReader.closed);
56
57     assert_array_equals(Object.keys(rsReader), ['closed']);
58     assert_array_equals(Object.getOwnPropertyNames(rsReader), ['closed']);
59 }, 'ReadableStreamReader closed should always return the same promise object');
60
61 test(function() {
62
63     rs = new ReadableStream();
64     assert_throws(new TypeError(), function() {
65         rs.getReader();
66         new ReadableStreamReader(rs);
67     });
68     rs = new ReadableStream();
69     assert_throws(new TypeError(), function() {
70         new ReadableStreamReader(rs);
71         rs.getReader();
72     });
73     rs = new ReadableStream();
74     assert_throws(new TypeError(), function() {
75         rs.getReader();
76         rs.getReader();
77     });
78     rs = new ReadableStream();
79     assert_throws(new TypeError(), function() {
80         new ReadableStreamReader(rs);
81         new ReadableStreamReader(rs);
82     });
83
84 }, 'ReadableStream getReader should throw if ReadableStream is locked');
85
86 test(function() {
87     rs = new ReadableStream({});
88     rs.getReader();
89     window.gc();
90     assert_throws(new TypeError(), function() { rs.getReader(); });
91 }, 'Collecting a ReadableStreamReader should not unlock its stream.');
92
93 </script>