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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/streams/writable-streams/aborting.js

Issue 2453713003: Implementation of WritableStream (Closed)
Patch Set: Add missing return to promise_test Created 4 years, 1 month 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 self.importScripts('../resources/test-utils.js');
6 self.importScripts('../resources/recording-streams.js');
7 }
8
9 const error1 = new Error('error1');
10 error1.name = 'error1';
11
12 promise_test(t => {
13 const ws = new WritableStream({
14 write() {
15 return new Promise(() => { }); // forever-pending, so normally .ready woul d not fulfill.
16 }
17 });
18
19 const writer = ws.getWriter();
20 writer.write('a');
21
22 const readyPromise = writer.ready;
23
24 writer.abort(error1);
25
26 assert_equals(writer.ready, readyPromise, 'the ready promise property should n ot change');
27
28 return promise_rejects(t, new TypeError(), readyPromise, 'the ready promise sh ould reject with a TypeError');
29 }, 'Aborting a WritableStream should cause the writer\'s unsettled ready promise to reject');
30
31 promise_test(t => {
32 const ws = new WritableStream();
33
34 const writer = ws.getWriter();
35 writer.write('a');
36
37 const readyPromise = writer.ready;
38
39 return readyPromise.then(() => {
40 writer.abort(error1);
41
42 assert_not_equals(writer.ready, readyPromise, 'the ready promise property sh ould change');
43 return promise_rejects(t, new TypeError(), writer.ready, 'the ready promise should reject with a TypeError');
44 });
45 }, 'Aborting a WritableStream should cause the writer\'s fulfilled ready promise to reset to a rejected one');
46
47 promise_test(t => {
48 const ws = new WritableStream();
49 const writer = ws.getWriter();
50
51 writer.releaseLock();
52
53 return promise_rejects(t, new TypeError(), writer.abort(), 'abort() should rej ect with a TypeError');
54 }, 'abort() on a released writer rejects');
55
56 promise_test(() => {
57 const ws = recordingWritableStream();
58
59 return delay(0)
60 .then(() => {
61 const writer = ws.getWriter();
62
63 writer.abort();
64 writer.write(1);
65 writer.write(2);
66 })
67 .then(() => {
68 assert_array_equals(ws.events, ['abort', undefined]);
69 });
70 }, 'Aborting a WritableStream immediately prevents future writes');
71
72 promise_test(() => {
73 const ws = recordingWritableStream();
74
75 return delay(0)
76 .then(() => {
77 const writer = ws.getWriter();
78
79 writer.write(1);
80 writer.write(2);
81 writer.write(3);
82 writer.abort();
83 writer.write(4);
84 writer.write(5);
85 }).then(() => {
86 assert_array_equals(ws.events, ['write', 1, 'abort', undefined]);
87 });
88 }, 'Aborting a WritableStream prevents further writes after any that are in prog ress');
89
90 promise_test(() => {
91 const ws = new WritableStream({
92 abort() {
93 return 'Hello';
94 }
95 });
96 const writer = ws.getWriter();
97
98 return writer.abort('a').then(value => {
99 assert_equals(value, undefined, 'fulfillment value must be undefined');
100 });
101 }, 'Fulfillment value of ws.abort() call must be undefined even if the underlyin g sink returns a non-undefined value');
102
103 promise_test(t => {
104 const ws = new WritableStream({
105 abort() {
106 throw error1;
107 }
108 });
109 const writer = ws.getWriter();
110
111 return promise_rejects(t, error1, writer.abort(undefined),
112 'rejection reason of abortPromise must be the error thrown by abort');
113 }, 'WritableStream if sink\'s abort throws, the promise returned by writer.abort () rejects');
114
115 promise_test(t => {
116 const ws = new WritableStream({
117 abort() {
118 throw error1;
119 }
120 });
121
122 return promise_rejects(t, error1, ws.abort(undefined),
123 'rejection reason of abortPromise must be the error thrown by abort');
124 }, 'WritableStream if sink\'s abort throws, the promise returned by ws.abort() r ejects');
125
126 test(() => {
127 const ws = recordingWritableStream();
128 const writer = ws.getWriter();
129
130 writer.abort(error1);
131
132 assert_array_equals(ws.events, ['abort', error1]);
133 }, 'Aborting a WritableStream passes through the given reason');
134
135 promise_test(t => {
136 const ws = new WritableStream();
137 const writer = ws.getWriter();
138
139 writer.abort(error1);
140
141 return Promise.all([
142 promise_rejects(t, new TypeError(), writer.write(), 'writing should reject w ith a TypeError'),
143 promise_rejects(t, new TypeError(), writer.close(), 'closing should reject w ith a TypeError'),
144 promise_rejects(t, new TypeError(), writer.abort(), 'aborting should reject with a TypeError'),
145 promise_rejects(t, new TypeError(), writer.closed, 'closed should reject wit h a TypeError')
146 ]);
147 }, 'Aborting a WritableStream puts it in an errored state, with a TypeError as t he stored error');
148
149 promise_test(t => {
150 const ws = new WritableStream();
151 const writer = ws.getWriter();
152
153 const writePromise = promise_rejects(t, new TypeError(), writer.write('a'),
154 'writing should reject with a TypeError');
155
156 writer.abort(error1);
157
158 return writePromise;
159 }, 'Aborting a WritableStream causes any outstanding write() promises to be reje cted with a TypeError');
160
161 promise_test(t => {
162 const ws = new WritableStream();
163 const writer = ws.getWriter();
164
165 writer.close();
166 writer.abort(error1);
167
168 return promise_rejects(t, new TypeError(), writer.closed, 'closed should rejec t with a TypeError');
169 }, 'Closing but then immediately aborting a WritableStream causes the stream to error');
170
171 promise_test(t => {
172 const ws = new WritableStream({
173 close() {
174 return new Promise(() => { }); // forever-pending
175 }
176 });
177 const writer = ws.getWriter();
178
179 writer.close();
180
181 return delay(20).then(() => {
182 writer.abort(error1);
183 })
184 .then(() => promise_rejects(t, new TypeError(), writer.closed, 'closed should reject with a TypeError'));
185 }, 'Closing a WritableStream and aborting it while it closes causes the stream t o error');
186
187 promise_test(() => {
188 const ws = new WritableStream();
189 const writer = ws.getWriter();
190
191 writer.close();
192
193 return delay(0).then(() => writer.abort());
194 }, 'Aborting a WritableStream after it is closed is a no-op');
195
196 test(() => {
197 const ws = recordingWritableStream();
198 const writer = ws.getWriter();
199
200 writer.abort();
201
202 return writer.closed.then(() => {
203 assert_array_equals(ws.events, ['close']);
204 });
205 }, 'WritableStream should call underlying sink\'s close if no abort is supplied' );
206
207 promise_test(() => {
208 let thenCalled = false;
209 const ws = new WritableStream({
210 abort() {
211 return {
212 then(onFulfilled) {
213 thenCalled = true;
214 onFulfilled();
215 }
216 };
217 }
218 });
219 const writer = ws.getWriter();
220 return writer.abort().then(() => assert_true(thenCalled, 'then() should be cal led'));
221 }, 'returning a thenable from abort() should work');
222
223 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698