Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(341)

Unified Diff: components/offline_pages/background/request_picker_unittest.cc

Issue 2395213002: Implement disabled list (Closed)
Patch Set: set pointer -> const ref Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/offline_pages/background/request_picker.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « components/offline_pages/background/request_picker.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698