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

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

Issue 2425873003: [Offline Pages] Add evaluation test support in RequestCoordinator. (Closed)
Patch Set: Addressed comments. 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 unified diff | Download patch
« no previous file with comments | « components/offline_pages/background/request_coordinator_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 20 matching lines...) Expand all
31 const ClientId kClientId2("bookmark", "5678"); 31 const ClientId kClientId2("bookmark", "5678");
32 const bool kUserRequested = true; 32 const bool kUserRequested = true;
33 const int kAttemptCount = 1; 33 const int kAttemptCount = 1;
34 const int kMaxStartedTries = 5; 34 const int kMaxStartedTries = 5;
35 const int kMaxCompletedTries = 1; 35 const int kMaxCompletedTries = 1;
36 36
37 // Constants for policy values - These settings represent the default values. 37 // Constants for policy values - These settings represent the default values.
38 const bool kPreferUntried = false; 38 const bool kPreferUntried = false;
39 const bool kPreferEarlier = true; 39 const bool kPreferEarlier = true;
40 const bool kPreferRetryCount = true; 40 const bool kPreferRetryCount = true;
41 const int kBackgroundProcessingTimeBudgetSeconds = 170;
dougarnett 2016/10/19 00:58:58 hmm, I wonder about creating instance of OfflinerP
romax 2016/10/19 01:03:21 Then I guess it's better to go with the idea which
dougarnett 2016/10/19 01:36:39 Sorry, never mind
41 42
42 // Default request 43 // Default request
43 const SavePageRequest kEmptyRequest(0UL, 44 const SavePageRequest kEmptyRequest(0UL,
44 GURL(""), 45 GURL(""),
45 ClientId("", ""), 46 ClientId("", ""),
46 base::Time(), 47 base::Time(),
47 true); 48 true);
48 } // namespace 49 } // namespace
49 50
50 class RequestNotifierStub : public RequestNotifier { 51 class RequestNotifierStub : public RequestNotifier {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 188
188 // Pump the loop again to give the async queue the opportunity to return 189 // Pump the loop again to give the async queue the opportunity to return
189 // results from the Get operation, and for the picker to call the "QueueEmpty" 190 // results from the Get operation, and for the picker to call the "QueueEmpty"
190 // callback. 191 // callback.
191 PumpLoop(); 192 PumpLoop();
192 193
193 EXPECT_TRUE(request_queue_not_picked_called_); 194 EXPECT_TRUE(request_queue_not_picked_called_);
194 } 195 }
195 196
196 TEST_F(RequestPickerTest, ChooseRequestWithHigherRetryCount) { 197 TEST_F(RequestPickerTest, ChooseRequestWithHigherRetryCount) {
197 policy_.reset(new OfflinerPolicy(kPreferUntried, kPreferEarlier, 198 policy_.reset(new OfflinerPolicy(
198 kPreferRetryCount, kMaxStartedTries, 199 kPreferUntried, kPreferEarlier, kPreferRetryCount, kMaxStartedTries,
199 kMaxCompletedTries + 1)); 200 kMaxCompletedTries + 1, kBackgroundProcessingTimeBudgetSeconds));
200 picker_.reset(new RequestPicker(queue_.get(), policy_.get(), notifier_.get(), 201 picker_.reset(new RequestPicker(queue_.get(), policy_.get(), notifier_.get(),
201 &event_logger_)); 202 &event_logger_));
202 203
203 base::Time creation_time = base::Time::Now(); 204 base::Time creation_time = base::Time::Now();
204 SavePageRequest request1( 205 SavePageRequest request1(
205 kRequestId1, kUrl1, kClientId1, creation_time, kUserRequested); 206 kRequestId1, kUrl1, kClientId1, creation_time, kUserRequested);
206 SavePageRequest request2( 207 SavePageRequest request2(
207 kRequestId2, kUrl2, kClientId2, creation_time, kUserRequested); 208 kRequestId2, kUrl2, kClientId2, creation_time, kUserRequested);
208 request2.set_completed_attempt_count(kAttemptCount); 209 request2.set_completed_attempt_count(kAttemptCount);
209 210
(...skipping 13 matching lines...) Expand all
223 kUserRequested); 224 kUserRequested);
224 225
225 QueueRequestsAndChooseOne(request1, request2); 226 QueueRequestsAndChooseOne(request1, request2);
226 227
227 EXPECT_EQ(kRequestId1, last_picked_->request_id()); 228 EXPECT_EQ(kRequestId1, last_picked_->request_id());
228 EXPECT_FALSE(request_queue_not_picked_called_); 229 EXPECT_FALSE(request_queue_not_picked_called_);
229 } 230 }
230 231
231 TEST_F(RequestPickerTest, ChooseEarlierRequest) { 232 TEST_F(RequestPickerTest, ChooseEarlierRequest) {
232 // We need a custom policy object prefering recency to retry count. 233 // We need a custom policy object prefering recency to retry count.
233 policy_.reset(new OfflinerPolicy(kPreferUntried, kPreferEarlier, 234 policy_.reset(new OfflinerPolicy(
234 !kPreferRetryCount, kMaxStartedTries, 235 kPreferUntried, kPreferEarlier, !kPreferRetryCount, kMaxStartedTries,
235 kMaxCompletedTries)); 236 kMaxCompletedTries, kBackgroundProcessingTimeBudgetSeconds));
236 picker_.reset(new RequestPicker(queue_.get(), policy_.get(), notifier_.get(), 237 picker_.reset(new RequestPicker(queue_.get(), policy_.get(), notifier_.get(),
237 &event_logger_)); 238 &event_logger_));
238 239
239 base::Time creation_time1 = 240 base::Time creation_time1 =
240 base::Time::Now() - base::TimeDelta::FromSeconds(10); 241 base::Time::Now() - base::TimeDelta::FromSeconds(10);
241 base::Time creation_time2 = base::Time::Now(); 242 base::Time creation_time2 = base::Time::Now();
242 SavePageRequest request1(kRequestId1, kUrl1, kClientId1, creation_time1, 243 SavePageRequest request1(kRequestId1, kUrl1, kClientId1, creation_time1,
243 kUserRequested); 244 kUserRequested);
244 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, creation_time2, 245 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, creation_time2,
245 kUserRequested); 246 kUserRequested);
246 request2.set_completed_attempt_count(kAttemptCount); 247 request2.set_completed_attempt_count(kAttemptCount);
247 248
248 QueueRequestsAndChooseOne(request1, request2); 249 QueueRequestsAndChooseOne(request1, request2);
249 250
250 EXPECT_EQ(kRequestId1, last_picked_->request_id()); 251 EXPECT_EQ(kRequestId1, last_picked_->request_id());
251 EXPECT_FALSE(request_queue_not_picked_called_); 252 EXPECT_FALSE(request_queue_not_picked_called_);
252 } 253 }
253 254
254 TEST_F(RequestPickerTest, ChooseSameTimeRequestWithHigherRetryCount) { 255 TEST_F(RequestPickerTest, ChooseSameTimeRequestWithHigherRetryCount) {
255 // We need a custom policy object preferring recency to retry count. 256 // We need a custom policy object preferring recency to retry count.
256 policy_.reset(new OfflinerPolicy(kPreferUntried, kPreferEarlier, 257 policy_.reset(new OfflinerPolicy(
257 !kPreferRetryCount, kMaxStartedTries, 258 kPreferUntried, kPreferEarlier, !kPreferRetryCount, kMaxStartedTries,
258 kMaxCompletedTries + 1)); 259 kMaxCompletedTries + 1, kBackgroundProcessingTimeBudgetSeconds));
259 picker_.reset(new RequestPicker(queue_.get(), policy_.get(), notifier_.get(), 260 picker_.reset(new RequestPicker(queue_.get(), policy_.get(), notifier_.get(),
260 &event_logger_)); 261 &event_logger_));
261 262
262 base::Time creation_time = base::Time::Now(); 263 base::Time creation_time = base::Time::Now();
263 SavePageRequest request1(kRequestId1, kUrl1, kClientId1, creation_time, 264 SavePageRequest request1(kRequestId1, kUrl1, kClientId1, creation_time,
264 kUserRequested); 265 kUserRequested);
265 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, creation_time, 266 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, creation_time,
266 kUserRequested); 267 kUserRequested);
267 request2.set_completed_attempt_count(kAttemptCount); 268 request2.set_completed_attempt_count(kAttemptCount);
268 269
269 QueueRequestsAndChooseOne(request1, request2); 270 QueueRequestsAndChooseOne(request1, request2);
270 271
271 EXPECT_EQ(kRequestId2, last_picked_->request_id()); 272 EXPECT_EQ(kRequestId2, last_picked_->request_id());
272 EXPECT_FALSE(request_queue_not_picked_called_); 273 EXPECT_FALSE(request_queue_not_picked_called_);
273 } 274 }
274 275
275 TEST_F(RequestPickerTest, ChooseRequestWithLowerRetryCount) { 276 TEST_F(RequestPickerTest, ChooseRequestWithLowerRetryCount) {
276 // We need a custom policy object preferring lower retry count. 277 // We need a custom policy object preferring lower retry count.
277 policy_.reset(new OfflinerPolicy(!kPreferUntried, kPreferEarlier, 278 policy_.reset(new OfflinerPolicy(
278 kPreferRetryCount, kMaxStartedTries, 279 !kPreferUntried, kPreferEarlier, kPreferRetryCount, kMaxStartedTries,
279 kMaxCompletedTries + 1)); 280 kMaxCompletedTries + 1, kBackgroundProcessingTimeBudgetSeconds));
280 picker_.reset(new RequestPicker(queue_.get(), policy_.get(), notifier_.get(), 281 picker_.reset(new RequestPicker(queue_.get(), policy_.get(), notifier_.get(),
281 &event_logger_)); 282 &event_logger_));
282 283
283 base::Time creation_time = base::Time::Now(); 284 base::Time creation_time = base::Time::Now();
284 SavePageRequest request1(kRequestId1, kUrl1, kClientId1, creation_time, 285 SavePageRequest request1(kRequestId1, kUrl1, kClientId1, creation_time,
285 kUserRequested); 286 kUserRequested);
286 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, creation_time, 287 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, creation_time,
287 kUserRequested); 288 kUserRequested);
288 request2.set_completed_attempt_count(kAttemptCount); 289 request2.set_completed_attempt_count(kAttemptCount);
289 290
290 QueueRequestsAndChooseOne(request1, request2); 291 QueueRequestsAndChooseOne(request1, request2);
291 292
292 EXPECT_EQ(kRequestId1, last_picked_->request_id()); 293 EXPECT_EQ(kRequestId1, last_picked_->request_id());
293 EXPECT_FALSE(request_queue_not_picked_called_); 294 EXPECT_FALSE(request_queue_not_picked_called_);
294 } 295 }
295 296
296 TEST_F(RequestPickerTest, ChooseLaterRequest) { 297 TEST_F(RequestPickerTest, ChooseLaterRequest) {
297 // We need a custom policy preferring recency over retry, and later requests. 298 // We need a custom policy preferring recency over retry, and later requests.
298 policy_.reset(new OfflinerPolicy(kPreferUntried, !kPreferEarlier, 299 policy_.reset(new OfflinerPolicy(
299 !kPreferRetryCount, kMaxStartedTries, 300 kPreferUntried, !kPreferEarlier, !kPreferRetryCount, kMaxStartedTries,
300 kMaxCompletedTries)); 301 kMaxCompletedTries, kBackgroundProcessingTimeBudgetSeconds));
301 picker_.reset(new RequestPicker(queue_.get(), policy_.get(), notifier_.get(), 302 picker_.reset(new RequestPicker(queue_.get(), policy_.get(), notifier_.get(),
302 &event_logger_)); 303 &event_logger_));
303 304
304 base::Time creation_time1 = 305 base::Time creation_time1 =
305 base::Time::Now() - base::TimeDelta::FromSeconds(10); 306 base::Time::Now() - base::TimeDelta::FromSeconds(10);
306 base::Time creation_time2 = base::Time::Now(); 307 base::Time creation_time2 = base::Time::Now();
307 SavePageRequest request1(kRequestId1, kUrl1, kClientId1, creation_time1, 308 SavePageRequest request1(kRequestId1, kUrl1, kClientId1, creation_time1,
308 kUserRequested); 309 kUserRequested);
309 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, creation_time2, 310 SavePageRequest request2(kRequestId2, kUrl2, kClientId2, creation_time2,
310 kUserRequested); 311 kUserRequested);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 request1.set_completed_attempt_count(policy_->GetMaxCompletedTries()); 371 request1.set_completed_attempt_count(policy_->GetMaxCompletedTries());
371 372
372 QueueRequestsAndChooseOne(request1, request2); 373 QueueRequestsAndChooseOne(request1, request2);
373 374
374 EXPECT_EQ(kRequestId2, last_picked_->request_id()); 375 EXPECT_EQ(kRequestId2, last_picked_->request_id());
375 EXPECT_FALSE(request_queue_not_picked_called_); 376 EXPECT_FALSE(request_queue_not_picked_called_);
376 } 377 }
377 378
378 379
379 TEST_F(RequestPickerTest, ChooseRequestThatIsNotDisabled) { 380 TEST_F(RequestPickerTest, ChooseRequestThatIsNotDisabled) {
380 policy_.reset(new OfflinerPolicy(kPreferUntried, kPreferEarlier, 381 policy_.reset(new OfflinerPolicy(
381 kPreferRetryCount, kMaxStartedTries, 382 kPreferUntried, kPreferEarlier, kPreferRetryCount, kMaxStartedTries,
382 kMaxCompletedTries + 1)); 383 kMaxCompletedTries + 1, kBackgroundProcessingTimeBudgetSeconds));
383 picker_.reset(new RequestPicker(queue_.get(), policy_.get(), notifier_.get(), 384 picker_.reset(new RequestPicker(queue_.get(), policy_.get(), notifier_.get(),
384 &event_logger_)); 385 &event_logger_));
385 386
386 base::Time creation_time = base::Time::Now(); 387 base::Time creation_time = base::Time::Now();
387 SavePageRequest request1( 388 SavePageRequest request1(
388 kRequestId1, kUrl1, kClientId1, creation_time, kUserRequested); 389 kRequestId1, kUrl1, kClientId1, creation_time, kUserRequested);
389 SavePageRequest request2( 390 SavePageRequest request2(
390 kRequestId2, kUrl2, kClientId2, creation_time, kUserRequested); 391 kRequestId2, kUrl2, kClientId2, creation_time, kUserRequested);
391 request2.set_completed_attempt_count(kAttemptCount); 392 request2.set_completed_attempt_count(kAttemptCount);
392 393
(...skipping 19 matching lines...) Expand all
412 413
413 // Pump the loop again to give the async queue the opportunity to return 414 // Pump the loop again to give the async queue the opportunity to return
414 // results from the Get operation, and for the picker to call the "picked" 415 // results from the Get operation, and for the picker to call the "picked"
415 // callback. 416 // callback.
416 PumpLoop(); 417 PumpLoop();
417 418
418 EXPECT_EQ(kRequestId1, last_picked_->request_id()); 419 EXPECT_EQ(kRequestId1, last_picked_->request_id());
419 EXPECT_FALSE(request_queue_not_picked_called_); 420 EXPECT_FALSE(request_queue_not_picked_called_);
420 } 421 }
421 } // namespace offline_pages 422 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/background/request_coordinator_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698