OLD | NEW |
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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(getScriptState()); | 305 stream->read(getScriptState()); |
306 | 306 |
307 isolate()->RunMicrotasks(); | 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(getScriptState()); | 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()); |
(...skipping 10 matching lines...) Expand all Loading... |
328 | 328 |
329 EXPECT_FALSE(stream->isDisturbed()); | 329 EXPECT_FALSE(stream->isDisturbed()); |
330 ScriptPromise promise = stream->cancel(getScriptState(), 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 isolate()->RunMicrotasks(); | 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(getScriptState()); | 345 ScriptState::Scope scope(getScriptState()); |
346 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property
", "interface", getScriptState()->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(getScriptState(), 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 isolate()->RunMicrotasks(); | 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(getScriptState()); | 368 ScriptState::Scope scope(getScriptState()); |
369 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property
", "interface", getScriptState()->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; |
(...skipping 13 matching lines...) Expand all Loading... |
385 ScriptPromise cancelResult = stream->cancel(getScriptState(), 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 isolate()->RunMicrotasks(); | 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(getScriptState()); | 402 ScriptState::Scope scope(getScriptState()); |
403 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property
", "interface", getScriptState()->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(getScriptState()->getExecut
ionContext(), 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(getScriptState(), ScriptValue(getScriptState(), v8::Undefined
(isolate()))).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 isolate()->RunMicrotasks(); | 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(getScriptState()); | 429 ScriptState::Scope scope(getScriptState()); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(getScriptState()).then(createCaptor(&onFulfilled), createCapt
or(&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 isolate()->RunMicrotasks(); | 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(getScriptState()); | 573 ScriptState::Scope scope(getScriptState()); |
574 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property
", "interface", getScriptState()->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(getScriptState()->getExecut
ionContext(), 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(getScriptState()).then(createCaptor(&onFulfilled), createCapt
or(&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 isolate()->RunMicrotasks(); | 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(getScriptState()); | 596 ScriptState::Scope scope(getScriptState()); |
597 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property
", "interface", getScriptState()->context()->Global(), isolate()); | 597 ExceptionState exceptionState(ExceptionState::ConstructionContext, "property
", "interface", getScriptState()->context()->Global(), isolate()); |
598 Checkpoint checkpoint; | 598 Checkpoint checkpoint; |
599 { | 599 { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 reader->read(getScriptState()); | 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(getScriptState()); | 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 |
OLD | NEW |