| 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/streams/ReadableStream.h" | 6 #include "core/streams/ReadableStream.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
| 9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 10 #include "bindings/core/v8/ScriptState.h" | 10 #include "bindings/core/v8/ScriptState.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 *m_value = toCoreString(value.v8Value()->ToString()); | 42 *m_value = toCoreString(value.v8Value()->ToString()); |
| 43 return value; | 43 return value; |
| 44 } | 44 } |
| 45 | 45 |
| 46 private: | 46 private: |
| 47 StringCapturingFunction(v8::Isolate* isolate, String* value) : ScriptFunctio
n(isolate), m_value(value) { } | 47 StringCapturingFunction(v8::Isolate* isolate, String* value) : ScriptFunctio
n(isolate), m_value(value) { } |
| 48 | 48 |
| 49 String* m_value; | 49 String* m_value; |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 class MockUnderlyingSource : public UnderlyingSource { | 52 class MockUnderlyingSource : public GarbageCollectedFinalized<MockUnderlyingSour
ce>, public UnderlyingSource { |
| 53 USING_GARBAGE_COLLECTED_MIXIN(MockUnderlyingSource); |
| 53 public: | 54 public: |
| 54 virtual ~MockUnderlyingSource() { } | 55 virtual ~MockUnderlyingSource() { } |
| 55 | 56 |
| 56 MOCK_METHOD1(startSource, ScriptPromise(ExceptionState*)); | |
| 57 MOCK_METHOD0(pullSource, void()); | 57 MOCK_METHOD0(pullSource, void()); |
| 58 MOCK_METHOD2(cancelSource, ScriptPromise(ScriptState*, ScriptValue)); | 58 MOCK_METHOD2(cancelSource, ScriptPromise(ScriptState*, ScriptValue)); |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 class ThrowError { | 61 class ThrowError { |
| 62 public: | 62 public: |
| 63 explicit ThrowError(const String& message) | 63 explicit ThrowError(const String& message) |
| 64 : m_message(message) { } | 64 : m_message(message) { } |
| 65 | 65 |
| 66 void operator()(ExceptionState* exceptionState) | 66 void operator()(ExceptionState* exceptionState) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 89 } | 89 } |
| 90 | 90 |
| 91 ScriptState* scriptState() { return ScriptState::forMainWorld(m_page->docume
nt().frame()); } | 91 ScriptState* scriptState() { return ScriptState::forMainWorld(m_page->docume
nt().frame()); } |
| 92 v8::Isolate* isolate() { return scriptState()->isolate(); } | 92 v8::Isolate* isolate() { return scriptState()->isolate(); } |
| 93 | 93 |
| 94 PassOwnPtr<StringCapturingFunction> createCaptor(String* value) | 94 PassOwnPtr<StringCapturingFunction> createCaptor(String* value) |
| 95 { | 95 { |
| 96 return StringCapturingFunction::create(isolate(), value); | 96 return StringCapturingFunction::create(isolate(), value); |
| 97 } | 97 } |
| 98 | 98 |
| 99 // Note: This function calls RunMicrotasks. | |
| 100 StringStream* construct() | 99 StringStream* construct() |
| 101 { | 100 { |
| 102 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(s
criptState()); | 101 StringStream* stream = new StringStream(scriptState()->executionContext(
), m_underlyingSource); |
| 103 ScriptPromise promise = resolver->promise(); | 102 stream->didSourceStart(); |
| 104 resolver->resolve(); | |
| 105 EXPECT_CALL(*m_underlyingSource, startSource(&m_exceptionState)).WillOnc
e(Return(promise)); | |
| 106 | |
| 107 StringStream* stream = new StringStream(scriptState(), m_underlyingSourc
e, &m_exceptionState); | |
| 108 isolate()->RunMicrotasks(); | |
| 109 return stream; | 103 return stream; |
| 110 } | 104 } |
| 111 | 105 |
| 112 OwnPtr<DummyPageHolder> m_page; | 106 OwnPtr<DummyPageHolder> m_page; |
| 113 ScriptState::Scope m_scope; | 107 ScriptState::Scope m_scope; |
| 114 Persistent<MockUnderlyingSource> m_underlyingSource; | 108 Persistent<MockUnderlyingSource> m_underlyingSource; |
| 115 ExceptionState m_exceptionState; | 109 ExceptionState m_exceptionState; |
| 116 }; | 110 }; |
| 117 | 111 |
| 118 TEST_F(ReadableStreamTest, Construct) | 112 TEST_F(ReadableStreamTest, Start) |
| 119 { | 113 { |
| 120 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState()); | 114 StringStream* stream = new StringStream(scriptState()->executionContext(), m
_underlyingSource); |
| 121 ScriptPromise promise = resolver->promise(); | |
| 122 { | |
| 123 InSequence s; | |
| 124 EXPECT_CALL(*m_underlyingSource, startSource(&m_exceptionState)).WillOnc
e(Return(promise)); | |
| 125 } | |
| 126 StringStream* stream = new StringStream(scriptState(), m_underlyingSource, &
m_exceptionState); | |
| 127 EXPECT_FALSE(m_exceptionState.hadException()); | 115 EXPECT_FALSE(m_exceptionState.hadException()); |
| 128 EXPECT_FALSE(stream->isStarted()); | 116 EXPECT_FALSE(stream->isStarted()); |
| 129 EXPECT_FALSE(stream->isDraining()); | 117 EXPECT_FALSE(stream->isDraining()); |
| 130 EXPECT_FALSE(stream->isPulling()); | 118 EXPECT_FALSE(stream->isPulling()); |
| 131 EXPECT_EQ(stream->state(), ReadableStream::Waiting); | 119 EXPECT_EQ(stream->state(), ReadableStream::Waiting); |
| 132 | 120 |
| 133 isolate()->RunMicrotasks(); | 121 stream->didSourceStart(); |
| 134 | |
| 135 EXPECT_FALSE(stream->isStarted()); | |
| 136 | |
| 137 resolver->resolve(); | |
| 138 isolate()->RunMicrotasks(); | |
| 139 | 122 |
| 140 EXPECT_TRUE(stream->isStarted()); | 123 EXPECT_TRUE(stream->isStarted()); |
| 141 EXPECT_FALSE(stream->isDraining()); | 124 EXPECT_FALSE(stream->isDraining()); |
| 142 EXPECT_FALSE(stream->isPulling()); | 125 EXPECT_FALSE(stream->isPulling()); |
| 143 EXPECT_EQ(stream->state(), ReadableStream::Waiting); | 126 EXPECT_EQ(stream->state(), ReadableStream::Waiting); |
| 144 } | 127 } |
| 145 | 128 |
| 146 TEST_F(ReadableStreamTest, ConstructError) | 129 TEST_F(ReadableStreamTest, StartFail) |
| 147 { | 130 { |
| 148 { | 131 StringStream* stream = new StringStream(scriptState()->executionContext(), m
_underlyingSource); |
| 149 InSequence s; | |
| 150 EXPECT_CALL(*m_underlyingSource, startSource(&m_exceptionState)) | |
| 151 .WillOnce(DoAll(Invoke(ThrowError("hello")), Return(ScriptPromise())
)); | |
| 152 } | |
| 153 new StringStream(scriptState(), m_underlyingSource, &m_exceptionState); | |
| 154 EXPECT_TRUE(m_exceptionState.hadException()); | |
| 155 } | |
| 156 | |
| 157 TEST_F(ReadableStreamTest, StartFailAsynchronously) | |
| 158 { | |
| 159 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState()); | |
| 160 ScriptPromise promise = resolver->promise(); | |
| 161 { | |
| 162 InSequence s; | |
| 163 EXPECT_CALL(*m_underlyingSource, startSource(&m_exceptionState)).WillOnc
e(Return(promise)); | |
| 164 } | |
| 165 StringStream* stream = new StringStream(scriptState(), m_underlyingSource, &
m_exceptionState); | |
| 166 EXPECT_FALSE(m_exceptionState.hadException()); | 132 EXPECT_FALSE(m_exceptionState.hadException()); |
| 167 EXPECT_FALSE(stream->isStarted()); | 133 EXPECT_FALSE(stream->isStarted()); |
| 168 EXPECT_FALSE(stream->isDraining()); | 134 EXPECT_FALSE(stream->isDraining()); |
| 169 EXPECT_FALSE(stream->isPulling()); | 135 EXPECT_FALSE(stream->isPulling()); |
| 170 EXPECT_EQ(stream->state(), ReadableStream::Waiting); | 136 EXPECT_EQ(stream->state(), ReadableStream::Waiting); |
| 171 | 137 |
| 172 isolate()->RunMicrotasks(); | 138 stream->error(DOMException::create(NotFoundError)); |
| 173 | 139 |
| 174 EXPECT_FALSE(stream->isStarted()); | 140 EXPECT_FALSE(stream->isStarted()); |
| 175 EXPECT_FALSE(stream->isDraining()); | 141 EXPECT_FALSE(stream->isDraining()); |
| 176 EXPECT_FALSE(stream->isPulling()); | |
| 177 EXPECT_EQ(stream->state(), ReadableStream::Waiting); | |
| 178 | |
| 179 resolver->reject(); | |
| 180 stream->error(DOMException::create(NotFoundError)); | |
| 181 isolate()->RunMicrotasks(); | |
| 182 | |
| 183 EXPECT_FALSE(stream->isStarted()); | |
| 184 EXPECT_FALSE(stream->isDraining()); | |
| 185 EXPECT_FALSE(stream->isPulling()); | 142 EXPECT_FALSE(stream->isPulling()); |
| 186 EXPECT_EQ(stream->state(), ReadableStream::Errored); | 143 EXPECT_EQ(stream->state(), ReadableStream::Errored); |
| 187 } | 144 } |
| 188 | 145 |
| 189 TEST_F(ReadableStreamTest, WaitOnWaiting) | 146 TEST_F(ReadableStreamTest, WaitOnWaiting) |
| 190 { | 147 { |
| 191 StringStream* stream = construct(); | 148 StringStream* stream = construct(); |
| 192 Checkpoint checkpoint; | 149 Checkpoint checkpoint; |
| 193 | 150 |
| 194 EXPECT_EQ(ReadableStream::Waiting, stream->state()); | 151 EXPECT_EQ(ReadableStream::Waiting, stream->state()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 207 ScriptPromise q = stream->wait(scriptState()); | 164 ScriptPromise q = stream->wait(scriptState()); |
| 208 checkpoint.Call(1); | 165 checkpoint.Call(1); |
| 209 | 166 |
| 210 EXPECT_EQ(ReadableStream::Waiting, stream->state()); | 167 EXPECT_EQ(ReadableStream::Waiting, stream->state()); |
| 211 EXPECT_TRUE(stream->isPulling()); | 168 EXPECT_TRUE(stream->isPulling()); |
| 212 EXPECT_EQ(q, p); | 169 EXPECT_EQ(q, p); |
| 213 } | 170 } |
| 214 | 171 |
| 215 TEST_F(ReadableStreamTest, WaitDuringStarting) | 172 TEST_F(ReadableStreamTest, WaitDuringStarting) |
| 216 { | 173 { |
| 217 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState()); | 174 StringStream* stream = new StringStream(scriptState()->executionContext(), m
_underlyingSource); |
| 218 ScriptPromise promise = resolver->promise(); | |
| 219 { | |
| 220 InSequence s; | |
| 221 EXPECT_CALL(*m_underlyingSource, startSource(&m_exceptionState)).WillOnc
e(Return(promise)); | |
| 222 } | |
| 223 StringStream* stream = new StringStream(scriptState(), m_underlyingSource, &
m_exceptionState); | |
| 224 Checkpoint checkpoint; | 175 Checkpoint checkpoint; |
| 225 | 176 |
| 226 EXPECT_EQ(ReadableStream::Waiting, stream->state()); | 177 EXPECT_EQ(ReadableStream::Waiting, stream->state()); |
| 227 EXPECT_FALSE(stream->isStarted()); | 178 EXPECT_FALSE(stream->isStarted()); |
| 228 EXPECT_FALSE(stream->isPulling()); | 179 EXPECT_FALSE(stream->isPulling()); |
| 229 | 180 |
| 230 { | 181 { |
| 231 InSequence s; | 182 InSequence s; |
| 232 EXPECT_CALL(checkpoint, Call(0)); | 183 EXPECT_CALL(checkpoint, Call(0)); |
| 233 EXPECT_CALL(checkpoint, Call(1)); | 184 EXPECT_CALL(checkpoint, Call(1)); |
| 234 EXPECT_CALL(*m_underlyingSource, pullSource()).Times(1); | 185 EXPECT_CALL(*m_underlyingSource, pullSource()).Times(1); |
| 235 } | 186 } |
| 236 | 187 |
| 237 checkpoint.Call(0); | 188 checkpoint.Call(0); |
| 238 stream->wait(scriptState()); | 189 stream->wait(scriptState()); |
| 239 checkpoint.Call(1); | 190 checkpoint.Call(1); |
| 240 | 191 |
| 241 EXPECT_TRUE(stream->isPulling()); | 192 EXPECT_TRUE(stream->isPulling()); |
| 242 | 193 |
| 243 resolver->resolve(); | 194 stream->didSourceStart(); |
| 244 isolate()->RunMicrotasks(); | |
| 245 | 195 |
| 246 EXPECT_EQ(ReadableStream::Waiting, stream->state()); | 196 EXPECT_EQ(ReadableStream::Waiting, stream->state()); |
| 247 EXPECT_TRUE(stream->isPulling()); | 197 EXPECT_TRUE(stream->isPulling()); |
| 248 } | 198 } |
| 249 | 199 |
| 250 TEST_F(ReadableStreamTest, WaitAndError) | 200 TEST_F(ReadableStreamTest, WaitAndError) |
| 251 { | 201 { |
| 252 StringStream* stream = construct(); | 202 StringStream* stream = construct(); |
| 253 String onFulfilled, onRejected; | 203 String onFulfilled, onRejected; |
| 254 | 204 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 EXPECT_TRUE(onFulfilled.isNull()); | 385 EXPECT_TRUE(onFulfilled.isNull()); |
| 436 EXPECT_EQ("NotFoundError: error", onRejected); | 386 EXPECT_EQ("NotFoundError: error", onRejected); |
| 437 } | 387 } |
| 438 | 388 |
| 439 TEST_F(ReadableStreamTest, ReadWhenWaiting) | 389 TEST_F(ReadableStreamTest, ReadWhenWaiting) |
| 440 { | 390 { |
| 441 StringStream* stream = construct(); | 391 StringStream* stream = construct(); |
| 442 EXPECT_EQ(ReadableStream::Waiting, stream->state()); | 392 EXPECT_EQ(ReadableStream::Waiting, stream->state()); |
| 443 EXPECT_FALSE(m_exceptionState.hadException()); | 393 EXPECT_FALSE(m_exceptionState.hadException()); |
| 444 | 394 |
| 445 stream->read(scriptState(), &m_exceptionState); | 395 stream->read(scriptState(), m_exceptionState); |
| 446 EXPECT_EQ(ReadableStream::Waiting, stream->state()); | 396 EXPECT_EQ(ReadableStream::Waiting, stream->state()); |
| 447 EXPECT_TRUE(m_exceptionState.hadException()); | 397 EXPECT_TRUE(m_exceptionState.hadException()); |
| 448 EXPECT_EQ(V8TypeError, m_exceptionState.code()); | 398 EXPECT_EQ(V8TypeError, m_exceptionState.code()); |
| 449 EXPECT_EQ("read is called while state is waiting", m_exceptionState.message(
)); | 399 EXPECT_EQ("read is called while state is waiting", m_exceptionState.message(
)); |
| 450 } | 400 } |
| 451 | 401 |
| 452 TEST_F(ReadableStreamTest, ReadWhenClosed) | 402 TEST_F(ReadableStreamTest, ReadWhenClosed) |
| 453 { | 403 { |
| 454 StringStream* stream = construct(); | 404 StringStream* stream = construct(); |
| 455 stream->close(); | 405 stream->close(); |
| 456 | 406 |
| 457 EXPECT_EQ(ReadableStream::Closed, stream->state()); | 407 EXPECT_EQ(ReadableStream::Closed, stream->state()); |
| 458 EXPECT_FALSE(m_exceptionState.hadException()); | 408 EXPECT_FALSE(m_exceptionState.hadException()); |
| 459 | 409 |
| 460 stream->read(scriptState(), &m_exceptionState); | 410 stream->read(scriptState(), m_exceptionState); |
| 461 EXPECT_EQ(ReadableStream::Closed, stream->state()); | 411 EXPECT_EQ(ReadableStream::Closed, stream->state()); |
| 462 EXPECT_TRUE(m_exceptionState.hadException()); | 412 EXPECT_TRUE(m_exceptionState.hadException()); |
| 463 EXPECT_EQ(V8TypeError, m_exceptionState.code()); | 413 EXPECT_EQ(V8TypeError, m_exceptionState.code()); |
| 464 EXPECT_EQ("read is called while state is closed", m_exceptionState.message()
); | 414 EXPECT_EQ("read is called while state is closed", m_exceptionState.message()
); |
| 465 } | 415 } |
| 466 | 416 |
| 467 TEST_F(ReadableStreamTest, ReadWhenErrored) | 417 TEST_F(ReadableStreamTest, ReadWhenErrored) |
| 468 { | 418 { |
| 469 // DOMException values specified in the spec are different from enum values | 419 // DOMException values specified in the spec are different from enum values |
| 470 // defined in ExceptionCode.h. | 420 // defined in ExceptionCode.h. |
| 471 const int notFoundExceptionCode = 8; | 421 const int notFoundExceptionCode = 8; |
| 472 StringStream* stream = construct(); | 422 StringStream* stream = construct(); |
| 473 stream->error(DOMException::create(NotFoundError, "error")); | 423 stream->error(DOMException::create(NotFoundError, "error")); |
| 474 | 424 |
| 475 EXPECT_EQ(ReadableStream::Errored, stream->state()); | 425 EXPECT_EQ(ReadableStream::Errored, stream->state()); |
| 476 EXPECT_FALSE(m_exceptionState.hadException()); | 426 EXPECT_FALSE(m_exceptionState.hadException()); |
| 477 | 427 |
| 478 stream->read(scriptState(), &m_exceptionState); | 428 stream->read(scriptState(), m_exceptionState); |
| 479 EXPECT_EQ(ReadableStream::Errored, stream->state()); | 429 EXPECT_EQ(ReadableStream::Errored, stream->state()); |
| 480 EXPECT_TRUE(m_exceptionState.hadException()); | 430 EXPECT_TRUE(m_exceptionState.hadException()); |
| 481 EXPECT_EQ(notFoundExceptionCode, m_exceptionState.code()); | 431 EXPECT_EQ(notFoundExceptionCode, m_exceptionState.code()); |
| 482 EXPECT_EQ("error", m_exceptionState.message()); | 432 EXPECT_EQ("error", m_exceptionState.message()); |
| 483 } | 433 } |
| 484 | 434 |
| 485 TEST_F(ReadableStreamTest, EnqueuedAndRead) | 435 TEST_F(ReadableStreamTest, EnqueuedAndRead) |
| 486 { | 436 { |
| 487 StringStream* stream = construct(); | 437 StringStream* stream = construct(); |
| 488 String onFulfilled, onRejected; | 438 String onFulfilled, onRejected; |
| 489 Checkpoint checkpoint; | 439 Checkpoint checkpoint; |
| 490 | 440 |
| 491 { | 441 { |
| 492 InSequence s; | 442 InSequence s; |
| 493 EXPECT_CALL(checkpoint, Call(0)); | 443 EXPECT_CALL(checkpoint, Call(0)); |
| 494 EXPECT_CALL(*m_underlyingSource, pullSource()).Times(1); | 444 EXPECT_CALL(*m_underlyingSource, pullSource()).Times(1); |
| 495 EXPECT_CALL(checkpoint, Call(1)); | 445 EXPECT_CALL(checkpoint, Call(1)); |
| 496 } | 446 } |
| 497 | 447 |
| 498 stream->enqueue("hello"); | 448 stream->enqueue("hello"); |
| 499 ScriptPromise promise = stream->wait(scriptState()); | 449 ScriptPromise promise = stream->wait(scriptState()); |
| 500 EXPECT_EQ(ReadableStream::Readable, stream->state()); | 450 EXPECT_EQ(ReadableStream::Readable, stream->state()); |
| 501 EXPECT_FALSE(stream->isPulling()); | 451 EXPECT_FALSE(stream->isPulling()); |
| 502 | 452 |
| 503 checkpoint.Call(0); | 453 checkpoint.Call(0); |
| 504 String chunk; | 454 String chunk; |
| 505 EXPECT_TRUE(stream->read(scriptState(), &m_exceptionState).toString(chunk)); | 455 EXPECT_TRUE(stream->read(scriptState(), m_exceptionState).toString(chunk)); |
| 506 checkpoint.Call(1); | 456 checkpoint.Call(1); |
| 507 EXPECT_FALSE(m_exceptionState.hadException()); | 457 EXPECT_FALSE(m_exceptionState.hadException()); |
| 508 EXPECT_EQ("hello", chunk); | 458 EXPECT_EQ("hello", chunk); |
| 509 EXPECT_EQ(ReadableStream::Waiting, stream->state()); | 459 EXPECT_EQ(ReadableStream::Waiting, stream->state()); |
| 510 EXPECT_TRUE(stream->isPulling()); | 460 EXPECT_TRUE(stream->isPulling()); |
| 511 EXPECT_FALSE(stream->isDraining()); | 461 EXPECT_FALSE(stream->isDraining()); |
| 512 | 462 |
| 513 ScriptPromise newPromise = stream->wait(scriptState()); | 463 ScriptPromise newPromise = stream->wait(scriptState()); |
| 514 newPromise.then(createCaptor(&onFulfilled), createCaptor(&onRejected)); | 464 newPromise.then(createCaptor(&onFulfilled), createCaptor(&onRejected)); |
| 515 isolate()->RunMicrotasks(); | 465 isolate()->RunMicrotasks(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 530 } | 480 } |
| 531 | 481 |
| 532 EXPECT_TRUE(stream->enqueue("hello")); | 482 EXPECT_TRUE(stream->enqueue("hello")); |
| 533 EXPECT_TRUE(stream->enqueue("bye")); | 483 EXPECT_TRUE(stream->enqueue("bye")); |
| 534 ScriptPromise promise = stream->wait(scriptState()); | 484 ScriptPromise promise = stream->wait(scriptState()); |
| 535 EXPECT_EQ(ReadableStream::Readable, stream->state()); | 485 EXPECT_EQ(ReadableStream::Readable, stream->state()); |
| 536 EXPECT_FALSE(stream->isPulling()); | 486 EXPECT_FALSE(stream->isPulling()); |
| 537 | 487 |
| 538 checkpoint.Call(0); | 488 checkpoint.Call(0); |
| 539 String chunk; | 489 String chunk; |
| 540 EXPECT_TRUE(stream->read(scriptState(), &m_exceptionState).toString(chunk)); | 490 EXPECT_TRUE(stream->read(scriptState(), m_exceptionState).toString(chunk)); |
| 541 checkpoint.Call(1); | 491 checkpoint.Call(1); |
| 542 EXPECT_FALSE(m_exceptionState.hadException()); | 492 EXPECT_FALSE(m_exceptionState.hadException()); |
| 543 EXPECT_EQ("hello", chunk); | 493 EXPECT_EQ("hello", chunk); |
| 544 EXPECT_EQ(ReadableStream::Readable, stream->state()); | 494 EXPECT_EQ(ReadableStream::Readable, stream->state()); |
| 545 EXPECT_FALSE(stream->isPulling()); | 495 EXPECT_FALSE(stream->isPulling()); |
| 546 EXPECT_FALSE(stream->isDraining()); | 496 EXPECT_FALSE(stream->isDraining()); |
| 547 | 497 |
| 548 ScriptPromise newPromise = stream->wait(scriptState()); | 498 ScriptPromise newPromise = stream->wait(scriptState()); |
| 549 EXPECT_EQ(promise, newPromise); | 499 EXPECT_EQ(promise, newPromise); |
| 550 } | 500 } |
| 551 | 501 |
| 552 TEST_F(ReadableStreamTest, CloseWhenReadable) | 502 TEST_F(ReadableStreamTest, CloseWhenReadable) |
| 553 { | 503 { |
| 554 StringStream* stream = construct(); | 504 StringStream* stream = construct(); |
| 555 String onWaitFulfilled, onWaitRejected; | 505 String onWaitFulfilled, onWaitRejected; |
| 556 String onClosedFulfilled, onClosedRejected; | 506 String onClosedFulfilled, onClosedRejected; |
| 557 | 507 |
| 558 stream->closed(scriptState()).then(createCaptor(&onClosedFulfilled), createC
aptor(&onClosedRejected)); | 508 stream->closed(scriptState()).then(createCaptor(&onClosedFulfilled), createC
aptor(&onClosedRejected)); |
| 559 EXPECT_TRUE(stream->enqueue("hello")); | 509 EXPECT_TRUE(stream->enqueue("hello")); |
| 560 EXPECT_TRUE(stream->enqueue("bye")); | 510 EXPECT_TRUE(stream->enqueue("bye")); |
| 561 stream->close(); | 511 stream->close(); |
| 562 EXPECT_FALSE(stream->enqueue("should be ignored")); | 512 EXPECT_FALSE(stream->enqueue("should be ignored")); |
| 563 | 513 |
| 564 ScriptPromise promise = stream->wait(scriptState()); | 514 ScriptPromise promise = stream->wait(scriptState()); |
| 565 EXPECT_EQ(ReadableStream::Readable, stream->state()); | 515 EXPECT_EQ(ReadableStream::Readable, stream->state()); |
| 566 EXPECT_FALSE(stream->isPulling()); | 516 EXPECT_FALSE(stream->isPulling()); |
| 567 EXPECT_TRUE(stream->isDraining()); | 517 EXPECT_TRUE(stream->isDraining()); |
| 568 | 518 |
| 569 String chunk; | 519 String chunk; |
| 570 EXPECT_TRUE(stream->read(scriptState(), &m_exceptionState).toString(chunk)); | 520 EXPECT_TRUE(stream->read(scriptState(), m_exceptionState).toString(chunk)); |
| 571 EXPECT_EQ("hello", chunk); | 521 EXPECT_EQ("hello", chunk); |
| 572 EXPECT_EQ(promise, stream->wait(scriptState())); | 522 EXPECT_EQ(promise, stream->wait(scriptState())); |
| 573 | 523 |
| 574 isolate()->RunMicrotasks(); | 524 isolate()->RunMicrotasks(); |
| 575 | 525 |
| 576 EXPECT_EQ(ReadableStream::Readable, stream->state()); | 526 EXPECT_EQ(ReadableStream::Readable, stream->state()); |
| 577 EXPECT_FALSE(stream->isPulling()); | 527 EXPECT_FALSE(stream->isPulling()); |
| 578 EXPECT_TRUE(stream->isDraining()); | 528 EXPECT_TRUE(stream->isDraining()); |
| 579 | 529 |
| 580 EXPECT_TRUE(stream->read(scriptState(), &m_exceptionState).toString(chunk)); | 530 EXPECT_TRUE(stream->read(scriptState(), m_exceptionState).toString(chunk)); |
| 581 EXPECT_EQ("bye", chunk); | 531 EXPECT_EQ("bye", chunk); |
| 582 EXPECT_FALSE(m_exceptionState.hadException()); | 532 EXPECT_FALSE(m_exceptionState.hadException()); |
| 583 | 533 |
| 584 EXPECT_NE(promise, stream->wait(scriptState())); | 534 EXPECT_NE(promise, stream->wait(scriptState())); |
| 585 stream->wait(scriptState()).then(createCaptor(&onWaitFulfilled), createCapto
r(&onWaitRejected)); | 535 stream->wait(scriptState()).then(createCaptor(&onWaitFulfilled), createCapto
r(&onWaitRejected)); |
| 586 | 536 |
| 587 EXPECT_EQ(ReadableStream::Closed, stream->state()); | 537 EXPECT_EQ(ReadableStream::Closed, stream->state()); |
| 588 EXPECT_FALSE(stream->isPulling()); | 538 EXPECT_FALSE(stream->isPulling()); |
| 589 EXPECT_TRUE(stream->isDraining()); | 539 EXPECT_TRUE(stream->isDraining()); |
| 590 | 540 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 EXPECT_TRUE(onRejected.isNull()); | 641 EXPECT_TRUE(onRejected.isNull()); |
| 692 | 642 |
| 693 isolate()->RunMicrotasks(); | 643 isolate()->RunMicrotasks(); |
| 694 EXPECT_EQ("undefined", onFulfilled); | 644 EXPECT_EQ("undefined", onFulfilled); |
| 695 EXPECT_TRUE(onRejected.isNull()); | 645 EXPECT_TRUE(onRejected.isNull()); |
| 696 } | 646 } |
| 697 | 647 |
| 698 TEST_F(ReadableStreamTest, ReadableArrayBufferCompileTest) | 648 TEST_F(ReadableStreamTest, ReadableArrayBufferCompileTest) |
| 699 { | 649 { |
| 700 // This test tests if ReadableStreamImpl<ArrayBuffer> can be instantiated. | 650 // This test tests if ReadableStreamImpl<ArrayBuffer> can be instantiated. |
| 701 { | 651 new ReadableStreamImpl<ReadableStreamChunkTypeTraits<ArrayBuffer> >(scriptSt
ate()->executionContext(), m_underlyingSource); |
| 702 InSequence s; | |
| 703 EXPECT_CALL(*m_underlyingSource, startSource(&m_exceptionState)).WillOnc
e(Return(ScriptPromise())); | |
| 704 } | |
| 705 | |
| 706 new ReadableStreamImpl<ReadableStreamChunkTypeTraits<ArrayBuffer> >(scriptSt
ate(), m_underlyingSource, &m_exceptionState); | |
| 707 } | 652 } |
| 708 | 653 |
| 709 } // namespace blink | 654 } // namespace blink |
| 710 | 655 |
| OLD | NEW |