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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/streams/writable-streams/start.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 promise_test(() => { 9 promise_test(() => {
10 let resolveStartPromise; 10 let resolveStartPromise;
11 const ws = recordingWritableStream({ 11 const ws = recordingWritableStream({
12 start() { 12 start() {
13 return new Promise(resolve => { 13 return new Promise(resolve => {
14 resolveStartPromise = resolve; 14 resolveStartPromise = resolve;
15 }); 15 });
16 } 16 }
17 }); 17 });
18 18
19 const writer = ws.getWriter(); 19 const writer = ws.getWriter();
20 20
21 assert_equals(writer.desiredSize, 1, 'desiredSize should be 1'); 21 assert_equals(writer.desiredSize, 1, 'desiredSize should be 1');
22 writer.write('a'); 22 writer.write('a');
23 assert_equals(writer.desiredSize, 0, 'desiredSize should be 0 after writer.wri te()'); 23 assert_equals(writer.desiredSize, 0, 'desiredSize should be 0 after writer.wri te()');
24 24
25 // Wait and verify that write isn't called. 25 // Wait and verify that write isn't called.
26 return delay(100) 26 return flushAsyncEvents()
27 .then(() => { 27 .then(() => {
28 assert_array_equals(ws.events, [], 'write should not be called until sta rt promise resolves'); 28 assert_array_equals(ws.events, [], 'write should not be called until sta rt promise resolves');
29 resolveStartPromise(); 29 resolveStartPromise();
30 return writer.ready; 30 return writer.ready;
31 }) 31 })
32 .then(() => assert_array_equals(ws.events, ['write', 'a'], 32 .then(() => assert_array_equals(ws.events, ['write', 'a'],
33 'write should not be called until start pr omise resolves')); 33 'write should not be called until start pr omise resolves'));
34 }, 'underlying sink\'s write should not be called until start finishes'); 34 }, 'underlying sink\'s write should not be called until start finishes');
35 35
36 promise_test(() => { 36 promise_test(() => {
37 let resolveStartPromise; 37 let resolveStartPromise;
38 const ws = recordingWritableStream({ 38 const ws = recordingWritableStream({
39 start() { 39 start() {
40 return new Promise(resolve => { 40 return new Promise(resolve => {
41 resolveStartPromise = resolve; 41 resolveStartPromise = resolve;
42 }); 42 });
43 } 43 }
44 }); 44 });
45 45
46 const writer = ws.getWriter(); 46 const writer = ws.getWriter();
47 47
48 writer.close(); 48 writer.close();
49 assert_equals(writer.desiredSize, 1, 'desiredSize should be 1'); 49 assert_equals(writer.desiredSize, 1, 'desiredSize should be 1');
50 50
51 // Wait and verify that write isn't called. 51 // Wait and verify that write isn't called.
52 return delay(100).then(() => { 52 return flushAsyncEvents().then(() => {
53 assert_array_equals(ws.events, [], 'close should not be called until start p romise resolves'); 53 assert_array_equals(ws.events, [], 'close should not be called until start p romise resolves');
54 resolveStartPromise(); 54 resolveStartPromise();
55 return writer.closed; 55 return writer.closed;
56 }); 56 });
57 }, 'underlying sink\'s close should not be called until start finishes'); 57 }, 'underlying sink\'s close should not be called until start finishes');
58 58
59 test(() => { 59 test(() => {
60 const passedError = new Error('horrible things'); 60 const passedError = new Error('horrible things');
61 61
62 let writeCalled = false; 62 let writeCalled = false;
(...skipping 18 matching lines...) Expand all
81 }, 'underlying sink\'s write or close should not be called if start throws'); 81 }, 'underlying sink\'s write or close should not be called if start throws');
82 82
83 promise_test(() => { 83 promise_test(() => {
84 const ws = recordingWritableStream({ 84 const ws = recordingWritableStream({
85 start() { 85 start() {
86 return Promise.reject(); 86 return Promise.reject();
87 } 87 }
88 }); 88 });
89 89
90 // Wait and verify that write or close aren't called. 90 // Wait and verify that write or close aren't called.
91 return delay(100) 91 return flushAsyncEvents()
92 .then(() => assert_array_equals(ws.events, [], 'write and close should not be called')); 92 .then(() => assert_array_equals(ws.events, [], 'write and close should not be called'));
93 }, 'underlying sink\'s write or close should not be invoked if the promise retur ned by start is rejected'); 93 }, 'underlying sink\'s write or close should not be invoked if the promise retur ned by start is rejected');
94 94
95 promise_test(t => { 95 promise_test(t => {
96 const rejection = { name: 'this is checked' }; 96 const rejection = { name: 'this is checked' };
97 const ws = new WritableStream({ 97 const ws = new WritableStream({
98 start() { 98 start() {
99 return { 99 return {
100 then(onFulfilled, onRejected) { onRejected(rejection); } 100 then(onFulfilled, onRejected) { onRejected(rejection); }
101 }; 101 };
102 } 102 }
103 }); 103 });
104 return promise_rejects(t, rejection, ws.getWriter().closed, 'closed promise sh ould be rejected'); 104 return promise_rejects(t, rejection, ws.getWriter().closed, 'closed promise sh ould be rejected');
105 }, 'returning a thenable from start() should work'); 105 }, 'returning a thenable from start() should work');
106 106
107 done(); 107 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698