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

Unified Diff: components/offline_pages/core/background/pick_request_task_unittest.cc

Issue 2729763002: [Offline Pages] Pick correct request when resuming. (Closed)
Patch Set: Moving logic to pick_request_task. Created 3 years, 10 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
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

Powered by Google App Engine
This is Rietveld 408576698