| 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 <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 void PumpLoop(); | 183 void PumpLoop(); |
| 184 | 184 |
| 185 RequestCoordinator* coordinator() { | 185 RequestCoordinator* coordinator() { |
| 186 return coordinator_.get(); | 186 return coordinator_.get(); |
| 187 } | 187 } |
| 188 | 188 |
| 189 bool is_busy() { | 189 bool is_busy() { |
| 190 return coordinator_->is_busy(); | 190 return coordinator_->is_busy(); |
| 191 } | 191 } |
| 192 | 192 |
| 193 bool is_starting() { |
| 194 return coordinator_->is_starting(); |
| 195 } |
| 196 |
| 193 // Empty callback function. | 197 // Empty callback function. |
| 194 void EmptyCallbackFunction(bool result) { | 198 void EmptyCallbackFunction(bool result) { |
| 195 } | 199 } |
| 196 | 200 |
| 197 // Callback function which releases a wait for it. | 201 // Callback function which releases a wait for it. |
| 198 void WaitingCallbackFunction(bool result) { | 202 void WaitingCallbackFunction(bool result) { |
| 199 waiter_.Signal(); | 203 waiter_.Signal(); |
| 200 } | 204 } |
| 201 | 205 |
| 202 // Callback for Add requests. | 206 // Callback for Add requests. |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 | 594 |
| 591 // If one item completes, and there are no more user requeted items left, | 595 // If one item completes, and there are no more user requeted items left, |
| 592 // we should make a scheduler entry for a non-user requested item. | 596 // we should make a scheduler entry for a non-user requested item. |
| 593 TEST_F(RequestCoordinatorTest, RequestNotPickedNonUserRequestedItemsRemain) { | 597 TEST_F(RequestCoordinatorTest, RequestNotPickedNonUserRequestedItemsRemain) { |
| 594 // Call start processing just to set up a scheduler callback. | 598 // Call start processing just to set up a scheduler callback. |
| 595 DeviceConditions device_conditions(false, 75, | 599 DeviceConditions device_conditions(false, 75, |
| 596 net::NetworkChangeNotifier::CONNECTION_3G); | 600 net::NetworkChangeNotifier::CONNECTION_3G); |
| 597 base::Callback<void(bool)> callback = base::Bind( | 601 base::Callback<void(bool)> callback = base::Bind( |
| 598 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this)); | 602 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this)); |
| 599 coordinator()->StartProcessing(device_conditions, callback); | 603 coordinator()->StartProcessing(device_conditions, callback); |
| 604 EXPECT_TRUE(is_starting()); |
| 600 | 605 |
| 601 // Call RequestNotPicked, and make sure we pick schedule a task for non user | 606 // Call RequestNotPicked, and make sure we pick schedule a task for non user |
| 602 // requested conditions. | 607 // requested conditions. |
| 603 CallRequestNotPicked(true); | 608 CallRequestNotPicked(true); |
| 604 PumpLoop(); | 609 PumpLoop(); |
| 605 | 610 |
| 611 EXPECT_FALSE(is_starting()); |
| 612 |
| 606 // The scheduler should have been called to schedule the non-user requested | 613 // The scheduler should have been called to schedule the non-user requested |
| 607 // task. | 614 // task. |
| 608 SchedulerStub* scheduler_stub = | 615 SchedulerStub* scheduler_stub = |
| 609 reinterpret_cast<SchedulerStub*>(coordinator()->scheduler()); | 616 reinterpret_cast<SchedulerStub*>(coordinator()->scheduler()); |
| 610 EXPECT_TRUE(scheduler_stub->schedule_called()); | 617 EXPECT_TRUE(scheduler_stub->schedule_called()); |
| 611 EXPECT_TRUE(scheduler_stub->unschedule_called()); | 618 EXPECT_TRUE(scheduler_stub->unschedule_called()); |
| 612 const Scheduler::TriggerConditions* conditions = scheduler_stub->conditions(); | 619 const Scheduler::TriggerConditions* conditions = scheduler_stub->conditions(); |
| 613 EXPECT_EQ(conditions->require_power_connected, | 620 EXPECT_EQ(conditions->require_power_connected, |
| 614 coordinator()->policy()->PowerRequired(!kUserRequested)); | 621 coordinator()->policy()->PowerRequired(!kUserRequested)); |
| 615 EXPECT_EQ( | 622 EXPECT_EQ( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 base::Unretained(this))); | 671 base::Unretained(this))); |
| 665 PumpLoop(); | 672 PumpLoop(); |
| 666 | 673 |
| 667 DeviceConditions device_conditions(false, 75, | 674 DeviceConditions device_conditions(false, 75, |
| 668 net::NetworkChangeNotifier::CONNECTION_3G); | 675 net::NetworkChangeNotifier::CONNECTION_3G); |
| 669 base::Callback<void(bool)> callback = | 676 base::Callback<void(bool)> callback = |
| 670 base::Bind( | 677 base::Bind( |
| 671 &RequestCoordinatorTest::EmptyCallbackFunction, | 678 &RequestCoordinatorTest::EmptyCallbackFunction, |
| 672 base::Unretained(this)); | 679 base::Unretained(this)); |
| 673 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); | 680 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); |
| 681 EXPECT_TRUE(is_starting()); |
| 674 | 682 |
| 675 // Now, quick, before it can do much (we haven't called PumpLoop), cancel it. | 683 // Now, quick, before it can do much (we haven't called PumpLoop), cancel it. |
| 676 coordinator()->StopProcessing(); | 684 coordinator()->StopProcessing(); |
| 685 EXPECT_FALSE(is_starting()); |
| 677 | 686 |
| 678 // Let the async callbacks in the request coordinator run. | 687 // Let the async callbacks in the request coordinator run. |
| 679 PumpLoop(); | 688 PumpLoop(); |
| 680 | 689 |
| 681 // OfflinerDoneCallback will not end up getting called with status SAVED, | 690 // OfflinerDoneCallback will not end up getting called with status SAVED, |
| 682 // since we cancelled the event before it called offliner_->LoadAndSave(). | 691 // since we cancelled the event before it called offliner_->LoadAndSave(). |
| 683 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED, | 692 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED, |
| 684 last_offlining_status()); | 693 last_offlining_status()); |
| 685 | 694 |
| 686 // Since offliner was not started, it will not have seen cancel call. | 695 // Since offliner was not started, it will not have seen cancel call. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 701 // Ensure the start processing request stops before the completion callback. | 710 // Ensure the start processing request stops before the completion callback. |
| 702 EnableOfflinerCallback(false); | 711 EnableOfflinerCallback(false); |
| 703 | 712 |
| 704 DeviceConditions device_conditions(false, 75, | 713 DeviceConditions device_conditions(false, 75, |
| 705 net::NetworkChangeNotifier::CONNECTION_3G); | 714 net::NetworkChangeNotifier::CONNECTION_3G); |
| 706 base::Callback<void(bool)> callback = | 715 base::Callback<void(bool)> callback = |
| 707 base::Bind( | 716 base::Bind( |
| 708 &RequestCoordinatorTest::EmptyCallbackFunction, | 717 &RequestCoordinatorTest::EmptyCallbackFunction, |
| 709 base::Unretained(this)); | 718 base::Unretained(this)); |
| 710 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); | 719 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); |
| 720 EXPECT_TRUE(is_starting()); |
| 711 | 721 |
| 712 // Let all the async parts of the start processing pipeline run to completion. | 722 // Let all the async parts of the start processing pipeline run to completion. |
| 713 PumpLoop(); | 723 PumpLoop(); |
| 714 | 724 |
| 715 // Coordinator should now be busy. | 725 // Coordinator should now be busy. |
| 716 EXPECT_TRUE(is_busy()); | 726 EXPECT_TRUE(is_busy()); |
| 727 EXPECT_FALSE(is_starting()); |
| 717 | 728 |
| 718 // Now we cancel it while the prerenderer is busy. | 729 // Now we cancel it while the prerenderer is busy. |
| 719 coordinator()->StopProcessing(); | 730 coordinator()->StopProcessing(); |
| 720 | 731 |
| 721 // Let the async callbacks in the cancel run. | 732 // Let the async callbacks in the cancel run. |
| 722 PumpLoop(); | 733 PumpLoop(); |
| 723 | 734 |
| 724 EXPECT_FALSE(is_busy()); | 735 EXPECT_FALSE(is_busy()); |
| 725 | 736 |
| 726 // OfflinerDoneCallback will not end up getting called with status SAVED, | 737 // OfflinerDoneCallback will not end up getting called with status SAVED, |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 net::NetworkChangeNotifier::ConnectionType::CONNECTION_3G); | 1004 net::NetworkChangeNotifier::ConnectionType::CONNECTION_3G); |
| 994 | 1005 |
| 995 // Resume the request while connected. | 1006 // Resume the request while connected. |
| 996 coordinator()->ResumeRequests(request_ids); | 1007 coordinator()->ResumeRequests(request_ids); |
| 997 EXPECT_FALSE(is_busy()); | 1008 EXPECT_FALSE(is_busy()); |
| 998 PumpLoop(); | 1009 PumpLoop(); |
| 999 EXPECT_TRUE(is_busy()); | 1010 EXPECT_TRUE(is_busy()); |
| 1000 } | 1011 } |
| 1001 | 1012 |
| 1002 } // namespace offline_pages | 1013 } // namespace offline_pages |
| OLD | NEW |