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

Side by Side Diff: components/offline_pages/background/request_picker_unittest.cc

Issue 2269173003: Adjust scheduling for non-user requested items (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tests written and working. Created 4 years, 3 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 unified diff | Download patch
OLDNEW
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_picker.h" 5 #include "components/offline_pages/background/request_picker.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/test/test_simple_task_runner.h" 8 #include "base/test/test_simple_task_runner.h"
9 #include "base/threading/thread_task_runner_handle.h" 9 #include "base/threading/thread_task_runner_handle.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 void SetUp() override; 87 void SetUp() override;
88 88
89 void PumpLoop(); 89 void PumpLoop();
90 90
91 void AddRequestDone(RequestQueue::AddRequestResult result, 91 void AddRequestDone(RequestQueue::AddRequestResult result,
92 const SavePageRequest& request); 92 const SavePageRequest& request);
93 93
94 void RequestPicked(const SavePageRequest& request); 94 void RequestPicked(const SavePageRequest& request);
95 95
96 void RequestQueueEmpty(); 96 void RequestQueueEmpty(const bool non_user_requested_tasks_remaining);
97 97
98 void QueueRequestsAndChooseOne(const SavePageRequest& request1, 98 void QueueRequestsAndChooseOne(const SavePageRequest& request1,
99 const SavePageRequest& request2); 99 const SavePageRequest& request2);
100 100
101 RequestNotifierStub* GetNotifier() { return notifier_.get(); } 101 RequestNotifierStub* GetNotifier() { return notifier_.get(); }
102 102
103 protected: 103 protected:
104 // The request queue is simple enough we will use a real queue with a memory 104 // The request queue is simple enough we will use a real queue with a memory
105 // store instead of a stub. 105 // store instead of a stub.
106 std::unique_ptr<RequestQueue> queue_; 106 std::unique_ptr<RequestQueue> queue_;
(...skipping 29 matching lines...) Expand all
136 task_runner_->RunUntilIdle(); 136 task_runner_->RunUntilIdle();
137 } 137 }
138 138
139 void RequestPickerTest::AddRequestDone(RequestQueue::AddRequestResult result, 139 void RequestPickerTest::AddRequestDone(RequestQueue::AddRequestResult result,
140 const SavePageRequest& request) {} 140 const SavePageRequest& request) {}
141 141
142 void RequestPickerTest::RequestPicked(const SavePageRequest& request) { 142 void RequestPickerTest::RequestPicked(const SavePageRequest& request) {
143 last_picked_.reset(new SavePageRequest(request)); 143 last_picked_.reset(new SavePageRequest(request));
144 } 144 }
145 145
146 void RequestPickerTest::RequestQueueEmpty() { 146 void RequestPickerTest::RequestQueueEmpty(
dougarnett 2016/08/29 15:47:22 rename here too
Pete Williamson 2016/09/01 00:10:31 Done.
147 const bool non_user_requested_tasks_remaining) {
147 request_queue_empty_called_ = true; 148 request_queue_empty_called_ = true;
148 } 149 }
149 150
150 // Test helper to queue the two given requests and then pick one of them per 151 // Test helper to queue the two given requests and then pick one of them per
151 // configured policy. 152 // configured policy.
152 void RequestPickerTest::QueueRequestsAndChooseOne( 153 void RequestPickerTest::QueueRequestsAndChooseOne(
153 const SavePageRequest& request1, const SavePageRequest& request2) { 154 const SavePageRequest& request1, const SavePageRequest& request2) {
154 DeviceConditions conditions; 155 DeviceConditions conditions;
155 // Add test requests on the Queue. 156 // Add test requests on the Queue.
156 queue_->AddRequest(request1, base::Bind(&RequestPickerTest::AddRequestDone, 157 queue_->AddRequest(request1, base::Bind(&RequestPickerTest::AddRequestDone,
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 // With default policy settings, we should choose the earlier request. 364 // With default policy settings, we should choose the earlier request.
364 // However, we will make the earlier reqeust exceed the limit. 365 // However, we will make the earlier reqeust exceed the limit.
365 request1.set_completed_attempt_count(policy_->GetMaxCompletedTries()); 366 request1.set_completed_attempt_count(policy_->GetMaxCompletedTries());
366 367
367 QueueRequestsAndChooseOne(request1, request2); 368 QueueRequestsAndChooseOne(request1, request2);
368 369
369 EXPECT_EQ(kRequestId2, last_picked_->request_id()); 370 EXPECT_EQ(kRequestId2, last_picked_->request_id());
370 EXPECT_FALSE(request_queue_empty_called_); 371 EXPECT_FALSE(request_queue_empty_called_);
371 } 372 }
372 } // namespace offline_pages 373 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698