| 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/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 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1083 PumpLoop(); | 1083 PumpLoop(); |
| 1084 | 1084 |
| 1085 // Wait for timeout to expire. Use a TaskRunner with a DelayedTaskRunner | 1085 // Wait for timeout to expire. Use a TaskRunner with a DelayedTaskRunner |
| 1086 // which won't time out immediately, so the watchdog thread doesn't kill valid | 1086 // which won't time out immediately, so the watchdog thread doesn't kill valid |
| 1087 // tasks too soon. | 1087 // tasks too soon. |
| 1088 WaitForCallback(); | 1088 WaitForCallback(); |
| 1089 PumpLoop(); | 1089 PumpLoop(); |
| 1090 | 1090 |
| 1091 EXPECT_FALSE(is_starting()); | 1091 EXPECT_FALSE(is_starting()); |
| 1092 EXPECT_TRUE(OfflinerWasCanceled()); | 1092 EXPECT_TRUE(OfflinerWasCanceled()); |
| 1093 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_TIMED_OUT, | |
| 1094 last_offlining_status()); | |
| 1095 } | 1093 } |
| 1096 | 1094 |
| 1097 TEST_F(RequestCoordinatorTest, WatchdogTimeoutForImmediateProcessing) { | 1095 TEST_F(RequestCoordinatorTest, WatchdogTimeoutForImmediateProcessing) { |
| 1098 // If low end device, pretend it is not so that immediate start happens. | 1096 // If low end device, pretend it is not so that immediate start happens. |
| 1099 SetIsLowEndDeviceForTest(false); | 1097 SetIsLowEndDeviceForTest(false); |
| 1100 | 1098 |
| 1101 // Set up the fake network conditions for the NetworkConnectionNotifier. | 1099 // Set up the fake network conditions for the NetworkConnectionNotifier. |
| 1102 SetNetworkConditionsForTest( | 1100 SetNetworkConditionsForTest( |
| 1103 net::NetworkChangeNotifier::ConnectionType::CONNECTION_3G); | 1101 net::NetworkChangeNotifier::ConnectionType::CONNECTION_3G); |
| 1104 // Set up the fake network conditions for the network quality estimator. | 1102 // Set up the fake network conditions for the network quality estimator. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1127 | 1125 |
| 1128 // Verify still busy. | 1126 // Verify still busy. |
| 1129 EXPECT_TRUE(coordinator()->is_busy()); | 1127 EXPECT_TRUE(coordinator()->is_busy()); |
| 1130 EXPECT_FALSE(OfflinerWasCanceled()); | 1128 EXPECT_FALSE(OfflinerWasCanceled()); |
| 1131 | 1129 |
| 1132 // Advance the mock clock past the watchdog timeout now. | 1130 // Advance the mock clock past the watchdog timeout now. |
| 1133 AdvanceClockBy(base::TimeDelta::FromSeconds(2)); | 1131 AdvanceClockBy(base::TimeDelta::FromSeconds(2)); |
| 1134 PumpLoop(); | 1132 PumpLoop(); |
| 1135 | 1133 |
| 1136 // Verify the request timed out. | 1134 // Verify the request timed out. |
| 1137 EXPECT_FALSE(coordinator()->is_busy()); | |
| 1138 EXPECT_TRUE(OfflinerWasCanceled()); | 1135 EXPECT_TRUE(OfflinerWasCanceled()); |
| 1139 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_TIMED_OUT, | |
| 1140 last_offlining_status()); | |
| 1141 } | 1136 } |
| 1142 | 1137 |
| 1143 TEST_F(RequestCoordinatorTest, TimeBudgetExceeded) { | 1138 TEST_F(RequestCoordinatorTest, TimeBudgetExceeded) { |
| 1144 // Build two requests to use with the pre-renderer, and put it on the queue. | 1139 // Build two requests to use with the pre-renderer, and put it on the queue. |
| 1145 offline_pages::SavePageRequest request1( | 1140 offline_pages::SavePageRequest request1( |
| 1146 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); | 1141 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); |
| 1147 offline_pages::SavePageRequest request2( | 1142 offline_pages::SavePageRequest request2( |
| 1148 kRequestId1 + 1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); | 1143 kRequestId1 + 1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); |
| 1149 request2.set_completed_attempt_count(kAttemptCount); | 1144 request2.set_completed_attempt_count(kAttemptCount); |
| 1150 coordinator()->queue()->AddRequest( | 1145 coordinator()->queue()->AddRequest( |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1355 // Now whether processing triggered immediately depends on whether test | 1350 // Now whether processing triggered immediately depends on whether test |
| 1356 // is run on svelte device or not. | 1351 // is run on svelte device or not. |
| 1357 if (base::SysInfo::IsLowEndDevice()) { | 1352 if (base::SysInfo::IsLowEndDevice()) { |
| 1358 EXPECT_FALSE(is_busy()); | 1353 EXPECT_FALSE(is_busy()); |
| 1359 } else { | 1354 } else { |
| 1360 EXPECT_TRUE(is_busy()); | 1355 EXPECT_TRUE(is_busy()); |
| 1361 } | 1356 } |
| 1362 } | 1357 } |
| 1363 | 1358 |
| 1364 } // namespace offline_pages | 1359 } // namespace offline_pages |
| OLD | NEW |