Index: components/offline_pages/background/request_picker_unittest.cc |
diff --git a/components/offline_pages/background/request_picker_unittest.cc b/components/offline_pages/background/request_picker_unittest.cc |
index 0f03754fccc0ad82b94a942c8804d654b604cc96..f71b406460e95dac3365f81cf76a7f8a1cf78243 100644 |
--- a/components/offline_pages/background/request_picker_unittest.cc |
+++ b/components/offline_pages/background/request_picker_unittest.cc |
@@ -155,6 +155,7 @@ void RequestPickerTest::RequestNotPicked( |
void RequestPickerTest::QueueRequestsAndChooseOne( |
const SavePageRequest& request1, const SavePageRequest& request2) { |
DeviceConditions conditions; |
+ std::set<int64_t> disabled_requests; |
// Add test requests on the Queue. |
queue_->AddRequest(request1, base::Bind(&RequestPickerTest::AddRequestDone, |
base::Unretained(this))); |
@@ -168,7 +169,7 @@ void RequestPickerTest::QueueRequestsAndChooseOne( |
picker_->ChooseNextRequest( |
base::Bind(&RequestPickerTest::RequestPicked, base::Unretained(this)), |
base::Bind(&RequestPickerTest::RequestNotPicked, base::Unretained(this)), |
- &conditions); |
+ &conditions, disabled_requests); |
// 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" |
@@ -178,10 +179,11 @@ void RequestPickerTest::QueueRequestsAndChooseOne( |
TEST_F(RequestPickerTest, PickFromEmptyQueue) { |
DeviceConditions conditions; |
+ std::set<int64_t> disabled_requests; |
picker_->ChooseNextRequest( |
base::Bind(&RequestPickerTest::RequestPicked, base::Unretained(this)), |
base::Bind(&RequestPickerTest::RequestNotPicked, base::Unretained(this)), |
- &conditions); |
+ &conditions, disabled_requests); |
// 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 "QueueEmpty" |
@@ -372,4 +374,48 @@ TEST_F(RequestPickerTest, ChooseRequestThatHasNotExceededCompletionLimit) { |
EXPECT_EQ(kRequestId2, last_picked_->request_id()); |
EXPECT_FALSE(request_queue_not_picked_called_); |
} |
+ |
+ |
+TEST_F(RequestPickerTest, ChooseRequestThatIsNotDisabled) { |
+ policy_.reset(new OfflinerPolicy(kPreferUntried, kPreferEarlier, |
+ kPreferRetryCount, kMaxStartedTries, |
+ kMaxCompletedTries + 1)); |
+ picker_.reset(new RequestPicker(queue_.get(), policy_.get(), notifier_.get(), |
+ &event_logger_)); |
+ |
+ base::Time creation_time = base::Time::Now(); |
+ SavePageRequest request1( |
+ kRequestId1, kUrl1, kClientId1, creation_time, kUserRequested); |
+ SavePageRequest request2( |
+ kRequestId2, kUrl2, kClientId2, creation_time, kUserRequested); |
+ request2.set_completed_attempt_count(kAttemptCount); |
+ |
+ // put request 2 on disabled list, ensure request1 picked instead, |
+ // even though policy would prefer 2. |
+ std::set<int64_t> disabled_requests {kRequestId2}; |
+ DeviceConditions conditions; |
+ |
+ // Add test requests on the Queue. |
+ queue_->AddRequest(request1, base::Bind(&RequestPickerTest::AddRequestDone, |
+ base::Unretained(this))); |
+ queue_->AddRequest(request2, base::Bind(&RequestPickerTest::AddRequestDone, |
+ base::Unretained(this))); |
+ |
+ // Pump the loop to give the async queue the opportunity to do the adds. |
+ PumpLoop(); |
+ |
+ // Call the method under test. |
+ picker_->ChooseNextRequest( |
+ base::Bind(&RequestPickerTest::RequestPicked, base::Unretained(this)), |
+ base::Bind(&RequestPickerTest::RequestNotPicked, base::Unretained(this)), |
+ &conditions, disabled_requests); |
+ |
+ // 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(kRequestId1, last_picked_->request_id()); |
+ EXPECT_FALSE(request_queue_not_picked_called_); |
+} |
} // namespace offline_pages |