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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/streams/writable-streams/bad-underlying-sinks.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
14 const ws = recordingWritableStream({
15 close() {
16 throw error1;
17 }
18 });
19
20 const writer = ws.getWriter();
21
22 return promise_rejects(t, error1, writer.close(), 'close() promise must reject with the thrown error')
23 .then(() => promise_rejects(t, error1, writer.ready, 'ready promise must rejec t with the thrown error'))
24 .then(() => promise_rejects(t, error1, writer.closed, 'closed promise must rej ect with the thrown error'))
25 .then(() => {
26 assert_array_equals(ws.events, ['close']);
27 });
28
29 }, 'close: throwing method should cause writer close() and ready to reject');
30
31 promise_test(t => {
32
33 const ws = recordingWritableStream({
34 close() {
35 return Promise.reject(error1);
36 }
37 });
38
39 const writer = ws.getWriter();
40
41 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'))
43 .then(() => {
44 assert_array_equals(ws.events, ['close']);
45 });
46
47 }, 'close: returning a rejected promise should cause writer close() and ready to reject');
48
49 promise_test(t => {
50
51 const startPromise = Promise.resolve();
52 let rejectSinkWritePromise;
53 const ws = recordingWritableStream({
54 start() {
55 return startPromise;
56 },
57 write() {
58 return new Promise((r, reject) => {
59 rejectSinkWritePromise = reject;
60 });
61 }
62 });
63
64 return startPromise.then(() => {
65 const writer = ws.getWriter();
66 const writePromise = writer.write('a');
67 rejectSinkWritePromise(error1);
68
69 return Promise.all([
70 promise_rejects(t, error1, writePromise, 'writer write must reject with th e same error'),
71 promise_rejects(t, error1, writer.ready, 'ready promise must reject with t he same error')
72 ]);
73 })
74 .then(() => {
75 assert_array_equals(ws.events, ['write', 'a']);
76 });
77
78 }, 'write: returning a promise that becomes rejected after the writer write() sh ould cause writer write() and ready ' +
79 'to reject');
80
81 promise_test(t => {
82
83 const ws = recordingWritableStream({
84 write() {
85 if (ws.events.length === 2) {
86 return delay(10);
87 }
88
89 return Promise.reject(error1);
90 }
91 });
92
93 const writer = ws.getWriter();
94
95 // 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)
97 writer.write('a');
98 const readyPromise = writer.ready;
99
100 return promise_rejects(t, error1, writer.write('b'), 'second write must reject with the same error').then(() => {
101 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 ' +
103 'transitioned');
104 return promise_rejects(t, error1, writer.ready, 'ready promise must reject w ith the same error');
105 })
106 .then(() => {
107 assert_array_equals(ws.events, ['write', 'a', 'write', 'b']);
108 });
109
110 }, 'write: returning a rejected promise (second write) should cause writer write () and ready to reject');
111
112 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698