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

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

Issue 2209813002: [Offline Pages] Moves Coordinator to using MarkAttemptStarted/MarkAttemptCompleted API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move enum2string functions to event logger and addressed some other Filip feedback Created 4 years, 4 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_coordinator.h" 5 #include "components/offline_pages/background/request_coordinator.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 EXPECT_EQ(coordinator() 308 EXPECT_EQ(coordinator()
309 ->GetTriggerConditionsForUserRequest() 309 ->GetTriggerConditionsForUserRequest()
310 .minimum_battery_percentage, 310 .minimum_battery_percentage,
311 scheduler_stub->conditions()->minimum_battery_percentage); 311 scheduler_stub->conditions()->minimum_battery_percentage);
312 } 312 }
313 313
314 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestSucceeded) { 314 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestSucceeded) {
315 // Add a request to the queue, wait for callbacks to finish. 315 // Add a request to the queue, wait for callbacks to finish.
316 offline_pages::SavePageRequest request( 316 offline_pages::SavePageRequest request(
317 kRequestId, kUrl, kClientId, base::Time::Now(), kUserRequested); 317 kRequestId, kUrl, kClientId, base::Time::Now(), kUserRequested);
318 request.MarkAttemptStarted(base::Time::Now());
318 coordinator()->queue()->AddRequest( 319 coordinator()->queue()->AddRequest(
319 request, 320 request,
320 base::Bind(&RequestCoordinatorTest::AddRequestDone, 321 base::Bind(&RequestCoordinatorTest::AddRequestDone,
321 base::Unretained(this))); 322 base::Unretained(this)));
322 PumpLoop(); 323 PumpLoop();
323 324
324 // We need to give a callback to the request. 325 // We need to give a callback to the request.
325 base::Callback<void(bool)> callback = 326 base::Callback<void(bool)> callback =
326 base::Bind( 327 base::Bind(
327 &RequestCoordinatorTest::EmptyCallbackFunction, 328 &RequestCoordinatorTest::EmptyCallbackFunction,
(...skipping 20 matching lines...) Expand all
348 // We should not find any requests in the queue anymore. 349 // We should not find any requests in the queue anymore.
349 // RequestPicker should *not* have tried to start an additional job, 350 // RequestPicker should *not* have tried to start an additional job,
350 // because the request queue is empty now. 351 // because the request queue is empty now.
351 EXPECT_EQ(0UL, last_requests().size()); 352 EXPECT_EQ(0UL, last_requests().size());
352 } 353 }
353 354
354 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailed) { 355 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailed) {
355 // Add a request to the queue, wait for callbacks to finish. 356 // Add a request to the queue, wait for callbacks to finish.
356 offline_pages::SavePageRequest request( 357 offline_pages::SavePageRequest request(
357 kRequestId, kUrl, kClientId, base::Time::Now(), kUserRequested); 358 kRequestId, kUrl, kClientId, base::Time::Now(), kUserRequested);
359 request.MarkAttemptStarted(base::Time::Now());
358 coordinator()->queue()->AddRequest( 360 coordinator()->queue()->AddRequest(
359 request, 361 request,
360 base::Bind(&RequestCoordinatorTest::AddRequestDone, 362 base::Bind(&RequestCoordinatorTest::AddRequestDone,
361 base::Unretained(this))); 363 base::Unretained(this)));
362 PumpLoop(); 364 PumpLoop();
363 365
364 // Add second request to the queue to check handling when first fails. 366 // Add second request to the queue to check handling when first fails.
365 offline_pages::SavePageRequest request2( 367 offline_pages::SavePageRequest request2(
366 kRequestId2, kUrl2, kClientId2, base::Time::Now(), kUserRequested); 368 kRequestId2, kUrl2, kClientId2, base::Time::Now(), kUserRequested);
367 coordinator()->queue()->AddRequest( 369 coordinator()->queue()->AddRequest(
(...skipping 24 matching lines...) Expand all
392 // TODO(dougarnett): Consider injecting mock RequestPicker for this test 394 // TODO(dougarnett): Consider injecting mock RequestPicker for this test
393 // and verifying that there is no attempt to pick another request following 395 // and verifying that there is no attempt to pick another request following
394 // this failure code. 396 // this failure code.
395 397
396 // Verify neither request is removed from the queue; wait for callbacks. 398 // Verify neither request is removed from the queue; wait for callbacks.
397 coordinator()->queue()->GetRequests( 399 coordinator()->queue()->GetRequests(
398 base::Bind(&RequestCoordinatorTest::GetRequestsDone, 400 base::Bind(&RequestCoordinatorTest::GetRequestsDone,
399 base::Unretained(this))); 401 base::Unretained(this)));
400 PumpLoop(); 402 PumpLoop();
401 403
402 // Still two requests in the queue. 404 // Now just one request in the queue since failed request removed
403 EXPECT_EQ(2UL, last_requests().size()); 405 // (for single attempt policy).
404 // Verify retry count was incremented for first request. 406 EXPECT_EQ(1UL, last_requests().size());
407 }
408
409 TEST_F(RequestCoordinatorTest, OfflinerDoneForegroundCancel) {
410 // Add a request to the queue, wait for callbacks to finish.
411 offline_pages::SavePageRequest request(kRequestId, kUrl, kClientId,
412 base::Time::Now(), kUserRequested);
413 request.MarkAttemptStarted(base::Time::Now());
414 coordinator()->queue()->AddRequest(
415 request, base::Bind(&RequestCoordinatorTest::AddRequestDone,
416 base::Unretained(this)));
417 PumpLoop();
418
419 // We need to give a callback to the request.
420 base::Callback<void(bool)> callback = base::Bind(
421 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this));
422 coordinator()->SetProcessingCallbackForTest(callback);
423
424 // Set up device conditions for the test.
425 DeviceConditions device_conditions(false, 75,
426 net::NetworkChangeNotifier::CONNECTION_3G);
427 SetDeviceConditionsForTest(device_conditions);
428
429 // Call the OfflinerDoneCallback to simulate the request failed, wait
430 // for callbacks.
431 EnableOfflinerCallback(true);
432 SendOfflinerDoneCallback(request,
433 Offliner::RequestStatus::FOREGROUND_CANCELED);
434 PumpLoop();
435
436 // Verify the request is not removed from the queue, and wait for callbacks.
437 coordinator()->queue()->GetRequests(base::Bind(
438 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this)));
439 PumpLoop();
440
441 // Request no longer in the queue (for single attempt policy).
442 EXPECT_EQ(1UL, last_requests().size());
443 // Verify foreground cancel not counted as an attempt after all.
405 const SavePageRequest& found_request = last_requests().front(); 444 const SavePageRequest& found_request = last_requests().front();
406 EXPECT_EQ(1L, found_request.attempt_count()); 445 EXPECT_EQ(0L, found_request.attempt_count());
407 } 446 }
408 447
409 // This tests a StopProcessing call before we have actually started the 448 // This tests a StopProcessing call before we have actually started the
410 // prerenderer. 449 // prerenderer.
411 TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingImmediately) { 450 TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingImmediately) {
412 // Add a request to the queue, wait for callbacks to finish. 451 // Add a request to the queue, wait for callbacks to finish.
413 offline_pages::SavePageRequest request( 452 offline_pages::SavePageRequest request(
414 kRequestId, kUrl, kClientId, base::Time::Now(), kUserRequested); 453 kRequestId, kUrl, kClientId, base::Time::Now(), kUserRequested);
415 coordinator()->queue()->AddRequest( 454 coordinator()->queue()->AddRequest(
416 request, 455 request,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 513
475 // OfflinerDoneCallback will not end up getting called with status SAVED, 514 // OfflinerDoneCallback will not end up getting called with status SAVED,
476 // since we cancelled the event before the LoadAndSave completed. 515 // since we cancelled the event before the LoadAndSave completed.
477 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED, 516 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED,
478 last_offlining_status()); 517 last_offlining_status());
479 518
480 // Since offliner was started, it will have seen cancel call. 519 // Since offliner was started, it will have seen cancel call.
481 EXPECT_TRUE(OfflinerWasCanceled()); 520 EXPECT_TRUE(OfflinerWasCanceled());
482 } 521 }
483 522
484 TEST_F(RequestCoordinatorTest, PrerendererTimeout) { 523 TEST_F(RequestCoordinatorTest, WatchdogTimeout) {
485 // Build a request to use with the pre-renderer, and put it on the queue. 524 // Build a request to use with the pre-renderer, and put it on the queue.
486 offline_pages::SavePageRequest request( 525 offline_pages::SavePageRequest request(
487 kRequestId, kUrl, kClientId, base::Time::Now(), kUserRequested); 526 kRequestId, kUrl, kClientId, base::Time::Now(), kUserRequested);
488 coordinator()->queue()->AddRequest( 527 coordinator()->queue()->AddRequest(
489 request, 528 request,
490 base::Bind(&RequestCoordinatorTest::AddRequestDone, 529 base::Bind(&RequestCoordinatorTest::AddRequestDone,
491 base::Unretained(this))); 530 base::Unretained(this)));
492 PumpLoop(); 531 PumpLoop();
493 532
494 // Set up for the call to StartProcessing. 533 // Set up for the call to StartProcessing.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 coordinator()->queue()->GetRequests( 605 coordinator()->queue()->GetRequests(
567 base::Bind(&RequestCoordinatorTest::GetRequestsDone, 606 base::Bind(&RequestCoordinatorTest::GetRequestsDone,
568 base::Unretained(this))); 607 base::Unretained(this)));
569 PumpLoop(); 608 PumpLoop();
570 609
571 // We should find one request in the queue. 610 // We should find one request in the queue.
572 EXPECT_EQ(1UL, last_requests().size()); 611 EXPECT_EQ(1UL, last_requests().size());
573 } 612 }
574 613
575 } // namespace offline_pages 614 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698