| 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 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1071 // Our observer should have seen SUCCESS instead of REMOVED. | 1071 // Our observer should have seen SUCCESS instead of REMOVED. |
| 1072 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::SUCCESS, | 1072 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::SUCCESS, |
| 1073 observer().last_status()); | 1073 observer().last_status()); |
| 1074 EXPECT_TRUE(observer().completed_called()); | 1074 EXPECT_TRUE(observer().completed_called()); |
| 1075 } | 1075 } |
| 1076 | 1076 |
| 1077 TEST_F(RequestCoordinatorTest, WatchdogTimeoutForScheduledProcessing) { | 1077 TEST_F(RequestCoordinatorTest, WatchdogTimeoutForScheduledProcessing) { |
| 1078 // Build a request to use with the pre-renderer, and put it on the queue. | 1078 // Build a request to use with the pre-renderer, and put it on the queue. |
| 1079 offline_pages::SavePageRequest request( | 1079 offline_pages::SavePageRequest request( |
| 1080 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); | 1080 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); |
| 1081 // Set request to allow one more completed attempt. |
| 1082 int max_tries = coordinator()->policy()->GetMaxCompletedTries(); |
| 1083 request.set_completed_attempt_count(max_tries - 1); |
| 1081 coordinator()->queue()->AddRequest( | 1084 coordinator()->queue()->AddRequest( |
| 1082 request, | 1085 request, |
| 1083 base::Bind(&RequestCoordinatorTest::AddRequestDone, | 1086 base::Bind(&RequestCoordinatorTest::AddRequestDone, |
| 1084 base::Unretained(this))); | 1087 base::Unretained(this))); |
| 1085 PumpLoop(); | 1088 PumpLoop(); |
| 1086 | 1089 |
| 1087 // Set up for the call to StartProcessing. | 1090 // Set up for the call to StartProcessing. |
| 1088 DeviceConditions device_conditions( | 1091 DeviceConditions device_conditions( |
| 1089 !kPowerRequired, kBatteryPercentageHigh, | 1092 !kPowerRequired, kBatteryPercentageHigh, |
| 1090 net::NetworkChangeNotifier::CONNECTION_3G); | 1093 net::NetworkChangeNotifier::CONNECTION_3G); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1107 ->GetSinglePageTimeLimitWhenBackgroundScheduledInSeconds() + 1)); | 1110 ->GetSinglePageTimeLimitWhenBackgroundScheduledInSeconds() + 1)); |
| 1108 PumpLoop(); | 1111 PumpLoop(); |
| 1109 | 1112 |
| 1110 // Wait for timeout to expire. Use a TaskRunner with a DelayedTaskRunner | 1113 // Wait for timeout to expire. Use a TaskRunner with a DelayedTaskRunner |
| 1111 // which won't time out immediately, so the watchdog thread doesn't kill valid | 1114 // which won't time out immediately, so the watchdog thread doesn't kill valid |
| 1112 // tasks too soon. | 1115 // tasks too soon. |
| 1113 WaitForCallback(); | 1116 WaitForCallback(); |
| 1114 PumpLoop(); | 1117 PumpLoop(); |
| 1115 | 1118 |
| 1116 EXPECT_FALSE(is_starting()); | 1119 EXPECT_FALSE(is_starting()); |
| 1120 EXPECT_FALSE(coordinator()->is_busy()); |
| 1117 EXPECT_TRUE(OfflinerWasCanceled()); | 1121 EXPECT_TRUE(OfflinerWasCanceled()); |
| 1118 } | 1122 } |
| 1119 | 1123 |
| 1120 TEST_F(RequestCoordinatorTest, WatchdogTimeoutForImmediateProcessing) { | 1124 TEST_F(RequestCoordinatorTest, WatchdogTimeoutForImmediateProcessing) { |
| 1121 // If low end device, pretend it is not so that immediate start happens. | 1125 // If low end device, pretend it is not so that immediate start happens. |
| 1122 SetIsLowEndDeviceForTest(false); | 1126 SetIsLowEndDeviceForTest(false); |
| 1123 | 1127 |
| 1124 // Ensure that the new request does not finish - we simulate it being | 1128 // Ensure that the new request does not finish - we simulate it being |
| 1125 // in progress by asking it to skip making the completion callback. | 1129 // in progress by asking it to skip making the completion callback. |
| 1126 EnableOfflinerCallback(false); | 1130 EnableOfflinerCallback(false); |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1458 // Now whether processing triggered immediately depends on whether test | 1462 // Now whether processing triggered immediately depends on whether test |
| 1459 // is run on svelte device or not. | 1463 // is run on svelte device or not. |
| 1460 if (base::SysInfo::IsLowEndDevice()) { | 1464 if (base::SysInfo::IsLowEndDevice()) { |
| 1461 EXPECT_FALSE(is_busy()); | 1465 EXPECT_FALSE(is_busy()); |
| 1462 } else { | 1466 } else { |
| 1463 EXPECT_TRUE(is_busy()); | 1467 EXPECT_TRUE(is_busy()); |
| 1464 } | 1468 } |
| 1465 } | 1469 } |
| 1466 | 1470 |
| 1467 } // namespace offline_pages | 1471 } // namespace offline_pages |
| OLD | NEW |