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

Side by Side Diff: third_party/WebKit/Source/core/streams/ReadableStreamTest.cpp

Issue 1773813007: blink: Rename modules/ method to prefix with get when they collide. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: clash-modules: rebase-fixes Created 4 years, 9 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/streams/ReadableStream.h" 5 #include "core/streams/ReadableStream.h"
6 6
7 #include "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "bindings/core/v8/ScriptPromiseResolver.h" 8 #include "bindings/core/v8/ScriptPromiseResolver.h"
9 #include "bindings/core/v8/ScriptState.h" 9 #include "bindings/core/v8/ScriptState.h"
10 #include "bindings/core/v8/V8Binding.h" 10 #include "bindings/core/v8/V8Binding.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 private: 44 private:
45 StringCapturingFunction(ScriptState* scriptState, String* value) 45 StringCapturingFunction(ScriptState* scriptState, String* value)
46 : ScriptFunction(scriptState) 46 : ScriptFunction(scriptState)
47 , m_value(value) 47 , m_value(value)
48 { 48 {
49 } 49 }
50 50
51 ScriptValue call(ScriptValue value) override 51 ScriptValue call(ScriptValue value) override
52 { 52 {
53 ASSERT(!value.isEmpty()); 53 ASSERT(!value.isEmpty());
54 *m_value = toCoreString(value.v8Value()->ToString(scriptState()->context ()).ToLocalChecked()); 54 *m_value = toCoreString(value.v8Value()->ToString(getScriptState()->cont ext()).ToLocalChecked());
55 return value; 55 return value;
56 } 56 }
57 57
58 String* m_value; 58 String* m_value;
59 }; 59 };
60 60
61 class MockUnderlyingSource : public GarbageCollectedFinalized<MockUnderlyingSour ce>, public UnderlyingSource { 61 class MockUnderlyingSource : public GarbageCollectedFinalized<MockUnderlyingSour ce>, public UnderlyingSource {
62 USING_GARBAGE_COLLECTED_MIXIN(MockUnderlyingSource); 62 USING_GARBAGE_COLLECTED_MIXIN(MockUnderlyingSource);
63 public: 63 public:
64 ~MockUnderlyingSource() override { } 64 ~MockUnderlyingSource() override { }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 ReadableStreamTest() 107 ReadableStreamTest()
108 : m_page(DummyPageHolder::create(IntSize(1, 1))) 108 : m_page(DummyPageHolder::create(IntSize(1, 1)))
109 , m_underlyingSource(new ::testing::StrictMock<MockUnderlyingSource>) 109 , m_underlyingSource(new ::testing::StrictMock<MockUnderlyingSource>)
110 { 110 {
111 } 111 }
112 112
113 ~ReadableStreamTest() override 113 ~ReadableStreamTest() override
114 { 114 {
115 } 115 }
116 116
117 ScriptState* scriptState() { return ScriptState::forMainWorld(m_page->docume nt().frame()); } 117 ScriptState* getScriptState() { return ScriptState::forMainWorld(m_page->doc ument().frame()); }
118 v8::Isolate* isolate() { return scriptState()->isolate(); } 118 v8::Isolate* isolate() { return getScriptState()->isolate(); }
119 119
120 v8::Local<v8::Function> createCaptor(String* value) 120 v8::Local<v8::Function> createCaptor(String* value)
121 { 121 {
122 return StringCapturingFunction::createFunction(scriptState(), value); 122 return StringCapturingFunction::createFunction(getScriptState(), value);
123 } 123 }
124 124
125 StringStream* construct(MockStrategy* strategy) 125 StringStream* construct(MockStrategy* strategy)
126 { 126 {
127 Checkpoint checkpoint; 127 Checkpoint checkpoint;
128 { 128 {
129 InSequence s; 129 InSequence s;
130 EXPECT_CALL(checkpoint, Call(0)); 130 EXPECT_CALL(checkpoint, Call(0));
131 EXPECT_CALL(*strategy, shouldApplyBackpressure(0, _)).WillOnce(Retur n(true)); 131 EXPECT_CALL(*strategy, shouldApplyBackpressure(0, _)).WillOnce(Retur n(true));
132 EXPECT_CALL(checkpoint, Call(1)); 132 EXPECT_CALL(checkpoint, Call(1));
(...skipping 19 matching lines...) Expand all
152 checkpoint.Call(1); 152 checkpoint.Call(1);
153 return stream; 153 return stream;
154 } 154 }
155 155
156 OwnPtr<DummyPageHolder> m_page; 156 OwnPtr<DummyPageHolder> m_page;
157 Persistent<MockUnderlyingSource> m_underlyingSource; 157 Persistent<MockUnderlyingSource> m_underlyingSource;
158 }; 158 };
159 159
160 TEST_F(ReadableStreamTest, Start) 160 TEST_F(ReadableStreamTest, Start)
161 { 161 {
162 ScriptState::Scope scope(scriptState()); 162 ScriptState::Scope scope(getScriptState());
163 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", scriptState()->context()->Global(), isolate()); 163 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", getScriptState()->context()->Global(), isolate());
164 Checkpoint checkpoint; 164 Checkpoint checkpoint;
165 { 165 {
166 InSequence s; 166 InSequence s;
167 EXPECT_CALL(checkpoint, Call(0)); 167 EXPECT_CALL(checkpoint, Call(0));
168 EXPECT_CALL(*m_underlyingSource, pullSource()).Times(1); 168 EXPECT_CALL(*m_underlyingSource, pullSource()).Times(1);
169 EXPECT_CALL(checkpoint, Call(1)); 169 EXPECT_CALL(checkpoint, Call(1));
170 } 170 }
171 171
172 StringStream* stream = new StringStream(m_underlyingSource); 172 StringStream* stream = new StringStream(m_underlyingSource);
173 EXPECT_FALSE(exceptionState.hadException()); 173 EXPECT_FALSE(exceptionState.hadException());
(...skipping 12 matching lines...) Expand all
186 EXPECT_TRUE(stream->isPulling()); 186 EXPECT_TRUE(stream->isPulling());
187 EXPECT_EQ(stream->stateInternal(), ReadableStream::Readable); 187 EXPECT_EQ(stream->stateInternal(), ReadableStream::Readable);
188 188
189 // We need to call |error| in order to make 189 // We need to call |error| in order to make
190 // ActiveDOMObject::hasPendingActivity return false. 190 // ActiveDOMObject::hasPendingActivity return false.
191 stream->error(DOMException::create(AbortError, "done")); 191 stream->error(DOMException::create(AbortError, "done"));
192 } 192 }
193 193
194 TEST_F(ReadableStreamTest, StartFail) 194 TEST_F(ReadableStreamTest, StartFail)
195 { 195 {
196 ScriptState::Scope scope(scriptState()); 196 ScriptState::Scope scope(getScriptState());
197 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", scriptState()->context()->Global(), isolate()); 197 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", getScriptState()->context()->Global(), isolate());
198 StringStream* stream = new StringStream(m_underlyingSource); 198 StringStream* stream = new StringStream(m_underlyingSource);
199 EXPECT_FALSE(exceptionState.hadException()); 199 EXPECT_FALSE(exceptionState.hadException());
200 EXPECT_FALSE(stream->isStarted()); 200 EXPECT_FALSE(stream->isStarted());
201 EXPECT_FALSE(stream->isDraining()); 201 EXPECT_FALSE(stream->isDraining());
202 EXPECT_FALSE(stream->isPulling()); 202 EXPECT_FALSE(stream->isPulling());
203 EXPECT_EQ(stream->stateInternal(), ReadableStream::Readable); 203 EXPECT_EQ(stream->stateInternal(), ReadableStream::Readable);
204 204
205 stream->error(DOMException::create(NotFoundError)); 205 stream->error(DOMException::create(NotFoundError));
206 206
207 EXPECT_FALSE(stream->isStarted()); 207 EXPECT_FALSE(stream->isStarted());
208 EXPECT_FALSE(stream->isDraining()); 208 EXPECT_FALSE(stream->isDraining());
209 EXPECT_FALSE(stream->isPulling()); 209 EXPECT_FALSE(stream->isPulling());
210 EXPECT_EQ(stream->stateInternal(), ReadableStream::Errored); 210 EXPECT_EQ(stream->stateInternal(), ReadableStream::Errored);
211 } 211 }
212 212
213 TEST_F(ReadableStreamTest, ErrorAndEnqueue) 213 TEST_F(ReadableStreamTest, ErrorAndEnqueue)
214 { 214 {
215 ScriptState::Scope scope(scriptState()); 215 ScriptState::Scope scope(getScriptState());
216 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", scriptState()->context()->Global(), isolate()); 216 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", getScriptState()->context()->Global(), isolate());
217 StringStream* stream = construct(); 217 StringStream* stream = construct();
218 218
219 stream->error(DOMException::create(NotFoundError, "error")); 219 stream->error(DOMException::create(NotFoundError, "error"));
220 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal()); 220 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal());
221 221
222 bool result = stream->enqueue("hello"); 222 bool result = stream->enqueue("hello");
223 EXPECT_FALSE(result); 223 EXPECT_FALSE(result);
224 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal()); 224 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal());
225 } 225 }
226 226
227 TEST_F(ReadableStreamTest, CloseAndEnqueue) 227 TEST_F(ReadableStreamTest, CloseAndEnqueue)
228 { 228 {
229 ScriptState::Scope scope(scriptState()); 229 ScriptState::Scope scope(getScriptState());
230 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", scriptState()->context()->Global(), isolate()); 230 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", getScriptState()->context()->Global(), isolate());
231 StringStream* stream = construct(); 231 StringStream* stream = construct();
232 232
233 stream->close(); 233 stream->close();
234 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); 234 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal());
235 235
236 bool result = stream->enqueue("hello"); 236 bool result = stream->enqueue("hello");
237 EXPECT_FALSE(result); 237 EXPECT_FALSE(result);
238 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); 238 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal());
239 } 239 }
240 240
241 TEST_F(ReadableStreamTest, CloseWhenErrored) 241 TEST_F(ReadableStreamTest, CloseWhenErrored)
242 { 242 {
243 ScriptState::Scope scope(scriptState()); 243 ScriptState::Scope scope(getScriptState());
244 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", scriptState()->context()->Global(), isolate()); 244 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", getScriptState()->context()->Global(), isolate());
245 StringStream* stream = construct(); 245 StringStream* stream = construct();
246 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); 246 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal());
247 247
248 stream->error(DOMException::create(NotFoundError, "error")); 248 stream->error(DOMException::create(NotFoundError, "error"));
249 stream->close(); 249 stream->close();
250 250
251 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal()); 251 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal());
252 } 252 }
253 253
254 TEST_F(ReadableStreamTest, ReadQueue) 254 TEST_F(ReadableStreamTest, ReadQueue)
255 { 255 {
256 ScriptState::Scope scope(scriptState()); 256 ScriptState::Scope scope(getScriptState());
257 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", scriptState()->context()->Global(), isolate()); 257 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", getScriptState()->context()->Global(), isolate());
258 StringStream* stream = construct(); 258 StringStream* stream = construct();
259 Checkpoint checkpoint; 259 Checkpoint checkpoint;
260 260
261 { 261 {
262 InSequence s; 262 InSequence s;
263 EXPECT_CALL(checkpoint, Call(0)); 263 EXPECT_CALL(checkpoint, Call(0));
264 EXPECT_CALL(*m_underlyingSource, pullSource()).Times(1); 264 EXPECT_CALL(*m_underlyingSource, pullSource()).Times(1);
265 EXPECT_CALL(checkpoint, Call(1)); 265 EXPECT_CALL(checkpoint, Call(1));
266 } 266 }
267 267
(...skipping 14 matching lines...) Expand all
282 EXPECT_EQ(std::make_pair(String("hello"), static_cast<size_t>(5)), queue[0]) ; 282 EXPECT_EQ(std::make_pair(String("hello"), static_cast<size_t>(5)), queue[0]) ;
283 EXPECT_EQ(std::make_pair(String("bye"), static_cast<size_t>(3)), queue[1]); 283 EXPECT_EQ(std::make_pair(String("bye"), static_cast<size_t>(3)), queue[1]);
284 284
285 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); 285 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal());
286 EXPECT_TRUE(stream->isPulling()); 286 EXPECT_TRUE(stream->isPulling());
287 EXPECT_FALSE(stream->isDraining()); 287 EXPECT_FALSE(stream->isDraining());
288 } 288 }
289 289
290 TEST_F(ReadableStreamTest, CloseWhenReadable) 290 TEST_F(ReadableStreamTest, CloseWhenReadable)
291 { 291 {
292 ScriptState::Scope scope(scriptState()); 292 ScriptState::Scope scope(getScriptState());
293 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", scriptState()->context()->Global(), isolate()); 293 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", getScriptState()->context()->Global(), isolate());
294 StringStream* stream = construct(); 294 StringStream* stream = construct();
295 295
296 EXPECT_TRUE(stream->enqueue("hello")); 296 EXPECT_TRUE(stream->enqueue("hello"));
297 EXPECT_TRUE(stream->enqueue("bye")); 297 EXPECT_TRUE(stream->enqueue("bye"));
298 stream->close(); 298 stream->close();
299 EXPECT_FALSE(stream->enqueue("should be ignored")); 299 EXPECT_FALSE(stream->enqueue("should be ignored"));
300 300
301 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); 301 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal());
302 EXPECT_FALSE(stream->isPulling()); 302 EXPECT_FALSE(stream->isPulling());
303 EXPECT_TRUE(stream->isDraining()); 303 EXPECT_TRUE(stream->isDraining());
304 304
305 stream->read(scriptState()); 305 stream->read(getScriptState());
306 306
307 v8::MicrotasksScope::PerformCheckpoint(isolate()); 307 v8::MicrotasksScope::PerformCheckpoint(isolate());
308 308
309 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); 309 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal());
310 EXPECT_FALSE(stream->isPulling()); 310 EXPECT_FALSE(stream->isPulling());
311 EXPECT_TRUE(stream->isDraining()); 311 EXPECT_TRUE(stream->isDraining());
312 312
313 stream->read(scriptState()); 313 stream->read(getScriptState());
314 314
315 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); 315 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal());
316 EXPECT_FALSE(stream->isPulling()); 316 EXPECT_FALSE(stream->isPulling());
317 EXPECT_TRUE(stream->isDraining()); 317 EXPECT_TRUE(stream->isDraining());
318 } 318 }
319 319
320 TEST_F(ReadableStreamTest, CancelWhenClosed) 320 TEST_F(ReadableStreamTest, CancelWhenClosed)
321 { 321 {
322 ScriptState::Scope scope(scriptState()); 322 ScriptState::Scope scope(getScriptState());
323 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", scriptState()->context()->Global(), isolate()); 323 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", getScriptState()->context()->Global(), isolate());
324 StringStream* stream = construct(); 324 StringStream* stream = construct();
325 String onFulfilled, onRejected; 325 String onFulfilled, onRejected;
326 stream->close(); 326 stream->close();
327 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); 327 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal());
328 328
329 EXPECT_FALSE(stream->isDisturbed()); 329 EXPECT_FALSE(stream->isDisturbed());
330 ScriptPromise promise = stream->cancel(scriptState(), ScriptValue()); 330 ScriptPromise promise = stream->cancel(getScriptState(), ScriptValue());
331 EXPECT_TRUE(stream->isDisturbed()); 331 EXPECT_TRUE(stream->isDisturbed());
332 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); 332 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal());
333 333
334 promise.then(createCaptor(&onFulfilled), createCaptor(&onRejected)); 334 promise.then(createCaptor(&onFulfilled), createCaptor(&onRejected));
335 EXPECT_TRUE(onFulfilled.isNull()); 335 EXPECT_TRUE(onFulfilled.isNull());
336 EXPECT_TRUE(onRejected.isNull()); 336 EXPECT_TRUE(onRejected.isNull());
337 337
338 v8::MicrotasksScope::PerformCheckpoint(isolate()); 338 v8::MicrotasksScope::PerformCheckpoint(isolate());
339 EXPECT_EQ("undefined", onFulfilled); 339 EXPECT_EQ("undefined", onFulfilled);
340 EXPECT_TRUE(onRejected.isNull()); 340 EXPECT_TRUE(onRejected.isNull());
341 } 341 }
342 342
343 TEST_F(ReadableStreamTest, CancelWhenErrored) 343 TEST_F(ReadableStreamTest, CancelWhenErrored)
344 { 344 {
345 ScriptState::Scope scope(scriptState()); 345 ScriptState::Scope scope(getScriptState());
346 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", scriptState()->context()->Global(), isolate()); 346 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", getScriptState()->context()->Global(), isolate());
347 StringStream* stream = construct(); 347 StringStream* stream = construct();
348 String onFulfilled, onRejected; 348 String onFulfilled, onRejected;
349 stream->error(DOMException::create(NotFoundError, "error")); 349 stream->error(DOMException::create(NotFoundError, "error"));
350 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal()); 350 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal());
351 351
352 EXPECT_FALSE(stream->isDisturbed()); 352 EXPECT_FALSE(stream->isDisturbed());
353 ScriptPromise promise = stream->cancel(scriptState(), ScriptValue()); 353 ScriptPromise promise = stream->cancel(getScriptState(), ScriptValue());
354 EXPECT_TRUE(stream->isDisturbed()); 354 EXPECT_TRUE(stream->isDisturbed());
355 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal()); 355 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal());
356 356
357 promise.then(createCaptor(&onFulfilled), createCaptor(&onRejected)); 357 promise.then(createCaptor(&onFulfilled), createCaptor(&onRejected));
358 EXPECT_TRUE(onFulfilled.isNull()); 358 EXPECT_TRUE(onFulfilled.isNull());
359 EXPECT_TRUE(onRejected.isNull()); 359 EXPECT_TRUE(onRejected.isNull());
360 360
361 v8::MicrotasksScope::PerformCheckpoint(isolate()); 361 v8::MicrotasksScope::PerformCheckpoint(isolate());
362 EXPECT_TRUE(onFulfilled.isNull()); 362 EXPECT_TRUE(onFulfilled.isNull());
363 EXPECT_EQ("NotFoundError: error", onRejected); 363 EXPECT_EQ("NotFoundError: error", onRejected);
364 } 364 }
365 365
366 TEST_F(ReadableStreamTest, CancelWhenReadable) 366 TEST_F(ReadableStreamTest, CancelWhenReadable)
367 { 367 {
368 ScriptState::Scope scope(scriptState()); 368 ScriptState::Scope scope(getScriptState());
369 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", scriptState()->context()->Global(), isolate()); 369 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", getScriptState()->context()->Global(), isolate());
370 StringStream* stream = construct(); 370 StringStream* stream = construct();
371 String onFulfilled, onRejected; 371 String onFulfilled, onRejected;
372 String onCancelFulfilled, onCancelRejected; 372 String onCancelFulfilled, onCancelRejected;
373 ScriptValue reason(scriptState(), v8String(scriptState()->isolate(), "reason ")); 373 ScriptValue reason(getScriptState(), v8String(getScriptState()->isolate(), " reason"));
374 ScriptPromise promise = ScriptPromise::cast(scriptState(), v8String(scriptSt ate()->isolate(), "hello")); 374 ScriptPromise promise = ScriptPromise::cast(getScriptState(), v8String(getSc riptState()->isolate(), "hello"));
375 375
376 { 376 {
377 InSequence s; 377 InSequence s;
378 EXPECT_CALL(*m_underlyingSource, cancelSource(scriptState(), reason)).Wi llOnce(ReturnPointee(&promise)); 378 EXPECT_CALL(*m_underlyingSource, cancelSource(getScriptState(), reason)) .WillOnce(ReturnPointee(&promise));
379 } 379 }
380 380
381 stream->enqueue("hello"); 381 stream->enqueue("hello");
382 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); 382 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal());
383 383
384 EXPECT_FALSE(stream->isDisturbed()); 384 EXPECT_FALSE(stream->isDisturbed());
385 ScriptPromise cancelResult = stream->cancel(scriptState(), reason); 385 ScriptPromise cancelResult = stream->cancel(getScriptState(), reason);
386 EXPECT_TRUE(stream->isDisturbed()); 386 EXPECT_TRUE(stream->isDisturbed());
387 cancelResult.then(createCaptor(&onCancelFulfilled), createCaptor(&onCancelRe jected)); 387 cancelResult.then(createCaptor(&onCancelFulfilled), createCaptor(&onCancelRe jected));
388 388
389 EXPECT_NE(promise, cancelResult); 389 EXPECT_NE(promise, cancelResult);
390 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); 390 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal());
391 391
392 EXPECT_TRUE(onCancelFulfilled.isNull()); 392 EXPECT_TRUE(onCancelFulfilled.isNull());
393 EXPECT_TRUE(onCancelRejected.isNull()); 393 EXPECT_TRUE(onCancelRejected.isNull());
394 394
395 v8::MicrotasksScope::PerformCheckpoint(isolate()); 395 v8::MicrotasksScope::PerformCheckpoint(isolate());
396 EXPECT_EQ("undefined", onCancelFulfilled); 396 EXPECT_EQ("undefined", onCancelFulfilled);
397 EXPECT_TRUE(onCancelRejected.isNull()); 397 EXPECT_TRUE(onCancelRejected.isNull());
398 } 398 }
399 399
400 TEST_F(ReadableStreamTest, CancelWhenLocked) 400 TEST_F(ReadableStreamTest, CancelWhenLocked)
401 { 401 {
402 ScriptState::Scope scope(scriptState()); 402 ScriptState::Scope scope(getScriptState());
403 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", scriptState()->context()->Global(), isolate()); 403 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", getScriptState()->context()->Global(), isolate());
404 String onFulfilled, onRejected; 404 String onFulfilled, onRejected;
405 StringStream* stream = construct(); 405 StringStream* stream = construct();
406 ReadableStreamReader* reader = stream->getReader(scriptState()->executionCon text(), exceptionState); 406 ReadableStreamReader* reader = stream->getReader(getScriptState()->getExecut ionContext(), exceptionState);
407 407
408 EXPECT_TRUE(reader->isActive()); 408 EXPECT_TRUE(reader->isActive());
409 EXPECT_FALSE(exceptionState.hadException()); 409 EXPECT_FALSE(exceptionState.hadException());
410 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); 410 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal());
411 411
412 EXPECT_FALSE(stream->isDisturbed()); 412 EXPECT_FALSE(stream->isDisturbed());
413 stream->cancel(scriptState(), ScriptValue(scriptState(), v8::Undefined(isola te()))).then(createCaptor(&onFulfilled), createCaptor(&onRejected)); 413 stream->cancel(getScriptState(), ScriptValue(getScriptState(), v8::Undefined (isolate()))).then(createCaptor(&onFulfilled), createCaptor(&onRejected));
414 EXPECT_FALSE(stream->isDisturbed()); 414 EXPECT_FALSE(stream->isDisturbed());
415 415
416 EXPECT_TRUE(onFulfilled.isNull()); 416 EXPECT_TRUE(onFulfilled.isNull());
417 EXPECT_TRUE(onRejected.isNull()); 417 EXPECT_TRUE(onRejected.isNull());
418 418
419 v8::MicrotasksScope::PerformCheckpoint(isolate()); 419 v8::MicrotasksScope::PerformCheckpoint(isolate());
420 420
421 EXPECT_TRUE(onFulfilled.isNull()); 421 EXPECT_TRUE(onFulfilled.isNull());
422 EXPECT_EQ("TypeError: this stream is locked to a ReadableStreamReader", onRe jected); 422 EXPECT_EQ("TypeError: this stream is locked to a ReadableStreamReader", onRe jected);
423 EXPECT_TRUE(reader->isActive()); 423 EXPECT_TRUE(reader->isActive());
424 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); 424 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal());
425 } 425 }
426 426
427 TEST_F(ReadableStreamTest, ReadableArrayBufferStreamCompileTest) 427 TEST_F(ReadableStreamTest, ReadableArrayBufferStreamCompileTest)
428 { 428 {
429 ScriptState::Scope scope(scriptState()); 429 ScriptState::Scope scope(getScriptState());
430 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", scriptState()->context()->Global(), isolate()); 430 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", getScriptState()->context()->Global(), isolate());
431 // This test tests if ReadableStreamImpl<DOMArrayBuffer> can be 431 // This test tests if ReadableStreamImpl<DOMArrayBuffer> can be
432 // instantiated. 432 // instantiated.
433 new ReadableStreamImpl<ReadableStreamChunkTypeTraits<DOMArrayBuffer>>(m_unde rlyingSource); 433 new ReadableStreamImpl<ReadableStreamChunkTypeTraits<DOMArrayBuffer>>(m_unde rlyingSource);
434 } 434 }
435 435
436 TEST_F(ReadableStreamTest, ReadableArrayBufferViewStreamCompileTest) 436 TEST_F(ReadableStreamTest, ReadableArrayBufferViewStreamCompileTest)
437 { 437 {
438 ScriptState::Scope scope(scriptState()); 438 ScriptState::Scope scope(getScriptState());
439 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", scriptState()->context()->Global(), isolate()); 439 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", getScriptState()->context()->Global(), isolate());
440 // This test tests if ReadableStreamImpl<DOMArrayBufferVIew> can be 440 // This test tests if ReadableStreamImpl<DOMArrayBufferVIew> can be
441 // instantiated. 441 // instantiated.
442 new ReadableStreamImpl<ReadableStreamChunkTypeTraits<DOMArrayBufferView>>(m_ underlyingSource); 442 new ReadableStreamImpl<ReadableStreamChunkTypeTraits<DOMArrayBufferView>>(m_ underlyingSource);
443 } 443 }
444 444
445 TEST_F(ReadableStreamTest, BackpressureOnEnqueueing) 445 TEST_F(ReadableStreamTest, BackpressureOnEnqueueing)
446 { 446 {
447 ScriptState::Scope scope(scriptState()); 447 ScriptState::Scope scope(getScriptState());
448 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", scriptState()->context()->Global(), isolate()); 448 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", getScriptState()->context()->Global(), isolate());
449 auto strategy = MockStrategy::create(); 449 auto strategy = MockStrategy::create();
450 Checkpoint checkpoint; 450 Checkpoint checkpoint;
451 451
452 StringStream* stream = construct(strategy); 452 StringStream* stream = construct(strategy);
453 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); 453 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal());
454 454
455 { 455 {
456 InSequence s; 456 InSequence s;
457 EXPECT_CALL(checkpoint, Call(0)); 457 EXPECT_CALL(checkpoint, Call(0));
458 EXPECT_CALL(*strategy, size(String("hello"), stream)).WillOnce(Return(1) ); 458 EXPECT_CALL(*strategy, size(String("hello"), stream)).WillOnce(Return(1) );
(...skipping 12 matching lines...) Expand all
471 checkpoint.Call(2); 471 checkpoint.Call(2);
472 result = stream->enqueue("world"); 472 result = stream->enqueue("world");
473 checkpoint.Call(3); 473 checkpoint.Call(3);
474 EXPECT_FALSE(result); 474 EXPECT_FALSE(result);
475 475
476 stream->error(DOMException::create(AbortError, "done")); 476 stream->error(DOMException::create(AbortError, "done"));
477 } 477 }
478 478
479 TEST_F(ReadableStreamTest, BackpressureOnReading) 479 TEST_F(ReadableStreamTest, BackpressureOnReading)
480 { 480 {
481 ScriptState::Scope scope(scriptState()); 481 ScriptState::Scope scope(getScriptState());
482 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", scriptState()->context()->Global(), isolate()); 482 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", getScriptState()->context()->Global(), isolate());
483 auto strategy = MockStrategy::create(); 483 auto strategy = MockStrategy::create();
484 Checkpoint checkpoint; 484 Checkpoint checkpoint;
485 485
486 StringStream* stream = construct(strategy); 486 StringStream* stream = construct(strategy);
487 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); 487 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal());
488 488
489 { 489 {
490 InSequence s; 490 InSequence s;
491 EXPECT_CALL(*strategy, size(String("hello"), stream)).WillOnce(Return(2) ); 491 EXPECT_CALL(*strategy, size(String("hello"), stream)).WillOnce(Return(2) );
492 EXPECT_CALL(*strategy, shouldApplyBackpressure(2, stream)).WillOnce(Retu rn(false)); 492 EXPECT_CALL(*strategy, shouldApplyBackpressure(2, stream)).WillOnce(Retu rn(false));
(...skipping 12 matching lines...) Expand all
505 EXPECT_CALL(*strategy, size(String("bar"), stream)).WillOnce(Return(5)); 505 EXPECT_CALL(*strategy, size(String("bar"), stream)).WillOnce(Return(5));
506 EXPECT_CALL(*strategy, shouldApplyBackpressure(9, stream)).WillOnce(Retu rn(true)); 506 EXPECT_CALL(*strategy, shouldApplyBackpressure(9, stream)).WillOnce(Retu rn(true));
507 EXPECT_CALL(checkpoint, Call(3)); 507 EXPECT_CALL(checkpoint, Call(3));
508 EXPECT_CALL(*strategy, shouldApplyBackpressure(5, stream)).WillOnce(Retu rn(true)); 508 EXPECT_CALL(*strategy, shouldApplyBackpressure(5, stream)).WillOnce(Retu rn(true));
509 EXPECT_CALL(checkpoint, Call(4)); 509 EXPECT_CALL(checkpoint, Call(4));
510 } 510 }
511 stream->enqueue("hello"); 511 stream->enqueue("hello");
512 stream->enqueue("world"); 512 stream->enqueue("world");
513 513
514 checkpoint.Call(0); 514 checkpoint.Call(0);
515 stream->read(scriptState()); 515 stream->read(getScriptState());
516 checkpoint.Call(1); 516 checkpoint.Call(1);
517 stream->read(scriptState()); 517 stream->read(getScriptState());
518 checkpoint.Call(2); 518 checkpoint.Call(2);
519 stream->enqueue("foo"); 519 stream->enqueue("foo");
520 stream->enqueue("bar"); 520 stream->enqueue("bar");
521 checkpoint.Call(3); 521 checkpoint.Call(3);
522 stream->read(scriptState()); 522 stream->read(getScriptState());
523 checkpoint.Call(4); 523 checkpoint.Call(4);
524 524
525 stream->error(DOMException::create(AbortError, "done")); 525 stream->error(DOMException::create(AbortError, "done"));
526 } 526 }
527 527
528 // Note: Detailed tests are on ReadableStreamReaderTest. 528 // Note: Detailed tests are on ReadableStreamReaderTest.
529 TEST_F(ReadableStreamTest, ReadableStreamReader) 529 TEST_F(ReadableStreamTest, ReadableStreamReader)
530 { 530 {
531 ScriptState::Scope scope(scriptState()); 531 ScriptState::Scope scope(getScriptState());
532 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", scriptState()->context()->Global(), isolate()); 532 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", getScriptState()->context()->Global(), isolate());
533 StringStream* stream = construct(); 533 StringStream* stream = construct();
534 ReadableStreamReader* reader = stream->getReader(scriptState()->executionCon text(), exceptionState); 534 ReadableStreamReader* reader = stream->getReader(getScriptState()->getExecut ionContext(), exceptionState);
535 535
536 ASSERT_TRUE(reader); 536 ASSERT_TRUE(reader);
537 EXPECT_FALSE(exceptionState.hadException()); 537 EXPECT_FALSE(exceptionState.hadException());
538 EXPECT_TRUE(reader->isActive()); 538 EXPECT_TRUE(reader->isActive());
539 EXPECT_TRUE(stream->isLockedTo(reader)); 539 EXPECT_TRUE(stream->isLockedTo(reader));
540 540
541 ReadableStreamReader* another = stream->getReader(scriptState()->executionCo ntext(), exceptionState); 541 ReadableStreamReader* another = stream->getReader(getScriptState()->getExecu tionContext(), exceptionState);
542 ASSERT_EQ(nullptr, another); 542 ASSERT_EQ(nullptr, another);
543 EXPECT_TRUE(exceptionState.hadException()); 543 EXPECT_TRUE(exceptionState.hadException());
544 EXPECT_TRUE(reader->isActive()); 544 EXPECT_TRUE(reader->isActive());
545 EXPECT_TRUE(stream->isLockedTo(reader)); 545 EXPECT_TRUE(stream->isLockedTo(reader));
546 } 546 }
547 547
548 TEST_F(ReadableStreamTest, GetClosedReader) 548 TEST_F(ReadableStreamTest, GetClosedReader)
549 { 549 {
550 ScriptState::Scope scope(scriptState()); 550 ScriptState::Scope scope(getScriptState());
551 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", scriptState()->context()->Global(), isolate()); 551 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", getScriptState()->context()->Global(), isolate());
552 StringStream* stream = construct(); 552 StringStream* stream = construct();
553 stream->close(); 553 stream->close();
554 ReadableStreamReader* reader = stream->getReader(scriptState()->executionCon text(), exceptionState); 554 ReadableStreamReader* reader = stream->getReader(getScriptState()->getExecut ionContext(), exceptionState);
555 555
556 ASSERT_TRUE(reader); 556 ASSERT_TRUE(reader);
557 EXPECT_FALSE(exceptionState.hadException()); 557 EXPECT_FALSE(exceptionState.hadException());
558 558
559 String onFulfilled, onRejected; 559 String onFulfilled, onRejected;
560 reader->closed(scriptState()).then(createCaptor(&onFulfilled), createCaptor( &onRejected)); 560 reader->closed(getScriptState()).then(createCaptor(&onFulfilled), createCapt or(&onRejected));
561 561
562 EXPECT_TRUE(reader->isActive()); 562 EXPECT_TRUE(reader->isActive());
563 EXPECT_TRUE(onFulfilled.isNull()); 563 EXPECT_TRUE(onFulfilled.isNull());
564 EXPECT_TRUE(onRejected.isNull()); 564 EXPECT_TRUE(onRejected.isNull());
565 565
566 v8::MicrotasksScope::PerformCheckpoint(isolate()); 566 v8::MicrotasksScope::PerformCheckpoint(isolate());
567 EXPECT_EQ("undefined", onFulfilled); 567 EXPECT_EQ("undefined", onFulfilled);
568 EXPECT_TRUE(onRejected.isNull()); 568 EXPECT_TRUE(onRejected.isNull());
569 } 569 }
570 570
571 TEST_F(ReadableStreamTest, GetErroredReader) 571 TEST_F(ReadableStreamTest, GetErroredReader)
572 { 572 {
573 ScriptState::Scope scope(scriptState()); 573 ScriptState::Scope scope(getScriptState());
574 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", scriptState()->context()->Global(), isolate()); 574 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", getScriptState()->context()->Global(), isolate());
575 StringStream* stream = construct(); 575 StringStream* stream = construct();
576 stream->error(DOMException::create(SyntaxError, "some error")); 576 stream->error(DOMException::create(SyntaxError, "some error"));
577 ReadableStreamReader* reader = stream->getReader(scriptState()->executionCon text(), exceptionState); 577 ReadableStreamReader* reader = stream->getReader(getScriptState()->getExecut ionContext(), exceptionState);
578 578
579 ASSERT_TRUE(reader); 579 ASSERT_TRUE(reader);
580 EXPECT_FALSE(exceptionState.hadException()); 580 EXPECT_FALSE(exceptionState.hadException());
581 581
582 String onFulfilled, onRejected; 582 String onFulfilled, onRejected;
583 reader->closed(scriptState()).then(createCaptor(&onFulfilled), createCaptor( &onRejected)); 583 reader->closed(getScriptState()).then(createCaptor(&onFulfilled), createCapt or(&onRejected));
584 584
585 EXPECT_TRUE(reader->isActive()); 585 EXPECT_TRUE(reader->isActive());
586 EXPECT_TRUE(onFulfilled.isNull()); 586 EXPECT_TRUE(onFulfilled.isNull());
587 EXPECT_TRUE(onRejected.isNull()); 587 EXPECT_TRUE(onRejected.isNull());
588 588
589 v8::MicrotasksScope::PerformCheckpoint(isolate()); 589 v8::MicrotasksScope::PerformCheckpoint(isolate());
590 EXPECT_TRUE(onFulfilled.isNull()); 590 EXPECT_TRUE(onFulfilled.isNull());
591 EXPECT_EQ("SyntaxError: some error", onRejected); 591 EXPECT_EQ("SyntaxError: some error", onRejected);
592 } 592 }
593 593
594 TEST_F(ReadableStreamTest, StrictStrategy) 594 TEST_F(ReadableStreamTest, StrictStrategy)
595 { 595 {
596 ScriptState::Scope scope(scriptState()); 596 ScriptState::Scope scope(getScriptState());
597 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", scriptState()->context()->Global(), isolate()); 597 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property ", "interface", getScriptState()->context()->Global(), isolate());
598 Checkpoint checkpoint; 598 Checkpoint checkpoint;
599 { 599 {
600 InSequence s; 600 InSequence s;
601 EXPECT_CALL(checkpoint, Call(0)); 601 EXPECT_CALL(checkpoint, Call(0));
602 EXPECT_CALL(checkpoint, Call(1)); 602 EXPECT_CALL(checkpoint, Call(1));
603 EXPECT_CALL(*m_underlyingSource, pullSource()); 603 EXPECT_CALL(*m_underlyingSource, pullSource());
604 EXPECT_CALL(checkpoint, Call(2)); 604 EXPECT_CALL(checkpoint, Call(2));
605 EXPECT_CALL(checkpoint, Call(3)); 605 EXPECT_CALL(checkpoint, Call(3));
606 EXPECT_CALL(*m_underlyingSource, pullSource()); 606 EXPECT_CALL(*m_underlyingSource, pullSource());
607 EXPECT_CALL(checkpoint, Call(4)); 607 EXPECT_CALL(checkpoint, Call(4));
608 EXPECT_CALL(checkpoint, Call(5)); 608 EXPECT_CALL(checkpoint, Call(5));
609 EXPECT_CALL(checkpoint, Call(6)); 609 EXPECT_CALL(checkpoint, Call(6));
610 EXPECT_CALL(checkpoint, Call(7)); 610 EXPECT_CALL(checkpoint, Call(7));
611 EXPECT_CALL(checkpoint, Call(8)); 611 EXPECT_CALL(checkpoint, Call(8));
612 EXPECT_CALL(checkpoint, Call(9)); 612 EXPECT_CALL(checkpoint, Call(9));
613 EXPECT_CALL(*m_underlyingSource, pullSource()); 613 EXPECT_CALL(*m_underlyingSource, pullSource());
614 } 614 }
615 StringStream* stream = new StringStream(m_underlyingSource, new StringStream ::StrictStrategy); 615 StringStream* stream = new StringStream(m_underlyingSource, new StringStream ::StrictStrategy);
616 ReadableStreamReader* reader = stream->getReader(scriptState()->executionCon text(), exceptionState); 616 ReadableStreamReader* reader = stream->getReader(getScriptState()->getExecut ionContext(), exceptionState);
617 617
618 checkpoint.Call(0); 618 checkpoint.Call(0);
619 stream->didSourceStart(); 619 stream->didSourceStart();
620 620
621 checkpoint.Call(1); 621 checkpoint.Call(1);
622 EXPECT_FALSE(stream->isPulling()); 622 EXPECT_FALSE(stream->isPulling());
623 reader->read(scriptState()); 623 reader->read(getScriptState());
624 EXPECT_TRUE(stream->isPulling()); 624 EXPECT_TRUE(stream->isPulling());
625 checkpoint.Call(2); 625 checkpoint.Call(2);
626 stream->enqueue("hello"); 626 stream->enqueue("hello");
627 EXPECT_FALSE(stream->isPulling()); 627 EXPECT_FALSE(stream->isPulling());
628 checkpoint.Call(3); 628 checkpoint.Call(3);
629 reader->read(scriptState()); 629 reader->read(getScriptState());
630 EXPECT_TRUE(stream->isPulling()); 630 EXPECT_TRUE(stream->isPulling());
631 checkpoint.Call(4); 631 checkpoint.Call(4);
632 reader->read(scriptState()); 632 reader->read(getScriptState());
633 EXPECT_TRUE(stream->isPulling()); 633 EXPECT_TRUE(stream->isPulling());
634 checkpoint.Call(5); 634 checkpoint.Call(5);
635 stream->enqueue("hello"); 635 stream->enqueue("hello");
636 EXPECT_FALSE(stream->isPulling()); 636 EXPECT_FALSE(stream->isPulling());
637 checkpoint.Call(6); 637 checkpoint.Call(6);
638 stream->enqueue("hello"); 638 stream->enqueue("hello");
639 EXPECT_FALSE(stream->isPulling()); 639 EXPECT_FALSE(stream->isPulling());
640 checkpoint.Call(7); 640 checkpoint.Call(7);
641 stream->enqueue("hello"); 641 stream->enqueue("hello");
642 EXPECT_FALSE(stream->isPulling()); 642 EXPECT_FALSE(stream->isPulling());
643 checkpoint.Call(8); 643 checkpoint.Call(8);
644 reader->read(scriptState()); 644 reader->read(getScriptState());
645 EXPECT_FALSE(stream->isPulling()); 645 EXPECT_FALSE(stream->isPulling());
646 checkpoint.Call(9); 646 checkpoint.Call(9);
647 reader->read(scriptState()); 647 reader->read(getScriptState());
648 EXPECT_TRUE(stream->isPulling()); 648 EXPECT_TRUE(stream->isPulling());
649 649
650 stream->error(DOMException::create(AbortError, "done")); 650 stream->error(DOMException::create(AbortError, "done"));
651 } 651 }
652 652
653 } // namespace blink 653 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698