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

Side by Side Diff: components/offline_pages/background/request_coordinator_unittest.cc

Issue 2548903002: [OfflinePages] Classifies PRERENDERING_FAILED cases whether to TryNext (Closed)
Patch Set: Added a PrerenderingLoader unittest Created 4 years 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
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 "components/offline_pages/background/request_coordinator.h" 5 #include "components/offline_pages/background/request_coordinator.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 // Add second request to the queue to check handling when first fails. 582 // Add second request to the queue to check handling when first fails.
583 AddRequest2(); 583 AddRequest2();
584 PumpLoop(); 584 PumpLoop();
585 585
586 // Call the OfflinerDoneCallback to simulate the request failed, wait 586 // Call the OfflinerDoneCallback to simulate the request failed, wait
587 // for callbacks. 587 // for callbacks.
588 SendOfflinerDoneCallback(request, 588 SendOfflinerDoneCallback(request,
589 Offliner::RequestStatus::PRERENDERING_FAILED); 589 Offliner::RequestStatus::PRERENDERING_FAILED);
590 PumpLoop(); 590 PumpLoop();
591 591
592 // For retriable failure, processing should stop and scheduler callback 592 // For retriable failure, processing should continue to 2nd request so
593 // called (so that request can be retried first next processing window). 593 // no scheduler callback yet.
594 EXPECT_TRUE(immediate_schedule_callback_called()); 594 EXPECT_FALSE(immediate_schedule_callback_called());
595 595
596 // TODO(dougarnett): Consider injecting mock RequestPicker for this test 596 // Busy processing 2nd request.
597 // and verifying that there is no attempt to pick another request following 597 EXPECT_TRUE(is_busy());
598 // this failure code.
599 598
600 coordinator()->queue()->GetRequests( 599 coordinator()->queue()->GetRequests(
601 base::Bind(&RequestCoordinatorTest::GetRequestsDone, 600 base::Bind(&RequestCoordinatorTest::GetRequestsDone,
602 base::Unretained(this))); 601 base::Unretained(this)));
603 PumpLoop(); 602 PumpLoop();
604 603
605 // Now just one request in the queue since failed request removed 604 // Now just one request in the queue since failed request removed
606 // (max number of attempts exceeded). 605 // (max number of attempts exceeded).
607 EXPECT_EQ(1UL, last_requests().size()); 606 EXPECT_EQ(1UL, last_requests().size());
608 // Check that the observer got the notification that we failed (and the 607 // Check that the observer got the notification that we failed (and the
609 // subsequent notification that the request was removed). 608 // subsequent notification that the request was removed) since we exceeded
609 // retry count.
610 EXPECT_TRUE(observer().completed_called()); 610 EXPECT_TRUE(observer().completed_called());
611 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::RETRY_COUNT_EXCEEDED, 611 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::RETRY_COUNT_EXCEEDED,
612 observer().last_status()); 612 observer().last_status());
613 } 613 }
614 614
615 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailedNoRetryFailure) { 615 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailedNoRetryFailure) {
616 // Add a request to the queue, wait for callbacks to finish. 616 // Add a request to the queue, wait for callbacks to finish.
617 offline_pages::SavePageRequest request(kRequestId1, kUrl1, kClientId1, 617 offline_pages::SavePageRequest request(kRequestId1, kUrl1, kClientId1,
618 base::Time::Now(), kUserRequested); 618 base::Time::Now(), kUserRequested);
619 SetupForOfflinerDoneCallbackTest(&request); 619 SetupForOfflinerDoneCallbackTest(&request);
620 EnableOfflinerCallback(false); 620 EnableOfflinerCallback(false);
621 621
622 // Add second request to the queue to check handling when first fails. 622 // Add second request to the queue to check handling when first fails.
623 AddRequest2(); 623 AddRequest2();
624 PumpLoop(); 624 PumpLoop();
625 625
626 // Call the OfflinerDoneCallback to simulate the request failed, wait 626 // Call the OfflinerDoneCallback to simulate the request failed, wait
627 // for callbacks. 627 // for callbacks.
628 SendOfflinerDoneCallback( 628 SendOfflinerDoneCallback(
629 request, Offliner::RequestStatus::PRERENDERING_FAILED_NO_RETRY); 629 request, Offliner::RequestStatus::PRERENDERING_FAILED_NO_RETRY);
630 PumpLoop(); 630 PumpLoop();
631 631
632 // For no retry failure, processing should continue to 2nd request so 632 // For no retry failure, processing should continue to 2nd request so
633 // no scheduler callback yet. 633 // no scheduler callback yet.
634 EXPECT_FALSE(immediate_schedule_callback_called()); 634 EXPECT_FALSE(immediate_schedule_callback_called());
635 635
636 // TODO(dougarnett): Consider injecting mock RequestPicker for this test 636 // Busy processing 2nd request.
637 // and verifying that there is as attempt to pick another request following 637 EXPECT_TRUE(is_busy());
638 // this non-retryable failure code.
639 638
640 coordinator()->queue()->GetRequests(base::Bind( 639 coordinator()->queue()->GetRequests(base::Bind(
641 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this))); 640 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this)));
642 PumpLoop(); 641 PumpLoop();
643 642
644 // Now just one request in the queue since non-retryable failure. 643 // Now just one request in the queue since non-retryable failure.
645 EXPECT_EQ(1UL, last_requests().size()); 644 EXPECT_EQ(1UL, last_requests().size());
646 // Check that the observer got the notification that we failed (and the 645 // Check that the observer got the notification that we failed (and the
647 // subsequent notification that the request was removed). 646 // subsequent notification that the request was removed).
648 EXPECT_TRUE(observer().completed_called()); 647 EXPECT_TRUE(observer().completed_called());
649 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::PRERENDER_FAILURE, 648 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::PRERENDER_FAILURE,
650 observer().last_status()); 649 observer().last_status());
651 } 650 }
652 651
652 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailedNoNextFailure) {
653 // Add a request to the queue, wait for callbacks to finish.
654 offline_pages::SavePageRequest request(kRequestId1, kUrl1, kClientId1,
655 base::Time::Now(), kUserRequested);
656 SetupForOfflinerDoneCallbackTest(&request);
657 EnableOfflinerCallback(false);
658
659 // Add second request to the queue to check handling when first fails.
660 AddRequest2();
661 PumpLoop();
662
663 // Call the OfflinerDoneCallback to simulate the request failed, wait
664 // for callbacks.
665 SendOfflinerDoneCallback(
666 request, Offliner::RequestStatus::PRERENDERING_FAILED_NO_NEXT);
667 PumpLoop();
668
669 // For no next failure, processing should not continue to 2nd request so
670 // expect scheduler callback.
671 EXPECT_TRUE(immediate_schedule_callback_called());
672
673 // Not busy for NO_NEXT failure.
674 EXPECT_FALSE(is_busy());
675
676 coordinator()->queue()->GetRequests(base::Bind(
677 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this)));
678 PumpLoop();
679
680 // Both requests still in queue.
681 EXPECT_EQ(2UL, last_requests().size());
682 }
683
653 TEST_F(RequestCoordinatorTest, OfflinerDoneForegroundCancel) { 684 TEST_F(RequestCoordinatorTest, OfflinerDoneForegroundCancel) {
654 // Add a request to the queue, wait for callbacks to finish. 685 // Add a request to the queue, wait for callbacks to finish.
655 offline_pages::SavePageRequest request( 686 offline_pages::SavePageRequest request(
656 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); 687 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested);
657 SetupForOfflinerDoneCallbackTest(&request); 688 SetupForOfflinerDoneCallbackTest(&request);
658 689
659 // Call the OfflinerDoneCallback to simulate the request failed, wait 690 // Call the OfflinerDoneCallback to simulate the request failed, wait
660 // for callbacks. 691 // for callbacks.
661 SendOfflinerDoneCallback(request, 692 SendOfflinerDoneCallback(request,
662 Offliner::RequestStatus::FOREGROUND_CANCELED); 693 Offliner::RequestStatus::FOREGROUND_CANCELED);
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 // Now whether processing triggered immediately depends on whether test 1343 // Now whether processing triggered immediately depends on whether test
1313 // is run on svelte device or not. 1344 // is run on svelte device or not.
1314 if (base::SysInfo::IsLowEndDevice()) { 1345 if (base::SysInfo::IsLowEndDevice()) {
1315 EXPECT_FALSE(is_busy()); 1346 EXPECT_FALSE(is_busy());
1316 } else { 1347 } else {
1317 EXPECT_TRUE(is_busy()); 1348 EXPECT_TRUE(is_busy());
1318 } 1349 }
1319 } 1350 }
1320 1351
1321 } // namespace offline_pages 1352 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/background/request_coordinator_event_logger.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698