Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/loader/ThreadableLoader.h" | 5 #include "core/loader/ThreadableLoader.h" |
| 6 | 6 |
| 7 #include "core/dom/CrossThreadTask.h" | 7 #include "core/dom/CrossThreadTask.h" |
| 8 #include "core/fetch/MemoryCache.h" | 8 #include "core/fetch/MemoryCache.h" |
| 9 #include "core/fetch/ResourceLoaderOptions.h" | 9 #include "core/fetch/ResourceLoaderOptions.h" |
| 10 #include "core/loader/DocumentThreadableLoader.h" | 10 #include "core/loader/DocumentThreadableLoader.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 void onSetUp() override | 133 void onSetUp() override |
| 134 { | 134 { |
| 135 } | 135 } |
| 136 | 136 |
| 137 void onServeRequests() override | 137 void onServeRequests() override |
| 138 { | 138 { |
| 139 } | 139 } |
| 140 | 140 |
| 141 void onTearDown() override | 141 void onTearDown() override |
| 142 { | 142 { |
| 143 m_loader.reset(); | 143 if (m_loader) { |
| 144 m_loader->cancel(); | |
| 145 m_loader.reset(); | |
| 146 } | |
| 144 } | 147 } |
| 145 | 148 |
| 146 private: | 149 private: |
| 147 Document& document() { return m_dummyPageHolder->document(); } | 150 Document& document() { return m_dummyPageHolder->document(); } |
| 148 | 151 |
| 149 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | 152 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
| 150 Checkpoint m_checkpoint; | 153 Checkpoint m_checkpoint; |
| 151 std::unique_ptr<DocumentThreadableLoader> m_loader; | 154 std::unique_ptr<DocumentThreadableLoader> m_loader; |
| 152 }; | 155 }; |
| 153 | 156 |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 448 EXPECT_CALL(checkpoint(), Call(2)).WillOnce(InvokeWithoutArgs(this, &Threada bleLoaderTest::cancelLoader)); | 451 EXPECT_CALL(checkpoint(), Call(2)).WillOnce(InvokeWithoutArgs(this, &Threada bleLoaderTest::cancelLoader)); |
| 449 EXPECT_CALL(*client(), didFail(Truly(isCancellation))); | 452 EXPECT_CALL(*client(), didFail(Truly(isCancellation))); |
| 450 EXPECT_CALL(checkpoint(), Call(3)); | 453 EXPECT_CALL(checkpoint(), Call(3)); |
| 451 | 454 |
| 452 startLoader(successURL()); | 455 startLoader(successURL()); |
| 453 callCheckpoint(2); | 456 callCheckpoint(2); |
| 454 callCheckpoint(3); | 457 callCheckpoint(3); |
| 455 serveRequests(); | 458 serveRequests(); |
| 456 } | 459 } |
| 457 | 460 |
| 458 TEST_P(ThreadableLoaderTest, ClearAfterStart) | |
|
hiroshige
2016/07/19 06:56:14
How about keeping these Clear.* tests by adding ca
yhirano
2016/07/19 08:05:04
Done.
| |
| 459 { | |
| 460 InSequence s; | |
| 461 EXPECT_CALL(checkpoint(), Call(1)); | |
| 462 createLoader(); | |
| 463 callCheckpoint(1); | |
| 464 | |
| 465 EXPECT_CALL(checkpoint(), Call(2)).WillOnce(InvokeWithoutArgs(this, &Threada bleLoaderTest::clearLoader)); | |
| 466 EXPECT_CALL(checkpoint(), Call(3)); | |
| 467 | |
| 468 startLoader(successURL()); | |
| 469 callCheckpoint(2); | |
| 470 callCheckpoint(3); | |
| 471 serveRequests(); | |
| 472 } | |
| 473 | |
| 474 TEST_P(ThreadableLoaderTest, CancelInDidReceiveResponse) | 461 TEST_P(ThreadableLoaderTest, CancelInDidReceiveResponse) |
| 475 { | 462 { |
| 476 InSequence s; | 463 InSequence s; |
| 477 EXPECT_CALL(checkpoint(), Call(1)); | 464 EXPECT_CALL(checkpoint(), Call(1)); |
| 478 createLoader(); | 465 createLoader(); |
| 479 callCheckpoint(1); | 466 callCheckpoint(1); |
| 480 | 467 |
| 481 EXPECT_CALL(checkpoint(), Call(2)); | 468 EXPECT_CALL(checkpoint(), Call(2)); |
| 482 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _)).WillOnce(InvokeWitho utArgs(this, &ThreadableLoaderTest::cancelLoader)); | 469 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _)).WillOnce(InvokeWitho utArgs(this, &ThreadableLoaderTest::cancelLoader)); |
| 483 EXPECT_CALL(*client(), didFail(Truly(isCancellation))); | 470 EXPECT_CALL(*client(), didFail(Truly(isCancellation))); |
| 484 | 471 |
| 485 startLoader(successURL()); | 472 startLoader(successURL()); |
| 486 callCheckpoint(2); | 473 callCheckpoint(2); |
| 487 serveRequests(); | 474 serveRequests(); |
| 488 } | 475 } |
| 489 | 476 |
| 490 TEST_P(ThreadableLoaderTest, ClearInDidReceiveResponse) | |
| 491 { | |
| 492 InSequence s; | |
| 493 EXPECT_CALL(checkpoint(), Call(1)); | |
| 494 createLoader(); | |
| 495 callCheckpoint(1); | |
| 496 | |
| 497 EXPECT_CALL(checkpoint(), Call(2)); | |
| 498 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _)).WillOnce(InvokeWitho utArgs(this, &ThreadableLoaderTest::clearLoader)); | |
| 499 | |
| 500 startLoader(successURL()); | |
| 501 callCheckpoint(2); | |
| 502 serveRequests(); | |
| 503 } | |
| 504 | |
| 505 TEST_P(ThreadableLoaderTest, CancelInDidReceiveData) | 477 TEST_P(ThreadableLoaderTest, CancelInDidReceiveData) |
| 506 { | 478 { |
| 507 InSequence s; | 479 InSequence s; |
| 508 EXPECT_CALL(checkpoint(), Call(1)); | 480 EXPECT_CALL(checkpoint(), Call(1)); |
| 509 createLoader(); | 481 createLoader(); |
| 510 callCheckpoint(1); | 482 callCheckpoint(1); |
| 511 | 483 |
| 512 EXPECT_CALL(checkpoint(), Call(2)); | 484 EXPECT_CALL(checkpoint(), Call(2)); |
| 513 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _)); | 485 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _)); |
| 514 EXPECT_CALL(*client(), didReceiveData(_, _)).WillOnce(InvokeWithoutArgs(this , &ThreadableLoaderTest::cancelLoader)); | 486 EXPECT_CALL(*client(), didReceiveData(_, _)).WillOnce(InvokeWithoutArgs(this , &ThreadableLoaderTest::cancelLoader)); |
| 515 EXPECT_CALL(*client(), didFail(Truly(isCancellation))); | 487 EXPECT_CALL(*client(), didFail(Truly(isCancellation))); |
| 516 | 488 |
| 517 startLoader(successURL()); | 489 startLoader(successURL()); |
| 518 callCheckpoint(2); | 490 callCheckpoint(2); |
| 519 serveRequests(); | 491 serveRequests(); |
| 520 } | 492 } |
| 521 | 493 |
| 522 TEST_P(ThreadableLoaderTest, ClearInDidReceiveData) | |
| 523 { | |
| 524 InSequence s; | |
| 525 EXPECT_CALL(checkpoint(), Call(1)); | |
| 526 createLoader(); | |
| 527 callCheckpoint(1); | |
| 528 | |
| 529 EXPECT_CALL(checkpoint(), Call(2)); | |
| 530 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _)); | |
| 531 EXPECT_CALL(*client(), didReceiveData(_, _)).WillOnce(InvokeWithoutArgs(this , &ThreadableLoaderTest::clearLoader)); | |
| 532 | |
| 533 startLoader(successURL()); | |
| 534 callCheckpoint(2); | |
| 535 serveRequests(); | |
| 536 } | |
| 537 | |
| 538 TEST_P(ThreadableLoaderTest, DidFinishLoading) | 494 TEST_P(ThreadableLoaderTest, DidFinishLoading) |
| 539 { | 495 { |
| 540 InSequence s; | 496 InSequence s; |
| 541 EXPECT_CALL(checkpoint(), Call(1)); | 497 EXPECT_CALL(checkpoint(), Call(1)); |
| 542 createLoader(); | 498 createLoader(); |
| 543 callCheckpoint(1); | 499 callCheckpoint(1); |
| 544 | 500 |
| 545 EXPECT_CALL(checkpoint(), Call(2)); | 501 EXPECT_CALL(checkpoint(), Call(2)); |
| 546 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _)); | 502 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _)); |
| 547 EXPECT_CALL(*client(), didReceiveData(StrEq("fox"), 4)); | 503 EXPECT_CALL(*client(), didReceiveData(StrEq("fox"), 4)); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 564 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _)); | 520 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _)); |
| 565 EXPECT_CALL(*client(), didReceiveData(_, _)); | 521 EXPECT_CALL(*client(), didReceiveData(_, _)); |
| 566 EXPECT_CALL(*client(), didReceiveResourceTiming(_)); | 522 EXPECT_CALL(*client(), didReceiveResourceTiming(_)); |
| 567 EXPECT_CALL(*client(), didFinishLoading(_, _)).WillOnce(InvokeWithoutArgs(th is, &ThreadableLoaderTest::cancelLoader)); | 523 EXPECT_CALL(*client(), didFinishLoading(_, _)).WillOnce(InvokeWithoutArgs(th is, &ThreadableLoaderTest::cancelLoader)); |
| 568 | 524 |
| 569 startLoader(successURL()); | 525 startLoader(successURL()); |
| 570 callCheckpoint(2); | 526 callCheckpoint(2); |
| 571 serveRequests(); | 527 serveRequests(); |
| 572 } | 528 } |
| 573 | 529 |
| 574 TEST_P(ThreadableLoaderTest, ClearInDidFinishLoading) | |
| 575 { | |
| 576 InSequence s; | |
| 577 EXPECT_CALL(checkpoint(), Call(1)); | |
| 578 createLoader(); | |
| 579 callCheckpoint(1); | |
| 580 | |
| 581 EXPECT_CALL(checkpoint(), Call(2)); | |
| 582 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _)); | |
| 583 EXPECT_CALL(*client(), didReceiveData(_, _)); | |
| 584 EXPECT_CALL(*client(), didReceiveResourceTiming(_)); | |
| 585 EXPECT_CALL(*client(), didFinishLoading(_, _)).WillOnce(InvokeWithoutArgs(th is, &ThreadableLoaderTest::clearLoader)); | |
| 586 | |
| 587 startLoader(successURL()); | |
| 588 callCheckpoint(2); | |
| 589 serveRequests(); | |
| 590 } | |
| 591 | |
| 592 TEST_P(ThreadableLoaderTest, DidFail) | 530 TEST_P(ThreadableLoaderTest, DidFail) |
| 593 { | 531 { |
| 594 InSequence s; | 532 InSequence s; |
| 595 EXPECT_CALL(checkpoint(), Call(1)); | 533 EXPECT_CALL(checkpoint(), Call(1)); |
| 596 createLoader(); | 534 createLoader(); |
| 597 callCheckpoint(1); | 535 callCheckpoint(1); |
| 598 | 536 |
| 599 EXPECT_CALL(checkpoint(), Call(2)); | 537 EXPECT_CALL(checkpoint(), Call(2)); |
| 600 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _)); | 538 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _)); |
| 601 EXPECT_CALL(*client(), didFail(Truly(isNotCancellation))); | 539 EXPECT_CALL(*client(), didFail(Truly(isNotCancellation))); |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 822 EXPECT_CALL(*client(), didFailRedirectCheck()).WillOnce(InvokeWithoutArgs(th is, &ThreadableLoaderTest::clearLoader)); | 760 EXPECT_CALL(*client(), didFailRedirectCheck()).WillOnce(InvokeWithoutArgs(th is, &ThreadableLoaderTest::clearLoader)); |
| 823 | 761 |
| 824 startLoader(redirectLoopURL()); | 762 startLoader(redirectLoopURL()); |
| 825 callCheckpoint(2); | 763 callCheckpoint(2); |
| 826 serveRequests(); | 764 serveRequests(); |
| 827 } | 765 } |
| 828 | 766 |
| 829 } // namespace | 767 } // namespace |
| 830 | 768 |
| 831 } // namespace blink | 769 } // namespace blink |
| OLD | NEW |