| 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 24 matching lines...) Expand all Loading... |
| 35 const GURL kUrl2("http://universe.com/toinfinityandbeyond"); | 35 const GURL kUrl2("http://universe.com/toinfinityandbeyond"); |
| 36 const std::string kClientNamespace("bookmark"); | 36 const std::string kClientNamespace("bookmark"); |
| 37 const std::string kId1("42"); | 37 const std::string kId1("42"); |
| 38 const std::string kId2("life*universe+everything"); | 38 const std::string kId2("life*universe+everything"); |
| 39 const ClientId kClientId1(kClientNamespace, kId1); | 39 const ClientId kClientId1(kClientNamespace, kId1); |
| 40 const ClientId kClientId2(kClientNamespace, kId2); | 40 const ClientId kClientId2(kClientNamespace, kId2); |
| 41 const int kRequestId1(1); | 41 const int kRequestId1(1); |
| 42 const int kRequestId2(2); | 42 const int kRequestId2(2); |
| 43 const long kTestTimeBudgetSeconds = 200; | 43 const long kTestTimeBudgetSeconds = 200; |
| 44 const int kBatteryPercentageHigh = 75; | 44 const int kBatteryPercentageHigh = 75; |
| 45 const int kMaxCompletedTries = 3; |
| 45 const bool kPowerRequired = true; | 46 const bool kPowerRequired = true; |
| 46 const bool kUserRequested = true; | 47 const bool kUserRequested = true; |
| 47 const int kAttemptCount = 1; | 48 const int kAttemptCount = 1; |
| 48 } // namespace | 49 } // namespace |
| 49 | 50 |
| 50 class SchedulerStub : public Scheduler { | 51 class SchedulerStub : public Scheduler { |
| 51 public: | 52 public: |
| 52 SchedulerStub() | 53 SchedulerStub() |
| 53 : schedule_called_(false), | 54 : schedule_called_(false), |
| 54 backup_schedule_called_(false), | 55 backup_schedule_called_(false), |
| (...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 // the request got removed from the queue. | 635 // the request got removed from the queue. |
| 635 EXPECT_TRUE(observer().completed_called()); | 636 EXPECT_TRUE(observer().completed_called()); |
| 636 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::SUCCESS, | 637 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::SUCCESS, |
| 637 observer().last_status()); | 638 observer().last_status()); |
| 638 } | 639 } |
| 639 | 640 |
| 640 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailed) { | 641 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailed) { |
| 641 // Add a request to the queue, wait for callbacks to finish. | 642 // Add a request to the queue, wait for callbacks to finish. |
| 642 offline_pages::SavePageRequest request( | 643 offline_pages::SavePageRequest request( |
| 643 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); | 644 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); |
| 645 request.set_completed_attempt_count(kMaxCompletedTries - 1); |
| 644 SetupForOfflinerDoneCallbackTest(&request); | 646 SetupForOfflinerDoneCallbackTest(&request); |
| 645 | 647 |
| 646 // Add second request to the queue to check handling when first fails. | 648 // Add second request to the queue to check handling when first fails. |
| 647 offline_pages::SavePageRequest request2( | 649 offline_pages::SavePageRequest request2( |
| 648 kRequestId2, kUrl2, kClientId2, base::Time::Now(), kUserRequested); | 650 kRequestId2, kUrl2, kClientId2, base::Time::Now(), kUserRequested); |
| 649 coordinator()->queue()->AddRequest( | 651 coordinator()->queue()->AddRequest( |
| 650 request2, | 652 request2, |
| 651 base::Bind(&RequestCoordinatorTest::AddRequestDone, | 653 base::Bind(&RequestCoordinatorTest::AddRequestDone, |
| 652 base::Unretained(this))); | 654 base::Unretained(this))); |
| 653 PumpLoop(); | 655 PumpLoop(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 665 // TODO(dougarnett): Consider injecting mock RequestPicker for this test | 667 // TODO(dougarnett): Consider injecting mock RequestPicker for this test |
| 666 // and verifying that there is no attempt to pick another request following | 668 // and verifying that there is no attempt to pick another request following |
| 667 // this failure code. | 669 // this failure code. |
| 668 | 670 |
| 669 coordinator()->queue()->GetRequests( | 671 coordinator()->queue()->GetRequests( |
| 670 base::Bind(&RequestCoordinatorTest::GetRequestsDone, | 672 base::Bind(&RequestCoordinatorTest::GetRequestsDone, |
| 671 base::Unretained(this))); | 673 base::Unretained(this))); |
| 672 PumpLoop(); | 674 PumpLoop(); |
| 673 | 675 |
| 674 // Now just one request in the queue since failed request removed | 676 // Now just one request in the queue since failed request removed |
| 675 // (for single attempt policy). | 677 // (max number of attempts exceeded). |
| 676 EXPECT_EQ(1UL, last_requests().size()); | 678 EXPECT_EQ(1UL, last_requests().size()); |
| 677 // Check that the observer got the notification that we failed (and the | 679 // Check that the observer got the notification that we failed (and the |
| 678 // subsequent notification that the request was removed). | 680 // subsequent notification that the request was removed). |
| 679 EXPECT_TRUE(observer().completed_called()); | 681 EXPECT_TRUE(observer().completed_called()); |
| 680 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::RETRY_COUNT_EXCEEDED, | 682 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::RETRY_COUNT_EXCEEDED, |
| 681 observer().last_status()); | 683 observer().last_status()); |
| 682 } | 684 } |
| 683 | 685 |
| 684 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailedNoRetryFailure) { | 686 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailedNoRetryFailure) { |
| 685 // Add a request to the queue, wait for callbacks to finish. | 687 // Add a request to the queue, wait for callbacks to finish. |
| (...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1350 // Now whether processing triggered immediately depends on whether test | 1352 // Now whether processing triggered immediately depends on whether test |
| 1351 // is run on svelte device or not. | 1353 // is run on svelte device or not. |
| 1352 if (base::SysInfo::IsLowEndDevice()) { | 1354 if (base::SysInfo::IsLowEndDevice()) { |
| 1353 EXPECT_FALSE(is_busy()); | 1355 EXPECT_FALSE(is_busy()); |
| 1354 } else { | 1356 } else { |
| 1355 EXPECT_TRUE(is_busy()); | 1357 EXPECT_TRUE(is_busy()); |
| 1356 } | 1358 } |
| 1357 } | 1359 } |
| 1358 | 1360 |
| 1359 } // namespace offline_pages | 1361 } // namespace offline_pages |
| OLD | NEW |