Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/streams/readable-streams/count-queuing-strategy-integration.js

Issue 1404523005: Implement author-constructible ReadableStream using V8 extras (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 'use strict';
2
3 if (self.importScripts) {
4 self.importScripts('/resources/testharness.js');
5 }
6
7 test(() => {
8 new ReadableStream({}, new CountQueuingStrategy({ highWaterMark: 4 }));
9 }, 'Can construct a readable stream with a valid CountQueuingStrategy');
10
11 var test1 = async_test('Correctly governs a ReadableStreamController\'s desiredS ize property (HWM = 0)');
12 test1.step(function() {
13 var controller;
14 var rs = new ReadableStream({
15 start: function(c) {
16 controller = c;
17 }
18 },
19 new CountQueuingStrategy({ highWaterMark: 0 })
20 );
21 var reader = rs.getReader();
22
23 assert_equals(controller.desiredSize, 0, '0 reads, 0 enqueues: desiredSize s hould be 0');
24 controller.enqueue('a');
25 assert_equals(controller.desiredSize, -1, '0 reads, 1 enqueue: desiredSize s hould be -1');
26 controller.enqueue('b');
27 assert_equals(controller.desiredSize, -2, '0 reads, 2 enqueues: desiredSize should be -2');
28 controller.enqueue('c');
29 assert_equals(controller.desiredSize, -3, '0 reads, 3 enqueues: desiredSize should be -3');
30 controller.enqueue('d');
31 assert_equals(controller.desiredSize, -4, '0 reads, 4 enqueues: desiredSize should be -4');
32
33 reader.read().then(test1.step_func(function(result) {
34 assert_object_equals(result, { value: 'a', done: false }, '1st read give s back the 1st chunk enqueued (queue now contains 3 chunks)');
35 return reader.read();
36 })).then(test1.step_func(function(result) {
37 assert_object_equals(result, { value: 'b', done: false }, '2nd read give s back the 2nd chunk enqueued (queue now contains 2 chunks)');
38 return reader.read();
39 })).then(test1.step_func(function(result) {
40 assert_object_equals(result, { value: 'c', done: false }, '3rd read give s back the 3rd chunk enqueued (queue now contains 1 chunk)');
41
42 assert_equals(controller.desiredSize, -1, '3 reads, 4 enqueues: desiredS ize should be -1');
43 controller.enqueue('e');
44 assert_equals(controller.desiredSize, -2, '3 reads, 5 enqueues: desiredS ize should be -2');
45
46 return reader.read();
47 })).then(test1.step_func(function(result) {
48 assert_object_equals(result, { value: 'd', done: false }, '4th read give s back the 4th chunk enqueued (queue now contains 1 chunks)');
49 return reader.read();
50 })).then(test1.step_func(function(result) {
51 assert_object_equals(result, { value: 'e', done: false }, '5th read give s back the 5th chunk enqueued (queue now contains 0 chunks)');
52
53 assert_equals(controller.desiredSize, 0, '5 reads, 5 enqueues: desiredSi ze should be 0');
54 controller.enqueue('f');
55 assert_equals(controller.desiredSize, -1, '5 reads, 6 enqueues: desiredS ize should be -1');
56 controller.enqueue('g');
57 assert_equals(controller.desiredSize, -2, '5 reads, 7 enqueues: desiredS ize should be -2');
58
59 test1.done();
60 })).catch(test1.step_func(function(e) { assert_unreached(e); } ));
61 });
62
63 var test2 = async_test('Correctly governs a ReadableStreamController\'s desiredS ize property (HWM = 1)');
64 test2.step(function() {
65 var controller;
66 var rs = new ReadableStream({
67 start: function(c) {
68 controller = c;
69 },
70 },
71 new CountQueuingStrategy({ highWaterMark: 1 })
72 );
73 var reader = rs.getReader();
74
75 assert_equals(controller.desiredSize, 1, '0 reads, 0 enqueues: desiredSize s hould be 1');
76 controller.enqueue('a');
77 assert_equals(controller.desiredSize, 0, '0 reads, 1 enqueue: desiredSize sh ould be 0');
78 controller.enqueue('b');
79 assert_equals(controller.desiredSize, -1, '0 reads, 2 enqueues: desiredSize should be -1');
80 controller.enqueue('c');
81 assert_equals(controller.desiredSize, -2, '0 reads, 3 enqueues: desiredSize should be -2');
82 controller.enqueue('d');
83 assert_equals(controller.desiredSize, -3, '0 reads, 4 enqueues: desiredSize should be -3');
84
85 reader.read().then(test2.step_func(function(result) {
86 assert_object_equals(result, { value: 'a', done: false }, '1st read give s back the 1st chunk enqueued (queue now contains 3 chunks)');
87 return reader.read();
88 })).then(test2.step_func(function(result) {
89 assert_object_equals(result, { value: 'b', done: false }, '2nd read give s back the 2nd chunk enqueued (queue now contains 2 chunks)');
90 return reader.read();
91 })).then(test2.step_func(function(result) {
92 assert_object_equals(result, { value: 'c', done: false }, '3rd read give s back the 3rd chunk enqueued (queue now contains 1 chunk)');
93
94 assert_equals(controller.desiredSize, 0, '3 reads, 4 enqueues: desiredSi ze should be 0');
95 controller.enqueue('e');
96 assert_equals(controller.desiredSize, -1, '3 reads, 5 enqueues: desiredS ize should be -1');
97
98 return reader.read();
99 })).then(test2.step_func(function(result) {
100 assert_object_equals(result, { value: 'd', done: false }, '4th read give s back the 4th chunk enqueued (queue now contains 1 chunks)');
101 return reader.read();
102 })).then(test2.step_func(function(result) {
103 assert_object_equals(result, { value: 'e', done: false }, '5th read give s back the 5th chunk enqueued (queue now contains 0 chunks)');
104
105 assert_equals(controller.desiredSize, 1, '5 reads, 5 enqueues: desiredSi ze should be 1');
106 controller.enqueue('f');
107 assert_equals(controller.desiredSize, 0, '5 reads, 6 enqueues: desiredSi ze should be 0');
108 controller.enqueue('g');
109 assert_equals(controller.desiredSize, -1, '5 reads, 7 enqueues: desiredS ize should be -1');
110
111 test2.done();
112 })).catch(test2.step_func(function(e) { assert_unreached(e); } ));
113 });
114
115 var test3 = async_test('Correctly governs a ReadableStreamController\'s desiredS ize property (HWM = 4)');
116 test3.step(function() {
117 var controller;
118 var rs = new ReadableStream({
119 start: function(c) {
120 controller = c;
121 }
122 },
123 new CountQueuingStrategy({ highWaterMark: 4 })
124 );
125 var reader = rs.getReader();
126
127 assert_equals(controller.desiredSize, 4, '0 reads, 0 enqueues: desiredSize s hould be 4');
128 controller.enqueue('a');
129 assert_equals(controller.desiredSize, 3, '0 reads, 1 enqueue: desiredSize sh ould be 3');
130 controller.enqueue('b');
131 assert_equals(controller.desiredSize, 2, '0 reads, 2 enqueues: desiredSize s hould be 2');
132 controller.enqueue('c');
133 assert_equals(controller.desiredSize, 1, '0 reads, 3 enqueues: desiredSize s hould be 1');
134 controller.enqueue('d');
135 assert_equals(controller.desiredSize, 0, '0 reads, 4 enqueues: desiredSize s hould be 0');
136 controller.enqueue('e');
137 assert_equals(controller.desiredSize, -1, '0 reads, 5 enqueues: desiredSize should be -1');
138 controller.enqueue('f');
139 assert_equals(controller.desiredSize, -2, '0 reads, 6 enqueues: desiredSize should be -2');
140
141
142 reader.read().then(test3.step_func(function(result) {
143 assert_object_equals(result, { value: 'a', done: false }, '1st read give s back the 1st chunk enqueued (queue now contains 5 chunks)');
144 return reader.read();
145 })).then(test3.step_func(function(result) {
146 assert_object_equals(result, { value: 'b', done: false }, '2nd read give s back the 2nd chunk enqueued (queue now contains 4 chunks)');
147
148 assert_equals(controller.desiredSize, 0, '2 reads, 6 enqueues: desiredSi ze should be 0');
149 controller.enqueue('g');
150 assert_equals(controller.desiredSize, -1, '2 reads, 7 enqueues: desiredS ize should be -1');
151
152 return reader.read();
153 })).then(test3.step_func(function(result) {
154 assert_object_equals(result, { value: 'c', done: false }, '3rd read give s back the 3rd chunk enqueued (queue now contains 4 chunks)');
155 return reader.read();
156 })).then(test3.step_func(function(result) {
157 assert_object_equals(result, { value: 'd', done: false }, '4th read give s back the 4th chunk enqueued (queue now contains 3 chunks)');
158 return reader.read();
159 })).then(test3.step_func(function(result) {
160 assert_object_equals(result, { value: 'e', done: false }, '5th read give s back the 5th chunk enqueued (queue now contains 2 chunks)');
161 return reader.read();
162 })).then(test3.step_func(function(result) {
163 assert_object_equals(result, { value: 'f', done: false }, '6th read give s back the 6th chunk enqueued (queue now contains 0 chunks)');
164
165 assert_equals(controller.desiredSize, 3, '6 reads, 7 enqueues: desiredSi ze should be 3');
166 controller.enqueue('h');
167 assert_equals(controller.desiredSize, 2, '6 reads, 8 enqueues: desiredSi ze should be 2');
168 controller.enqueue('i');
169 assert_equals(controller.desiredSize, 1, '6 reads, 9 enqueues: desiredSi ze should be 1');
170 controller.enqueue('j');
171 assert_equals(controller.desiredSize, 0, '6 reads, 10 enqueues: desiredS ize should be 0');
172 controller.enqueue('k');
173 assert_equals(controller.desiredSize, -1, '6 reads, 11 enqueues: desired Size should be -1');
174
175 test3.done();
176 })).catch(test3.step_func(function(e) { assert_unreached(e); } ));
177 });
178
179 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698