Chromium Code Reviews| Index: components/offline_pages/core/background/pick_request_task_unittest.cc |
| diff --git a/components/offline_pages/core/background/pick_request_task_unittest.cc b/components/offline_pages/core/background/pick_request_task_unittest.cc |
| index f1e249b1ab608dc95542acedb9007df85978b812..704eb2408837cc5d89a5121d98cd5583fdee90f4 100644 |
| --- a/components/offline_pages/core/background/pick_request_task_unittest.cc |
| +++ b/components/offline_pages/core/background/pick_request_task_unittest.cc |
| @@ -124,6 +124,7 @@ class PickRequestTaskTest : public testing::Test { |
| std::unique_ptr<OfflinerPolicy> policy_; |
| RequestCoordinatorEventLogger event_logger_; |
| std::set<int64_t> disabled_requests_; |
| + std::list<int64_t> priortized_requests_; |
| std::unique_ptr<PickRequestTask> task_; |
| bool request_queue_not_picked_called_; |
| bool cleanup_needed_; |
| @@ -212,7 +213,7 @@ void PickRequestTaskTest::MakePickRequestTask() { |
| base::Unretained(this)), |
| base::Bind(&PickRequestTaskTest::RequestCountCallback, |
| base::Unretained(this)), |
| - conditions, disabled_requests_)); |
| + conditions, disabled_requests_, priortized_requests_)); |
| task_->SetTaskCompletionCallbackForTesting( |
| task_runner_.get(), |
| base::Bind(&PickRequestTaskTest::TaskCompletionCallback, |
| @@ -490,4 +491,37 @@ TEST_F(PickRequestTaskTest, ChooseRequestThatIsNotDisabled) { |
| EXPECT_TRUE(task_complete_called_); |
| } |
| +TEST_F(PickRequestTaskTest, ChoosePriortizedRequests) { |
|
Pete Williamson
2017/03/06 18:30:57
Let's add a test with two prioritized requests, bo
romax
2017/03/07 18:40:44
Done.
|
| + priortized_requests_.push_back(kRequestId2); |
| + MakePickRequestTask(); |
| + |
| + base::Time creation_time = base::Time::Now(); |
| + SavePageRequest request1(kRequestId1, kUrl1, kClientId1, creation_time, |
| + kUserRequested); |
| + SavePageRequest request2(kRequestId2, kUrl2, kClientId2, creation_time, |
| + kUserRequested); |
| + // Since default policy prefer untried requests, make request1 the favorable |
| + // pick if no priortized requests. But request2 is priortized so it should be |
| + // picked. |
| + request2.set_completed_attempt_count(kAttemptCount); |
| + |
| + // Add test requests on the Queue. |
| + QueueRequests(request1, request2); |
| + |
| + task()->Run(); |
| + PumpLoop(); |
| + |
| + // Pump the loop again to give the async queue the opportunity to return |
| + // results from the Get operation, and for the picker to call the "picked" |
| + // callback. |
| + PumpLoop(); |
| + |
| + EXPECT_EQ(kRequestId2, last_picked_->request_id()); |
| + EXPECT_FALSE(request_queue_not_picked_called_); |
| + EXPECT_EQ(2UL, total_request_count_); |
| + EXPECT_EQ(2UL, available_request_count_); |
| + EXPECT_TRUE(task_complete_called_); |
| + EXPECT_EQ(0UL, priortized_requests_.size()); |
| +} |
| + |
| } // namespace offline_pages |