| 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 28 matching lines...) Expand all Loading... |
| 39 // put test constants here | 39 // put test constants here |
| 40 const GURL kUrl1("http://universe.com/everything"); | 40 const GURL kUrl1("http://universe.com/everything"); |
| 41 const GURL kUrl2("http://universe.com/toinfinityandbeyond"); | 41 const GURL kUrl2("http://universe.com/toinfinityandbeyond"); |
| 42 const std::string kClientNamespace("bookmark"); | 42 const std::string kClientNamespace("bookmark"); |
| 43 const std::string kId1("42"); | 43 const std::string kId1("42"); |
| 44 const std::string kId2("life*universe+everything"); | 44 const std::string kId2("life*universe+everything"); |
| 45 const ClientId kClientId1(kClientNamespace, kId1); | 45 const ClientId kClientId1(kClientNamespace, kId1); |
| 46 const ClientId kClientId2(kClientNamespace, kId2); | 46 const ClientId kClientId2(kClientNamespace, kId2); |
| 47 const int kRequestId1(1); | 47 const int kRequestId1(1); |
| 48 const int kRequestId2(2); | 48 const int kRequestId2(2); |
| 49 const long kTestTimeBudgetSeconds = 200; | |
| 50 const int kBatteryPercentageHigh = 75; | 49 const int kBatteryPercentageHigh = 75; |
| 51 const int kMaxCompletedTries = 3; | 50 const int kMaxCompletedTries = 3; |
| 52 const bool kPowerRequired = true; | 51 const bool kPowerRequired = true; |
| 53 const bool kUserRequested = true; | 52 const bool kUserRequested = true; |
| 54 const int kAttemptCount = 1; | 53 const int kAttemptCount = 1; |
| 55 } // namespace | 54 } // namespace |
| 56 | 55 |
| 57 class ObserverStub : public RequestCoordinator::Observer { | 56 class ObserverStub : public RequestCoordinator::Observer { |
| 58 public: | 57 public: |
| 59 ObserverStub() | 58 ObserverStub() |
| (...skipping 1162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1222 PumpLoop(); | 1221 PumpLoop(); |
| 1223 | 1222 |
| 1224 // Sending the request to the offliner. | 1223 // Sending the request to the offliner. |
| 1225 EXPECT_TRUE(coordinator()->StartScheduledProcessing(device_conditions(), | 1224 EXPECT_TRUE(coordinator()->StartScheduledProcessing(device_conditions(), |
| 1226 waiting_callback())); | 1225 waiting_callback())); |
| 1227 PumpLoop(); | 1226 PumpLoop(); |
| 1228 | 1227 |
| 1229 // Advance the mock clock far enough to exceed our time budget. | 1228 // Advance the mock clock far enough to exceed our time budget. |
| 1230 // The first request will time out, and because we are over time budget, | 1229 // The first request will time out, and because we are over time budget, |
| 1231 // the second request will not be started. | 1230 // the second request will not be started. |
| 1232 AdvanceClockBy(base::TimeDelta::FromSeconds(kTestTimeBudgetSeconds)); | 1231 int over_time_budget_seconds = |
| 1232 OfflinerPolicy() |
| 1233 .GetProcessingTimeBudgetWhenBackgroundScheduledInSeconds() + |
| 1234 10; |
| 1235 AdvanceClockBy(base::TimeDelta::FromSeconds(over_time_budget_seconds)); |
| 1233 PumpLoop(); | 1236 PumpLoop(); |
| 1234 | 1237 |
| 1235 // TryNextRequest should decide that there is no more work to be done, | 1238 // TryNextRequest should decide that there is no more work to be done, |
| 1236 // and call back to the scheduler, even though there is another request in the | 1239 // and call back to the scheduler, even though there is another request in the |
| 1237 // queue. Both requests should be left in the queue. | 1240 // queue. Both requests should be left in the queue. |
| 1238 coordinator()->queue()->GetRequests(base::Bind( | 1241 coordinator()->queue()->GetRequests(base::Bind( |
| 1239 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this))); | 1242 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this))); |
| 1240 PumpLoop(); | 1243 PumpLoop(); |
| 1241 | 1244 |
| 1242 // We should find two requests in the queue. | 1245 // We should find two requests in the queue. |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1579 PumpLoop(); | 1582 PumpLoop(); |
| 1580 | 1583 |
| 1581 // 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. |
| 1582 EXPECT_FALSE(OfflinerWasCanceled()); | 1585 EXPECT_FALSE(OfflinerWasCanceled()); |
| 1583 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::SUCCESS, | 1586 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::SUCCESS, |
| 1584 observer().last_status()); | 1587 observer().last_status()); |
| 1585 EXPECT_TRUE(observer().completed_called()); | 1588 EXPECT_TRUE(observer().completed_called()); |
| 1586 } | 1589 } |
| 1587 | 1590 |
| 1588 } // namespace offline_pages | 1591 } // namespace offline_pages |
| OLD | NEW |