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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/streams/readable-streams/cancel.js

Issue 1902673003: Reflect recent spec changes to V8 Extra ReadableStream impl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed build Created 4 years, 7 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
1 'use strict'; 1 'use strict';
2 2
3 if (self.importScripts) { 3 if (self.importScripts) {
4 self.importScripts('../resources/test-utils.js'); 4 self.importScripts('../resources/test-utils.js');
5 self.importScripts('../resources/rs-utils.js'); 5 self.importScripts('../resources/rs-utils.js');
6 self.importScripts('/resources/testharness.js'); 6 self.importScripts('/resources/testharness.js');
7 } 7 }
8 8
9 promise_test(() => { 9 promise_test(() => {
10 10
11 const randomSource = new RandomPushSource(); 11 const randomSource = new RandomPushSource();
12 12
13 let cancellationFinished = false; 13 let cancellationFinished = false;
14 const rs = new ReadableStream({ 14 const rs = new ReadableStream({
15 start(c) { 15 start(c) {
16 randomSource.ondata = c.enqueue.bind(c); 16 randomSource.ondata = c.enqueue.bind(c);
17 randomSource.onend = c.close.bind(c); 17 randomSource.onend = c.close.bind(c);
18 randomSource.onerror = c.error.bind(c); 18 randomSource.onerror = c.error.bind(c);
19 }, 19 },
20 20
21 pull() { 21 pull() {
22 randomSource.readStart(); 22 randomSource.readStart();
23 }, 23 },
24 24
25 cancel() { 25 cancel() {
26 randomSource.readStop(); 26 randomSource.readStop();
27 randomSource.onend();
28 27
29 return new Promise(resolve => { 28 return new Promise(resolve => {
30 setTimeout(() => { 29 setTimeout(() => {
31 cancellationFinished = true; 30 cancellationFinished = true;
32 resolve(); 31 resolve();
33 }, 1); 32 }, 1);
34 }); 33 });
35 } 34 }
36 }); 35 });
37 36
38 const reader = rs.getReader(); 37 const reader = rs.getReader();
39 38
40 // We call delay multiple times to avoid cancelling too early for the 39 // We call delay multiple times to avoid cancelling too early for the
41 // source to enqueue at least one chunk. 40 // source to enqueue at least one chunk.
42 const cancel = delay(5).then(() => delay(5)).then(() => delay(5)).then(() => r eader.cancel()); 41 const cancel = delay(5).then(() => delay(5)).then(() => delay(5)).then(() => {
42 let cancelPromise = reader.cancel();
43 assert_false(cancellationFinished, 'cancellation in source should happen lat er');
44 return cancelPromise;
45 })
43 46
44 return readableStreamToArray(rs, reader).then(chunks => { 47 return readableStreamToArray(rs, reader).then(chunks => {
45 assert_greater_than(chunks.length, 0, 'at least one chunk should be read'); 48 assert_greater_than(chunks.length, 0, 'at least one chunk should be read');
46 for (let i = 0; i < chunks.length; i++) { 49 for (let i = 0; i < chunks.length; i++) {
47 assert_equals(chunks[i].length, 128, 'chunk ' + i + ' should have 128 byte s'); 50 assert_equals(chunks[i].length, 128, 'chunk ' + i + ' should have 128 byte s');
48 } 51 }
49 assert_false(cancellationFinished, 'it did not wait for the cancellation pro cess to finish before closing');
50 return cancel; 52 return cancel;
51 }).then(() => { 53 }).then(() => {
52 assert_true(cancellationFinished, 'it returns a promise that is fulfilled wh en the cancellation finishes'); 54 assert_true(cancellationFinished, 'it returns a promise that is fulfilled wh en the cancellation finishes');
53 }); 55 });
54 56
55 }, 'ReadableStream cancellation: integration test on an infinite stream derived from a random push source'); 57 }, 'ReadableStream cancellation: integration test on an infinite stream derived from a random push source');
56 58
57 test(() => { 59 test(() => {
58 60
59 let recordedReason; 61 let recordedReason;
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 pull() { 232 pull() {
231 assert_unreached('pull should not have been called'); 233 assert_unreached('pull should not have been called');
232 } 234 }
233 }); 235 });
234 236
235 return Promise.all([rs.cancel(), rs.getReader().closed]); 237 return Promise.all([rs.cancel(), rs.getReader().closed]);
236 238
237 }, 'ReadableStream cancellation: cancelling before start finishes should prevent pull() from being called'); 239 }, 'ReadableStream cancellation: cancelling before start finishes should prevent pull() from being called');
238 240
239 done(); 241 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698