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

Side by Side Diff: third_party/WebKit/Source/core/loader/ThreadableLoaderTest.cpp

Issue 2800963003: Rename checkpoint() method to getCheckpoint(). (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory> 7 #include <memory>
8 #include "core/loader/DocumentThreadableLoader.h" 8 #include "core/loader/DocumentThreadableLoader.h"
9 #include "core/loader/ThreadableLoaderClient.h" 9 #include "core/loader/ThreadableLoaderClient.h"
10 #include "core/loader/ThreadableLoadingContext.h" 10 #include "core/loader/ThreadableLoadingContext.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 class ThreadableLoaderTestHelper { 107 class ThreadableLoaderTestHelper {
108 public: 108 public:
109 virtual ~ThreadableLoaderTestHelper() {} 109 virtual ~ThreadableLoaderTestHelper() {}
110 110
111 virtual void createLoader(ThreadableLoaderClient*, 111 virtual void createLoader(ThreadableLoaderClient*,
112 CrossOriginRequestPolicy) = 0; 112 CrossOriginRequestPolicy) = 0;
113 virtual void startLoader(const ResourceRequest&) = 0; 113 virtual void startLoader(const ResourceRequest&) = 0;
114 virtual void cancelLoader() = 0; 114 virtual void cancelLoader() = 0;
115 virtual void cancelAndClearLoader() = 0; 115 virtual void cancelAndClearLoader() = 0;
116 virtual void clearLoader() = 0; 116 virtual void clearLoader() = 0;
117 virtual Checkpoint& checkpoint() = 0; 117 virtual Checkpoint& getCheckpoint() = 0;
118 virtual void callCheckpoint(int) = 0; 118 virtual void callCheckpoint(int) = 0;
119 virtual void onSetUp() = 0; 119 virtual void onSetUp() = 0;
120 virtual void onServeRequests() = 0; 120 virtual void onServeRequests() = 0;
121 virtual void onTearDown() = 0; 121 virtual void onTearDown() = 0;
122 }; 122 };
123 123
124 class DocumentThreadableLoaderTestHelper : public ThreadableLoaderTestHelper { 124 class DocumentThreadableLoaderTestHelper : public ThreadableLoaderTestHelper {
125 public: 125 public:
126 DocumentThreadableLoaderTestHelper() 126 DocumentThreadableLoaderTestHelper()
127 : m_dummyPageHolder(DummyPageHolder::create(IntSize(1, 1))) {} 127 : m_dummyPageHolder(DummyPageHolder::create(IntSize(1, 1))) {}
(...skipping 12 matching lines...) Expand all
140 void startLoader(const ResourceRequest& request) override { 140 void startLoader(const ResourceRequest& request) override {
141 m_loader->start(request); 141 m_loader->start(request);
142 } 142 }
143 143
144 void cancelLoader() override { m_loader->cancel(); } 144 void cancelLoader() override { m_loader->cancel(); }
145 void cancelAndClearLoader() override { 145 void cancelAndClearLoader() override {
146 m_loader->cancel(); 146 m_loader->cancel();
147 m_loader = nullptr; 147 m_loader = nullptr;
148 } 148 }
149 void clearLoader() override { m_loader = nullptr; } 149 void clearLoader() override { m_loader = nullptr; }
150 Checkpoint& checkpoint() override { return m_checkpoint; } 150 Checkpoint& getCheckpoint() override { return m_checkpoint; }
151 void callCheckpoint(int n) override { m_checkpoint.Call(n); } 151 void callCheckpoint(int n) override { m_checkpoint.Call(n); }
152 152
153 void onSetUp() override {} 153 void onSetUp() override {}
154 154
155 void onServeRequests() override {} 155 void onServeRequests() override {}
156 156
157 void onTearDown() override { 157 void onTearDown() override {
158 if (m_loader) { 158 if (m_loader) {
159 m_loader->cancel(); 159 m_loader->cancel();
160 m_loader = nullptr; 160 m_loader = nullptr;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 m_loader = nullptr; 215 m_loader = nullptr;
216 } 216 }
217 217
218 // Must be called on the worker thread. 218 // Must be called on the worker thread.
219 void clearLoader() override { 219 void clearLoader() override {
220 DCHECK(m_workerThread); 220 DCHECK(m_workerThread);
221 DCHECK(m_workerThread->isCurrentThread()); 221 DCHECK(m_workerThread->isCurrentThread());
222 m_loader = nullptr; 222 m_loader = nullptr;
223 } 223 }
224 224
225 Checkpoint& checkpoint() override { return m_checkpoint; } 225 Checkpoint& getCheckpoint() override { return m_checkpoint; }
226 226
227 void callCheckpoint(int n) override { 227 void callCheckpoint(int n) override {
228 testing::runPendingTasks(); 228 testing::runPendingTasks();
229 229
230 std::unique_ptr<WaitableEvent> completionEvent = 230 std::unique_ptr<WaitableEvent> completionEvent =
231 WTF::makeUnique<WaitableEvent>(); 231 WTF::makeUnique<WaitableEvent>();
232 postTaskToWorkerGlobalScope( 232 postTaskToWorkerGlobalScope(
233 BLINK_FROM_HERE, 233 BLINK_FROM_HERE,
234 crossThreadBind(&WorkerThreadableLoaderTestHelper::workerCallCheckpoint, 234 crossThreadBind(&WorkerThreadableLoaderTestHelper::workerCallCheckpoint,
235 crossThreadUnretained(this), 235 crossThreadUnretained(this),
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 367
368 void startLoader(const KURL& url) { 368 void startLoader(const KURL& url) {
369 ResourceRequest request(url); 369 ResourceRequest request(url);
370 request.setRequestContext(WebURLRequest::RequestContextObject); 370 request.setRequestContext(WebURLRequest::RequestContextObject);
371 m_helper->startLoader(request); 371 m_helper->startLoader(request);
372 } 372 }
373 373
374 void cancelLoader() { m_helper->cancelLoader(); } 374 void cancelLoader() { m_helper->cancelLoader(); }
375 void cancelAndClearLoader() { m_helper->cancelAndClearLoader(); } 375 void cancelAndClearLoader() { m_helper->cancelAndClearLoader(); }
376 void clearLoader() { m_helper->clearLoader(); } 376 void clearLoader() { m_helper->clearLoader(); }
377 Checkpoint& checkpoint() { return m_helper->checkpoint(); } 377 Checkpoint& getCheckpoint() { return m_helper->getCheckpoint(); }
378 void callCheckpoint(int n) { m_helper->callCheckpoint(n); } 378 void callCheckpoint(int n) { m_helper->callCheckpoint(n); }
379 379
380 void serveRequests() { 380 void serveRequests() {
381 m_helper->onServeRequests(); 381 m_helper->onServeRequests();
382 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); 382 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
383 } 383 }
384 384
385 void createLoader(CrossOriginRequestPolicy crossOriginRequestPolicy = 385 void createLoader(CrossOriginRequestPolicy crossOriginRequestPolicy =
386 AllowCrossOriginRequests) { 386 AllowCrossOriginRequests) {
387 m_helper->createLoader(client(), crossOriginRequestPolicy); 387 m_helper->createLoader(client(), crossOriginRequestPolicy);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 ::testing::Values(DocumentThreadableLoaderTest)); 460 ::testing::Values(DocumentThreadableLoaderTest));
461 461
462 INSTANTIATE_TEST_CASE_P(Worker, 462 INSTANTIATE_TEST_CASE_P(Worker,
463 ThreadableLoaderTest, 463 ThreadableLoaderTest,
464 ::testing::Values(WorkerThreadableLoaderTest)); 464 ::testing::Values(WorkerThreadableLoaderTest));
465 465
466 TEST_P(ThreadableLoaderTest, StartAndStop) {} 466 TEST_P(ThreadableLoaderTest, StartAndStop) {}
467 467
468 TEST_P(ThreadableLoaderTest, CancelAfterStart) { 468 TEST_P(ThreadableLoaderTest, CancelAfterStart) {
469 InSequence s; 469 InSequence s;
470 EXPECT_CALL(checkpoint(), Call(1)); 470 EXPECT_CALL(getCheckpoint(), Call(1));
471 createLoader(); 471 createLoader();
472 callCheckpoint(1); 472 callCheckpoint(1);
473 473
474 EXPECT_CALL(checkpoint(), Call(2)) 474 EXPECT_CALL(getCheckpoint(), Call(2))
475 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::cancelLoader)); 475 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::cancelLoader));
476 EXPECT_CALL(*client(), didFail(Truly(isCancellation))); 476 EXPECT_CALL(*client(), didFail(Truly(isCancellation)));
477 EXPECT_CALL(checkpoint(), Call(3)); 477 EXPECT_CALL(getCheckpoint(), Call(3));
478 478
479 startLoader(successURL()); 479 startLoader(successURL());
480 callCheckpoint(2); 480 callCheckpoint(2);
481 callCheckpoint(3); 481 callCheckpoint(3);
482 serveRequests(); 482 serveRequests();
483 } 483 }
484 484
485 TEST_P(ThreadableLoaderTest, CancelAndClearAfterStart) { 485 TEST_P(ThreadableLoaderTest, CancelAndClearAfterStart) {
486 InSequence s; 486 InSequence s;
487 EXPECT_CALL(checkpoint(), Call(1)); 487 EXPECT_CALL(getCheckpoint(), Call(1));
488 createLoader(); 488 createLoader();
489 callCheckpoint(1); 489 callCheckpoint(1);
490 490
491 EXPECT_CALL(checkpoint(), Call(2)) 491 EXPECT_CALL(getCheckpoint(), Call(2))
492 .WillOnce( 492 .WillOnce(
493 InvokeWithoutArgs(this, &ThreadableLoaderTest::cancelAndClearLoader)); 493 InvokeWithoutArgs(this, &ThreadableLoaderTest::cancelAndClearLoader));
494 EXPECT_CALL(*client(), didFail(Truly(isCancellation))); 494 EXPECT_CALL(*client(), didFail(Truly(isCancellation)));
495 EXPECT_CALL(checkpoint(), Call(3)); 495 EXPECT_CALL(getCheckpoint(), Call(3));
496 496
497 startLoader(successURL()); 497 startLoader(successURL());
498 callCheckpoint(2); 498 callCheckpoint(2);
499 callCheckpoint(3); 499 callCheckpoint(3);
500 serveRequests(); 500 serveRequests();
501 } 501 }
502 502
503 TEST_P(ThreadableLoaderTest, CancelInDidReceiveResponse) { 503 TEST_P(ThreadableLoaderTest, CancelInDidReceiveResponse) {
504 InSequence s; 504 InSequence s;
505 EXPECT_CALL(checkpoint(), Call(1)); 505 EXPECT_CALL(getCheckpoint(), Call(1));
506 createLoader(); 506 createLoader();
507 callCheckpoint(1); 507 callCheckpoint(1);
508 508
509 EXPECT_CALL(checkpoint(), Call(2)); 509 EXPECT_CALL(getCheckpoint(), Call(2));
510 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _)) 510 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _))
511 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::cancelLoader)); 511 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::cancelLoader));
512 EXPECT_CALL(*client(), didFail(Truly(isCancellation))); 512 EXPECT_CALL(*client(), didFail(Truly(isCancellation)));
513 513
514 startLoader(successURL()); 514 startLoader(successURL());
515 callCheckpoint(2); 515 callCheckpoint(2);
516 serveRequests(); 516 serveRequests();
517 } 517 }
518 518
519 TEST_P(ThreadableLoaderTest, CancelAndClearInDidReceiveResponse) { 519 TEST_P(ThreadableLoaderTest, CancelAndClearInDidReceiveResponse) {
520 InSequence s; 520 InSequence s;
521 EXPECT_CALL(checkpoint(), Call(1)); 521 EXPECT_CALL(getCheckpoint(), Call(1));
522 createLoader(); 522 createLoader();
523 callCheckpoint(1); 523 callCheckpoint(1);
524 524
525 EXPECT_CALL(checkpoint(), Call(2)); 525 EXPECT_CALL(getCheckpoint(), Call(2));
526 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _)) 526 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _))
527 .WillOnce( 527 .WillOnce(
528 InvokeWithoutArgs(this, &ThreadableLoaderTest::cancelAndClearLoader)); 528 InvokeWithoutArgs(this, &ThreadableLoaderTest::cancelAndClearLoader));
529 EXPECT_CALL(*client(), didFail(Truly(isCancellation))); 529 EXPECT_CALL(*client(), didFail(Truly(isCancellation)));
530 530
531 startLoader(successURL()); 531 startLoader(successURL());
532 callCheckpoint(2); 532 callCheckpoint(2);
533 serveRequests(); 533 serveRequests();
534 } 534 }
535 535
536 TEST_P(ThreadableLoaderTest, CancelInDidReceiveData) { 536 TEST_P(ThreadableLoaderTest, CancelInDidReceiveData) {
537 InSequence s; 537 InSequence s;
538 EXPECT_CALL(checkpoint(), Call(1)); 538 EXPECT_CALL(getCheckpoint(), Call(1));
539 createLoader(); 539 createLoader();
540 callCheckpoint(1); 540 callCheckpoint(1);
541 541
542 EXPECT_CALL(checkpoint(), Call(2)); 542 EXPECT_CALL(getCheckpoint(), Call(2));
543 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _)); 543 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _));
544 EXPECT_CALL(*client(), didReceiveData(_, _)) 544 EXPECT_CALL(*client(), didReceiveData(_, _))
545 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::cancelLoader)); 545 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::cancelLoader));
546 EXPECT_CALL(*client(), didFail(Truly(isCancellation))); 546 EXPECT_CALL(*client(), didFail(Truly(isCancellation)));
547 547
548 startLoader(successURL()); 548 startLoader(successURL());
549 callCheckpoint(2); 549 callCheckpoint(2);
550 serveRequests(); 550 serveRequests();
551 } 551 }
552 552
553 TEST_P(ThreadableLoaderTest, CancelAndClearInDidReceiveData) { 553 TEST_P(ThreadableLoaderTest, CancelAndClearInDidReceiveData) {
554 InSequence s; 554 InSequence s;
555 EXPECT_CALL(checkpoint(), Call(1)); 555 EXPECT_CALL(getCheckpoint(), Call(1));
556 createLoader(); 556 createLoader();
557 callCheckpoint(1); 557 callCheckpoint(1);
558 558
559 EXPECT_CALL(checkpoint(), Call(2)); 559 EXPECT_CALL(getCheckpoint(), Call(2));
560 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _)); 560 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _));
561 EXPECT_CALL(*client(), didReceiveData(_, _)) 561 EXPECT_CALL(*client(), didReceiveData(_, _))
562 .WillOnce( 562 .WillOnce(
563 InvokeWithoutArgs(this, &ThreadableLoaderTest::cancelAndClearLoader)); 563 InvokeWithoutArgs(this, &ThreadableLoaderTest::cancelAndClearLoader));
564 EXPECT_CALL(*client(), didFail(Truly(isCancellation))); 564 EXPECT_CALL(*client(), didFail(Truly(isCancellation)));
565 565
566 startLoader(successURL()); 566 startLoader(successURL());
567 callCheckpoint(2); 567 callCheckpoint(2);
568 serveRequests(); 568 serveRequests();
569 } 569 }
570 570
571 TEST_P(ThreadableLoaderTest, DidFinishLoading) { 571 TEST_P(ThreadableLoaderTest, DidFinishLoading) {
572 InSequence s; 572 InSequence s;
573 EXPECT_CALL(checkpoint(), Call(1)); 573 EXPECT_CALL(getCheckpoint(), Call(1));
574 createLoader(); 574 createLoader();
575 callCheckpoint(1); 575 callCheckpoint(1);
576 576
577 EXPECT_CALL(checkpoint(), Call(2)); 577 EXPECT_CALL(getCheckpoint(), Call(2));
578 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _)); 578 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _));
579 EXPECT_CALL(*client(), didReceiveData(StrEq("fox"), 4)); 579 EXPECT_CALL(*client(), didReceiveData(StrEq("fox"), 4));
580 // We expect didReceiveResourceTiming() calls in DocumentThreadableLoader; 580 // We expect didReceiveResourceTiming() calls in DocumentThreadableLoader;
581 // it's used to connect DocumentThreadableLoader to WorkerThreadableLoader, 581 // it's used to connect DocumentThreadableLoader to WorkerThreadableLoader,
582 // not to ThreadableLoaderClient. 582 // not to ThreadableLoaderClient.
583 EXPECT_CALL(*client(), didReceiveResourceTiming(_)); 583 EXPECT_CALL(*client(), didReceiveResourceTiming(_));
584 EXPECT_CALL(*client(), didFinishLoading(_, _)); 584 EXPECT_CALL(*client(), didFinishLoading(_, _));
585 585
586 startLoader(successURL()); 586 startLoader(successURL());
587 callCheckpoint(2); 587 callCheckpoint(2);
588 serveRequests(); 588 serveRequests();
589 } 589 }
590 590
591 TEST_P(ThreadableLoaderTest, CancelInDidFinishLoading) { 591 TEST_P(ThreadableLoaderTest, CancelInDidFinishLoading) {
592 InSequence s; 592 InSequence s;
593 EXPECT_CALL(checkpoint(), Call(1)); 593 EXPECT_CALL(getCheckpoint(), Call(1));
594 createLoader(); 594 createLoader();
595 callCheckpoint(1); 595 callCheckpoint(1);
596 596
597 EXPECT_CALL(checkpoint(), Call(2)); 597 EXPECT_CALL(getCheckpoint(), Call(2));
598 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _)); 598 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _));
599 EXPECT_CALL(*client(), didReceiveData(_, _)); 599 EXPECT_CALL(*client(), didReceiveData(_, _));
600 EXPECT_CALL(*client(), didReceiveResourceTiming(_)); 600 EXPECT_CALL(*client(), didReceiveResourceTiming(_));
601 EXPECT_CALL(*client(), didFinishLoading(_, _)) 601 EXPECT_CALL(*client(), didFinishLoading(_, _))
602 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::cancelLoader)); 602 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::cancelLoader));
603 603
604 startLoader(successURL()); 604 startLoader(successURL());
605 callCheckpoint(2); 605 callCheckpoint(2);
606 serveRequests(); 606 serveRequests();
607 } 607 }
608 608
609 TEST_P(ThreadableLoaderTest, ClearInDidFinishLoading) { 609 TEST_P(ThreadableLoaderTest, ClearInDidFinishLoading) {
610 InSequence s; 610 InSequence s;
611 EXPECT_CALL(checkpoint(), Call(1)); 611 EXPECT_CALL(getCheckpoint(), Call(1));
612 createLoader(); 612 createLoader();
613 callCheckpoint(1); 613 callCheckpoint(1);
614 614
615 EXPECT_CALL(checkpoint(), Call(2)); 615 EXPECT_CALL(getCheckpoint(), Call(2));
616 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _)); 616 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _));
617 EXPECT_CALL(*client(), didReceiveData(_, _)); 617 EXPECT_CALL(*client(), didReceiveData(_, _));
618 EXPECT_CALL(*client(), didReceiveResourceTiming(_)); 618 EXPECT_CALL(*client(), didReceiveResourceTiming(_));
619 EXPECT_CALL(*client(), didFinishLoading(_, _)) 619 EXPECT_CALL(*client(), didFinishLoading(_, _))
620 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::clearLoader)); 620 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::clearLoader));
621 621
622 startLoader(successURL()); 622 startLoader(successURL());
623 callCheckpoint(2); 623 callCheckpoint(2);
624 serveRequests(); 624 serveRequests();
625 } 625 }
626 626
627 TEST_P(ThreadableLoaderTest, DidFail) { 627 TEST_P(ThreadableLoaderTest, DidFail) {
628 InSequence s; 628 InSequence s;
629 EXPECT_CALL(checkpoint(), Call(1)); 629 EXPECT_CALL(getCheckpoint(), Call(1));
630 createLoader(); 630 createLoader();
631 callCheckpoint(1); 631 callCheckpoint(1);
632 632
633 EXPECT_CALL(checkpoint(), Call(2)); 633 EXPECT_CALL(getCheckpoint(), Call(2));
634 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _)); 634 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _));
635 EXPECT_CALL(*client(), didFail(Truly(isNotCancellation))); 635 EXPECT_CALL(*client(), didFail(Truly(isNotCancellation)));
636 636
637 startLoader(errorURL()); 637 startLoader(errorURL());
638 callCheckpoint(2); 638 callCheckpoint(2);
639 serveRequests(); 639 serveRequests();
640 } 640 }
641 641
642 TEST_P(ThreadableLoaderTest, CancelInDidFail) { 642 TEST_P(ThreadableLoaderTest, CancelInDidFail) {
643 InSequence s; 643 InSequence s;
644 EXPECT_CALL(checkpoint(), Call(1)); 644 EXPECT_CALL(getCheckpoint(), Call(1));
645 createLoader(); 645 createLoader();
646 callCheckpoint(1); 646 callCheckpoint(1);
647 647
648 EXPECT_CALL(checkpoint(), Call(2)); 648 EXPECT_CALL(getCheckpoint(), Call(2));
649 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _)); 649 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _));
650 EXPECT_CALL(*client(), didFail(_)) 650 EXPECT_CALL(*client(), didFail(_))
651 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::cancelLoader)); 651 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::cancelLoader));
652 652
653 startLoader(errorURL()); 653 startLoader(errorURL());
654 callCheckpoint(2); 654 callCheckpoint(2);
655 serveRequests(); 655 serveRequests();
656 } 656 }
657 657
658 TEST_P(ThreadableLoaderTest, ClearInDidFail) { 658 TEST_P(ThreadableLoaderTest, ClearInDidFail) {
659 InSequence s; 659 InSequence s;
660 EXPECT_CALL(checkpoint(), Call(1)); 660 EXPECT_CALL(getCheckpoint(), Call(1));
661 createLoader(); 661 createLoader();
662 callCheckpoint(1); 662 callCheckpoint(1);
663 663
664 EXPECT_CALL(checkpoint(), Call(2)); 664 EXPECT_CALL(getCheckpoint(), Call(2));
665 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _)); 665 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _));
666 EXPECT_CALL(*client(), didFail(_)) 666 EXPECT_CALL(*client(), didFail(_))
667 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::clearLoader)); 667 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::clearLoader));
668 668
669 startLoader(errorURL()); 669 startLoader(errorURL());
670 callCheckpoint(2); 670 callCheckpoint(2);
671 serveRequests(); 671 serveRequests();
672 } 672 }
673 673
674 TEST_P(ThreadableLoaderTest, DidFailInStart) { 674 TEST_P(ThreadableLoaderTest, DidFailInStart) {
675 InSequence s; 675 InSequence s;
676 EXPECT_CALL(checkpoint(), Call(1)); 676 EXPECT_CALL(getCheckpoint(), Call(1));
677 createLoader(DenyCrossOriginRequests); 677 createLoader(DenyCrossOriginRequests);
678 callCheckpoint(1); 678 callCheckpoint(1);
679 679
680 EXPECT_CALL( 680 EXPECT_CALL(
681 *client(), 681 *client(),
682 didFail(ResourceError(errorDomainBlinkInternal, 0, errorURL().getString(), 682 didFail(ResourceError(errorDomainBlinkInternal, 0, errorURL().getString(),
683 "Cross origin requests are not supported."))); 683 "Cross origin requests are not supported.")));
684 EXPECT_CALL(checkpoint(), Call(2)); 684 EXPECT_CALL(getCheckpoint(), Call(2));
685 685
686 startLoader(errorURL()); 686 startLoader(errorURL());
687 callCheckpoint(2); 687 callCheckpoint(2);
688 serveRequests(); 688 serveRequests();
689 } 689 }
690 690
691 TEST_P(ThreadableLoaderTest, CancelInDidFailInStart) { 691 TEST_P(ThreadableLoaderTest, CancelInDidFailInStart) {
692 InSequence s; 692 InSequence s;
693 EXPECT_CALL(checkpoint(), Call(1)); 693 EXPECT_CALL(getCheckpoint(), Call(1));
694 createLoader(DenyCrossOriginRequests); 694 createLoader(DenyCrossOriginRequests);
695 callCheckpoint(1); 695 callCheckpoint(1);
696 696
697 EXPECT_CALL(*client(), didFail(_)) 697 EXPECT_CALL(*client(), didFail(_))
698 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::cancelLoader)); 698 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::cancelLoader));
699 EXPECT_CALL(checkpoint(), Call(2)); 699 EXPECT_CALL(getCheckpoint(), Call(2));
700 700
701 startLoader(errorURL()); 701 startLoader(errorURL());
702 callCheckpoint(2); 702 callCheckpoint(2);
703 serveRequests(); 703 serveRequests();
704 } 704 }
705 705
706 TEST_P(ThreadableLoaderTest, ClearInDidFailInStart) { 706 TEST_P(ThreadableLoaderTest, ClearInDidFailInStart) {
707 InSequence s; 707 InSequence s;
708 EXPECT_CALL(checkpoint(), Call(1)); 708 EXPECT_CALL(getCheckpoint(), Call(1));
709 createLoader(DenyCrossOriginRequests); 709 createLoader(DenyCrossOriginRequests);
710 callCheckpoint(1); 710 callCheckpoint(1);
711 711
712 EXPECT_CALL(*client(), didFail(_)) 712 EXPECT_CALL(*client(), didFail(_))
713 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::clearLoader)); 713 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::clearLoader));
714 EXPECT_CALL(checkpoint(), Call(2)); 714 EXPECT_CALL(getCheckpoint(), Call(2));
715 715
716 startLoader(errorURL()); 716 startLoader(errorURL());
717 callCheckpoint(2); 717 callCheckpoint(2);
718 serveRequests(); 718 serveRequests();
719 } 719 }
720 720
721 TEST_P(ThreadableLoaderTest, DidFailAccessControlCheck) { 721 TEST_P(ThreadableLoaderTest, DidFailAccessControlCheck) {
722 InSequence s; 722 InSequence s;
723 EXPECT_CALL(checkpoint(), Call(1)); 723 EXPECT_CALL(getCheckpoint(), Call(1));
724 createLoader(UseAccessControl); 724 createLoader(UseAccessControl);
725 callCheckpoint(1); 725 callCheckpoint(1);
726 726
727 EXPECT_CALL(checkpoint(), Call(2)); 727 EXPECT_CALL(getCheckpoint(), Call(2));
728 EXPECT_CALL( 728 EXPECT_CALL(
729 *client(), 729 *client(),
730 didFailAccessControlCheck(ResourceError( 730 didFailAccessControlCheck(ResourceError(
731 errorDomainBlinkInternal, 0, successURL().getString(), 731 errorDomainBlinkInternal, 0, successURL().getString(),
732 "No 'Access-Control-Allow-Origin' header is present on the requested " 732 "No 'Access-Control-Allow-Origin' header is present on the requested "
733 "resource. Origin 'null' is therefore not allowed access."))); 733 "resource. Origin 'null' is therefore not allowed access.")));
734 734
735 startLoader(successURL()); 735 startLoader(successURL());
736 callCheckpoint(2); 736 callCheckpoint(2);
737 serveRequests(); 737 serveRequests();
738 } 738 }
739 739
740 TEST_P(ThreadableLoaderTest, CancelInDidFailAccessControlCheck) { 740 TEST_P(ThreadableLoaderTest, CancelInDidFailAccessControlCheck) {
741 InSequence s; 741 InSequence s;
742 EXPECT_CALL(checkpoint(), Call(1)); 742 EXPECT_CALL(getCheckpoint(), Call(1));
743 createLoader(UseAccessControl); 743 createLoader(UseAccessControl);
744 callCheckpoint(1); 744 callCheckpoint(1);
745 745
746 EXPECT_CALL(checkpoint(), Call(2)); 746 EXPECT_CALL(getCheckpoint(), Call(2));
747 EXPECT_CALL(*client(), didFailAccessControlCheck(_)) 747 EXPECT_CALL(*client(), didFailAccessControlCheck(_))
748 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::cancelLoader)); 748 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::cancelLoader));
749 749
750 startLoader(successURL()); 750 startLoader(successURL());
751 callCheckpoint(2); 751 callCheckpoint(2);
752 serveRequests(); 752 serveRequests();
753 } 753 }
754 754
755 TEST_P(ThreadableLoaderTest, ClearInDidFailAccessControlCheck) { 755 TEST_P(ThreadableLoaderTest, ClearInDidFailAccessControlCheck) {
756 InSequence s; 756 InSequence s;
757 EXPECT_CALL(checkpoint(), Call(1)); 757 EXPECT_CALL(getCheckpoint(), Call(1));
758 createLoader(UseAccessControl); 758 createLoader(UseAccessControl);
759 callCheckpoint(1); 759 callCheckpoint(1);
760 760
761 EXPECT_CALL(checkpoint(), Call(2)); 761 EXPECT_CALL(getCheckpoint(), Call(2));
762 EXPECT_CALL(*client(), didFailAccessControlCheck(_)) 762 EXPECT_CALL(*client(), didFailAccessControlCheck(_))
763 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::clearLoader)); 763 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::clearLoader));
764 764
765 startLoader(successURL()); 765 startLoader(successURL());
766 callCheckpoint(2); 766 callCheckpoint(2);
767 serveRequests(); 767 serveRequests();
768 } 768 }
769 769
770 TEST_P(ThreadableLoaderTest, RedirectDidFinishLoading) { 770 TEST_P(ThreadableLoaderTest, RedirectDidFinishLoading) {
771 InSequence s; 771 InSequence s;
772 EXPECT_CALL(checkpoint(), Call(1)); 772 EXPECT_CALL(getCheckpoint(), Call(1));
773 createLoader(); 773 createLoader();
774 callCheckpoint(1); 774 callCheckpoint(1);
775 775
776 EXPECT_CALL(checkpoint(), Call(2)); 776 EXPECT_CALL(getCheckpoint(), Call(2));
777 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _)); 777 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _));
778 EXPECT_CALL(*client(), didReceiveData(StrEq("fox"), 4)); 778 EXPECT_CALL(*client(), didReceiveData(StrEq("fox"), 4));
779 EXPECT_CALL(*client(), didReceiveResourceTiming(_)); 779 EXPECT_CALL(*client(), didReceiveResourceTiming(_));
780 EXPECT_CALL(*client(), didFinishLoading(_, _)); 780 EXPECT_CALL(*client(), didFinishLoading(_, _));
781 781
782 startLoader(redirectURL()); 782 startLoader(redirectURL());
783 callCheckpoint(2); 783 callCheckpoint(2);
784 serveRequests(); 784 serveRequests();
785 } 785 }
786 786
787 TEST_P(ThreadableLoaderTest, CancelInRedirectDidFinishLoading) { 787 TEST_P(ThreadableLoaderTest, CancelInRedirectDidFinishLoading) {
788 InSequence s; 788 InSequence s;
789 EXPECT_CALL(checkpoint(), Call(1)); 789 EXPECT_CALL(getCheckpoint(), Call(1));
790 createLoader(); 790 createLoader();
791 callCheckpoint(1); 791 callCheckpoint(1);
792 792
793 EXPECT_CALL(checkpoint(), Call(2)); 793 EXPECT_CALL(getCheckpoint(), Call(2));
794 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _)); 794 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _));
795 EXPECT_CALL(*client(), didReceiveData(StrEq("fox"), 4)); 795 EXPECT_CALL(*client(), didReceiveData(StrEq("fox"), 4));
796 EXPECT_CALL(*client(), didReceiveResourceTiming(_)); 796 EXPECT_CALL(*client(), didReceiveResourceTiming(_));
797 EXPECT_CALL(*client(), didFinishLoading(_, _)) 797 EXPECT_CALL(*client(), didFinishLoading(_, _))
798 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::cancelLoader)); 798 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::cancelLoader));
799 799
800 startLoader(redirectURL()); 800 startLoader(redirectURL());
801 callCheckpoint(2); 801 callCheckpoint(2);
802 serveRequests(); 802 serveRequests();
803 } 803 }
804 804
805 TEST_P(ThreadableLoaderTest, ClearInRedirectDidFinishLoading) { 805 TEST_P(ThreadableLoaderTest, ClearInRedirectDidFinishLoading) {
806 InSequence s; 806 InSequence s;
807 EXPECT_CALL(checkpoint(), Call(1)); 807 EXPECT_CALL(getCheckpoint(), Call(1));
808 createLoader(); 808 createLoader();
809 callCheckpoint(1); 809 callCheckpoint(1);
810 810
811 EXPECT_CALL(checkpoint(), Call(2)); 811 EXPECT_CALL(getCheckpoint(), Call(2));
812 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _)); 812 EXPECT_CALL(*client(), didReceiveResponseMock(_, _, _));
813 EXPECT_CALL(*client(), didReceiveData(StrEq("fox"), 4)); 813 EXPECT_CALL(*client(), didReceiveData(StrEq("fox"), 4));
814 EXPECT_CALL(*client(), didReceiveResourceTiming(_)); 814 EXPECT_CALL(*client(), didReceiveResourceTiming(_));
815 EXPECT_CALL(*client(), didFinishLoading(_, _)) 815 EXPECT_CALL(*client(), didFinishLoading(_, _))
816 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::clearLoader)); 816 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::clearLoader));
817 817
818 startLoader(redirectURL()); 818 startLoader(redirectURL());
819 callCheckpoint(2); 819 callCheckpoint(2);
820 serveRequests(); 820 serveRequests();
821 } 821 }
822 822
823 TEST_P(ThreadableLoaderTest, DidFailRedirectCheck) { 823 TEST_P(ThreadableLoaderTest, DidFailRedirectCheck) {
824 InSequence s; 824 InSequence s;
825 EXPECT_CALL(checkpoint(), Call(1)); 825 EXPECT_CALL(getCheckpoint(), Call(1));
826 createLoader(UseAccessControl); 826 createLoader(UseAccessControl);
827 callCheckpoint(1); 827 callCheckpoint(1);
828 828
829 EXPECT_CALL(checkpoint(), Call(2)); 829 EXPECT_CALL(getCheckpoint(), Call(2));
830 EXPECT_CALL(*client(), didFailRedirectCheck()); 830 EXPECT_CALL(*client(), didFailRedirectCheck());
831 831
832 startLoader(redirectLoopURL()); 832 startLoader(redirectLoopURL());
833 callCheckpoint(2); 833 callCheckpoint(2);
834 serveRequests(); 834 serveRequests();
835 } 835 }
836 836
837 TEST_P(ThreadableLoaderTest, CancelInDidFailRedirectCheck) { 837 TEST_P(ThreadableLoaderTest, CancelInDidFailRedirectCheck) {
838 InSequence s; 838 InSequence s;
839 EXPECT_CALL(checkpoint(), Call(1)); 839 EXPECT_CALL(getCheckpoint(), Call(1));
840 createLoader(UseAccessControl); 840 createLoader(UseAccessControl);
841 callCheckpoint(1); 841 callCheckpoint(1);
842 842
843 EXPECT_CALL(checkpoint(), Call(2)); 843 EXPECT_CALL(getCheckpoint(), Call(2));
844 EXPECT_CALL(*client(), didFailRedirectCheck()) 844 EXPECT_CALL(*client(), didFailRedirectCheck())
845 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::cancelLoader)); 845 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::cancelLoader));
846 846
847 startLoader(redirectLoopURL()); 847 startLoader(redirectLoopURL());
848 callCheckpoint(2); 848 callCheckpoint(2);
849 serveRequests(); 849 serveRequests();
850 } 850 }
851 851
852 TEST_P(ThreadableLoaderTest, ClearInDidFailRedirectCheck) { 852 TEST_P(ThreadableLoaderTest, ClearInDidFailRedirectCheck) {
853 InSequence s; 853 InSequence s;
854 EXPECT_CALL(checkpoint(), Call(1)); 854 EXPECT_CALL(getCheckpoint(), Call(1));
855 createLoader(UseAccessControl); 855 createLoader(UseAccessControl);
856 callCheckpoint(1); 856 callCheckpoint(1);
857 857
858 EXPECT_CALL(checkpoint(), Call(2)); 858 EXPECT_CALL(getCheckpoint(), Call(2));
859 EXPECT_CALL(*client(), didFailRedirectCheck()) 859 EXPECT_CALL(*client(), didFailRedirectCheck())
860 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::clearLoader)); 860 .WillOnce(InvokeWithoutArgs(this, &ThreadableLoaderTest::clearLoader));
861 861
862 startLoader(redirectLoopURL()); 862 startLoader(redirectLoopURL());
863 callCheckpoint(2); 863 callCheckpoint(2);
864 serveRequests(); 864 serveRequests();
865 } 865 }
866 866
867 // This test case checks blink doesn't crash even when the response arrives 867 // This test case checks blink doesn't crash even when the response arrives
868 // synchronously. 868 // synchronously.
869 TEST_P(ThreadableLoaderTest, GetResponseSynchronously) { 869 TEST_P(ThreadableLoaderTest, GetResponseSynchronously) {
870 InSequence s; 870 InSequence s;
871 EXPECT_CALL(checkpoint(), Call(1)); 871 EXPECT_CALL(getCheckpoint(), Call(1));
872 createLoader(UseAccessControl); 872 createLoader(UseAccessControl);
873 callCheckpoint(1); 873 callCheckpoint(1);
874 874
875 EXPECT_CALL(*client(), didFailAccessControlCheck(_)); 875 EXPECT_CALL(*client(), didFailAccessControlCheck(_));
876 EXPECT_CALL(checkpoint(), Call(2)); 876 EXPECT_CALL(getCheckpoint(), Call(2));
877 877
878 // Currently didFailAccessControlCheck is dispatched synchronously. This 878 // Currently didFailAccessControlCheck is dispatched synchronously. This
879 // test is not saying that didFailAccessControlCheck should be dispatched 879 // test is not saying that didFailAccessControlCheck should be dispatched
880 // synchronously, but is saying that even when a response is served 880 // synchronously, but is saying that even when a response is served
881 // synchronously it should not lead to a crash. 881 // synchronously it should not lead to a crash.
882 startLoader(KURL(KURL(), "about:blank")); 882 startLoader(KURL(KURL(), "about:blank"));
883 callCheckpoint(2); 883 callCheckpoint(2);
884 } 884 }
885 885
886 } // namespace 886 } // namespace
887 887
888 } // namespace blink 888 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698