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 "components/offline_pages/core/background/request_coordinator.h" | 5 #include "components/offline_pages/core/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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 bool completed_called_; | 111 bool completed_called_; |
112 bool changed_called_; | 112 bool changed_called_; |
113 bool network_progress_called_; | 113 bool network_progress_called_; |
114 int64_t network_progress_bytes_; | 114 int64_t network_progress_bytes_; |
115 RequestCoordinator::BackgroundSavePageResult last_status_; | 115 RequestCoordinator::BackgroundSavePageResult last_status_; |
116 SavePageRequest::RequestState state_; | 116 SavePageRequest::RequestState state_; |
117 }; | 117 }; |
118 | 118 |
119 class RequestCoordinatorTest : public testing::Test { | 119 class RequestCoordinatorTest : public testing::Test { |
120 public: | 120 public: |
| 121 using RequestCoordinatorState = RequestCoordinator::RequestCoordinatorState; |
| 122 |
121 RequestCoordinatorTest(); | 123 RequestCoordinatorTest(); |
122 ~RequestCoordinatorTest() override; | 124 ~RequestCoordinatorTest() override; |
123 | 125 |
124 void SetUp() override; | 126 void SetUp() override; |
125 | 127 |
126 void PumpLoop(); | 128 void PumpLoop(); |
127 | 129 |
128 RequestCoordinator* coordinator() const { | 130 RequestCoordinator* coordinator() const { |
129 return coordinator_taco_->request_coordinator(); | 131 return coordinator_taco_->request_coordinator(); |
130 } | 132 } |
131 | 133 |
132 bool is_busy() { return coordinator()->is_busy(); } | 134 RequestCoordinatorState state() { return coordinator()->state(); } |
133 | |
134 bool is_starting() { return coordinator()->is_starting(); } | |
135 | 135 |
136 // Test processing callback function. | 136 // Test processing callback function. |
137 void ProcessingCallbackFunction(bool result) { | 137 void ProcessingCallbackFunction(bool result) { |
138 processing_callback_called_ = true; | 138 processing_callback_called_ = true; |
139 processing_callback_result_ = result; | 139 processing_callback_result_ = result; |
140 } | 140 } |
141 | 141 |
142 // Callback function which releases a wait for it. | 142 // Callback function which releases a wait for it. |
143 void WaitingCallbackFunction(bool result) { waiter_.Signal(); } | 143 void WaitingCallbackFunction(bool result) { waiter_.Signal(); } |
144 | 144 |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 | 485 |
486 // Ensure that the forthcoming request does not finish - we simulate it being | 486 // Ensure that the forthcoming request does not finish - we simulate it being |
487 // in progress by asking it to skip making the completion callback. | 487 // in progress by asking it to skip making the completion callback. |
488 EnableOfflinerCallback(false); | 488 EnableOfflinerCallback(false); |
489 | 489 |
490 // Sending the request to the offliner should make it busy. | 490 // Sending the request to the offliner should make it busy. |
491 EXPECT_TRUE(coordinator()->StartScheduledProcessing(device_conditions(), | 491 EXPECT_TRUE(coordinator()->StartScheduledProcessing(device_conditions(), |
492 processing_callback())); | 492 processing_callback())); |
493 PumpLoop(); | 493 PumpLoop(); |
494 | 494 |
495 EXPECT_TRUE(is_busy()); | 495 EXPECT_TRUE(state() == RequestCoordinatorState::OFFLINING); |
496 // Since the offliner is disabled, this callback should not be called. | 496 // Since the offliner is disabled, this callback should not be called. |
497 EXPECT_FALSE(processing_callback_called()); | 497 EXPECT_FALSE(processing_callback_called()); |
498 | 498 |
499 // Now trying to start processing should return false since already busy. | 499 // Now trying to start processing should return false since already busy. |
500 EXPECT_FALSE(coordinator()->StartScheduledProcessing(device_conditions(), | 500 EXPECT_FALSE(coordinator()->StartScheduledProcessing(device_conditions(), |
501 processing_callback())); | 501 processing_callback())); |
502 } | 502 } |
503 | 503 |
504 TEST_F(RequestCoordinatorTest, StartImmediateProcessingWithNoRequests) { | 504 TEST_F(RequestCoordinatorTest, StartImmediateProcessingWithNoRequests) { |
505 EXPECT_TRUE(coordinator()->StartImmediateProcessing(processing_callback())); | 505 EXPECT_TRUE(coordinator()->StartImmediateProcessing(processing_callback())); |
(...skipping 28 matching lines...) Expand all Loading... |
534 // Start processing for this request. | 534 // Start processing for this request. |
535 EXPECT_NE(0, SavePageLater()); | 535 EXPECT_NE(0, SavePageLater()); |
536 | 536 |
537 // Disable the automatic offliner callback. | 537 // Disable the automatic offliner callback. |
538 EnableOfflinerCallback(false); | 538 EnableOfflinerCallback(false); |
539 | 539 |
540 // Sending the request to the offliner should make it busy. | 540 // Sending the request to the offliner should make it busy. |
541 EXPECT_TRUE(coordinator()->StartImmediateProcessing(processing_callback())); | 541 EXPECT_TRUE(coordinator()->StartImmediateProcessing(processing_callback())); |
542 PumpLoop(); | 542 PumpLoop(); |
543 | 543 |
544 EXPECT_TRUE(is_busy()); | 544 EXPECT_TRUE(state() == RequestCoordinatorState::OFFLINING); |
545 // Since the offliner is disabled, this callback should not be called. | 545 // Since the offliner is disabled, this callback should not be called. |
546 EXPECT_FALSE(processing_callback_called()); | 546 EXPECT_FALSE(processing_callback_called()); |
547 | 547 |
548 // Now trying to start processing should return false since already busy. | 548 // Now trying to start processing should return false since already busy. |
549 EXPECT_FALSE(coordinator()->StartImmediateProcessing(processing_callback())); | 549 EXPECT_FALSE(coordinator()->StartImmediateProcessing(processing_callback())); |
550 | 550 |
551 histograms().ExpectBucketCount("OfflinePages.Background.ImmediateStartStatus", | 551 histograms().ExpectBucketCount("OfflinePages.Background.ImmediateStartStatus", |
552 1 /* BUSY */, 1); | 552 1 /* BUSY */, 1); |
553 } | 553 } |
554 | 554 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 // Disconnect network. | 689 // Disconnect network. |
690 SetNetworkConnected(false); | 690 SetNetworkConnected(false); |
691 | 691 |
692 // Call the OfflinerDoneCallback to simulate the page being completed, wait | 692 // Call the OfflinerDoneCallback to simulate the page being completed, wait |
693 // for callbacks. | 693 // for callbacks. |
694 SendOfflinerDoneCallback(request, Offliner::RequestStatus::SAVED); | 694 SendOfflinerDoneCallback(request, Offliner::RequestStatus::SAVED); |
695 PumpLoop(); | 695 PumpLoop(); |
696 EXPECT_TRUE(processing_callback_called()); | 696 EXPECT_TRUE(processing_callback_called()); |
697 | 697 |
698 // Verify not busy with 2nd request (since no connection). | 698 // Verify not busy with 2nd request (since no connection). |
699 EXPECT_FALSE(is_busy()); | 699 EXPECT_FALSE(state() == RequestCoordinatorState::OFFLINING); |
700 | 700 |
701 // Now connect network and verify processing starts. | 701 // Now connect network and verify processing starts. |
702 SetNetworkConnected(true); | 702 SetNetworkConnected(true); |
703 CallConnectionTypeObserver(); | 703 CallConnectionTypeObserver(); |
704 PumpLoop(); | 704 PumpLoop(); |
705 EXPECT_TRUE(is_busy()); | 705 EXPECT_TRUE(state() == RequestCoordinatorState::OFFLINING); |
706 } | 706 } |
707 | 707 |
708 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailed) { | 708 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailed) { |
709 // Add a request to the queue, wait for callbacks to finish. | 709 // Add a request to the queue, wait for callbacks to finish. |
710 offline_pages::SavePageRequest request(kRequestId1, kUrl1, kClientId1, | 710 offline_pages::SavePageRequest request(kRequestId1, kUrl1, kClientId1, |
711 base::Time::Now(), kUserRequested); | 711 base::Time::Now(), kUserRequested); |
712 request.set_completed_attempt_count(kMaxCompletedTries - 1); | 712 request.set_completed_attempt_count(kMaxCompletedTries - 1); |
713 SetupForOfflinerDoneCallbackTest(&request); | 713 SetupForOfflinerDoneCallbackTest(&request); |
714 // Stop processing before completing the second request on the queue. | 714 // Stop processing before completing the second request on the queue. |
715 EnableOfflinerCallback(false); | 715 EnableOfflinerCallback(false); |
716 | 716 |
717 // Add second request to the queue to check handling when first fails. | 717 // Add second request to the queue to check handling when first fails. |
718 AddRequest2(); | 718 AddRequest2(); |
719 PumpLoop(); | 719 PumpLoop(); |
720 | 720 |
721 // Call the OfflinerDoneCallback to simulate the request failed, wait | 721 // Call the OfflinerDoneCallback to simulate the request failed, wait |
722 // for callbacks. | 722 // for callbacks. |
723 SendOfflinerDoneCallback(request, Offliner::RequestStatus::LOADING_FAILED); | 723 SendOfflinerDoneCallback(request, Offliner::RequestStatus::LOADING_FAILED); |
724 PumpLoop(); | 724 PumpLoop(); |
725 | 725 |
726 // For retriable failure, processing should continue to 2nd request so | 726 // For retriable failure, processing should continue to 2nd request so |
727 // no scheduler callback yet. | 727 // no scheduler callback yet. |
728 EXPECT_FALSE(processing_callback_called()); | 728 EXPECT_FALSE(processing_callback_called()); |
729 | 729 |
730 // Busy processing 2nd request. | 730 // Busy processing 2nd request. |
731 EXPECT_TRUE(is_busy()); | 731 EXPECT_TRUE(state() == RequestCoordinatorState::OFFLINING); |
732 | 732 |
733 coordinator()->queue()->GetRequests(base::Bind( | 733 coordinator()->queue()->GetRequests(base::Bind( |
734 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this))); | 734 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this))); |
735 PumpLoop(); | 735 PumpLoop(); |
736 | 736 |
737 // Now just one request in the queue since failed request removed | 737 // Now just one request in the queue since failed request removed |
738 // (max number of attempts exceeded). | 738 // (max number of attempts exceeded). |
739 EXPECT_EQ(1UL, last_requests().size()); | 739 EXPECT_EQ(1UL, last_requests().size()); |
740 // Check that the observer got the notification that we failed (and the | 740 // Check that the observer got the notification that we failed (and the |
741 // subsequent notification that the request was removed) since we exceeded | 741 // subsequent notification that the request was removed) since we exceeded |
(...skipping 21 matching lines...) Expand all Loading... |
763 // for callbacks. | 763 // for callbacks. |
764 SendOfflinerDoneCallback(request, | 764 SendOfflinerDoneCallback(request, |
765 Offliner::RequestStatus::LOADING_FAILED_NO_RETRY); | 765 Offliner::RequestStatus::LOADING_FAILED_NO_RETRY); |
766 PumpLoop(); | 766 PumpLoop(); |
767 | 767 |
768 // For no retry failure, processing should continue to 2nd request so | 768 // For no retry failure, processing should continue to 2nd request so |
769 // no scheduler callback yet. | 769 // no scheduler callback yet. |
770 EXPECT_FALSE(processing_callback_called()); | 770 EXPECT_FALSE(processing_callback_called()); |
771 | 771 |
772 // Busy processing 2nd request. | 772 // Busy processing 2nd request. |
773 EXPECT_TRUE(is_busy()); | 773 EXPECT_TRUE(state() == RequestCoordinatorState::OFFLINING); |
774 | 774 |
775 coordinator()->queue()->GetRequests(base::Bind( | 775 coordinator()->queue()->GetRequests(base::Bind( |
776 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this))); | 776 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this))); |
777 PumpLoop(); | 777 PumpLoop(); |
778 | 778 |
779 // Now just one request in the queue since non-retryable failure. | 779 // Now just one request in the queue since non-retryable failure. |
780 EXPECT_EQ(1UL, last_requests().size()); | 780 EXPECT_EQ(1UL, last_requests().size()); |
781 // Check that the observer got the notification that we failed (and the | 781 // Check that the observer got the notification that we failed (and the |
782 // subsequent notification that the request was removed). | 782 // subsequent notification that the request was removed). |
783 EXPECT_TRUE(observer().completed_called()); | 783 EXPECT_TRUE(observer().completed_called()); |
(...skipping 16 matching lines...) Expand all Loading... |
800 // for callbacks. | 800 // for callbacks. |
801 SendOfflinerDoneCallback(request, | 801 SendOfflinerDoneCallback(request, |
802 Offliner::RequestStatus::LOADING_FAILED_NO_NEXT); | 802 Offliner::RequestStatus::LOADING_FAILED_NO_NEXT); |
803 PumpLoop(); | 803 PumpLoop(); |
804 | 804 |
805 // For no next failure, processing should not continue to 2nd request so | 805 // For no next failure, processing should not continue to 2nd request so |
806 // expect scheduler callback. | 806 // expect scheduler callback. |
807 EXPECT_TRUE(processing_callback_called()); | 807 EXPECT_TRUE(processing_callback_called()); |
808 | 808 |
809 // Not busy for NO_NEXT failure. | 809 // Not busy for NO_NEXT failure. |
810 EXPECT_FALSE(is_busy()); | 810 EXPECT_FALSE(state() == RequestCoordinatorState::OFFLINING); |
811 | 811 |
812 coordinator()->queue()->GetRequests(base::Bind( | 812 coordinator()->queue()->GetRequests(base::Bind( |
813 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this))); | 813 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this))); |
814 PumpLoop(); | 814 PumpLoop(); |
815 | 815 |
816 // Both requests still in queue. | 816 // Both requests still in queue. |
817 EXPECT_EQ(2UL, last_requests().size()); | 817 EXPECT_EQ(2UL, last_requests().size()); |
818 } | 818 } |
819 | 819 |
820 TEST_F(RequestCoordinatorTest, OfflinerDoneForegroundCancel) { | 820 TEST_F(RequestCoordinatorTest, OfflinerDoneForegroundCancel) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
864 const std::unique_ptr<SavePageRequest>& found_request = | 864 const std::unique_ptr<SavePageRequest>& found_request = |
865 last_requests().front(); | 865 last_requests().front(); |
866 EXPECT_EQ(0L, found_request->completed_attempt_count()); | 866 EXPECT_EQ(0L, found_request->completed_attempt_count()); |
867 } | 867 } |
868 | 868 |
869 // If one item completes, and there are no more user requeted items left, | 869 // If one item completes, and there are no more user requeted items left, |
870 // we should make a scheduler entry for a non-user requested item. | 870 // we should make a scheduler entry for a non-user requested item. |
871 TEST_F(RequestCoordinatorTest, RequestNotPickedDisabledItemsRemain) { | 871 TEST_F(RequestCoordinatorTest, RequestNotPickedDisabledItemsRemain) { |
872 coordinator()->StartScheduledProcessing(device_conditions(), | 872 coordinator()->StartScheduledProcessing(device_conditions(), |
873 processing_callback()); | 873 processing_callback()); |
874 EXPECT_TRUE(is_starting()); | 874 EXPECT_TRUE(state() == RequestCoordinatorState::PICKING); |
875 | 875 |
876 // Call RequestNotPicked, simulating a request on the disabled list. | 876 // Call RequestNotPicked, simulating a request on the disabled list. |
877 CallRequestNotPicked(false, true); | 877 CallRequestNotPicked(false, true); |
878 PumpLoop(); | 878 PumpLoop(); |
879 | 879 |
880 EXPECT_FALSE(is_starting()); | 880 EXPECT_FALSE(state() == RequestCoordinatorState::PICKING); |
881 | 881 |
882 // The scheduler should have been called to schedule the disabled task for | 882 // The scheduler should have been called to schedule the disabled task for |
883 // 5 minutes from now. | 883 // 5 minutes from now. |
884 SchedulerStub* scheduler_stub = | 884 SchedulerStub* scheduler_stub = |
885 reinterpret_cast<SchedulerStub*>(coordinator()->scheduler()); | 885 reinterpret_cast<SchedulerStub*>(coordinator()->scheduler()); |
886 EXPECT_TRUE(scheduler_stub->backup_schedule_called()); | 886 EXPECT_TRUE(scheduler_stub->backup_schedule_called()); |
887 EXPECT_TRUE(scheduler_stub->unschedule_called()); | 887 EXPECT_TRUE(scheduler_stub->unschedule_called()); |
888 } | 888 } |
889 | 889 |
890 // If one item completes, and there are no more user requeted items left, | 890 // If one item completes, and there are no more user requeted items left, |
891 // we should make a scheduler entry for a non-user requested item. | 891 // we should make a scheduler entry for a non-user requested item. |
892 TEST_F(RequestCoordinatorTest, RequestNotPickedNonUserRequestedItemsRemain) { | 892 TEST_F(RequestCoordinatorTest, RequestNotPickedNonUserRequestedItemsRemain) { |
893 coordinator()->StartScheduledProcessing(device_conditions(), | 893 coordinator()->StartScheduledProcessing(device_conditions(), |
894 processing_callback()); | 894 processing_callback()); |
895 EXPECT_TRUE(is_starting()); | 895 EXPECT_TRUE(state() == RequestCoordinatorState::PICKING); |
896 | 896 |
897 // Call RequestNotPicked, and make sure we pick schedule a task for non user | 897 // Call RequestNotPicked, and make sure we pick schedule a task for non user |
898 // requested conditions, with no tasks on the disabled list. | 898 // requested conditions, with no tasks on the disabled list. |
899 CallRequestNotPicked(true, false); | 899 CallRequestNotPicked(true, false); |
900 PumpLoop(); | 900 PumpLoop(); |
901 | 901 |
902 EXPECT_FALSE(is_starting()); | 902 EXPECT_FALSE(state() == RequestCoordinatorState::PICKING); |
903 EXPECT_TRUE(processing_callback_called()); | 903 EXPECT_TRUE(processing_callback_called()); |
904 | 904 |
905 // The scheduler should have been called to schedule the non-user requested | 905 // The scheduler should have been called to schedule the non-user requested |
906 // task. | 906 // task. |
907 SchedulerStub* scheduler_stub = | 907 SchedulerStub* scheduler_stub = |
908 reinterpret_cast<SchedulerStub*>(coordinator()->scheduler()); | 908 reinterpret_cast<SchedulerStub*>(coordinator()->scheduler()); |
909 EXPECT_TRUE(scheduler_stub->schedule_called()); | 909 EXPECT_TRUE(scheduler_stub->schedule_called()); |
910 EXPECT_TRUE(scheduler_stub->unschedule_called()); | 910 EXPECT_TRUE(scheduler_stub->unschedule_called()); |
911 const Scheduler::TriggerConditions* conditions = | 911 const Scheduler::TriggerConditions* conditions = |
912 scheduler_stub->trigger_conditions(); | 912 scheduler_stub->trigger_conditions(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
955 PumpLoop(); | 955 PumpLoop(); |
956 | 956 |
957 DisableLoading(); | 957 DisableLoading(); |
958 EXPECT_TRUE(coordinator()->StartScheduledProcessing(device_conditions(), | 958 EXPECT_TRUE(coordinator()->StartScheduledProcessing(device_conditions(), |
959 processing_callback())); | 959 processing_callback())); |
960 | 960 |
961 // Let the async callbacks in the request coordinator run. | 961 // Let the async callbacks in the request coordinator run. |
962 PumpLoop(); | 962 PumpLoop(); |
963 EXPECT_TRUE(processing_callback_called()); | 963 EXPECT_TRUE(processing_callback_called()); |
964 | 964 |
965 EXPECT_FALSE(is_starting()); | 965 EXPECT_FALSE(state() == RequestCoordinatorState::PICKING); |
966 EXPECT_EQ(Offliner::LOADING_NOT_ACCEPTED, last_offlining_status()); | 966 EXPECT_EQ(Offliner::LOADING_NOT_ACCEPTED, last_offlining_status()); |
967 } | 967 } |
968 | 968 |
969 // TODO(dougarnett): Add StartScheduledProcessing test for QUEUE_UPDATE_FAILED. | 969 // TODO(dougarnett): Add StartScheduledProcessing test for QUEUE_UPDATE_FAILED. |
970 | 970 |
971 // This tests a StopProcessing call before we have actually started the | 971 // This tests a StopProcessing call before we have actually started the |
972 // offliner. | 972 // offliner. |
973 TEST_F(RequestCoordinatorTest, | 973 TEST_F(RequestCoordinatorTest, |
974 StartScheduledProcessingThenStopProcessingImmediately) { | 974 StartScheduledProcessingThenStopProcessingImmediately) { |
975 // Add a request to the queue, wait for callbacks to finish. | 975 // Add a request to the queue, wait for callbacks to finish. |
976 AddRequest1(); | 976 AddRequest1(); |
977 PumpLoop(); | 977 PumpLoop(); |
978 | 978 |
979 EXPECT_TRUE(coordinator()->StartScheduledProcessing(device_conditions(), | 979 EXPECT_TRUE(coordinator()->StartScheduledProcessing(device_conditions(), |
980 processing_callback())); | 980 processing_callback())); |
981 EXPECT_TRUE(is_starting()); | 981 EXPECT_TRUE(state() == RequestCoordinatorState::PICKING); |
982 | 982 |
983 // Now, quick, before it can do much (we haven't called PumpLoop), cancel it. | 983 // Now, quick, before it can do much (we haven't called PumpLoop), cancel it. |
984 coordinator()->StopProcessing(Offliner::REQUEST_COORDINATOR_CANCELED); | 984 coordinator()->StopProcessing(Offliner::REQUEST_COORDINATOR_CANCELED); |
985 | 985 |
986 // Let the async callbacks in the request coordinator run. | 986 // Let the async callbacks in the request coordinator run. |
987 PumpLoop(); | 987 PumpLoop(); |
988 EXPECT_TRUE(processing_callback_called()); | 988 EXPECT_TRUE(processing_callback_called()); |
989 | 989 |
990 EXPECT_FALSE(is_starting()); | 990 EXPECT_FALSE(state() == RequestCoordinatorState::PICKING); |
991 | 991 |
992 // OfflinerDoneCallback will not end up getting called with status SAVED, | 992 // OfflinerDoneCallback will not end up getting called with status SAVED, |
993 // since we cancelled the event before it called offliner_->LoadAndSave(). | 993 // since we cancelled the event before it called offliner_->LoadAndSave(). |
994 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED, | 994 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED, |
995 last_offlining_status()); | 995 last_offlining_status()); |
996 | 996 |
997 // Since offliner was not started, it will not have seen cancel call. | 997 // Since offliner was not started, it will not have seen cancel call. |
998 EXPECT_FALSE(OfflinerWasCanceled()); | 998 EXPECT_FALSE(OfflinerWasCanceled()); |
999 } | 999 } |
1000 | 1000 |
1001 // This tests a StopProcessing call after the prerenderer has been started. | 1001 // This tests a StopProcessing call after the prerenderer has been started. |
1002 TEST_F(RequestCoordinatorTest, | 1002 TEST_F(RequestCoordinatorTest, |
1003 StartScheduledProcessingThenStopProcessingLater) { | 1003 StartScheduledProcessingThenStopProcessingLater) { |
1004 // Add a request to the queue, wait for callbacks to finish. | 1004 // Add a request to the queue, wait for callbacks to finish. |
1005 AddRequest1(); | 1005 AddRequest1(); |
1006 PumpLoop(); | 1006 PumpLoop(); |
1007 | 1007 |
1008 // Ensure the start processing request stops before the completion callback. | 1008 // Ensure the start processing request stops before the completion callback. |
1009 EnableOfflinerCallback(false); | 1009 EnableOfflinerCallback(false); |
1010 | 1010 |
1011 EXPECT_TRUE(coordinator()->StartScheduledProcessing(device_conditions(), | 1011 EXPECT_TRUE(coordinator()->StartScheduledProcessing(device_conditions(), |
1012 processing_callback())); | 1012 processing_callback())); |
1013 EXPECT_TRUE(is_starting()); | 1013 EXPECT_TRUE(state() == RequestCoordinatorState::PICKING); |
1014 | 1014 |
1015 // Let all the async parts of the start processing pipeline run to completion. | 1015 // Let all the async parts of the start processing pipeline run to completion. |
1016 PumpLoop(); | 1016 PumpLoop(); |
1017 | 1017 |
1018 // Observer called for starting processing. | 1018 // Observer called for starting processing. |
1019 EXPECT_TRUE(observer().changed_called()); | 1019 EXPECT_TRUE(observer().changed_called()); |
1020 EXPECT_EQ(SavePageRequest::RequestState::OFFLINING, observer().state()); | 1020 EXPECT_EQ(SavePageRequest::RequestState::OFFLINING, observer().state()); |
1021 observer().Clear(); | 1021 observer().Clear(); |
1022 | 1022 |
1023 // Since the offliner is disabled, this callback should not be called. | 1023 // Since the offliner is disabled, this callback should not be called. |
1024 EXPECT_FALSE(processing_callback_called()); | 1024 EXPECT_FALSE(processing_callback_called()); |
1025 | 1025 |
1026 // Coordinator should now be busy. | 1026 // Coordinator should now be busy. |
1027 EXPECT_TRUE(is_busy()); | 1027 EXPECT_TRUE(state() == RequestCoordinatorState::OFFLINING); |
1028 EXPECT_FALSE(is_starting()); | 1028 EXPECT_FALSE(state() == RequestCoordinatorState::PICKING); |
1029 | 1029 |
1030 // Now we cancel it while the prerenderer is busy. | 1030 // Now we cancel it while the prerenderer is busy. |
1031 coordinator()->StopProcessing(Offliner::REQUEST_COORDINATOR_CANCELED); | 1031 coordinator()->StopProcessing(Offliner::REQUEST_COORDINATOR_CANCELED); |
1032 | 1032 |
1033 // Let the async callbacks in the cancel run. | 1033 // Let the async callbacks in the cancel run. |
1034 PumpLoop(); | 1034 PumpLoop(); |
1035 | 1035 |
1036 // Observer called for stopped processing. | 1036 // Observer called for stopped processing. |
1037 EXPECT_TRUE(observer().changed_called()); | 1037 EXPECT_TRUE(observer().changed_called()); |
1038 EXPECT_EQ(SavePageRequest::RequestState::AVAILABLE, observer().state()); | 1038 EXPECT_EQ(SavePageRequest::RequestState::AVAILABLE, observer().state()); |
1039 observer().Clear(); | 1039 observer().Clear(); |
1040 | 1040 |
1041 EXPECT_FALSE(is_busy()); | 1041 EXPECT_FALSE(state() == RequestCoordinatorState::OFFLINING); |
1042 | 1042 |
1043 // OfflinerDoneCallback will not end up getting called with status SAVED, | 1043 // OfflinerDoneCallback will not end up getting called with status SAVED, |
1044 // since we cancelled the event before the LoadAndSave completed. | 1044 // since we cancelled the event before the LoadAndSave completed. |
1045 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED, | 1045 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED, |
1046 last_offlining_status()); | 1046 last_offlining_status()); |
1047 | 1047 |
1048 // Since offliner was started, it will have seen cancel call. | 1048 // Since offliner was started, it will have seen cancel call. |
1049 EXPECT_TRUE(OfflinerWasCanceled()); | 1049 EXPECT_TRUE(OfflinerWasCanceled()); |
1050 } | 1050 } |
1051 | 1051 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1163 ->GetSinglePageTimeLimitWhenBackgroundScheduledInSeconds() + | 1163 ->GetSinglePageTimeLimitWhenBackgroundScheduledInSeconds() + |
1164 1)); | 1164 1)); |
1165 PumpLoop(); | 1165 PumpLoop(); |
1166 | 1166 |
1167 // Wait for timeout to expire. Use a TaskRunner with a DelayedTaskRunner | 1167 // Wait for timeout to expire. Use a TaskRunner with a DelayedTaskRunner |
1168 // which won't time out immediately, so the watchdog thread doesn't kill valid | 1168 // which won't time out immediately, so the watchdog thread doesn't kill valid |
1169 // tasks too soon. | 1169 // tasks too soon. |
1170 WaitForCallback(); | 1170 WaitForCallback(); |
1171 PumpLoop(); | 1171 PumpLoop(); |
1172 | 1172 |
1173 EXPECT_FALSE(is_starting()); | 1173 EXPECT_FALSE(state() == RequestCoordinatorState::PICKING); |
1174 EXPECT_FALSE(coordinator()->is_busy()); | 1174 EXPECT_FALSE(state() == RequestCoordinatorState::OFFLINING); |
1175 EXPECT_TRUE(OfflinerWasCanceled()); | 1175 EXPECT_TRUE(OfflinerWasCanceled()); |
1176 } | 1176 } |
1177 | 1177 |
1178 TEST_F(RequestCoordinatorTest, | 1178 TEST_F(RequestCoordinatorTest, |
1179 WatchdogTimeoutForImmediateProcessingNoLastSnapshot) { | 1179 WatchdogTimeoutForImmediateProcessingNoLastSnapshot) { |
1180 // Ensure that the new request does not finish - we simulate it being | 1180 // Ensure that the new request does not finish - we simulate it being |
1181 // in progress by asking it to skip making the completion callback. | 1181 // in progress by asking it to skip making the completion callback. |
1182 EnableOfflinerCallback(false); | 1182 EnableOfflinerCallback(false); |
1183 | 1183 |
1184 EXPECT_NE(0, SavePageLater()); | 1184 EXPECT_NE(0, SavePageLater()); |
1185 PumpLoop(); | 1185 PumpLoop(); |
1186 | 1186 |
1187 // Verify that immediate start from adding the request did happen. | 1187 // Verify that immediate start from adding the request did happen. |
1188 EXPECT_TRUE(coordinator()->is_busy()); | 1188 EXPECT_TRUE(state() == RequestCoordinatorState::OFFLINING); |
1189 | 1189 |
1190 // Advance the mock clock 1 second before the watchdog timeout. | 1190 // Advance the mock clock 1 second before the watchdog timeout. |
1191 AdvanceClockBy(base::TimeDelta::FromSeconds( | 1191 AdvanceClockBy(base::TimeDelta::FromSeconds( |
1192 coordinator() | 1192 coordinator() |
1193 ->policy() | 1193 ->policy() |
1194 ->GetSinglePageTimeLimitForImmediateLoadInSeconds() - | 1194 ->GetSinglePageTimeLimitForImmediateLoadInSeconds() - |
1195 1)); | 1195 1)); |
1196 PumpLoop(); | 1196 PumpLoop(); |
1197 | 1197 |
1198 // Verify still busy. | 1198 // Verify still busy. |
1199 EXPECT_TRUE(coordinator()->is_busy()); | 1199 EXPECT_TRUE(state() == RequestCoordinatorState::OFFLINING); |
1200 EXPECT_FALSE(OfflinerWasCanceled()); | 1200 EXPECT_FALSE(OfflinerWasCanceled()); |
1201 | 1201 |
1202 // Advance the mock clock past the watchdog timeout now. | 1202 // Advance the mock clock past the watchdog timeout now. |
1203 AdvanceClockBy(base::TimeDelta::FromSeconds(2)); | 1203 AdvanceClockBy(base::TimeDelta::FromSeconds(2)); |
1204 PumpLoop(); | 1204 PumpLoop(); |
1205 | 1205 |
1206 // Verify the request timed out. | 1206 // Verify the request timed out. |
1207 EXPECT_TRUE(OfflinerWasCanceled()); | 1207 EXPECT_TRUE(OfflinerWasCanceled()); |
1208 } | 1208 } |
1209 | 1209 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1253 AddRequest2(); | 1253 AddRequest2(); |
1254 PumpLoop(); | 1254 PumpLoop(); |
1255 | 1255 |
1256 // Set up for the call to StartScheduledProcessing. | 1256 // Set up for the call to StartScheduledProcessing. |
1257 EnableOfflinerCallback(false); | 1257 EnableOfflinerCallback(false); |
1258 | 1258 |
1259 // Sending the request to the offliner. | 1259 // Sending the request to the offliner. |
1260 EXPECT_TRUE(coordinator()->StartScheduledProcessing(device_conditions(), | 1260 EXPECT_TRUE(coordinator()->StartScheduledProcessing(device_conditions(), |
1261 waiting_callback())); | 1261 waiting_callback())); |
1262 PumpLoop(); | 1262 PumpLoop(); |
1263 EXPECT_TRUE(coordinator()->is_busy()); | 1263 EXPECT_TRUE(state() == RequestCoordinatorState::OFFLINING); |
1264 | 1264 |
1265 // Now lose the network connection. | 1265 // Now lose the network connection. |
1266 SetNetworkConnected(false); | 1266 SetNetworkConnected(false); |
1267 | 1267 |
1268 // Complete first request and then TryNextRequest should decide not | 1268 // Complete first request and then TryNextRequest should decide not |
1269 // to pick another request (because of no network connection). | 1269 // to pick another request (because of no network connection). |
1270 SendOfflinerDoneCallback(request1, Offliner::RequestStatus::SAVED); | 1270 SendOfflinerDoneCallback(request1, Offliner::RequestStatus::SAVED); |
1271 PumpLoop(); | 1271 PumpLoop(); |
1272 | 1272 |
1273 // Not starting nor busy with next request. | 1273 // Not starting nor busy with next request. |
1274 EXPECT_FALSE(coordinator()->is_starting()); | 1274 EXPECT_FALSE(state() == RequestCoordinatorState::PICKING); |
1275 EXPECT_FALSE(coordinator()->is_busy()); | 1275 EXPECT_FALSE(state() == RequestCoordinatorState::OFFLINING); |
1276 | 1276 |
1277 // Get queued requests. | 1277 // Get queued requests. |
1278 coordinator()->queue()->GetRequests(base::Bind( | 1278 coordinator()->queue()->GetRequests(base::Bind( |
1279 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this))); | 1279 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this))); |
1280 PumpLoop(); | 1280 PumpLoop(); |
1281 | 1281 |
1282 // We should find one request in the queue. | 1282 // We should find one request in the queue. |
1283 EXPECT_EQ(1UL, last_requests().size()); | 1283 EXPECT_EQ(1UL, last_requests().size()); |
1284 } | 1284 } |
1285 | 1285 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1369 } | 1369 } |
1370 | 1370 |
1371 TEST_F(RequestCoordinatorTest, | 1371 TEST_F(RequestCoordinatorTest, |
1372 SavePageStartsProcessingWhenConnectedAndNotLowEndDevice) { | 1372 SavePageStartsProcessingWhenConnectedAndNotLowEndDevice) { |
1373 // Turn off the callback so that the request stops before processing in | 1373 // Turn off the callback so that the request stops before processing in |
1374 // PumpLoop. | 1374 // PumpLoop. |
1375 EnableOfflinerCallback(false); | 1375 EnableOfflinerCallback(false); |
1376 EXPECT_NE(0, SavePageLater()); | 1376 EXPECT_NE(0, SavePageLater()); |
1377 PumpLoop(); | 1377 PumpLoop(); |
1378 | 1378 |
1379 EXPECT_TRUE(is_busy()); | 1379 EXPECT_TRUE(state() == RequestCoordinatorState::OFFLINING); |
1380 } | 1380 } |
1381 | 1381 |
1382 TEST_F(RequestCoordinatorTest, | 1382 TEST_F(RequestCoordinatorTest, |
1383 SavePageStartsProcessingWhenConnectedOnLowEndDeviceIfFlagEnabled) { | 1383 SavePageStartsProcessingWhenConnectedOnLowEndDeviceIfFlagEnabled) { |
1384 // Mark device as low-end device. | 1384 // Mark device as low-end device. |
1385 SetIsLowEndDeviceForTest(true); | 1385 SetIsLowEndDeviceForTest(true); |
1386 EXPECT_FALSE(offline_pages::IsOfflinePagesSvelteConcurrentLoadingEnabled()); | 1386 EXPECT_FALSE(offline_pages::IsOfflinePagesSvelteConcurrentLoadingEnabled()); |
1387 | 1387 |
1388 // Make a request. | 1388 // Make a request. |
1389 EXPECT_NE(0, SavePageLater()); | 1389 EXPECT_NE(0, SavePageLater()); |
1390 PumpLoop(); | 1390 PumpLoop(); |
1391 | 1391 |
1392 // Verify not immediately busy (since low-end device). | 1392 // Verify not immediately busy (since low-end device). |
1393 EXPECT_FALSE(is_busy()); | 1393 EXPECT_FALSE(state() == RequestCoordinatorState::OFFLINING); |
1394 | 1394 |
1395 // Set feature flag to allow concurrent loads. | 1395 // Set feature flag to allow concurrent loads. |
1396 base::test::ScopedFeatureList scoped_feature_list; | 1396 base::test::ScopedFeatureList scoped_feature_list; |
1397 scoped_feature_list.InitAndEnableFeature( | 1397 scoped_feature_list.InitAndEnableFeature( |
1398 kOfflinePagesSvelteConcurrentLoadingFeature); | 1398 kOfflinePagesSvelteConcurrentLoadingFeature); |
1399 EXPECT_TRUE(offline_pages::IsOfflinePagesSvelteConcurrentLoadingEnabled()); | 1399 EXPECT_TRUE(offline_pages::IsOfflinePagesSvelteConcurrentLoadingEnabled()); |
1400 | 1400 |
1401 // Turn off the callback so that the request stops before processing in | 1401 // Turn off the callback so that the request stops before processing in |
1402 // PumpLoop. | 1402 // PumpLoop. |
1403 EnableOfflinerCallback(false); | 1403 EnableOfflinerCallback(false); |
1404 | 1404 |
1405 // Make another request. | 1405 // Make another request. |
1406 RequestCoordinator::SavePageLaterParams params; | 1406 RequestCoordinator::SavePageLaterParams params; |
1407 params.url = kUrl2; | 1407 params.url = kUrl2; |
1408 params.client_id = kClientId2; | 1408 params.client_id = kClientId2; |
1409 params.user_requested = kUserRequested; | 1409 params.user_requested = kUserRequested; |
1410 EXPECT_NE(0, coordinator()->SavePageLater(params)); | 1410 EXPECT_NE(0, coordinator()->SavePageLater(params)); |
1411 PumpLoop(); | 1411 PumpLoop(); |
1412 | 1412 |
1413 // Verify immediate processing did start this time. | 1413 // Verify immediate processing did start this time. |
1414 EXPECT_TRUE(is_busy()); | 1414 EXPECT_TRUE(state() == RequestCoordinatorState::OFFLINING); |
1415 } | 1415 } |
1416 | 1416 |
1417 TEST_F(RequestCoordinatorTest, SavePageDoesntStartProcessingWhenDisconnected) { | 1417 TEST_F(RequestCoordinatorTest, SavePageDoesntStartProcessingWhenDisconnected) { |
1418 SetNetworkConnected(false); | 1418 SetNetworkConnected(false); |
1419 EnableOfflinerCallback(false); | 1419 EnableOfflinerCallback(false); |
1420 EXPECT_NE(0, SavePageLater()); | 1420 EXPECT_NE(0, SavePageLater()); |
1421 PumpLoop(); | 1421 PumpLoop(); |
1422 EXPECT_FALSE(is_busy()); | 1422 EXPECT_FALSE(state() == RequestCoordinatorState::OFFLINING); |
1423 | 1423 |
1424 // Now connect network and verify processing starts. | 1424 // Now connect network and verify processing starts. |
1425 SetNetworkConnected(true); | 1425 SetNetworkConnected(true); |
1426 CallConnectionTypeObserver(); | 1426 CallConnectionTypeObserver(); |
1427 PumpLoop(); | 1427 PumpLoop(); |
1428 EXPECT_TRUE(is_busy()); | 1428 EXPECT_TRUE(state() == RequestCoordinatorState::OFFLINING); |
1429 } | 1429 } |
1430 | 1430 |
1431 TEST_F(RequestCoordinatorTest, | 1431 TEST_F(RequestCoordinatorTest, |
1432 SavePageDoesStartProcessingWhenPoorlyConnected) { | 1432 SavePageDoesStartProcessingWhenPoorlyConnected) { |
1433 // Set specific network type for 2G with poor effective connection. | 1433 // Set specific network type for 2G with poor effective connection. |
1434 DeviceConditions device_conditions(!kPowerRequired, kBatteryPercentageHigh, | 1434 DeviceConditions device_conditions(!kPowerRequired, kBatteryPercentageHigh, |
1435 net::NetworkChangeNotifier::CONNECTION_2G); | 1435 net::NetworkChangeNotifier::CONNECTION_2G); |
1436 SetDeviceConditionsForTest(device_conditions); | 1436 SetDeviceConditionsForTest(device_conditions); |
1437 SetEffectiveConnectionTypeForTest( | 1437 SetEffectiveConnectionTypeForTest( |
1438 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_SLOW_2G); | 1438 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_SLOW_2G); |
1439 | 1439 |
1440 // Turn off the callback so that the request stops before processing in | 1440 // Turn off the callback so that the request stops before processing in |
1441 // PumpLoop. | 1441 // PumpLoop. |
1442 EnableOfflinerCallback(false); | 1442 EnableOfflinerCallback(false); |
1443 | 1443 |
1444 EXPECT_NE(0, SavePageLater()); | 1444 EXPECT_NE(0, SavePageLater()); |
1445 PumpLoop(); | 1445 PumpLoop(); |
1446 EXPECT_TRUE(is_busy()); | 1446 EXPECT_TRUE(state() == RequestCoordinatorState::OFFLINING); |
1447 } | 1447 } |
1448 | 1448 |
1449 TEST_F(RequestCoordinatorTest, | 1449 TEST_F(RequestCoordinatorTest, |
1450 ResumeStartsProcessingWhenConnectedAndNotLowEndDevice) { | 1450 ResumeStartsProcessingWhenConnectedAndNotLowEndDevice) { |
1451 // Start unconnected. | 1451 // Start unconnected. |
1452 SetNetworkConnected(false); | 1452 SetNetworkConnected(false); |
1453 | 1453 |
1454 // Turn off the callback so that the request stops before processing in | 1454 // Turn off the callback so that the request stops before processing in |
1455 // PumpLoop. | 1455 // PumpLoop. |
1456 EnableOfflinerCallback(false); | 1456 EnableOfflinerCallback(false); |
1457 | 1457 |
1458 // Add a request to the queue. | 1458 // Add a request to the queue. |
1459 AddRequest1(); | 1459 AddRequest1(); |
1460 PumpLoop(); | 1460 PumpLoop(); |
1461 EXPECT_FALSE(is_busy()); | 1461 EXPECT_FALSE(state() == RequestCoordinatorState::OFFLINING); |
1462 | 1462 |
1463 // Pause the request. | 1463 // Pause the request. |
1464 std::vector<int64_t> request_ids; | 1464 std::vector<int64_t> request_ids; |
1465 request_ids.push_back(kRequestId1); | 1465 request_ids.push_back(kRequestId1); |
1466 coordinator()->PauseRequests(request_ids); | 1466 coordinator()->PauseRequests(request_ids); |
1467 PumpLoop(); | 1467 PumpLoop(); |
1468 | 1468 |
1469 // Resume the request while disconnected. | 1469 // Resume the request while disconnected. |
1470 coordinator()->ResumeRequests(request_ids); | 1470 coordinator()->ResumeRequests(request_ids); |
1471 PumpLoop(); | 1471 PumpLoop(); |
1472 EXPECT_FALSE(is_busy()); | 1472 EXPECT_FALSE(state() == RequestCoordinatorState::OFFLINING); |
1473 EXPECT_EQ(1UL, prioritized_requests().size()); | 1473 EXPECT_EQ(1UL, prioritized_requests().size()); |
1474 | 1474 |
1475 // Pause the request again. | 1475 // Pause the request again. |
1476 coordinator()->PauseRequests(request_ids); | 1476 coordinator()->PauseRequests(request_ids); |
1477 PumpLoop(); | 1477 PumpLoop(); |
1478 EXPECT_EQ(0UL, prioritized_requests().size()); | 1478 EXPECT_EQ(0UL, prioritized_requests().size()); |
1479 | 1479 |
1480 // Now simulate reasonable connection. | 1480 // Now simulate reasonable connection. |
1481 SetNetworkConnected(true); | 1481 SetNetworkConnected(true); |
1482 | 1482 |
1483 // Resume the request while connected. | 1483 // Resume the request while connected. |
1484 coordinator()->ResumeRequests(request_ids); | 1484 coordinator()->ResumeRequests(request_ids); |
1485 EXPECT_FALSE(is_busy()); | 1485 EXPECT_FALSE(state() == RequestCoordinatorState::OFFLINING); |
1486 PumpLoop(); | 1486 PumpLoop(); |
1487 EXPECT_EQ(1UL, prioritized_requests().size()); | 1487 EXPECT_EQ(1UL, prioritized_requests().size()); |
1488 | 1488 |
1489 EXPECT_TRUE(is_busy()); | 1489 EXPECT_TRUE(state() == RequestCoordinatorState::OFFLINING); |
1490 } | 1490 } |
1491 | 1491 |
1492 TEST_F(RequestCoordinatorTest, SnapshotOnLastTryForScheduledProcessing) { | 1492 TEST_F(RequestCoordinatorTest, SnapshotOnLastTryForScheduledProcessing) { |
1493 // Build a request to use with the pre-renderer, and put it on the queue. | 1493 // Build a request to use with the pre-renderer, and put it on the queue. |
1494 offline_pages::SavePageRequest request(kRequestId1, kUrl1, kClientId1, | 1494 offline_pages::SavePageRequest request(kRequestId1, kUrl1, kClientId1, |
1495 base::Time::Now(), kUserRequested); | 1495 base::Time::Now(), kUserRequested); |
1496 // Set request to allow one more completed attempt. So that the next try would | 1496 // Set request to allow one more completed attempt. So that the next try would |
1497 // be the last retry. | 1497 // be the last retry. |
1498 int max_tries = coordinator()->policy()->GetMaxCompletedTries(); | 1498 int max_tries = coordinator()->policy()->GetMaxCompletedTries(); |
1499 request.set_completed_attempt_count(max_tries - 1); | 1499 request.set_completed_attempt_count(max_tries - 1); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1545 // Repeat the timeout for MaxCompleteTries - 1 times in order to increase the | 1545 // Repeat the timeout for MaxCompleteTries - 1 times in order to increase the |
1546 // completed tries on this request. | 1546 // completed tries on this request. |
1547 int max_tries = coordinator()->policy()->GetMaxCompletedTries(); | 1547 int max_tries = coordinator()->policy()->GetMaxCompletedTries(); |
1548 for (int i = 0; i < max_tries - 1; i++) { | 1548 for (int i = 0; i < max_tries - 1; i++) { |
1549 PumpLoop(); | 1549 PumpLoop(); |
1550 // Reset states. | 1550 // Reset states. |
1551 ResetOfflinerWasCanceled(); | 1551 ResetOfflinerWasCanceled(); |
1552 observer().Clear(); | 1552 observer().Clear(); |
1553 | 1553 |
1554 // Verify that the request is being processed. | 1554 // Verify that the request is being processed. |
1555 EXPECT_TRUE(coordinator()->is_busy()); | 1555 EXPECT_TRUE(state() == RequestCoordinatorState::OFFLINING); |
1556 | 1556 |
1557 // Advance the mock clock 1 second more than the watchdog timeout. | 1557 // Advance the mock clock 1 second more than the watchdog timeout. |
1558 AdvanceClockBy(base::TimeDelta::FromSeconds( | 1558 AdvanceClockBy(base::TimeDelta::FromSeconds( |
1559 coordinator() | 1559 coordinator() |
1560 ->policy() | 1560 ->policy() |
1561 ->GetSinglePageTimeLimitForImmediateLoadInSeconds() + | 1561 ->GetSinglePageTimeLimitForImmediateLoadInSeconds() + |
1562 1)); | 1562 1)); |
1563 PumpLoop(); | 1563 PumpLoop(); |
1564 | 1564 |
1565 // Verify the request timed out. | 1565 // Verify the request timed out. |
(...skipping 16 matching lines...) Expand all Loading... |
1582 PumpLoop(); | 1582 PumpLoop(); |
1583 | 1583 |
1584 // The last time would trigger the snapshot on last retry and succeed. | 1584 // The last time would trigger the snapshot on last retry and succeed. |
1585 EXPECT_FALSE(OfflinerWasCanceled()); | 1585 EXPECT_FALSE(OfflinerWasCanceled()); |
1586 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::SUCCESS, | 1586 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::SUCCESS, |
1587 observer().last_status()); | 1587 observer().last_status()); |
1588 EXPECT_TRUE(observer().completed_called()); | 1588 EXPECT_TRUE(observer().completed_called()); |
1589 } | 1589 } |
1590 | 1590 |
1591 } // namespace offline_pages | 1591 } // namespace offline_pages |
OLD | NEW |