Chromium Code Reviews| 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 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1064 // Our observer should have seen SUCCESS instead of REMOVED. | 1064 // Our observer should have seen SUCCESS instead of REMOVED. |
| 1065 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::SUCCESS, | 1065 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::SUCCESS, |
| 1066 observer().last_status()); | 1066 observer().last_status()); |
| 1067 EXPECT_TRUE(observer().completed_called()); | 1067 EXPECT_TRUE(observer().completed_called()); |
| 1068 } | 1068 } |
| 1069 | 1069 |
| 1070 TEST_F(RequestCoordinatorTest, WatchdogTimeoutForScheduledProcessing) { | 1070 TEST_F(RequestCoordinatorTest, WatchdogTimeoutForScheduledProcessing) { |
| 1071 // Build a request to use with the pre-renderer, and put it on the queue. | 1071 // Build a request to use with the pre-renderer, and put it on the queue. |
| 1072 offline_pages::SavePageRequest request( | 1072 offline_pages::SavePageRequest request( |
| 1073 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); | 1073 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); |
| 1074 // Set request to allow one more completed attempt. | |
| 1075 int max_tries = coordinator()->policy()->GetMaxCompletedTries(); | |
| 1076 while (request.completed_attempt_count() < max_tries - 1) | |
| 1077 request.MarkAttemptCompleted(); | |
|
Pete Williamson
2016/11/11 00:24:04
Instead of calling MarkAttemptCompleted, why not j
dougarnett
2016/11/11 16:36:45
Done.
| |
| 1074 coordinator()->queue()->AddRequest( | 1078 coordinator()->queue()->AddRequest( |
| 1075 request, | 1079 request, |
| 1076 base::Bind(&RequestCoordinatorTest::AddRequestDone, | 1080 base::Bind(&RequestCoordinatorTest::AddRequestDone, |
| 1077 base::Unretained(this))); | 1081 base::Unretained(this))); |
| 1078 PumpLoop(); | 1082 PumpLoop(); |
| 1079 | 1083 |
| 1080 // Set up for the call to StartProcessing. | 1084 // Set up for the call to StartProcessing. |
| 1081 DeviceConditions device_conditions( | 1085 DeviceConditions device_conditions( |
| 1082 !kPowerRequired, kBatteryPercentageHigh, | 1086 !kPowerRequired, kBatteryPercentageHigh, |
| 1083 net::NetworkChangeNotifier::CONNECTION_3G); | 1087 net::NetworkChangeNotifier::CONNECTION_3G); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1100 ->GetSinglePageTimeLimitWhenBackgroundScheduledInSeconds() + 1)); | 1104 ->GetSinglePageTimeLimitWhenBackgroundScheduledInSeconds() + 1)); |
| 1101 PumpLoop(); | 1105 PumpLoop(); |
| 1102 | 1106 |
| 1103 // Wait for timeout to expire. Use a TaskRunner with a DelayedTaskRunner | 1107 // Wait for timeout to expire. Use a TaskRunner with a DelayedTaskRunner |
| 1104 // which won't time out immediately, so the watchdog thread doesn't kill valid | 1108 // which won't time out immediately, so the watchdog thread doesn't kill valid |
| 1105 // tasks too soon. | 1109 // tasks too soon. |
| 1106 WaitForCallback(); | 1110 WaitForCallback(); |
| 1107 PumpLoop(); | 1111 PumpLoop(); |
| 1108 | 1112 |
| 1109 EXPECT_FALSE(is_starting()); | 1113 EXPECT_FALSE(is_starting()); |
| 1114 EXPECT_FALSE(coordinator()->is_busy()); | |
| 1110 EXPECT_TRUE(OfflinerWasCanceled()); | 1115 EXPECT_TRUE(OfflinerWasCanceled()); |
| 1111 } | 1116 } |
| 1112 | 1117 |
| 1113 TEST_F(RequestCoordinatorTest, WatchdogTimeoutForImmediateProcessing) { | 1118 TEST_F(RequestCoordinatorTest, WatchdogTimeoutForImmediateProcessing) { |
| 1114 // If low end device, pretend it is not so that immediate start happens. | 1119 // If low end device, pretend it is not so that immediate start happens. |
| 1115 SetIsLowEndDeviceForTest(false); | 1120 SetIsLowEndDeviceForTest(false); |
| 1116 | 1121 |
| 1117 // Ensure that the new request does not finish - we simulate it being | 1122 // Ensure that the new request does not finish - we simulate it being |
| 1118 // in progress by asking it to skip making the completion callback. | 1123 // in progress by asking it to skip making the completion callback. |
| 1119 EnableOfflinerCallback(false); | 1124 EnableOfflinerCallback(false); |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1412 // Now whether processing triggered immediately depends on whether test | 1417 // Now whether processing triggered immediately depends on whether test |
| 1413 // is run on svelte device or not. | 1418 // is run on svelte device or not. |
| 1414 if (base::SysInfo::IsLowEndDevice()) { | 1419 if (base::SysInfo::IsLowEndDevice()) { |
| 1415 EXPECT_FALSE(is_busy()); | 1420 EXPECT_FALSE(is_busy()); |
| 1416 } else { | 1421 } else { |
| 1417 EXPECT_TRUE(is_busy()); | 1422 EXPECT_TRUE(is_busy()); |
| 1418 } | 1423 } |
| 1419 } | 1424 } |
| 1420 | 1425 |
| 1421 } // namespace offline_pages | 1426 } // namespace offline_pages |
| OLD | NEW |