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

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

Issue 2361883002: [Offline Pages] Adds classification of some prerender FinalStatus codes as canceled operations or a… (Closed)
Patch Set: Reworked per feedback 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
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 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 base::Unretained(this)); 457 base::Unretained(this));
458 coordinator()->SetProcessingCallbackForTest(callback); 458 coordinator()->SetProcessingCallbackForTest(callback);
459 459
460 // Set up device conditions for the test. 460 // Set up device conditions for the test.
461 DeviceConditions device_conditions( 461 DeviceConditions device_conditions(
462 false, 75, net::NetworkChangeNotifier::CONNECTION_3G); 462 false, 75, net::NetworkChangeNotifier::CONNECTION_3G);
463 SetDeviceConditionsForTest(device_conditions); 463 SetDeviceConditionsForTest(device_conditions);
464 464
465 // Call the OfflinerDoneCallback to simulate the page being completed, wait 465 // Call the OfflinerDoneCallback to simulate the page being completed, wait
466 // for callbacks. 466 // for callbacks.
467 EnableOfflinerCallback(true);
468 SendOfflinerDoneCallback(request, Offliner::RequestStatus::SAVED); 467 SendOfflinerDoneCallback(request, Offliner::RequestStatus::SAVED);
469 PumpLoop(); 468 PumpLoop();
470 469
471 // Verify the request gets removed from the queue, and wait for callbacks. 470 // Verify the request gets removed from the queue, and wait for callbacks.
472 coordinator()->queue()->GetRequests( 471 coordinator()->queue()->GetRequests(
473 base::Bind(&RequestCoordinatorTest::GetRequestsDone, 472 base::Bind(&RequestCoordinatorTest::GetRequestsDone,
474 base::Unretained(this))); 473 base::Unretained(this)));
475 PumpLoop(); 474 PumpLoop();
476 475
477 // We should not find any requests in the queue anymore. 476 // We should not find any requests in the queue anymore.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 base::Unretained(this)); 511 base::Unretained(this));
513 coordinator()->SetProcessingCallbackForTest(callback); 512 coordinator()->SetProcessingCallbackForTest(callback);
514 513
515 // Set up device conditions for the test. 514 // Set up device conditions for the test.
516 DeviceConditions device_conditions( 515 DeviceConditions device_conditions(
517 false, 75, net::NetworkChangeNotifier::CONNECTION_3G); 516 false, 75, net::NetworkChangeNotifier::CONNECTION_3G);
518 SetDeviceConditionsForTest(device_conditions); 517 SetDeviceConditionsForTest(device_conditions);
519 518
520 // Call the OfflinerDoneCallback to simulate the request failed, wait 519 // Call the OfflinerDoneCallback to simulate the request failed, wait
521 // for callbacks. 520 // for callbacks.
522 EnableOfflinerCallback(true);
523 SendOfflinerDoneCallback(request, 521 SendOfflinerDoneCallback(request,
524 Offliner::RequestStatus::PRERENDERING_FAILED); 522 Offliner::RequestStatus::PRERENDERING_FAILED);
525 PumpLoop(); 523 PumpLoop();
526 524
527 // TODO(dougarnett): Consider injecting mock RequestPicker for this test 525 // TODO(dougarnett): Consider injecting mock RequestPicker for this test
528 // and verifying that there is no attempt to pick another request following 526 // and verifying that there is no attempt to pick another request following
529 // this failure code. 527 // this failure code.
530 528
531 // Verify neither request is removed from the queue; wait for callbacks.
532 coordinator()->queue()->GetRequests( 529 coordinator()->queue()->GetRequests(
533 base::Bind(&RequestCoordinatorTest::GetRequestsDone, 530 base::Bind(&RequestCoordinatorTest::GetRequestsDone,
534 base::Unretained(this))); 531 base::Unretained(this)));
535 PumpLoop(); 532 PumpLoop();
536 533
537 // Now just one request in the queue since failed request removed 534 // Now just one request in the queue since failed request removed
538 // (for single attempt policy). 535 // (for single attempt policy).
539 EXPECT_EQ(1UL, last_requests().size()); 536 EXPECT_EQ(1UL, last_requests().size());
540 // Check that the observer got the notification that we failed (and the 537 // Check that the observer got the notification that we failed (and the
541 // subsequent notification that the request was removed). 538 // subsequent notification that the request was removed).
542 EXPECT_TRUE(observer().completed_called()); 539 EXPECT_TRUE(observer().completed_called());
543 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::RETRY_COUNT_EXCEEDED, 540 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::RETRY_COUNT_EXCEEDED,
544 observer().last_status()); 541 observer().last_status());
545 } 542 }
546 543
544 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailedNoRetryFailure) {
545 // Add a request to the queue, wait for callbacks to finish.
546 offline_pages::SavePageRequest request(kRequestId1, kUrl1, kClientId1,
547 base::Time::Now(), kUserRequested);
548 request.MarkAttemptStarted(base::Time::Now());
549 coordinator()->queue()->AddRequest(
550 request, base::Bind(&RequestCoordinatorTest::AddRequestDone,
551 base::Unretained(this)));
552 PumpLoop();
553
554 // Add second request to the queue to check handling when first fails.
555 offline_pages::SavePageRequest request2(kRequestId2, kUrl2, kClientId2,
556 base::Time::Now(), kUserRequested);
557 coordinator()->queue()->AddRequest(
558 request2, base::Bind(&RequestCoordinatorTest::AddRequestDone,
559 base::Unretained(this)));
560 PumpLoop();
561
562 // We need to give a callback to the request.
563 base::Callback<void(bool)> callback = base::Bind(
564 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this));
565 coordinator()->SetProcessingCallbackForTest(callback);
566
567 // Set up device conditions for the test.
568 DeviceConditions device_conditions(false, 75,
569 net::NetworkChangeNotifier::CONNECTION_3G);
570 SetDeviceConditionsForTest(device_conditions);
571
572 // Call the OfflinerDoneCallback to simulate the request failed, wait
573 // for callbacks.
574 SendOfflinerDoneCallback(
575 request, Offliner::RequestStatus::PRERENDERING_FAILED_NO_RETRY);
576 PumpLoop();
577
578 // TODO(dougarnett): Consider injecting mock RequestPicker for this test
579 // and verifying that there is as attempt to pick another request following
580 // this non-retryable failure code.
581
582 coordinator()->queue()->GetRequests(base::Bind(
583 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this)));
584 PumpLoop();
585
586 // Now just one request in the queue since non-retryable failure.
587 EXPECT_EQ(1UL, last_requests().size());
588 // Check that the observer got the notification that we failed (and the
589 // subsequent notification that the request was removed).
590 EXPECT_TRUE(observer().completed_called());
591 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::PRERENDER_FAILURE,
592 observer().last_status());
593 }
594
547 TEST_F(RequestCoordinatorTest, OfflinerDoneForegroundCancel) { 595 TEST_F(RequestCoordinatorTest, OfflinerDoneForegroundCancel) {
548 // Add a request to the queue, wait for callbacks to finish. 596 // Add a request to the queue, wait for callbacks to finish.
549 offline_pages::SavePageRequest request( 597 offline_pages::SavePageRequest request(
550 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); 598 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested);
551 request.MarkAttemptStarted(base::Time::Now()); 599 request.MarkAttemptStarted(base::Time::Now());
552 coordinator()->queue()->AddRequest( 600 coordinator()->queue()->AddRequest(
553 request, base::Bind(&RequestCoordinatorTest::AddRequestDone, 601 request, base::Bind(&RequestCoordinatorTest::AddRequestDone,
554 base::Unretained(this))); 602 base::Unretained(this)));
555 PumpLoop(); 603 PumpLoop();
556 604
557 // We need to give a callback to the request. 605 // We need to give a callback to the request.
558 base::Callback<void(bool)> callback = base::Bind( 606 base::Callback<void(bool)> callback = base::Bind(
559 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this)); 607 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this));
560 coordinator()->SetProcessingCallbackForTest(callback); 608 coordinator()->SetProcessingCallbackForTest(callback);
561 609
562 // Set up device conditions for the test. 610 // Set up device conditions for the test.
563 DeviceConditions device_conditions(false, 75, 611 DeviceConditions device_conditions(false, 75,
564 net::NetworkChangeNotifier::CONNECTION_3G); 612 net::NetworkChangeNotifier::CONNECTION_3G);
565 SetDeviceConditionsForTest(device_conditions); 613 SetDeviceConditionsForTest(device_conditions);
566 614
567 // Call the OfflinerDoneCallback to simulate the request failed, wait 615 // Call the OfflinerDoneCallback to simulate the request failed, wait
568 // for callbacks. 616 // for callbacks.
569 EnableOfflinerCallback(true);
570 SendOfflinerDoneCallback(request, 617 SendOfflinerDoneCallback(request,
571 Offliner::RequestStatus::FOREGROUND_CANCELED); 618 Offliner::RequestStatus::FOREGROUND_CANCELED);
572 PumpLoop(); 619 PumpLoop();
573 620
574 // Verify the request is not removed from the queue, and wait for callbacks. 621 // Verify the request is not removed from the queue, and wait for callbacks.
575 coordinator()->queue()->GetRequests(base::Bind( 622 coordinator()->queue()->GetRequests(base::Bind(
576 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this))); 623 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this)));
577 PumpLoop(); 624 PumpLoop();
578 625
579 // Request no longer in the queue (for single attempt policy). 626 // Request no longer in the queue (for single attempt policy).
(...skipping 17 matching lines...) Expand all
597 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this)); 644 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this));
598 coordinator()->SetProcessingCallbackForTest(callback); 645 coordinator()->SetProcessingCallbackForTest(callback);
599 646
600 // Set up device conditions for the test. 647 // Set up device conditions for the test.
601 DeviceConditions device_conditions(false, 75, 648 DeviceConditions device_conditions(false, 75,
602 net::NetworkChangeNotifier::CONNECTION_3G); 649 net::NetworkChangeNotifier::CONNECTION_3G);
603 SetDeviceConditionsForTest(device_conditions); 650 SetDeviceConditionsForTest(device_conditions);
604 651
605 // Call the OfflinerDoneCallback to simulate the request failed, wait 652 // Call the OfflinerDoneCallback to simulate the request failed, wait
606 // for callbacks. 653 // for callbacks.
607 EnableOfflinerCallback(true);
608 SendOfflinerDoneCallback(request, 654 SendOfflinerDoneCallback(request,
609 Offliner::RequestStatus::PRERENDERING_CANCELED); 655 Offliner::RequestStatus::PRERENDERING_CANCELED);
610 PumpLoop(); 656 PumpLoop();
611 657
612 // Verify the request is not removed from the queue, and wait for callbacks. 658 // Verify the request is not removed from the queue, and wait for callbacks.
613 coordinator()->queue()->GetRequests(base::Bind( 659 coordinator()->queue()->GetRequests(base::Bind(
614 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this))); 660 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this)));
615 PumpLoop(); 661 PumpLoop();
616 662
617 // Request still in the queue. 663 // Request still in the queue.
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 // Now whether processing triggered immediately depends on whether test 1103 // Now whether processing triggered immediately depends on whether test
1058 // is run on svelte device or not. 1104 // is run on svelte device or not.
1059 if (base::SysInfo::IsLowEndDevice()) { 1105 if (base::SysInfo::IsLowEndDevice()) {
1060 EXPECT_FALSE(is_busy()); 1106 EXPECT_FALSE(is_busy());
1061 } else { 1107 } else {
1062 EXPECT_TRUE(is_busy()); 1108 EXPECT_TRUE(is_busy());
1063 } 1109 }
1064 } 1110 }
1065 1111
1066 } // namespace offline_pages 1112 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698