Chromium Code Reviews| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 { | 92 { |
| 93 exceptionState->throwTypeError(m_message); | 93 exceptionState->throwTypeError(m_message); |
| 94 } | 94 } |
| 95 | 95 |
| 96 private: | 96 private: |
| 97 String m_message; | 97 String m_message; |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 } // unnamed namespace | 100 } // unnamed namespace |
| 101 | 101 |
| 102 // ReadableStream::read and some related functionalities are tested in | |
| 103 // ReadableStreamReaderTest. | |
| 102 class ReadableStreamTest : public ::testing::Test { | 104 class ReadableStreamTest : public ::testing::Test { |
| 103 public: | 105 public: |
| 104 ReadableStreamTest() | 106 ReadableStreamTest() |
| 105 : m_page(DummyPageHolder::create(IntSize(1, 1))) | 107 : m_page(DummyPageHolder::create(IntSize(1, 1))) |
| 106 , m_scope(scriptState()) | 108 , m_scope(scriptState()) |
| 107 , m_underlyingSource(new ::testing::StrictMock<MockUnderlyingSource>) | 109 , m_underlyingSource(new ::testing::StrictMock<MockUnderlyingSource>) |
| 108 , m_exceptionState(ExceptionState::ConstructionContext, "property", "int erface", scriptState()->context()->Global(), isolate()) | 110 , m_exceptionState(ExceptionState::ConstructionContext, "property", "int erface", scriptState()->context()->Global(), isolate()) |
| 109 { | 111 { |
| 110 } | 112 } |
| 111 | 113 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 EXPECT_CALL(checkpoint, Call(0)); | 168 EXPECT_CALL(checkpoint, Call(0)); |
| 167 EXPECT_CALL(*m_underlyingSource, pullSource()).Times(1); | 169 EXPECT_CALL(*m_underlyingSource, pullSource()).Times(1); |
| 168 EXPECT_CALL(checkpoint, Call(1)); | 170 EXPECT_CALL(checkpoint, Call(1)); |
| 169 } | 171 } |
| 170 | 172 |
| 171 StringStream* stream = new StringStream(scriptState()->executionContext(), m _underlyingSource); | 173 StringStream* stream = new StringStream(scriptState()->executionContext(), m _underlyingSource); |
| 172 EXPECT_FALSE(m_exceptionState.hadException()); | 174 EXPECT_FALSE(m_exceptionState.hadException()); |
| 173 EXPECT_FALSE(stream->isStarted()); | 175 EXPECT_FALSE(stream->isStarted()); |
| 174 EXPECT_FALSE(stream->isDraining()); | 176 EXPECT_FALSE(stream->isDraining()); |
| 175 EXPECT_FALSE(stream->isPulling()); | 177 EXPECT_FALSE(stream->isPulling()); |
| 176 EXPECT_EQ(stream->stateInternal(), ReadableStream::Waiting); | 178 EXPECT_EQ(stream->stateInternal(), ReadableStream::Readable); |
| 177 | 179 |
| 178 checkpoint.Call(0); | 180 checkpoint.Call(0); |
| 179 stream->didSourceStart(); | 181 stream->didSourceStart(); |
| 180 checkpoint.Call(1); | 182 checkpoint.Call(1); |
| 181 | 183 |
| 182 EXPECT_TRUE(stream->isStarted()); | 184 EXPECT_TRUE(stream->isStarted()); |
| 183 EXPECT_FALSE(stream->isDraining()); | 185 EXPECT_FALSE(stream->isDraining()); |
| 184 EXPECT_TRUE(stream->isPulling()); | 186 EXPECT_TRUE(stream->isPulling()); |
| 185 EXPECT_EQ(stream->stateInternal(), ReadableStream::Waiting); | 187 EXPECT_EQ(stream->stateInternal(), ReadableStream::Readable); |
| 186 | 188 |
| 187 // We need to call |error| in order to make | 189 // We need to call |error| in order to make |
| 188 // ActiveDOMObject::hasPendingActivity return false. | 190 // ActiveDOMObject::hasPendingActivity return false. |
| 189 stream->error(DOMException::create(AbortError, "done")); | 191 stream->error(DOMException::create(AbortError, "done")); |
| 190 } | 192 } |
| 191 | 193 |
| 192 TEST_F(ReadableStreamTest, StartFail) | 194 TEST_F(ReadableStreamTest, StartFail) |
| 193 { | 195 { |
| 194 StringStream* stream = new StringStream(scriptState()->executionContext(), m _underlyingSource); | 196 StringStream* stream = new StringStream(scriptState()->executionContext(), m _underlyingSource); |
| 195 EXPECT_FALSE(m_exceptionState.hadException()); | 197 EXPECT_FALSE(m_exceptionState.hadException()); |
| 196 EXPECT_FALSE(stream->isStarted()); | 198 EXPECT_FALSE(stream->isStarted()); |
| 197 EXPECT_FALSE(stream->isDraining()); | 199 EXPECT_FALSE(stream->isDraining()); |
| 198 EXPECT_FALSE(stream->isPulling()); | 200 EXPECT_FALSE(stream->isPulling()); |
| 199 EXPECT_EQ(stream->stateInternal(), ReadableStream::Waiting); | 201 EXPECT_EQ(stream->stateInternal(), ReadableStream::Readable); |
| 200 | 202 |
| 201 stream->error(DOMException::create(NotFoundError)); | 203 stream->error(DOMException::create(NotFoundError)); |
| 202 | 204 |
| 203 EXPECT_FALSE(stream->isStarted()); | 205 EXPECT_FALSE(stream->isStarted()); |
| 204 EXPECT_FALSE(stream->isDraining()); | 206 EXPECT_FALSE(stream->isDraining()); |
| 205 EXPECT_FALSE(stream->isPulling()); | 207 EXPECT_FALSE(stream->isPulling()); |
| 206 EXPECT_EQ(stream->stateInternal(), ReadableStream::Errored); | 208 EXPECT_EQ(stream->stateInternal(), ReadableStream::Errored); |
| 207 } | 209 } |
| 208 | 210 |
| 209 TEST_F(ReadableStreamTest, WaitOnWaiting) | |
| 210 { | |
| 211 StringStream* stream = construct(); | |
| 212 Checkpoint checkpoint; | |
| 213 | |
| 214 EXPECT_EQ(ReadableStream::Waiting, stream->stateInternal()); | |
| 215 EXPECT_TRUE(stream->isStarted()); | |
| 216 EXPECT_TRUE(stream->isPulling()); | |
| 217 | |
| 218 EXPECT_EQ(ReadableStream::Waiting, stream->stateInternal()); | |
| 219 | |
| 220 stream->error(DOMException::create(AbortError, "done")); | |
| 221 } | |
| 222 | |
| 223 TEST_F(ReadableStreamTest, WaitDuringStarting) | |
| 224 { | |
| 225 StringStream* stream = new StringStream(scriptState()->executionContext(), m _underlyingSource); | |
| 226 Checkpoint checkpoint; | |
| 227 | |
| 228 EXPECT_EQ(ReadableStream::Waiting, stream->stateInternal()); | |
| 229 EXPECT_FALSE(stream->isStarted()); | |
| 230 EXPECT_FALSE(stream->isPulling()); | |
| 231 | |
| 232 { | |
| 233 InSequence s; | |
| 234 EXPECT_CALL(checkpoint, Call(0)); | |
| 235 EXPECT_CALL(*m_underlyingSource, pullSource()).Times(1); | |
| 236 EXPECT_CALL(checkpoint, Call(1)); | |
| 237 } | |
| 238 | |
| 239 stream->ready(scriptState()); | |
| 240 checkpoint.Call(0); | |
| 241 stream->didSourceStart(); | |
| 242 checkpoint.Call(1); | |
| 243 | |
| 244 EXPECT_EQ(ReadableStream::Waiting, stream->stateInternal()); | |
| 245 EXPECT_TRUE(stream->isStarted()); | |
| 246 EXPECT_TRUE(stream->isPulling()); | |
| 247 | |
| 248 stream->error(DOMException::create(AbortError, "done")); | |
| 249 } | |
| 250 | |
| 251 TEST_F(ReadableStreamTest, WaitAndError) | |
| 252 { | |
| 253 StringStream* stream = construct(); | |
| 254 String onFulfilled, onRejected; | |
| 255 | |
| 256 ScriptPromise promise = stream->ready(scriptState()); | |
| 257 promise.then(createCaptor(&onFulfilled), createCaptor(&onRejected)); | |
| 258 EXPECT_EQ(ReadableStream::Waiting, stream->stateInternal()); | |
| 259 EXPECT_TRUE(stream->isPulling()); | |
| 260 stream->error(DOMException::create(NotFoundError, "hello, error")); | |
| 261 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal()); | |
| 262 EXPECT_TRUE(stream->isPulling()); | |
| 263 EXPECT_TRUE(onFulfilled.isNull()); | |
| 264 EXPECT_TRUE(onRejected.isNull()); | |
| 265 | |
| 266 isolate()->RunMicrotasks(); | |
| 267 EXPECT_TRUE(onFulfilled.isNull()); | |
| 268 EXPECT_EQ("NotFoundError: hello, error", onRejected); | |
| 269 } | |
| 270 | |
| 271 TEST_F(ReadableStreamTest, ErrorAndEnqueue) | 211 TEST_F(ReadableStreamTest, ErrorAndEnqueue) |
| 272 { | 212 { |
| 273 StringStream* stream = construct(); | 213 StringStream* stream = construct(); |
| 274 | 214 |
| 275 stream->error(DOMException::create(NotFoundError, "error")); | 215 stream->error(DOMException::create(NotFoundError, "error")); |
| 276 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal()); | 216 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal()); |
| 277 | 217 |
| 278 bool result = stream->enqueue("hello"); | 218 bool result = stream->enqueue("hello"); |
| 279 EXPECT_FALSE(result); | 219 EXPECT_FALSE(result); |
| 280 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal()); | 220 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal()); |
| 281 } | 221 } |
| 282 | 222 |
| 283 TEST_F(ReadableStreamTest, CloseAndEnqueue) | 223 TEST_F(ReadableStreamTest, CloseAndEnqueue) |
| 284 { | 224 { |
| 285 StringStream* stream = construct(); | 225 StringStream* stream = construct(); |
| 286 | 226 |
| 287 stream->close(); | 227 stream->close(); |
| 288 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); | 228 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); |
| 289 | 229 |
| 290 bool result = stream->enqueue("hello"); | 230 bool result = stream->enqueue("hello"); |
| 291 EXPECT_FALSE(result); | 231 EXPECT_FALSE(result); |
| 292 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); | 232 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); |
| 293 } | 233 } |
| 294 | 234 |
| 295 TEST_F(ReadableStreamTest, EnqueueAndWait) | |
| 296 { | |
| 297 StringStream* stream = construct(); | |
| 298 String onFulfilled, onRejected; | |
| 299 EXPECT_EQ(ReadableStream::Waiting, stream->stateInternal()); | |
| 300 | |
| 301 bool result = stream->enqueue("hello"); | |
| 302 EXPECT_TRUE(result); | |
| 303 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); | |
| 304 | |
| 305 stream->ready(scriptState()).then(createCaptor(&onFulfilled), createCaptor(& onRejected)); | |
| 306 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); | |
| 307 EXPECT_FALSE(stream->isPulling()); | |
| 308 EXPECT_TRUE(onFulfilled.isNull()); | |
| 309 EXPECT_TRUE(onRejected.isNull()); | |
| 310 | |
| 311 isolate()->RunMicrotasks(); | |
| 312 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); | |
| 313 EXPECT_FALSE(stream->isPulling()); | |
| 314 EXPECT_EQ("undefined", onFulfilled); | |
| 315 EXPECT_TRUE(onRejected.isNull()); | |
| 316 | |
| 317 stream->error(DOMException::create(AbortError, "done")); | |
| 318 } | |
| 319 | |
| 320 TEST_F(ReadableStreamTest, WaitAndEnqueue) | |
| 321 { | |
| 322 StringStream* stream = construct(); | |
| 323 String onFulfilled, onRejected; | |
| 324 EXPECT_EQ(ReadableStream::Waiting, stream->stateInternal()); | |
| 325 | |
| 326 stream->ready(scriptState()).then(createCaptor(&onFulfilled), createCaptor(& onRejected)); | |
| 327 isolate()->RunMicrotasks(); | |
| 328 | |
| 329 EXPECT_EQ(ReadableStream::Waiting, stream->stateInternal()); | |
| 330 EXPECT_TRUE(stream->isPulling()); | |
| 331 EXPECT_TRUE(onFulfilled.isNull()); | |
| 332 EXPECT_TRUE(onRejected.isNull()); | |
| 333 | |
| 334 bool result = stream->enqueue("hello"); | |
| 335 EXPECT_TRUE(result); | |
| 336 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); | |
| 337 EXPECT_FALSE(stream->isPulling()); | |
| 338 EXPECT_TRUE(onFulfilled.isNull()); | |
| 339 EXPECT_TRUE(onRejected.isNull()); | |
| 340 | |
| 341 isolate()->RunMicrotasks(); | |
| 342 EXPECT_EQ("undefined", onFulfilled); | |
| 343 EXPECT_TRUE(onRejected.isNull()); | |
| 344 | |
| 345 stream->error(DOMException::create(AbortError, "done")); | |
| 346 } | |
| 347 | |
| 348 TEST_F(ReadableStreamTest, WaitAndEnqueueAndError) | |
| 349 { | |
| 350 StringStream* stream = construct(); | |
| 351 String onFulfilled, onRejected; | |
| 352 EXPECT_EQ(ReadableStream::Waiting, stream->stateInternal()); | |
| 353 | |
| 354 ScriptPromise promise = stream->ready(scriptState()); | |
| 355 promise.then(createCaptor(&onFulfilled), createCaptor(&onRejected)); | |
| 356 isolate()->RunMicrotasks(); | |
| 357 | |
| 358 EXPECT_EQ(ReadableStream::Waiting, stream->stateInternal()); | |
| 359 EXPECT_TRUE(stream->isPulling()); | |
| 360 EXPECT_TRUE(onFulfilled.isNull()); | |
| 361 EXPECT_TRUE(onRejected.isNull()); | |
| 362 | |
| 363 bool result = stream->enqueue("hello"); | |
| 364 EXPECT_TRUE(result); | |
| 365 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); | |
| 366 EXPECT_FALSE(stream->isPulling()); | |
| 367 EXPECT_TRUE(onFulfilled.isNull()); | |
| 368 EXPECT_TRUE(onRejected.isNull()); | |
| 369 | |
| 370 isolate()->RunMicrotasks(); | |
| 371 EXPECT_EQ("undefined", onFulfilled); | |
| 372 EXPECT_TRUE(onRejected.isNull()); | |
| 373 | |
| 374 stream->error(DOMException::create(NotFoundError, "error")); | |
| 375 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal()); | |
| 376 | |
| 377 EXPECT_NE(promise, stream->ready(scriptState())); | |
| 378 } | |
| 379 | |
| 380 TEST_F(ReadableStreamTest, CloseWhenWaiting) | |
| 381 { | |
| 382 String onWaitFulfilled, onWaitRejected; | |
| 383 String onClosedFulfilled, onClosedRejected; | |
| 384 | |
| 385 StringStream* stream = construct(); | |
| 386 | |
| 387 EXPECT_EQ(ReadableStream::Waiting, stream->stateInternal()); | |
| 388 stream->ready(scriptState()).then(createCaptor(&onWaitFulfilled), createCapt or(&onWaitRejected)); | |
| 389 stream->closed(scriptState()).then(createCaptor(&onClosedFulfilled), createC aptor(&onClosedRejected)); | |
| 390 | |
| 391 isolate()->RunMicrotasks(); | |
| 392 EXPECT_TRUE(onWaitFulfilled.isNull()); | |
| 393 EXPECT_TRUE(onWaitRejected.isNull()); | |
| 394 EXPECT_TRUE(onClosedFulfilled.isNull()); | |
| 395 EXPECT_TRUE(onClosedRejected.isNull()); | |
| 396 | |
| 397 stream->close(); | |
| 398 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); | |
| 399 isolate()->RunMicrotasks(); | |
| 400 EXPECT_EQ("undefined", onWaitFulfilled); | |
| 401 EXPECT_TRUE(onWaitRejected.isNull()); | |
| 402 EXPECT_EQ("undefined", onClosedFulfilled); | |
| 403 EXPECT_TRUE(onClosedRejected.isNull()); | |
| 404 } | |
| 405 | |
| 406 TEST_F(ReadableStreamTest, CloseWhenErrored) | 235 TEST_F(ReadableStreamTest, CloseWhenErrored) |
| 407 { | 236 { |
| 408 String onFulfilled, onRejected; | |
| 409 StringStream* stream = construct(); | 237 StringStream* stream = construct(); |
| 410 EXPECT_EQ(ReadableStream::Waiting, stream->stateInternal()); | 238 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); |
| 411 stream->closed(scriptState()).then(createCaptor(&onFulfilled), createCaptor( &onRejected)); | |
| 412 | 239 |
| 413 stream->error(DOMException::create(NotFoundError, "error")); | 240 stream->error(DOMException::create(NotFoundError, "error")); |
| 414 stream->close(); | 241 stream->close(); |
| 415 | 242 |
| 416 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal()); | 243 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal()); |
| 417 isolate()->RunMicrotasks(); | |
| 418 | |
| 419 EXPECT_TRUE(onFulfilled.isNull()); | |
| 420 EXPECT_EQ("NotFoundError: error", onRejected); | |
| 421 } | |
| 422 | |
| 423 TEST_F(ReadableStreamTest, ReadWhenWaiting) | |
| 424 { | |
| 425 StringStream* stream = construct(); | |
| 426 EXPECT_EQ(ReadableStream::Waiting, stream->stateInternal()); | |
| 427 EXPECT_FALSE(m_exceptionState.hadException()); | |
| 428 | |
| 429 stream->read(scriptState(), m_exceptionState); | |
| 430 EXPECT_EQ(ReadableStream::Waiting, stream->stateInternal()); | |
| 431 EXPECT_TRUE(m_exceptionState.hadException()); | |
| 432 EXPECT_EQ(V8TypeError, m_exceptionState.code()); | |
| 433 EXPECT_EQ("read is called while state is waiting", m_exceptionState.message( )); | |
| 434 | |
| 435 stream->error(DOMException::create(AbortError, "done")); | |
| 436 } | |
| 437 | |
| 438 TEST_F(ReadableStreamTest, ReadWhenClosed) | |
| 439 { | |
| 440 StringStream* stream = construct(); | |
| 441 stream->close(); | |
| 442 | |
| 443 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); | |
| 444 EXPECT_FALSE(m_exceptionState.hadException()); | |
| 445 | |
| 446 stream->read(scriptState(), m_exceptionState); | |
| 447 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); | |
| 448 EXPECT_TRUE(m_exceptionState.hadException()); | |
| 449 EXPECT_EQ(V8TypeError, m_exceptionState.code()); | |
| 450 EXPECT_EQ("read is called while state is closed", m_exceptionState.message() ); | |
| 451 } | |
| 452 | |
| 453 TEST_F(ReadableStreamTest, ReadWhenErrored) | |
| 454 { | |
| 455 // DOMException values specified in the spec are different from enum values | |
| 456 // defined in ExceptionCode.h. | |
| 457 const int notFoundExceptionCode = 8; | |
| 458 StringStream* stream = construct(); | |
| 459 stream->error(DOMException::create(NotFoundError, "error")); | |
| 460 | |
| 461 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal()); | |
| 462 EXPECT_FALSE(m_exceptionState.hadException()); | |
| 463 | |
| 464 stream->read(scriptState(), m_exceptionState); | |
| 465 EXPECT_EQ(ReadableStream::Errored, stream->stateInternal()); | |
| 466 EXPECT_TRUE(m_exceptionState.hadException()); | |
| 467 EXPECT_EQ(notFoundExceptionCode, m_exceptionState.code()); | |
| 468 EXPECT_EQ("error", m_exceptionState.message()); | |
| 469 } | |
| 470 | |
| 471 TEST_F(ReadableStreamTest, EnqueuedAndRead) | |
| 472 { | |
| 473 StringStream* stream = construct(); | |
| 474 String onFulfilled, onRejected; | |
| 475 Checkpoint checkpoint; | |
| 476 | |
| 477 { | |
| 478 InSequence s; | |
| 479 EXPECT_CALL(checkpoint, Call(0)); | |
| 480 EXPECT_CALL(*m_underlyingSource, pullSource()).Times(1); | |
| 481 EXPECT_CALL(checkpoint, Call(1)); | |
| 482 } | |
| 483 | |
| 484 stream->enqueue("hello"); | |
| 485 ScriptPromise promise = stream->ready(scriptState()); | |
| 486 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); | |
| 487 EXPECT_FALSE(stream->isPulling()); | |
| 488 | |
| 489 checkpoint.Call(0); | |
| 490 String chunk; | |
| 491 EXPECT_TRUE(stream->read(scriptState(), m_exceptionState).toString(chunk)); | |
| 492 checkpoint.Call(1); | |
| 493 EXPECT_FALSE(m_exceptionState.hadException()); | |
| 494 EXPECT_EQ("hello", chunk); | |
| 495 EXPECT_EQ(ReadableStream::Waiting, stream->stateInternal()); | |
| 496 EXPECT_TRUE(stream->isPulling()); | |
| 497 EXPECT_FALSE(stream->isDraining()); | |
| 498 | |
| 499 ScriptPromise newPromise = stream->ready(scriptState()); | |
| 500 newPromise.then(createCaptor(&onFulfilled), createCaptor(&onRejected)); | |
| 501 isolate()->RunMicrotasks(); | |
| 502 EXPECT_NE(promise, newPromise); | |
| 503 EXPECT_TRUE(onFulfilled.isNull()); | |
| 504 EXPECT_TRUE(onRejected.isNull()); | |
| 505 | |
| 506 stream->error(DOMException::create(AbortError, "done")); | |
| 507 isolate()->RunMicrotasks(); | |
| 508 } | |
| 509 | |
| 510 TEST_F(ReadableStreamTest, EnqueueTwiceAndRead) | |
| 511 { | |
| 512 StringStream* stream = construct(); | |
| 513 Checkpoint checkpoint; | |
| 514 | |
| 515 { | |
| 516 InSequence s; | |
| 517 EXPECT_CALL(checkpoint, Call(0)); | |
| 518 EXPECT_CALL(*m_underlyingSource, pullSource()).Times(1); | |
| 519 EXPECT_CALL(checkpoint, Call(1)); | |
| 520 } | |
| 521 | |
| 522 EXPECT_TRUE(stream->enqueue("hello")); | |
| 523 EXPECT_TRUE(stream->enqueue("bye")); | |
| 524 ScriptPromise promise = stream->ready(scriptState()); | |
| 525 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); | |
| 526 EXPECT_FALSE(stream->isPulling()); | |
| 527 | |
| 528 String chunk; | |
| 529 checkpoint.Call(0); | |
| 530 EXPECT_TRUE(stream->read(scriptState(), m_exceptionState).toString(chunk)); | |
| 531 checkpoint.Call(1); | |
| 532 EXPECT_FALSE(m_exceptionState.hadException()); | |
| 533 EXPECT_EQ("hello", chunk); | |
| 534 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); | |
| 535 EXPECT_TRUE(stream->isPulling()); | |
| 536 EXPECT_FALSE(stream->isDraining()); | |
| 537 | |
| 538 ScriptPromise newPromise = stream->ready(scriptState()); | |
| 539 EXPECT_EQ(promise, newPromise); | |
| 540 | |
| 541 stream->error(DOMException::create(AbortError, "done")); | |
| 542 } | 244 } |
| 543 | 245 |
| 544 TEST_F(ReadableStreamTest, ReadQueue) | 246 TEST_F(ReadableStreamTest, ReadQueue) |
| 545 { | 247 { |
| 546 StringStream* stream = construct(); | 248 StringStream* stream = construct(); |
| 547 Checkpoint checkpoint; | 249 Checkpoint checkpoint; |
| 548 | 250 |
| 549 { | 251 { |
| 550 InSequence s; | 252 InSequence s; |
| 551 EXPECT_CALL(checkpoint, Call(0)); | 253 EXPECT_CALL(checkpoint, Call(0)); |
| 552 EXPECT_CALL(*m_underlyingSource, pullSource()).Times(1); | 254 EXPECT_CALL(*m_underlyingSource, pullSource()).Times(1); |
| 553 EXPECT_CALL(checkpoint, Call(1)); | 255 EXPECT_CALL(checkpoint, Call(1)); |
| 554 } | 256 } |
| 555 | 257 |
| 556 Deque<std::pair<String, size_t>> queue; | 258 Deque<std::pair<String, size_t>> queue; |
| 557 | 259 |
| 558 EXPECT_TRUE(stream->enqueue("hello")); | 260 EXPECT_TRUE(stream->enqueue("hello")); |
| 559 EXPECT_TRUE(stream->enqueue("bye")); | 261 EXPECT_TRUE(stream->enqueue("bye")); |
| 560 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); | 262 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); |
| 561 EXPECT_FALSE(stream->isPulling()); | 263 EXPECT_FALSE(stream->isPulling()); |
| 562 | 264 |
| 563 String chunk; | |
| 564 checkpoint.Call(0); | 265 checkpoint.Call(0); |
| 565 stream->readInternal(queue); | 266 stream->readInternal(queue); |
| 566 checkpoint.Call(1); | 267 checkpoint.Call(1); |
| 567 ASSERT_EQ(2u, queue.size()); | 268 ASSERT_EQ(2u, queue.size()); |
| 568 | 269 |
| 569 EXPECT_EQ(std::make_pair(String("hello"), static_cast<size_t>(5)), queue[0]) ; | 270 EXPECT_EQ(std::make_pair(String("hello"), static_cast<size_t>(5)), queue[0]) ; |
| 570 EXPECT_EQ(std::make_pair(String("bye"), static_cast<size_t>(3)), queue[1]); | 271 EXPECT_EQ(std::make_pair(String("bye"), static_cast<size_t>(3)), queue[1]); |
| 571 | 272 |
| 572 EXPECT_EQ(ReadableStream::Waiting, stream->stateInternal()); | 273 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); |
| 573 EXPECT_TRUE(stream->isPulling()); | 274 EXPECT_TRUE(stream->isPulling()); |
| 574 EXPECT_FALSE(stream->isDraining()); | 275 EXPECT_FALSE(stream->isDraining()); |
| 575 } | 276 } |
| 576 | 277 |
| 577 TEST_F(ReadableStreamTest, CloseWhenReadable) | 278 TEST_F(ReadableStreamTest, CloseWhenReadable) |
| 578 { | 279 { |
| 579 StringStream* stream = construct(); | 280 StringStream* stream = construct(); |
| 580 String onClosedFulfilled, onClosedRejected; | |
| 581 | 281 |
| 582 stream->closed(scriptState()).then(createCaptor(&onClosedFulfilled), createC aptor(&onClosedRejected)); | |
| 583 EXPECT_TRUE(stream->enqueue("hello")); | 282 EXPECT_TRUE(stream->enqueue("hello")); |
| 584 EXPECT_TRUE(stream->enqueue("bye")); | 283 EXPECT_TRUE(stream->enqueue("bye")); |
| 585 stream->close(); | 284 stream->close(); |
| 586 EXPECT_FALSE(stream->enqueue("should be ignored")); | 285 EXPECT_FALSE(stream->enqueue("should be ignored")); |
| 587 | 286 |
| 588 ScriptPromise promise = stream->ready(scriptState()); | |
| 589 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); | 287 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); |
| 590 EXPECT_FALSE(stream->isPulling()); | 288 EXPECT_FALSE(stream->isPulling()); |
| 591 EXPECT_TRUE(stream->isDraining()); | 289 EXPECT_TRUE(stream->isDraining()); |
| 592 | 290 |
| 593 String chunk; | 291 stream->read(scriptState()); |
| 594 EXPECT_TRUE(stream->read(scriptState(), m_exceptionState).toString(chunk)); | |
| 595 EXPECT_EQ("hello", chunk); | |
| 596 EXPECT_EQ(promise, stream->ready(scriptState())); | |
| 597 | 292 |
| 598 isolate()->RunMicrotasks(); | 293 isolate()->RunMicrotasks(); |
| 599 | 294 |
| 600 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); | 295 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); |
| 601 EXPECT_FALSE(stream->isPulling()); | 296 EXPECT_FALSE(stream->isPulling()); |
| 602 EXPECT_TRUE(stream->isDraining()); | 297 EXPECT_TRUE(stream->isDraining()); |
| 603 | 298 |
| 604 EXPECT_TRUE(stream->read(scriptState(), m_exceptionState).toString(chunk)); | 299 stream->read(scriptState()); |
| 605 EXPECT_EQ("bye", chunk); | |
| 606 EXPECT_FALSE(m_exceptionState.hadException()); | |
| 607 | |
| 608 EXPECT_EQ(promise, stream->ready(scriptState())); | |
| 609 | 300 |
| 610 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); | 301 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); |
| 611 EXPECT_FALSE(stream->isPulling()); | 302 EXPECT_FALSE(stream->isPulling()); |
| 612 EXPECT_TRUE(stream->isDraining()); | 303 EXPECT_TRUE(stream->isDraining()); |
| 613 | |
| 614 EXPECT_TRUE(onClosedFulfilled.isNull()); | |
| 615 EXPECT_TRUE(onClosedRejected.isNull()); | |
| 616 | |
| 617 isolate()->RunMicrotasks(); | |
| 618 EXPECT_EQ("undefined", onClosedFulfilled); | |
| 619 EXPECT_TRUE(onClosedRejected.isNull()); | |
| 620 } | 304 } |
| 621 | 305 |
| 622 TEST_F(ReadableStreamTest, CancelWhenClosed) | 306 TEST_F(ReadableStreamTest, CancelWhenClosed) |
| 623 { | 307 { |
| 624 StringStream* stream = construct(); | 308 StringStream* stream = construct(); |
| 625 String onFulfilled, onRejected; | 309 String onFulfilled, onRejected; |
| 626 stream->close(); | 310 stream->close(); |
| 627 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); | 311 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); |
| 628 | 312 |
| 629 ScriptPromise promise = stream->cancel(scriptState(), ScriptValue()); | 313 ScriptPromise promise = stream->cancel(scriptState(), ScriptValue()); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 650 | 334 |
| 651 promise.then(createCaptor(&onFulfilled), createCaptor(&onRejected)); | 335 promise.then(createCaptor(&onFulfilled), createCaptor(&onRejected)); |
| 652 EXPECT_TRUE(onFulfilled.isNull()); | 336 EXPECT_TRUE(onFulfilled.isNull()); |
| 653 EXPECT_TRUE(onRejected.isNull()); | 337 EXPECT_TRUE(onRejected.isNull()); |
| 654 | 338 |
| 655 isolate()->RunMicrotasks(); | 339 isolate()->RunMicrotasks(); |
| 656 EXPECT_TRUE(onFulfilled.isNull()); | 340 EXPECT_TRUE(onFulfilled.isNull()); |
| 657 EXPECT_EQ("NotFoundError: error", onRejected); | 341 EXPECT_EQ("NotFoundError: error", onRejected); |
| 658 } | 342 } |
| 659 | 343 |
| 660 TEST_F(ReadableStreamTest, CancelWhenWaiting) | |
| 661 { | |
| 662 StringStream* stream = construct(); | |
| 663 String onFulfilled, onRejected; | |
| 664 ScriptValue reason(scriptState(), v8String(scriptState()->isolate(), "reason ")); | |
| 665 ScriptPromise promise = ScriptPromise::cast(scriptState(), v8String(scriptSt ate()->isolate(), "hello")); | |
| 666 | |
| 667 { | |
| 668 InSequence s; | |
| 669 EXPECT_CALL(*m_underlyingSource, cancelSource(scriptState(), reason)).Wi llOnce(Return(promise)); | |
| 670 } | |
| 671 | |
| 672 EXPECT_EQ(ReadableStream::Waiting, stream->stateInternal()); | |
| 673 ScriptPromise ready = stream->ready(scriptState()); | |
| 674 EXPECT_NE(promise, stream->cancel(scriptState(), reason)); | |
| 675 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); | |
| 676 | |
| 677 ready.then(createCaptor(&onFulfilled), createCaptor(&onRejected)); | |
| 678 EXPECT_TRUE(onFulfilled.isNull()); | |
| 679 EXPECT_TRUE(onRejected.isNull()); | |
| 680 | |
| 681 isolate()->RunMicrotasks(); | |
| 682 EXPECT_EQ("undefined", onFulfilled); | |
| 683 EXPECT_TRUE(onRejected.isNull()); | |
| 684 } | |
| 685 | |
| 686 TEST_F(ReadableStreamTest, CancelWhenReadable) | 344 TEST_F(ReadableStreamTest, CancelWhenReadable) |
| 687 { | 345 { |
| 688 StringStream* stream = construct(); | 346 StringStream* stream = construct(); |
| 689 String onFulfilled, onRejected; | 347 String onFulfilled, onRejected; |
| 690 String onCancelFulfilled, onCancelRejected; | 348 String onCancelFulfilled, onCancelRejected; |
| 691 ScriptValue reason(scriptState(), v8String(scriptState()->isolate(), "reason ")); | 349 ScriptValue reason(scriptState(), v8String(scriptState()->isolate(), "reason ")); |
| 692 ScriptPromise promise = ScriptPromise::cast(scriptState(), v8String(scriptSt ate()->isolate(), "hello")); | 350 ScriptPromise promise = ScriptPromise::cast(scriptState(), v8String(scriptSt ate()->isolate(), "hello")); |
| 693 | 351 |
| 694 { | 352 { |
| 695 InSequence s; | 353 InSequence s; |
| 696 EXPECT_CALL(*m_underlyingSource, cancelSource(scriptState(), reason)).Wi llOnce(Return(promise)); | 354 EXPECT_CALL(*m_underlyingSource, cancelSource(scriptState(), reason)).Wi llOnce(Return(promise)); |
| 697 } | 355 } |
| 698 | 356 |
| 699 stream->enqueue("hello"); | 357 stream->enqueue("hello"); |
| 700 ScriptPromise ready = stream->ready(scriptState()); | |
| 701 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); | 358 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); |
| 702 | 359 |
| 703 ScriptPromise cancelResult = stream->cancel(scriptState(), reason); | 360 ScriptPromise cancelResult = stream->cancel(scriptState(), reason); |
| 704 cancelResult.then(createCaptor(&onCancelFulfilled), createCaptor(&onCancelRe jected)); | 361 cancelResult.then(createCaptor(&onCancelFulfilled), createCaptor(&onCancelRe jected)); |
| 705 | 362 |
| 706 EXPECT_NE(promise, cancelResult); | 363 EXPECT_NE(promise, cancelResult); |
| 707 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); | 364 EXPECT_EQ(ReadableStream::Closed, stream->stateInternal()); |
| 708 | 365 |
| 709 EXPECT_EQ(stream->ready(scriptState()), ready); | |
| 710 | |
| 711 EXPECT_TRUE(onCancelFulfilled.isNull()); | 366 EXPECT_TRUE(onCancelFulfilled.isNull()); |
| 712 EXPECT_TRUE(onCancelRejected.isNull()); | 367 EXPECT_TRUE(onCancelRejected.isNull()); |
| 713 | 368 |
| 714 isolate()->RunMicrotasks(); | 369 isolate()->RunMicrotasks(); |
| 715 EXPECT_EQ("undefined", onCancelFulfilled); | 370 EXPECT_EQ("undefined", onCancelFulfilled); |
| 716 EXPECT_TRUE(onCancelRejected.isNull()); | 371 EXPECT_TRUE(onCancelRejected.isNull()); |
| 717 } | 372 } |
| 718 | 373 |
| 374 TEST_F(ReadableStreamTest, CancelWhenLocked) | |
| 375 { | |
| 376 String onFulfilled, onRejected; | |
| 377 StringStream* stream = construct(); | |
| 378 ReadableStreamReader* reader = stream->getReader(m_exceptionState); | |
| 379 | |
| 380 EXPECT_TRUE(reader->isActive()); | |
| 381 EXPECT_FALSE(m_exceptionState.hadException()); | |
| 382 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); | |
| 383 | |
| 384 stream->cancel(scriptState(), ScriptValue(scriptState(), v8::Undefined(isola te()))).then(createCaptor(&onFulfilled), createCaptor(&onRejected)); | |
| 385 | |
| 386 EXPECT_TRUE(onFulfilled.isNull()); | |
| 387 EXPECT_TRUE(onRejected.isNull()); | |
| 388 | |
| 389 isolate()->RunMicrotasks(); | |
| 390 | |
| 391 EXPECT_TRUE(onFulfilled.isNull()); | |
| 392 EXPECT_EQ("TypeError: this stream is locked to a ReadableStreamReader", onRe jected); | |
| 393 EXPECT_TRUE(reader->isActive()); | |
| 394 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); | |
| 395 } | |
| 396 | |
| 719 TEST_F(ReadableStreamTest, ReadableArrayBufferCompileTest) | 397 TEST_F(ReadableStreamTest, ReadableArrayBufferCompileTest) |
| 720 { | 398 { |
| 721 // This test tests if ReadableStreamImpl<DOMArrayBuffer> can be | 399 // This test tests if ReadableStreamImpl<DOMArrayBuffer> can be |
| 722 // instantiated. | 400 // instantiated. |
| 723 new ReadableStreamImpl<ReadableStreamChunkTypeTraits<DOMArrayBuffer>>(script State()->executionContext(), m_underlyingSource); | 401 new ReadableStreamImpl<ReadableStreamChunkTypeTraits<DOMArrayBuffer>>(script State()->executionContext(), m_underlyingSource); |
| 724 } | 402 } |
| 725 | 403 |
| 726 TEST_F(ReadableStreamTest, BackpressureOnEnqueueing) | 404 TEST_F(ReadableStreamTest, BackpressureOnEnqueueing) |
| 727 { | 405 { |
| 728 auto strategy = MockStrategy::create(); | 406 auto strategy = MockStrategy::create(); |
| 729 Checkpoint checkpoint; | 407 Checkpoint checkpoint; |
| 730 | 408 |
| 731 StringStream* stream = construct(strategy); | 409 StringStream* stream = construct(strategy); |
| 732 EXPECT_EQ(ReadableStream::Waiting, stream->stateInternal()); | 410 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); |
| 733 | 411 |
| 734 { | 412 { |
| 735 InSequence s; | 413 InSequence s; |
| 736 EXPECT_CALL(checkpoint, Call(0)); | 414 EXPECT_CALL(checkpoint, Call(0)); |
| 737 EXPECT_CALL(*strategy, size(String("hello"), stream)).WillOnce(Return(1) ); | 415 EXPECT_CALL(*strategy, size(String("hello"), stream)).WillOnce(Return(1) ); |
| 738 EXPECT_CALL(*strategy, shouldApplyBackpressure(1, stream)).WillOnce(Retu rn(false)); | 416 EXPECT_CALL(*strategy, shouldApplyBackpressure(1, stream)).WillOnce(Retu rn(false)); |
| 739 EXPECT_CALL(checkpoint, Call(1)); | 417 EXPECT_CALL(checkpoint, Call(1)); |
| 740 EXPECT_CALL(checkpoint, Call(2)); | 418 EXPECT_CALL(checkpoint, Call(2)); |
| 741 EXPECT_CALL(*strategy, size(String("world"), stream)).WillOnce(Return(2) ); | 419 EXPECT_CALL(*strategy, size(String("world"), stream)).WillOnce(Return(2) ); |
| 742 EXPECT_CALL(*strategy, shouldApplyBackpressure(3, stream)).WillOnce(Retu rn(true)); | 420 EXPECT_CALL(*strategy, shouldApplyBackpressure(3, stream)).WillOnce(Retu rn(true)); |
| 743 EXPECT_CALL(checkpoint, Call(3)); | 421 EXPECT_CALL(checkpoint, Call(3)); |
| 744 } | 422 } |
| 745 checkpoint.Call(0); | 423 checkpoint.Call(0); |
| 746 bool result = stream->enqueue("hello"); | 424 bool result = stream->enqueue("hello"); |
| 747 checkpoint.Call(1); | 425 checkpoint.Call(1); |
| 748 EXPECT_TRUE(result); | 426 EXPECT_TRUE(result); |
| 749 | 427 |
| 750 checkpoint.Call(2); | 428 checkpoint.Call(2); |
| 751 result = stream->enqueue("world"); | 429 result = stream->enqueue("world"); |
| 752 checkpoint.Call(3); | 430 checkpoint.Call(3); |
| 753 EXPECT_FALSE(result); | 431 EXPECT_FALSE(result); |
| 754 | 432 |
| 755 stream->error(DOMException::create(AbortError, "done")); | 433 stream->error(DOMException::create(AbortError, "done")); |
| 756 } | 434 } |
| 757 | 435 |
| 758 TEST_F(ReadableStreamTest, BackpressureOnReading) | 436 TEST_F(ReadableStreamTest, BackpressureOnReading) |
| 759 { | 437 { |
| 760 auto strategy = MockStrategy::create(); | 438 auto strategy = MockStrategy::create(); |
| 761 Checkpoint checkpoint; | 439 Checkpoint checkpoint; |
| 440 String onFulfilled, onRejected; | |
| 441 String onFulfilled2, onRejected2; | |
|
tyoshino (SeeGerritForStatus)
2015/03/19 07:54:52
unused?
yhirano
2015/03/19 08:39:02
Thanks, done.
| |
| 762 | 442 |
| 763 StringStream* stream = construct(strategy); | 443 StringStream* stream = construct(strategy); |
| 764 EXPECT_EQ(ReadableStream::Waiting, stream->stateInternal()); | 444 EXPECT_EQ(ReadableStream::Readable, stream->stateInternal()); |
| 765 | 445 |
| 766 { | 446 { |
| 767 InSequence s; | 447 InSequence s; |
| 768 EXPECT_CALL(*strategy, size(String("hello"), stream)).WillOnce(Return(2) ); | 448 EXPECT_CALL(*strategy, size(String("hello"), stream)).WillOnce(Return(2) ); |
| 769 EXPECT_CALL(*strategy, shouldApplyBackpressure(2, stream)).WillOnce(Retu rn(false)); | 449 EXPECT_CALL(*strategy, shouldApplyBackpressure(2, stream)).WillOnce(Retu rn(false)); |
| 770 EXPECT_CALL(*strategy, size(String("world"), stream)).WillOnce(Return(3) ); | 450 EXPECT_CALL(*strategy, size(String("world"), stream)).WillOnce(Return(3) ); |
| 771 EXPECT_CALL(*strategy, shouldApplyBackpressure(5, stream)).WillOnce(Retu rn(false)); | 451 EXPECT_CALL(*strategy, shouldApplyBackpressure(5, stream)).WillOnce(Retu rn(false)); |
| 772 | 452 |
| 773 EXPECT_CALL(checkpoint, Call(0)); | 453 EXPECT_CALL(checkpoint, Call(0)); |
| 774 EXPECT_CALL(*strategy, shouldApplyBackpressure(3, stream)).WillOnce(Retu rn(false)); | 454 EXPECT_CALL(*strategy, shouldApplyBackpressure(3, stream)).WillOnce(Retu rn(false)); |
| 775 EXPECT_CALL(*m_underlyingSource, pullSource()).Times(1); | 455 EXPECT_CALL(*m_underlyingSource, pullSource()).Times(1); |
| 776 EXPECT_CALL(checkpoint, Call(1)); | 456 EXPECT_CALL(checkpoint, Call(1)); |
| 777 // shouldApplyBackpressure and pullSource are not called because the | 457 // shouldApplyBackpressure and pullSource are not called because the |
| 778 // stream is pulling. | 458 // stream is pulling. |
| 779 EXPECT_CALL(checkpoint, Call(2)); | 459 EXPECT_CALL(checkpoint, Call(2)); |
| 780 EXPECT_CALL(*strategy, size(String("foo"), stream)).WillOnce(Return(4)); | 460 EXPECT_CALL(*strategy, size(String("foo"), stream)).WillOnce(Return(4)); |
| 781 EXPECT_CALL(*strategy, shouldApplyBackpressure(4, stream)).WillOnce(Retu rn(true)); | 461 EXPECT_CALL(*strategy, shouldApplyBackpressure(4, stream)).WillOnce(Retu rn(true)); |
| 782 EXPECT_CALL(*strategy, size(String("bar"), stream)).WillOnce(Return(5)); | 462 EXPECT_CALL(*strategy, size(String("bar"), stream)).WillOnce(Return(5)); |
| 783 EXPECT_CALL(*strategy, shouldApplyBackpressure(9, stream)).WillOnce(Retu rn(true)); | 463 EXPECT_CALL(*strategy, shouldApplyBackpressure(9, stream)).WillOnce(Retu rn(true)); |
| 784 EXPECT_CALL(checkpoint, Call(3)); | 464 EXPECT_CALL(checkpoint, Call(3)); |
| 785 EXPECT_CALL(*strategy, shouldApplyBackpressure(5, stream)).WillOnce(Retu rn(true)); | 465 EXPECT_CALL(*strategy, shouldApplyBackpressure(5, stream)).WillOnce(Retu rn(true)); |
| 786 EXPECT_CALL(checkpoint, Call(4)); | 466 EXPECT_CALL(checkpoint, Call(4)); |
| 787 } | 467 } |
| 788 stream->enqueue("hello"); | 468 stream->enqueue("hello"); |
| 789 stream->enqueue("world"); | 469 stream->enqueue("world"); |
| 790 | 470 |
| 791 String chunk; | |
| 792 checkpoint.Call(0); | 471 checkpoint.Call(0); |
| 793 EXPECT_TRUE(stream->read(scriptState(), m_exceptionState).toString(chunk)); | 472 stream->read(scriptState()); |
| 794 EXPECT_EQ("hello", chunk); | |
| 795 checkpoint.Call(1); | 473 checkpoint.Call(1); |
| 796 EXPECT_TRUE(stream->read(scriptState(), m_exceptionState).toString(chunk)); | 474 stream->read(scriptState()); |
| 797 EXPECT_EQ("world", chunk); | |
| 798 checkpoint.Call(2); | 475 checkpoint.Call(2); |
| 799 stream->enqueue("foo"); | 476 stream->enqueue("foo"); |
| 800 stream->enqueue("bar"); | 477 stream->enqueue("bar"); |
| 801 checkpoint.Call(3); | 478 checkpoint.Call(3); |
| 802 EXPECT_TRUE(stream->read(scriptState(), m_exceptionState).toString(chunk)); | 479 stream->read(scriptState()); |
| 803 EXPECT_EQ("foo", chunk); | |
| 804 checkpoint.Call(4); | 480 checkpoint.Call(4); |
| 805 | 481 |
| 806 stream->error(DOMException::create(AbortError, "done")); | 482 stream->error(DOMException::create(AbortError, "done")); |
| 807 } | 483 } |
| 808 | 484 |
| 809 // Note: Detailed tests are on ReadableStreamReaderTest. | 485 // Note: Detailed tests are on ReadableStreamReaderTest. |
| 810 TEST_F(ReadableStreamTest, ReadableStreamReader) | 486 TEST_F(ReadableStreamTest, ReadableStreamReader) |
| 811 { | 487 { |
| 812 StringStream* stream = construct(); | 488 StringStream* stream = construct(); |
| 813 ReadableStreamReader* reader = stream->getReader(m_exceptionState); | 489 ReadableStreamReader* reader = stream->getReader(m_exceptionState); |
| 814 | 490 |
| 815 ASSERT_TRUE(reader); | 491 ASSERT_TRUE(reader); |
| 816 EXPECT_FALSE(m_exceptionState.hadException()); | 492 EXPECT_FALSE(m_exceptionState.hadException()); |
| 817 EXPECT_TRUE(reader->isActive()); | 493 EXPECT_TRUE(reader->isActive()); |
| 818 EXPECT_TRUE(stream->isLockedTo(reader)); | 494 EXPECT_TRUE(stream->isLockedTo(reader)); |
| 819 | 495 |
| 820 ReadableStreamReader* another = stream->getReader(m_exceptionState); | 496 ReadableStreamReader* another = stream->getReader(m_exceptionState); |
| 821 ASSERT_EQ(nullptr, another); | 497 ASSERT_EQ(nullptr, another); |
| 822 EXPECT_TRUE(m_exceptionState.hadException()); | 498 EXPECT_TRUE(m_exceptionState.hadException()); |
| 823 EXPECT_TRUE(reader->isActive()); | 499 EXPECT_TRUE(reader->isActive()); |
| 824 EXPECT_TRUE(stream->isLockedTo(reader)); | 500 EXPECT_TRUE(stream->isLockedTo(reader)); |
| 825 } | 501 } |
| 826 | 502 |
| 503 TEST_F(ReadableStreamTest, GetClosedReader) | |
| 504 { | |
| 505 StringStream* stream = construct(); | |
| 506 stream->close(); | |
| 507 ReadableStreamReader* reader = stream->getReader(m_exceptionState); | |
| 508 | |
| 509 ASSERT_TRUE(reader); | |
| 510 EXPECT_FALSE(m_exceptionState.hadException()); | |
| 511 | |
| 512 String onFulfilled, onRejected; | |
| 513 reader->closed(scriptState()).then(createCaptor(&onFulfilled), createCaptor( &onRejected)); | |
| 514 | |
| 515 EXPECT_FALSE(reader->isActive()); | |
| 516 EXPECT_TRUE(onFulfilled.isNull()); | |
| 517 EXPECT_TRUE(onRejected.isNull()); | |
| 518 | |
| 519 isolate()->RunMicrotasks(); | |
| 520 EXPECT_EQ("undefined", onFulfilled); | |
| 521 EXPECT_TRUE(onRejected.isNull()); | |
| 522 } | |
| 523 | |
| 524 TEST_F(ReadableStreamTest, GetErroredReader) | |
| 525 { | |
| 526 StringStream* stream = construct(); | |
| 527 stream->error(DOMException::create(SyntaxError, "some error")); | |
| 528 ReadableStreamReader* reader = stream->getReader(m_exceptionState); | |
| 529 | |
| 530 ASSERT_TRUE(reader); | |
| 531 EXPECT_FALSE(m_exceptionState.hadException()); | |
| 532 | |
| 533 String onFulfilled, onRejected; | |
| 534 reader->closed(scriptState()).then(createCaptor(&onFulfilled), createCaptor( &onRejected)); | |
| 535 | |
| 536 EXPECT_FALSE(reader->isActive()); | |
| 537 EXPECT_TRUE(onFulfilled.isNull()); | |
| 538 EXPECT_TRUE(onRejected.isNull()); | |
| 539 | |
| 540 isolate()->RunMicrotasks(); | |
| 541 EXPECT_TRUE(onFulfilled.isNull()); | |
| 542 EXPECT_EQ("SyntaxError: some error", onRejected); | |
| 543 } | |
| 544 | |
| 827 } // namespace blink | 545 } // namespace blink |
| OLD | NEW |