| OLD | NEW |
| 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 <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 void GetRequestsDone(RequestQueue::GetRequestsResult result, | 255 void GetRequestsDone(RequestQueue::GetRequestsResult result, |
| 256 std::vector<std::unique_ptr<SavePageRequest>> requests); | 256 std::vector<std::unique_ptr<SavePageRequest>> requests); |
| 257 | 257 |
| 258 // Callback for removing requests. | 258 // Callback for removing requests. |
| 259 void RemoveRequestsDone(const MultipleItemStatuses& results); | 259 void RemoveRequestsDone(const MultipleItemStatuses& results); |
| 260 | 260 |
| 261 // Callback for getting request statuses. | 261 // Callback for getting request statuses. |
| 262 void GetQueuedRequestsDone( | 262 void GetQueuedRequestsDone( |
| 263 std::vector<std::unique_ptr<SavePageRequest>> requests); | 263 std::vector<std::unique_ptr<SavePageRequest>> requests); |
| 264 | 264 |
| 265 void SetupForOfflinerDoneCallbackTest( |
| 266 offline_pages::SavePageRequest* request); |
| 267 |
| 265 void SendOfflinerDoneCallback(const SavePageRequest& request, | 268 void SendOfflinerDoneCallback(const SavePageRequest& request, |
| 266 Offliner::RequestStatus status); | 269 Offliner::RequestStatus status); |
| 267 | 270 |
| 268 RequestQueue::GetRequestsResult last_get_requests_result() const { | 271 RequestQueue::GetRequestsResult last_get_requests_result() const { |
| 269 return last_get_requests_result_; | 272 return last_get_requests_result_; |
| 270 } | 273 } |
| 271 | 274 |
| 272 const std::vector<std::unique_ptr<SavePageRequest>>& last_requests() const { | 275 const std::vector<std::unique_ptr<SavePageRequest>>& last_requests() const { |
| 273 return last_requests_; | 276 return last_requests_; |
| 274 } | 277 } |
| 275 | 278 |
| 276 const MultipleItemStatuses& last_remove_results() const { | 279 const MultipleItemStatuses& last_remove_results() const { |
| 277 return last_remove_results_; | 280 return last_remove_results_; |
| 278 } | 281 } |
| 279 | 282 |
| 280 void DisableLoading() { | 283 void DisableLoading() { |
| 281 offliner_->disable_loading(); | 284 offliner_->disable_loading(); |
| 282 } | 285 } |
| 283 | 286 |
| 284 void EnableOfflinerCallback(bool enable) { | 287 void EnableOfflinerCallback(bool enable) { |
| 285 offliner_->enable_callback(enable); | 288 offliner_->enable_callback(enable); |
| 286 } | 289 } |
| 287 | 290 |
| 288 void SetNetworkConditionsForTest( | 291 void SetNetworkConditionsForTest( |
| 289 net::NetworkChangeNotifier::ConnectionType connection) { | 292 net::NetworkChangeNotifier::ConnectionType connection) { |
| 290 coordinator()->SetNetworkConditionsForTest(connection); | 293 coordinator()->SetNetworkConditionsForTest(connection); |
| 291 } | 294 } |
| 292 | 295 |
| 296 void SetIsLowEndDeviceForTest(bool is_low_end_device) { |
| 297 coordinator()->is_low_end_device_ = is_low_end_device; |
| 298 } |
| 299 |
| 300 void SetProcessingStateForTest( |
| 301 RequestCoordinator::ProcessingWindowState processing_state) { |
| 302 coordinator()->processing_state_ = processing_state; |
| 303 } |
| 304 |
| 305 void SetOperationStartTimeForTest(base::Time start_time) { |
| 306 coordinator()->operation_start_time_ = start_time; |
| 307 } |
| 308 |
| 293 void SetEffectiveConnectionTypeForTest(net::EffectiveConnectionType type) { | 309 void SetEffectiveConnectionTypeForTest(net::EffectiveConnectionType type) { |
| 294 network_quality_estimator_->SetEffectiveConnectionTypeForTest(type); | 310 network_quality_estimator_->SetEffectiveConnectionTypeForTest(type); |
| 295 } | 311 } |
| 296 | 312 |
| 297 void ScheduleForTest() { coordinator_->ScheduleAsNeeded(); } | 313 void ScheduleForTest() { coordinator_->ScheduleAsNeeded(); } |
| 298 | 314 |
| 299 void CallRequestNotPicked(bool non_user_requested_tasks_remaining, | 315 void CallRequestNotPicked(bool non_user_requested_tasks_remaining, |
| 300 bool disabled_tasks_remaining) { | 316 bool disabled_tasks_remaining) { |
| 301 if (disabled_tasks_remaining) | 317 if (disabled_tasks_remaining) |
| 302 coordinator_->disabled_requests_.insert(kRequestId1); | 318 coordinator_->disabled_requests_.insert(kRequestId1); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 void RequestCoordinatorTest::GetQueuedRequestsDone( | 412 void RequestCoordinatorTest::GetQueuedRequestsDone( |
| 397 std::vector<std::unique_ptr<SavePageRequest>> requests) { | 413 std::vector<std::unique_ptr<SavePageRequest>> requests) { |
| 398 last_requests_ = std::move(requests); | 414 last_requests_ = std::move(requests); |
| 399 waiter_.Signal(); | 415 waiter_.Signal(); |
| 400 } | 416 } |
| 401 | 417 |
| 402 void RequestCoordinatorTest::AddRequestDone( | 418 void RequestCoordinatorTest::AddRequestDone( |
| 403 RequestQueue::AddRequestResult result, | 419 RequestQueue::AddRequestResult result, |
| 404 const SavePageRequest& request) {} | 420 const SavePageRequest& request) {} |
| 405 | 421 |
| 422 void RequestCoordinatorTest::SetupForOfflinerDoneCallbackTest( |
| 423 offline_pages::SavePageRequest* request) { |
| 424 // Mark request as started and add it to the queue, |
| 425 // then wait for callback to finish. |
| 426 request->MarkAttemptStarted(base::Time::Now()); |
| 427 coordinator()->queue()->AddRequest( |
| 428 *request, base::Bind(&RequestCoordinatorTest::AddRequestDone, |
| 429 base::Unretained(this))); |
| 430 PumpLoop(); |
| 431 |
| 432 // Override the processing callback for test visiblity. |
| 433 base::Callback<void(bool)> callback = |
| 434 base::Bind(&RequestCoordinatorTest::ImmediateScheduleCallbackFunction, |
| 435 base::Unretained(this)); |
| 436 coordinator()->SetProcessingCallbackForTest(callback); |
| 437 |
| 438 // Mock that coordinator is in actively processing state starting now. |
| 439 SetProcessingStateForTest( |
| 440 RequestCoordinator::ProcessingWindowState::IMMEDIATE_WINDOW); |
| 441 SetOperationStartTimeForTest(base::Time::Now()); |
| 442 |
| 443 // Set up good device conditions for the test. |
| 444 DeviceConditions device_conditions(false, 75, |
| 445 net::NetworkChangeNotifier::CONNECTION_3G); |
| 446 SetDeviceConditionsForTest(device_conditions); |
| 447 } |
| 448 |
| 406 void RequestCoordinatorTest::SendOfflinerDoneCallback( | 449 void RequestCoordinatorTest::SendOfflinerDoneCallback( |
| 407 const SavePageRequest& request, Offliner::RequestStatus status) { | 450 const SavePageRequest& request, Offliner::RequestStatus status) { |
| 408 // Using the fact that the test class is a friend, call to the callback | 451 // Using the fact that the test class is a friend, call to the callback |
| 409 coordinator_->OfflinerDoneCallback(request, status); | 452 coordinator_->OfflinerDoneCallback(request, status); |
| 410 } | 453 } |
| 411 | 454 |
| 412 TEST_F(RequestCoordinatorTest, StartProcessingWithNoRequests) { | 455 TEST_F(RequestCoordinatorTest, StartProcessingWithNoRequests) { |
| 413 DeviceConditions device_conditions(false, 75, | 456 DeviceConditions device_conditions(false, 75, |
| 414 net::NetworkChangeNotifier::CONNECTION_3G); | 457 net::NetworkChangeNotifier::CONNECTION_3G); |
| 415 base::Callback<void(bool)> callback = | 458 base::Callback<void(bool)> callback = |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 scheduler_stub->conditions()->minimum_battery_percentage); | 589 scheduler_stub->conditions()->minimum_battery_percentage); |
| 547 | 590 |
| 548 // Check that the observer got the notification that a page is available | 591 // Check that the observer got the notification that a page is available |
| 549 EXPECT_TRUE(observer().added_called()); | 592 EXPECT_TRUE(observer().added_called()); |
| 550 } | 593 } |
| 551 | 594 |
| 552 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestSucceeded) { | 595 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestSucceeded) { |
| 553 // Add a request to the queue, wait for callbacks to finish. | 596 // Add a request to the queue, wait for callbacks to finish. |
| 554 offline_pages::SavePageRequest request( | 597 offline_pages::SavePageRequest request( |
| 555 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); | 598 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); |
| 556 request.MarkAttemptStarted(base::Time::Now()); | 599 SetupForOfflinerDoneCallbackTest(&request); |
| 557 coordinator()->queue()->AddRequest( | |
| 558 request, | |
| 559 base::Bind(&RequestCoordinatorTest::AddRequestDone, | |
| 560 base::Unretained(this))); | |
| 561 PumpLoop(); | |
| 562 | |
| 563 // We need to give a callback to the request. | |
| 564 base::Callback<void(bool)> callback = | |
| 565 base::Bind(&RequestCoordinatorTest::ImmediateScheduleCallbackFunction, | |
| 566 base::Unretained(this)); | |
| 567 coordinator()->SetProcessingCallbackForTest(callback); | |
| 568 | |
| 569 // Set up device conditions for the test. | |
| 570 DeviceConditions device_conditions( | |
| 571 false, 75, net::NetworkChangeNotifier::CONNECTION_3G); | |
| 572 SetDeviceConditionsForTest(device_conditions); | |
| 573 | 600 |
| 574 // Call the OfflinerDoneCallback to simulate the page being completed, wait | 601 // Call the OfflinerDoneCallback to simulate the page being completed, wait |
| 575 // for callbacks. | 602 // for callbacks. |
| 576 SendOfflinerDoneCallback(request, Offliner::RequestStatus::SAVED); | 603 SendOfflinerDoneCallback(request, Offliner::RequestStatus::SAVED); |
| 577 PumpLoop(); | 604 PumpLoop(); |
| 578 EXPECT_TRUE(immediate_schedule_callback_called()); | 605 EXPECT_TRUE(immediate_schedule_callback_called()); |
| 579 | 606 |
| 580 // Verify the request gets removed from the queue, and wait for callbacks. | 607 // Verify the request gets removed from the queue, and wait for callbacks. |
| 581 coordinator()->queue()->GetRequests( | 608 coordinator()->queue()->GetRequests( |
| 582 base::Bind(&RequestCoordinatorTest::GetRequestsDone, | 609 base::Bind(&RequestCoordinatorTest::GetRequestsDone, |
| 583 base::Unretained(this))); | 610 base::Unretained(this))); |
| 584 PumpLoop(); | 611 PumpLoop(); |
| 585 | 612 |
| 586 // We should not find any requests in the queue anymore. | 613 // We should not find any requests in the queue anymore. |
| 587 // RequestPicker should *not* have tried to start an additional job, | 614 // RequestPicker should *not* have tried to start an additional job, |
| 588 // because the request queue is empty now. | 615 // because the request queue is empty now. |
| 589 EXPECT_EQ(0UL, last_requests().size()); | 616 EXPECT_EQ(0UL, last_requests().size()); |
| 590 // Check that the observer got the notification that we succeeded, and that | 617 // Check that the observer got the notification that we succeeded, and that |
| 591 // the request got removed from the queue. | 618 // the request got removed from the queue. |
| 592 EXPECT_TRUE(observer().completed_called()); | 619 EXPECT_TRUE(observer().completed_called()); |
| 593 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::SUCCESS, | 620 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::SUCCESS, |
| 594 observer().last_status()); | 621 observer().last_status()); |
| 595 } | 622 } |
| 596 | 623 |
| 597 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailed) { | 624 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailed) { |
| 598 // Add a request to the queue, wait for callbacks to finish. | 625 // Add a request to the queue, wait for callbacks to finish. |
| 599 offline_pages::SavePageRequest request( | 626 offline_pages::SavePageRequest request( |
| 600 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); | 627 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); |
| 601 request.MarkAttemptStarted(base::Time::Now()); | 628 SetupForOfflinerDoneCallbackTest(&request); |
| 602 coordinator()->queue()->AddRequest( | |
| 603 request, | |
| 604 base::Bind(&RequestCoordinatorTest::AddRequestDone, | |
| 605 base::Unretained(this))); | |
| 606 PumpLoop(); | |
| 607 | 629 |
| 608 // Add second request to the queue to check handling when first fails. | 630 // Add second request to the queue to check handling when first fails. |
| 609 offline_pages::SavePageRequest request2( | 631 offline_pages::SavePageRequest request2( |
| 610 kRequestId2, kUrl2, kClientId2, base::Time::Now(), kUserRequested); | 632 kRequestId2, kUrl2, kClientId2, base::Time::Now(), kUserRequested); |
| 611 coordinator()->queue()->AddRequest( | 633 coordinator()->queue()->AddRequest( |
| 612 request2, | 634 request2, |
| 613 base::Bind(&RequestCoordinatorTest::AddRequestDone, | 635 base::Bind(&RequestCoordinatorTest::AddRequestDone, |
| 614 base::Unretained(this))); | 636 base::Unretained(this))); |
| 615 PumpLoop(); | 637 PumpLoop(); |
| 616 | 638 |
| 617 // We need to give a callback to the request. | |
| 618 base::Callback<void(bool)> callback = | |
| 619 base::Bind(&RequestCoordinatorTest::ImmediateScheduleCallbackFunction, | |
| 620 base::Unretained(this)); | |
| 621 coordinator()->SetProcessingCallbackForTest(callback); | |
| 622 | |
| 623 // Set up device conditions for the test. | |
| 624 DeviceConditions device_conditions( | |
| 625 false, 75, net::NetworkChangeNotifier::CONNECTION_3G); | |
| 626 SetDeviceConditionsForTest(device_conditions); | |
| 627 | |
| 628 // Call the OfflinerDoneCallback to simulate the request failed, wait | 639 // Call the OfflinerDoneCallback to simulate the request failed, wait |
| 629 // for callbacks. | 640 // for callbacks. |
| 630 SendOfflinerDoneCallback(request, | 641 SendOfflinerDoneCallback(request, |
| 631 Offliner::RequestStatus::PRERENDERING_FAILED); | 642 Offliner::RequestStatus::PRERENDERING_FAILED); |
| 632 PumpLoop(); | 643 PumpLoop(); |
| 644 |
| 645 // For retriable failure, processing should stop and scheduler callback |
| 646 // called (so that request can be retried first next processing window). |
| 633 EXPECT_TRUE(immediate_schedule_callback_called()); | 647 EXPECT_TRUE(immediate_schedule_callback_called()); |
| 634 | 648 |
| 635 // TODO(dougarnett): Consider injecting mock RequestPicker for this test | 649 // TODO(dougarnett): Consider injecting mock RequestPicker for this test |
| 636 // and verifying that there is no attempt to pick another request following | 650 // and verifying that there is no attempt to pick another request following |
| 637 // this failure code. | 651 // this failure code. |
| 638 | 652 |
| 639 coordinator()->queue()->GetRequests( | 653 coordinator()->queue()->GetRequests( |
| 640 base::Bind(&RequestCoordinatorTest::GetRequestsDone, | 654 base::Bind(&RequestCoordinatorTest::GetRequestsDone, |
| 641 base::Unretained(this))); | 655 base::Unretained(this))); |
| 642 PumpLoop(); | 656 PumpLoop(); |
| 643 | 657 |
| 644 // Now just one request in the queue since failed request removed | 658 // Now just one request in the queue since failed request removed |
| 645 // (for single attempt policy). | 659 // (for single attempt policy). |
| 646 EXPECT_EQ(1UL, last_requests().size()); | 660 EXPECT_EQ(1UL, last_requests().size()); |
| 647 // Check that the observer got the notification that we failed (and the | 661 // Check that the observer got the notification that we failed (and the |
| 648 // subsequent notification that the request was removed). | 662 // subsequent notification that the request was removed). |
| 649 EXPECT_TRUE(observer().completed_called()); | 663 EXPECT_TRUE(observer().completed_called()); |
| 650 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::RETRY_COUNT_EXCEEDED, | 664 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::RETRY_COUNT_EXCEEDED, |
| 651 observer().last_status()); | 665 observer().last_status()); |
| 652 } | 666 } |
| 653 | 667 |
| 654 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailedNoRetryFailure) { | 668 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailedNoRetryFailure) { |
| 655 // Add a request to the queue, wait for callbacks to finish. | 669 // Add a request to the queue, wait for callbacks to finish. |
| 656 offline_pages::SavePageRequest request(kRequestId1, kUrl1, kClientId1, | 670 offline_pages::SavePageRequest request(kRequestId1, kUrl1, kClientId1, |
| 657 base::Time::Now(), kUserRequested); | 671 base::Time::Now(), kUserRequested); |
| 658 request.MarkAttemptStarted(base::Time::Now()); | 672 SetupForOfflinerDoneCallbackTest(&request); |
| 659 coordinator()->queue()->AddRequest( | |
| 660 request, base::Bind(&RequestCoordinatorTest::AddRequestDone, | |
| 661 base::Unretained(this))); | |
| 662 PumpLoop(); | |
| 663 | 673 |
| 664 // Add second request to the queue to check handling when first fails. | 674 // Add second request to the queue to check handling when first fails. |
| 665 offline_pages::SavePageRequest request2(kRequestId2, kUrl2, kClientId2, | 675 offline_pages::SavePageRequest request2(kRequestId2, kUrl2, kClientId2, |
| 666 base::Time::Now(), kUserRequested); | 676 base::Time::Now(), kUserRequested); |
| 667 coordinator()->queue()->AddRequest( | 677 coordinator()->queue()->AddRequest( |
| 668 request2, base::Bind(&RequestCoordinatorTest::AddRequestDone, | 678 request2, base::Bind(&RequestCoordinatorTest::AddRequestDone, |
| 669 base::Unretained(this))); | 679 base::Unretained(this))); |
| 670 PumpLoop(); | 680 PumpLoop(); |
| 671 | 681 |
| 672 // We need to give a callback to the request. | |
| 673 base::Callback<void(bool)> callback = | |
| 674 base::Bind(&RequestCoordinatorTest::ImmediateScheduleCallbackFunction, | |
| 675 base::Unretained(this)); | |
| 676 coordinator()->SetProcessingCallbackForTest(callback); | |
| 677 | |
| 678 // Set up device conditions for the test. | |
| 679 DeviceConditions device_conditions(false, 75, | |
| 680 net::NetworkChangeNotifier::CONNECTION_3G); | |
| 681 SetDeviceConditionsForTest(device_conditions); | |
| 682 | |
| 683 // Call the OfflinerDoneCallback to simulate the request failed, wait | 682 // Call the OfflinerDoneCallback to simulate the request failed, wait |
| 684 // for callbacks. | 683 // for callbacks. |
| 685 SendOfflinerDoneCallback( | 684 SendOfflinerDoneCallback( |
| 686 request, Offliner::RequestStatus::PRERENDERING_FAILED_NO_RETRY); | 685 request, Offliner::RequestStatus::PRERENDERING_FAILED_NO_RETRY); |
| 687 PumpLoop(); | 686 PumpLoop(); |
| 688 EXPECT_TRUE(immediate_schedule_callback_called()); | 687 |
| 688 // For no retry failure, processing should continue to 2nd request so |
| 689 // no scheduler callback yet. |
| 690 EXPECT_FALSE(immediate_schedule_callback_called()); |
| 689 | 691 |
| 690 // TODO(dougarnett): Consider injecting mock RequestPicker for this test | 692 // TODO(dougarnett): Consider injecting mock RequestPicker for this test |
| 691 // and verifying that there is as attempt to pick another request following | 693 // and verifying that there is as attempt to pick another request following |
| 692 // this non-retryable failure code. | 694 // this non-retryable failure code. |
| 693 | 695 |
| 694 coordinator()->queue()->GetRequests(base::Bind( | 696 coordinator()->queue()->GetRequests(base::Bind( |
| 695 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this))); | 697 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this))); |
| 696 PumpLoop(); | 698 PumpLoop(); |
| 697 | 699 |
| 698 // Now just one request in the queue since non-retryable failure. | 700 // Now just one request in the queue since non-retryable failure. |
| 699 EXPECT_EQ(1UL, last_requests().size()); | 701 EXPECT_EQ(1UL, last_requests().size()); |
| 700 // Check that the observer got the notification that we failed (and the | 702 // Check that the observer got the notification that we failed (and the |
| 701 // subsequent notification that the request was removed). | 703 // subsequent notification that the request was removed). |
| 702 EXPECT_TRUE(observer().completed_called()); | 704 EXPECT_TRUE(observer().completed_called()); |
| 703 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::PRERENDER_FAILURE, | 705 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::PRERENDER_FAILURE, |
| 704 observer().last_status()); | 706 observer().last_status()); |
| 705 } | 707 } |
| 706 | 708 |
| 707 TEST_F(RequestCoordinatorTest, OfflinerDoneForegroundCancel) { | 709 TEST_F(RequestCoordinatorTest, OfflinerDoneForegroundCancel) { |
| 708 // Add a request to the queue, wait for callbacks to finish. | 710 // Add a request to the queue, wait for callbacks to finish. |
| 709 offline_pages::SavePageRequest request( | 711 offline_pages::SavePageRequest request( |
| 710 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); | 712 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); |
| 711 request.MarkAttemptStarted(base::Time::Now()); | 713 SetupForOfflinerDoneCallbackTest(&request); |
| 712 coordinator()->queue()->AddRequest( | |
| 713 request, base::Bind(&RequestCoordinatorTest::AddRequestDone, | |
| 714 base::Unretained(this))); | |
| 715 PumpLoop(); | |
| 716 | |
| 717 // We need to give a callback to the request. | |
| 718 base::Callback<void(bool)> callback = | |
| 719 base::Bind(&RequestCoordinatorTest::ImmediateScheduleCallbackFunction, | |
| 720 base::Unretained(this)); | |
| 721 coordinator()->SetProcessingCallbackForTest(callback); | |
| 722 | |
| 723 // Set up device conditions for the test. | |
| 724 DeviceConditions device_conditions(false, 75, | |
| 725 net::NetworkChangeNotifier::CONNECTION_3G); | |
| 726 SetDeviceConditionsForTest(device_conditions); | |
| 727 | 714 |
| 728 // Call the OfflinerDoneCallback to simulate the request failed, wait | 715 // Call the OfflinerDoneCallback to simulate the request failed, wait |
| 729 // for callbacks. | 716 // for callbacks. |
| 730 SendOfflinerDoneCallback(request, | 717 SendOfflinerDoneCallback(request, |
| 731 Offliner::RequestStatus::FOREGROUND_CANCELED); | 718 Offliner::RequestStatus::FOREGROUND_CANCELED); |
| 732 PumpLoop(); | 719 PumpLoop(); |
| 733 EXPECT_TRUE(immediate_schedule_callback_called()); | 720 EXPECT_TRUE(immediate_schedule_callback_called()); |
| 734 | 721 |
| 735 // Verify the request is not removed from the queue, and wait for callbacks. | 722 // Verify the request is not removed from the queue, and wait for callbacks. |
| 736 coordinator()->queue()->GetRequests(base::Bind( | 723 coordinator()->queue()->GetRequests(base::Bind( |
| 737 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this))); | 724 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this))); |
| 738 PumpLoop(); | 725 PumpLoop(); |
| 739 | 726 |
| 740 // Request no longer in the queue (for single attempt policy). | 727 // Request no longer in the queue (for single attempt policy). |
| 741 EXPECT_EQ(1UL, last_requests().size()); | 728 EXPECT_EQ(1UL, last_requests().size()); |
| 742 // Verify foreground cancel not counted as an attempt after all. | 729 // Verify foreground cancel not counted as an attempt after all. |
| 743 EXPECT_EQ(0L, last_requests().at(0)->completed_attempt_count()); | 730 EXPECT_EQ(0L, last_requests().at(0)->completed_attempt_count()); |
| 744 } | 731 } |
| 745 | 732 |
| 746 TEST_F(RequestCoordinatorTest, OfflinerDonePrerenderingCancel) { | 733 TEST_F(RequestCoordinatorTest, OfflinerDonePrerenderingCancel) { |
| 747 // Add a request to the queue, wait for callbacks to finish. | 734 // Add a request to the queue, wait for callbacks to finish. |
| 748 offline_pages::SavePageRequest request(kRequestId1, kUrl1, kClientId1, | 735 offline_pages::SavePageRequest request(kRequestId1, kUrl1, kClientId1, |
| 749 base::Time::Now(), kUserRequested); | 736 base::Time::Now(), kUserRequested); |
| 750 request.MarkAttemptStarted(base::Time::Now()); | 737 SetupForOfflinerDoneCallbackTest(&request); |
| 751 coordinator()->queue()->AddRequest( | |
| 752 request, base::Bind(&RequestCoordinatorTest::AddRequestDone, | |
| 753 base::Unretained(this))); | |
| 754 PumpLoop(); | |
| 755 | |
| 756 // We need to give a callback to the request. | |
| 757 base::Callback<void(bool)> callback = | |
| 758 base::Bind(&RequestCoordinatorTest::ImmediateScheduleCallbackFunction, | |
| 759 base::Unretained(this)); | |
| 760 coordinator()->SetProcessingCallbackForTest(callback); | |
| 761 | |
| 762 // Set up device conditions for the test. | |
| 763 DeviceConditions device_conditions(false, 75, | |
| 764 net::NetworkChangeNotifier::CONNECTION_3G); | |
| 765 SetDeviceConditionsForTest(device_conditions); | |
| 766 | 738 |
| 767 // Call the OfflinerDoneCallback to simulate the request failed, wait | 739 // Call the OfflinerDoneCallback to simulate the request failed, wait |
| 768 // for callbacks. | 740 // for callbacks. |
| 769 SendOfflinerDoneCallback(request, | 741 SendOfflinerDoneCallback(request, |
| 770 Offliner::RequestStatus::PRERENDERING_CANCELED); | 742 Offliner::RequestStatus::PRERENDERING_CANCELED); |
| 771 PumpLoop(); | 743 PumpLoop(); |
| 772 EXPECT_TRUE(immediate_schedule_callback_called()); | 744 EXPECT_TRUE(immediate_schedule_callback_called()); |
| 773 | 745 |
| 774 // Verify the request is not removed from the queue, and wait for callbacks. | 746 // Verify the request is not removed from the queue, and wait for callbacks. |
| 775 coordinator()->queue()->GetRequests(base::Bind( | 747 coordinator()->queue()->GetRequests(base::Bind( |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1100 WaitForCallback(); | 1072 WaitForCallback(); |
| 1101 PumpLoop(); | 1073 PumpLoop(); |
| 1102 | 1074 |
| 1103 EXPECT_FALSE(is_starting()); | 1075 EXPECT_FALSE(is_starting()); |
| 1104 EXPECT_TRUE(OfflinerWasCanceled()); | 1076 EXPECT_TRUE(OfflinerWasCanceled()); |
| 1105 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_TIMED_OUT, | 1077 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_TIMED_OUT, |
| 1106 last_offlining_status()); | 1078 last_offlining_status()); |
| 1107 } | 1079 } |
| 1108 | 1080 |
| 1109 TEST_F(RequestCoordinatorTest, WatchdogTimeoutForImmediateProcessing) { | 1081 TEST_F(RequestCoordinatorTest, WatchdogTimeoutForImmediateProcessing) { |
| 1110 // Test only applies on non-svelte device. | 1082 // If low end device, pretend it is not so that immediate start happens. |
| 1111 if (base::SysInfo::IsLowEndDevice()) | 1083 SetIsLowEndDeviceForTest(false); |
| 1112 return; | |
| 1113 | 1084 |
| 1114 // Set good network connection so that adding request will trigger | 1085 // Set good network connection so that adding request will trigger |
| 1115 // immediate processing. | 1086 // immediate processing. |
| 1116 SetEffectiveConnectionTypeForTest( | 1087 SetEffectiveConnectionTypeForTest( |
| 1117 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_3G); | 1088 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_3G); |
| 1118 | 1089 |
| 1119 // Ensure that the new request does not finish - we simulate it being | 1090 // Ensure that the new request does not finish - we simulate it being |
| 1120 // in progress by asking it to skip making the completion callback. | 1091 // in progress by asking it to skip making the completion callback. |
| 1121 EnableOfflinerCallback(false); | 1092 EnableOfflinerCallback(false); |
| 1122 | 1093 |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1360 // Now whether processing triggered immediately depends on whether test | 1331 // Now whether processing triggered immediately depends on whether test |
| 1361 // is run on svelte device or not. | 1332 // is run on svelte device or not. |
| 1362 if (base::SysInfo::IsLowEndDevice()) { | 1333 if (base::SysInfo::IsLowEndDevice()) { |
| 1363 EXPECT_FALSE(is_busy()); | 1334 EXPECT_FALSE(is_busy()); |
| 1364 } else { | 1335 } else { |
| 1365 EXPECT_TRUE(is_busy()); | 1336 EXPECT_TRUE(is_busy()); |
| 1366 } | 1337 } |
| 1367 } | 1338 } |
| 1368 | 1339 |
| 1369 } // namespace offline_pages | 1340 } // namespace offline_pages |
| OLD | NEW |