| 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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 // Empty callback function. | 240 // Empty callback function. |
| 241 void ImmediateScheduleCallbackFunction(bool result) { | 241 void ImmediateScheduleCallbackFunction(bool result) { |
| 242 immediate_schedule_callback_called_ = true; | 242 immediate_schedule_callback_called_ = true; |
| 243 } | 243 } |
| 244 | 244 |
| 245 // Callback function which releases a wait for it. | 245 // Callback function which releases a wait for it. |
| 246 void WaitingCallbackFunction(bool result) { | 246 void WaitingCallbackFunction(bool result) { |
| 247 waiter_.Signal(); | 247 waiter_.Signal(); |
| 248 } | 248 } |
| 249 | 249 |
| 250 net::NetworkChangeNotifier::ConnectionType GetConnectionType() { |
| 251 return coordinator()->GetConnectionType(); |
| 252 } |
| 253 |
| 250 // Callback for Add requests. | 254 // Callback for Add requests. |
| 251 void AddRequestDone(RequestQueue::AddRequestResult result, | 255 void AddRequestDone(RequestQueue::AddRequestResult result, |
| 252 const SavePageRequest& request); | 256 const SavePageRequest& request); |
| 253 | 257 |
| 254 // Callback for getting requests. | 258 // Callback for getting requests. |
| 255 void GetRequestsDone(RequestQueue::GetRequestsResult result, | 259 void GetRequestsDone(RequestQueue::GetRequestsResult result, |
| 256 std::vector<std::unique_ptr<SavePageRequest>> requests); | 260 std::vector<std::unique_ptr<SavePageRequest>> requests); |
| 257 | 261 |
| 258 // Callback for removing requests. | 262 // Callback for removing requests. |
| 259 void RemoveRequestsDone(const MultipleItemStatuses& results); | 263 void RemoveRequestsDone(const MultipleItemStatuses& results); |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 | 494 |
| 491 // Now trying to start processing on another request should return false. | 495 // Now trying to start processing on another request should return false. |
| 492 EXPECT_FALSE(coordinator()->StartProcessing(device_conditions, callback)); | 496 EXPECT_FALSE(coordinator()->StartProcessing(device_conditions, callback)); |
| 493 } | 497 } |
| 494 | 498 |
| 495 TEST_F(RequestCoordinatorTest, SavePageLater) { | 499 TEST_F(RequestCoordinatorTest, SavePageLater) { |
| 496 // Set up device conditions for the test and enable the offliner. | 500 // Set up device conditions for the test and enable the offliner. |
| 497 DeviceConditions device_conditions(false, 75, | 501 DeviceConditions device_conditions(false, 75, |
| 498 net::NetworkChangeNotifier::CONNECTION_3G); | 502 net::NetworkChangeNotifier::CONNECTION_3G); |
| 499 SetDeviceConditionsForTest(device_conditions); | 503 SetDeviceConditionsForTest(device_conditions); |
| 504 // Set up the fake network conditions for the NetworkConnectionNotifier. |
| 505 SetNetworkConditionsForTest( |
| 506 net::NetworkChangeNotifier::ConnectionType::CONNECTION_3G); |
| 507 // Set up the fake network conditions for the network quality estimator. |
| 500 SetEffectiveConnectionTypeForTest( | 508 SetEffectiveConnectionTypeForTest( |
| 501 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_3G); | 509 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_3G); |
| 502 EnableOfflinerCallback(true); | 510 EnableOfflinerCallback(true); |
| 503 base::Callback<void(bool)> callback = | 511 base::Callback<void(bool)> callback = |
| 504 base::Bind(&RequestCoordinatorTest::ImmediateScheduleCallbackFunction, | 512 base::Bind(&RequestCoordinatorTest::ImmediateScheduleCallbackFunction, |
| 505 base::Unretained(this)); | 513 base::Unretained(this)); |
| 506 | 514 |
| 507 // The user-requested request which gets processed by SavePageLater | 515 // The user-requested request which gets processed by SavePageLater |
| 508 // would invoke user request callback. | 516 // would invoke user request callback. |
| 509 coordinator()->SetImmediateScheduleCallbackForTest(callback); | 517 coordinator()->SetImmediateScheduleCallbackForTest(callback); |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1075 EXPECT_FALSE(is_starting()); | 1083 EXPECT_FALSE(is_starting()); |
| 1076 EXPECT_TRUE(OfflinerWasCanceled()); | 1084 EXPECT_TRUE(OfflinerWasCanceled()); |
| 1077 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_TIMED_OUT, | 1085 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_TIMED_OUT, |
| 1078 last_offlining_status()); | 1086 last_offlining_status()); |
| 1079 } | 1087 } |
| 1080 | 1088 |
| 1081 TEST_F(RequestCoordinatorTest, WatchdogTimeoutForImmediateProcessing) { | 1089 TEST_F(RequestCoordinatorTest, WatchdogTimeoutForImmediateProcessing) { |
| 1082 // If low end device, pretend it is not so that immediate start happens. | 1090 // If low end device, pretend it is not so that immediate start happens. |
| 1083 SetIsLowEndDeviceForTest(false); | 1091 SetIsLowEndDeviceForTest(false); |
| 1084 | 1092 |
| 1085 // Set good network connection so that adding request will trigger | 1093 // Set up the fake network conditions for the NetworkConnectionNotifier. |
| 1086 // immediate processing. | 1094 SetNetworkConditionsForTest( |
| 1095 net::NetworkChangeNotifier::ConnectionType::CONNECTION_3G); |
| 1096 // Set up the fake network conditions for the network quality estimator. |
| 1087 SetEffectiveConnectionTypeForTest( | 1097 SetEffectiveConnectionTypeForTest( |
| 1088 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_3G); | 1098 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_3G); |
| 1089 | 1099 |
| 1090 // Ensure that the new request does not finish - we simulate it being | 1100 // Ensure that the new request does not finish - we simulate it being |
| 1091 // in progress by asking it to skip making the completion callback. | 1101 // in progress by asking it to skip making the completion callback. |
| 1092 EnableOfflinerCallback(false); | 1102 EnableOfflinerCallback(false); |
| 1093 | 1103 |
| 1094 EXPECT_NE( | 1104 EXPECT_NE( |
| 1095 coordinator()->SavePageLater( | 1105 coordinator()->SavePageLater( |
| 1096 kUrl1, kClientId1, kUserRequested, | 1106 kUrl1, kClientId1, kUserRequested, |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1248 | 1258 |
| 1249 EXPECT_TRUE(observer().completed_called()); | 1259 EXPECT_TRUE(observer().completed_called()); |
| 1250 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::REMOVED, | 1260 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::REMOVED, |
| 1251 observer().last_status()); | 1261 observer().last_status()); |
| 1252 EXPECT_EQ(1UL, last_remove_results().size()); | 1262 EXPECT_EQ(1UL, last_remove_results().size()); |
| 1253 EXPECT_EQ(kRequestId1, std::get<0>(last_remove_results().at(0))); | 1263 EXPECT_EQ(kRequestId1, std::get<0>(last_remove_results().at(0))); |
| 1254 } | 1264 } |
| 1255 | 1265 |
| 1256 TEST_F(RequestCoordinatorTest, | 1266 TEST_F(RequestCoordinatorTest, |
| 1257 SavePageStartsProcessingWhenConnectedAndNotLowEndDevice) { | 1267 SavePageStartsProcessingWhenConnectedAndNotLowEndDevice) { |
| 1268 // Set up the fake network conditions for the NetworkConnectionNotifier. |
| 1269 SetNetworkConditionsForTest( |
| 1270 net::NetworkChangeNotifier::ConnectionType::CONNECTION_3G); |
| 1271 // Set up the fake network conditions for the network quality estimator. |
| 1258 SetEffectiveConnectionTypeForTest( | 1272 SetEffectiveConnectionTypeForTest( |
| 1259 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_3G); | 1273 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_3G); |
| 1260 EXPECT_NE( | 1274 EXPECT_NE( |
| 1261 coordinator()->SavePageLater( | 1275 coordinator()->SavePageLater( |
| 1262 kUrl1, kClientId1, kUserRequested, | 1276 kUrl1, kClientId1, kUserRequested, |
| 1263 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), 0); | 1277 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), 0); |
| 1264 PumpLoop(); | 1278 PumpLoop(); |
| 1265 | 1279 |
| 1266 // Now whether processing triggered immediately depends on whether test | 1280 // Now whether processing triggered immediately depends on whether test |
| 1267 // is run on svelte device or not. | 1281 // is run on svelte device or not. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1313 // Resume the request while disconnected. | 1327 // Resume the request while disconnected. |
| 1314 coordinator()->ResumeRequests(request_ids); | 1328 coordinator()->ResumeRequests(request_ids); |
| 1315 PumpLoop(); | 1329 PumpLoop(); |
| 1316 EXPECT_FALSE(is_busy()); | 1330 EXPECT_FALSE(is_busy()); |
| 1317 | 1331 |
| 1318 // Pause the request again. | 1332 // Pause the request again. |
| 1319 coordinator()->PauseRequests(request_ids); | 1333 coordinator()->PauseRequests(request_ids); |
| 1320 PumpLoop(); | 1334 PumpLoop(); |
| 1321 | 1335 |
| 1322 // Now simulate reasonable connection. | 1336 // Now simulate reasonable connection. |
| 1337 SetNetworkConditionsForTest( |
| 1338 net::NetworkChangeNotifier::ConnectionType::CONNECTION_3G); |
| 1323 SetEffectiveConnectionTypeForTest( | 1339 SetEffectiveConnectionTypeForTest( |
| 1324 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_3G); | 1340 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_3G); |
| 1325 | 1341 |
| 1326 // Resume the request while connected. | 1342 // Resume the request while connected. |
| 1327 coordinator()->ResumeRequests(request_ids); | 1343 coordinator()->ResumeRequests(request_ids); |
| 1328 EXPECT_FALSE(is_busy()); | 1344 EXPECT_FALSE(is_busy()); |
| 1329 PumpLoop(); | 1345 PumpLoop(); |
| 1330 | 1346 |
| 1331 // Now whether processing triggered immediately depends on whether test | 1347 // Now whether processing triggered immediately depends on whether test |
| 1332 // is run on svelte device or not. | 1348 // is run on svelte device or not. |
| 1333 if (base::SysInfo::IsLowEndDevice()) { | 1349 if (base::SysInfo::IsLowEndDevice()) { |
| 1334 EXPECT_FALSE(is_busy()); | 1350 EXPECT_FALSE(is_busy()); |
| 1335 } else { | 1351 } else { |
| 1336 EXPECT_TRUE(is_busy()); | 1352 EXPECT_TRUE(is_busy()); |
| 1337 } | 1353 } |
| 1338 } | 1354 } |
| 1339 | 1355 |
| 1340 } // namespace offline_pages | 1356 } // namespace offline_pages |
| OLD | NEW |