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

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

Issue 2808853003: Remove Blink copies of readable-streams layout tests (Closed)
Patch Set: Restore rs-utils.js as it is used by fetch tests Created 3 years, 8 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
(Empty)
1 'use strict';
2
3 if (self.importScripts) {
4 self.importScripts('/resources/testharness.js');
5 }
6
7 test(() => {
8
9 const theError = new Error('a unique string');
10
11 assert_throws(theError, () => {
12 new ReadableStream({}, {
13 get size() {
14 throw theError;
15 },
16 highWaterMark: 5
17 });
18 }, 'construction should re-throw the error');
19
20 }, 'Readable stream: throwing strategy.size getter');
21
22 promise_test(t => {
23
24 const controllerError = { name: 'controller error' };
25 const thrownError = { name: 'thrown error' };
26
27 let controller;
28 const rs = new ReadableStream(
29 {
30 start(c) {
31 controller = c;
32 }
33 },
34 {
35 size() {
36 controller.error(controllerError);
37 throw thrownError;
38 },
39 highWaterMark: 5
40 }
41 );
42
43 assert_throws(thrownError, () => controller.enqueue('a'), 'enqueue should re-t hrow the error');
44
45 return promise_rejects(t, controllerError, rs.getReader().closed);
46
47 }, 'Readable stream: strategy.size errors the stream and then throws');
48
49 promise_test(t => {
50
51 const theError = { name: 'my error' };
52
53 let controller;
54 const rs = new ReadableStream(
55 {
56 start(c) {
57 controller = c;
58 }
59 },
60 {
61 size() {
62 controller.error(theError);
63 return Infinity;
64 },
65 highWaterMark: 5
66 }
67 );
68
69 assert_throws(new RangeError(), () => controller.enqueue('a'), 'enqueue should throw a RangeError');
70
71 return promise_rejects(t, theError, rs.getReader().closed, 'closed should reje ct with the error');
72
73 }, 'Readable stream: strategy.size errors the stream and then returns Infinity') ;
74
75 promise_test(() => {
76
77 const theError = new Error('a unique string');
78 const rs = new ReadableStream(
79 {
80 start(c) {
81 assert_throws(theError, () => c.enqueue('a'), 'enqueue should throw the error');
82 }
83 },
84 {
85 size() {
86 throw theError;
87 },
88 highWaterMark: 5
89 }
90 );
91
92 return rs.getReader().closed.catch(e => {
93 assert_equals(e, theError, 'closed should reject with the error');
94 });
95
96 }, 'Readable stream: throwing strategy.size method');
97
98 test(() => {
99
100 const theError = new Error('a unique string');
101
102 assert_throws(theError, () => {
103 new ReadableStream({}, {
104 size() {
105 return 1;
106 },
107 get highWaterMark() {
108 throw theError;
109 }
110 });
111 }, 'construction should re-throw the error');
112
113 }, 'Readable stream: throwing strategy.highWaterMark getter');
114
115 test(() => {
116
117 for (const highWaterMark of [-1, -Infinity]) {
118 assert_throws(new RangeError(), () => {
119 new ReadableStream({}, {
120 size() {
121 return 1;
122 },
123 highWaterMark
124 });
125 }, 'construction should throw a RangeError for ' + highWaterMark);
126 }
127
128 for (const highWaterMark of [NaN, 'foo', {}]) {
129 assert_throws(new RangeError(), () => {
130 new ReadableStream({}, {
131 size() {
132 return 1;
133 },
134 highWaterMark
135 });
136 }, 'construction should throw a RangeError for ' + highWaterMark);
137 }
138
139 }, 'Readable stream: invalid strategy.highWaterMark');
140
141 promise_test(() => {
142
143 const promises = [];
144 for (const size of [NaN, -Infinity, Infinity, -1]) {
145 let theError;
146 const rs = new ReadableStream(
147 {
148 start(c) {
149 try {
150 c.enqueue('hi');
151 assert_unreached('enqueue didn\'t throw');
152 } catch (error) {
153 assert_equals(error.name, 'RangeError', 'enqueue should throw a Rang eError for ' + size);
154 theError = error;
155 }
156 }
157 },
158 {
159 size() {
160 return size;
161 },
162 highWaterMark: 5
163 }
164 );
165
166 promises.push(rs.getReader().closed.catch(e => {
167 assert_equals(e, theError, 'closed should reject with the error for ' + si ze);
168 }));
169 }
170
171 return Promise.all(promises);
172
173 }, 'Readable stream: invalid strategy.size return value');
174
175 done();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698