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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/streams/writable-streams/bad-underlying-sinks.js

Issue 2500833002: Import latest WritableStream tests from upstream (Closed)
Patch Set: 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
1 'use strict'; 1 'use strict';
2 2
3 if (self.importScripts) { 3 if (self.importScripts) {
4 self.importScripts('/resources/testharness.js'); 4 self.importScripts('/resources/testharness.js');
5 self.importScripts('../resources/test-utils.js'); 5 self.importScripts('../resources/test-utils.js');
6 self.importScripts('../resources/recording-streams.js'); 6 self.importScripts('../resources/recording-streams.js');
7 } 7 }
8 8
9 const error1 = new Error('error1'); 9 const error1 = new Error('error1');
10 error1.name = 'error1'; 10 error1.name = 'error1';
11 11
12 test(() => {
13 assert_throws(error1, () => {
14 new WritableStream({
15 get start() {
16 throw error1;
17 }
18 });
19 }, 'constructor should throw same error as throwing start getter');
20
21 assert_throws(error1, () => {
22 new WritableStream({
23 start() {
24 throw error1;
25 }
26 });
27 }, 'constructor should throw same error as throwing start method');
28
29 assert_throws(new TypeError(), () => {
30 new WritableStream({
31 start: 'not a function or undefined'
32 });
33 }, 'constructor should throw TypeError when passed a non-function start proper ty');
34
35 assert_throws(new TypeError(), () => {
36 new WritableStream({
37 start: { apply() {} }
38 });
39 }, 'constructor should throw TypeError when passed a non-function start proper ty with an .apply method');
40 }, 'start: errors in start cause WritableStream constructor to throw');
41
12 promise_test(t => { 42 promise_test(t => {
13 43
14 const ws = recordingWritableStream({ 44 const ws = recordingWritableStream({
15 close() { 45 close() {
16 throw error1; 46 throw error1;
17 } 47 }
18 }); 48 });
19 49
20 const writer = ws.getWriter(); 50 const writer = ws.getWriter();
21 51
(...skipping 11 matching lines...) Expand all
33 const ws = recordingWritableStream({ 63 const ws = recordingWritableStream({
34 close() { 64 close() {
35 return Promise.reject(error1); 65 return Promise.reject(error1);
36 } 66 }
37 }); 67 });
38 68
39 const writer = ws.getWriter(); 69 const writer = ws.getWriter();
40 70
41 return promise_rejects(t, error1, writer.close(), 'close() promise must reject with the same error') 71 return promise_rejects(t, error1, writer.close(), 'close() promise must reject with the same error')
42 .then(() => promise_rejects(t, error1, writer.ready, 'ready promise must rejec t with the same error')) 72 .then(() => promise_rejects(t, error1, writer.ready, 'ready promise must rejec t with the same error'))
43 .then(() => { 73 .then(() => assert_array_equals(ws.events, ['close']));
44 assert_array_equals(ws.events, ['close']); 74
75 }, 'close: returning a rejected promise should cause writer close() and ready to reject');
76
77 promise_test(t => {
78 const ws = new WritableStream({
79 get close() {
80 throw error1;
81 }
45 }); 82 });
46 83
47 }, 'close: returning a rejected promise should cause writer close() and ready to reject'); 84 const writer = ws.getWriter();
85
86 return promise_rejects(t, error1, writer.close(), 'close should reject with th e thrown error');
87 }, 'close: throwing getter should cause writer close() to reject');
88
89 promise_test(t => {
90 const ws = new WritableStream({
91 get write() {
92 throw error1;
93 }
94 });
95
96 const writer = ws.getWriter();
97
98 return promise_rejects(t, error1, writer.write('a'), 'write should reject with the thrown error')
99 .then(() => promise_rejects(t, error1, writer.closed, 'closed should reject wi th the thrown error'));
100 }, 'write: throwing getter should cause write() and closed to reject');
101
102 promise_test(t => {
103 const ws = new WritableStream({
104 write() {
105 throw error1;
106 }
107 });
108
109 const writer = ws.getWriter();
110
111 return promise_rejects(t, error1, writer.write('a'), 'write should reject with the thrown error')
112 .then(() => promise_rejects(t, error1, writer.closed, 'closed should reject wi th the thrown error'));
113 }, 'write: throwing method should cause write() and closed to reject');
48 114
49 promise_test(t => { 115 promise_test(t => {
50 116
51 const startPromise = Promise.resolve(); 117 const startPromise = Promise.resolve();
52 let rejectSinkWritePromise; 118 let rejectSinkWritePromise;
53 const ws = recordingWritableStream({ 119 const ws = recordingWritableStream({
54 start() { 120 start() {
55 return startPromise; 121 return startPromise;
56 }, 122 },
57 write() { 123 write() {
(...skipping 18 matching lines...) Expand all
76 }); 142 });
77 143
78 }, 'write: returning a promise that becomes rejected after the writer write() sh ould cause writer write() and ready ' + 144 }, 'write: returning a promise that becomes rejected after the writer write() sh ould cause writer write() and ready ' +
79 'to reject'); 145 'to reject');
80 146
81 promise_test(t => { 147 promise_test(t => {
82 148
83 const ws = recordingWritableStream({ 149 const ws = recordingWritableStream({
84 write() { 150 write() {
85 if (ws.events.length === 2) { 151 if (ws.events.length === 2) {
86 return delay(10); 152 return delay(0);
87 } 153 }
88 154
89 return Promise.reject(error1); 155 return Promise.reject(error1);
90 } 156 }
91 }); 157 });
92 158
93 const writer = ws.getWriter(); 159 const writer = ws.getWriter();
94 160
95 // Do not wait for this; we want to test the ready promise when the stream is "full" (desiredSize = 0), but if we wait 161 // Do not wait for this; we want to test the ready promise when the stream is "full" (desiredSize = 0), but if we wait
96 // then the stream will transition back to "empty" (desiredSize = 1) 162 // then the stream will transition back to "empty" (desiredSize = 1)
97 writer.write('a'); 163 writer.write('a');
98 const readyPromise = writer.ready; 164 const readyPromise = writer.ready;
99 165
100 return promise_rejects(t, error1, writer.write('b'), 'second write must reject with the same error').then(() => { 166 return promise_rejects(t, error1, writer.write('b'), 'second write must reject with the same error').then(() => {
101 assert_equals(writer.ready, readyPromise, 167 assert_equals(writer.ready, readyPromise,
102 'the ready promise must not change, since the queue was full after the fir st write, so the pending one simply ' + 168 'the ready promise must not change, since the queue was full after the fir st write, so the pending one simply ' +
103 'transitioned'); 169 'transitioned');
104 return promise_rejects(t, error1, writer.ready, 'ready promise must reject w ith the same error'); 170 return promise_rejects(t, error1, writer.ready, 'ready promise must reject w ith the same error');
105 }) 171 })
106 .then(() => { 172 .then(() => assert_array_equals(ws.events, ['write', 'a', 'write', 'b']));
107 assert_array_equals(ws.events, ['write', 'a', 'write', 'b']);
108 });
109 173
110 }, 'write: returning a rejected promise (second write) should cause writer write () and ready to reject'); 174 }, 'write: returning a rejected promise (second write) should cause writer write () and ready to reject');
111 175
176 promise_test(t => {
177 const ws = new WritableStream({
178 abort: { apply() {} }
179 });
180
181 return promise_rejects(t, new TypeError(), ws.abort(error1), 'abort should rej ect with TypeError').then(() => {
182 const writer = ws.getWriter();
183 return promise_rejects(t, new TypeError(), writer.closed, 'closed should rej ect with a TypeError');
184 });
185 }, 'abort: non-function abort method with .apply');
186
187 promise_test(t => {
188 const abortReason = new Error('different string');
189 const ws = new WritableStream({
190 get abort() {
191 throw error1;
192 }
193 });
194
195 const writer = ws.getWriter();
196
197 return promise_rejects(t, error1, writer.abort(abortReason), 'abort should rej ect with the thrown error')
198 .then(() => promise_rejects(t, new TypeError(), writer.closed, 'closed should reject with a TypeError'));
199 }, 'abort: throwing getter should cause abort() and closed to reject');
200
201 promise_test(t => {
202 const abortReason = new Error('different string');
203 const ws = new WritableStream({
204 abort() {
205 throw error1;
206 }
207 });
208
209 const writer = ws.getWriter();
210
211 return promise_rejects(t, error1, writer.abort(abortReason), 'abort should rej ect with the thrown error')
212 .then(() => promise_rejects(t, new TypeError(), writer.closed, 'closed should reject with a TypeError'));
213 }, 'abort: throwing method should cause abort() and closed to reject');
214
112 done(); 215 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698