| 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 12 matching lines...) Expand all Loading... |
| 23 #include "components/offline_pages/background/request_queue.h" | 23 #include "components/offline_pages/background/request_queue.h" |
| 24 #include "components/offline_pages/background/request_queue_in_memory_store.h" | 24 #include "components/offline_pages/background/request_queue_in_memory_store.h" |
| 25 #include "components/offline_pages/background/save_page_request.h" | 25 #include "components/offline_pages/background/save_page_request.h" |
| 26 #include "components/offline_pages/background/scheduler.h" | 26 #include "components/offline_pages/background/scheduler.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 28 |
| 29 namespace offline_pages { | 29 namespace offline_pages { |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 // put test constants here | 32 // put test constants here |
| 33 const bool kIsBackgroundScheduled = true; |
| 33 const GURL kUrl1("http://universe.com/everything"); | 34 const GURL kUrl1("http://universe.com/everything"); |
| 34 const GURL kUrl2("http://universe.com/toinfinityandbeyond"); | 35 const GURL kUrl2("http://universe.com/toinfinityandbeyond"); |
| 35 const std::string kClientNamespace("bookmark"); | 36 const std::string kClientNamespace("bookmark"); |
| 36 const std::string kId1("42"); | 37 const std::string kId1("42"); |
| 37 const std::string kId2("life*universe+everything"); | 38 const std::string kId2("life*universe+everything"); |
| 38 const ClientId kClientId1(kClientNamespace, kId1); | 39 const ClientId kClientId1(kClientNamespace, kId1); |
| 39 const ClientId kClientId2(kClientNamespace, kId2); | 40 const ClientId kClientId2(kClientNamespace, kId2); |
| 40 const int kRequestId1(1); | 41 const int kRequestId1(1); |
| 41 const int kRequestId2(2); | 42 const int kRequestId2(2); |
| 42 const long kTestTimeoutSeconds = 1; | 43 const long kTestTimeoutSeconds = 1; |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 coordinator_->OfflinerDoneCallback(request, status); | 408 coordinator_->OfflinerDoneCallback(request, status); |
| 408 } | 409 } |
| 409 | 410 |
| 410 TEST_F(RequestCoordinatorTest, StartProcessingWithNoRequests) { | 411 TEST_F(RequestCoordinatorTest, StartProcessingWithNoRequests) { |
| 411 DeviceConditions device_conditions(false, 75, | 412 DeviceConditions device_conditions(false, 75, |
| 412 net::NetworkChangeNotifier::CONNECTION_3G); | 413 net::NetworkChangeNotifier::CONNECTION_3G); |
| 413 base::Callback<void(bool)> callback = | 414 base::Callback<void(bool)> callback = |
| 414 base::Bind( | 415 base::Bind( |
| 415 &RequestCoordinatorTest::EmptyCallbackFunction, | 416 &RequestCoordinatorTest::EmptyCallbackFunction, |
| 416 base::Unretained(this)); | 417 base::Unretained(this)); |
| 417 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); | 418 EXPECT_TRUE(coordinator()->StartProcessing(kIsBackgroundScheduled, |
| 419 device_conditions, callback)); |
| 418 } | 420 } |
| 419 | 421 |
| 420 TEST_F(RequestCoordinatorTest, StartProcessingWithRequestInProgress) { | 422 TEST_F(RequestCoordinatorTest, StartProcessingWithRequestInProgress) { |
| 421 // Put the request on the queue. | 423 // Put the request on the queue. |
| 422 EXPECT_TRUE( | 424 EXPECT_TRUE( |
| 423 coordinator()->SavePageLater( | 425 coordinator()->SavePageLater( |
| 424 kUrl1, kClientId1, kUserRequested, | 426 kUrl1, kClientId1, kUserRequested, |
| 425 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER) != 0); | 427 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER) != 0); |
| 426 | 428 |
| 427 // Set up for the call to StartProcessing by building arguments. | 429 // Set up for the call to StartProcessing by building arguments. |
| 428 DeviceConditions device_conditions( | 430 DeviceConditions device_conditions( |
| 429 false, 75, net::NetworkChangeNotifier::CONNECTION_3G); | 431 false, 75, net::NetworkChangeNotifier::CONNECTION_3G); |
| 430 base::Callback<void(bool)> callback = | 432 base::Callback<void(bool)> callback = |
| 431 base::Bind(&RequestCoordinatorTest::EmptyCallbackFunction, | 433 base::Bind(&RequestCoordinatorTest::EmptyCallbackFunction, |
| 432 base::Unretained(this)); | 434 base::Unretained(this)); |
| 433 | 435 |
| 434 // Ensure that the forthcoming request does not finish - we simulate it being | 436 // Ensure that the forthcoming request does not finish - we simulate it being |
| 435 // in progress by asking it to skip making the completion callback. | 437 // in progress by asking it to skip making the completion callback. |
| 436 EnableOfflinerCallback(false); | 438 EnableOfflinerCallback(false); |
| 437 | 439 |
| 438 // Sending the request to the offliner should make it busy. | 440 // Sending the request to the offliner should make it busy. |
| 439 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); | 441 EXPECT_TRUE(coordinator()->StartProcessing(kIsBackgroundScheduled, |
| 442 device_conditions, callback)); |
| 440 PumpLoop(); | 443 PumpLoop(); |
| 441 EXPECT_TRUE(is_busy()); | 444 EXPECT_TRUE(is_busy()); |
| 442 | 445 |
| 443 // Now trying to start processing on another request should return false. | 446 // Now trying to start processing on another request should return false. |
| 444 EXPECT_FALSE(coordinator()->StartProcessing(device_conditions, callback)); | 447 EXPECT_FALSE(coordinator()->StartProcessing(kIsBackgroundScheduled, |
| 448 device_conditions, callback)); |
| 445 } | 449 } |
| 446 | 450 |
| 447 TEST_F(RequestCoordinatorTest, SavePageLater) { | 451 TEST_F(RequestCoordinatorTest, SavePageLater) { |
| 448 EXPECT_TRUE( | 452 EXPECT_TRUE( |
| 449 coordinator()->SavePageLater( | 453 coordinator()->SavePageLater( |
| 450 kUrl1, kClientId1, kUserRequested, | 454 kUrl1, kClientId1, kUserRequested, |
| 451 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER) != 0); | 455 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER) != 0); |
| 452 | 456 |
| 453 // Expect that a request got placed on the queue. | 457 // Expect that a request got placed on the queue. |
| 454 coordinator()->queue()->GetRequests( | 458 coordinator()->queue()->GetRequests( |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 } | 710 } |
| 707 | 711 |
| 708 // If one item completes, and there are no more user requeted items left, | 712 // If one item completes, and there are no more user requeted items left, |
| 709 // we should make a scheduler entry for a non-user requested item. | 713 // we should make a scheduler entry for a non-user requested item. |
| 710 TEST_F(RequestCoordinatorTest, RequestNotPickedDisabledItemsRemain) { | 714 TEST_F(RequestCoordinatorTest, RequestNotPickedDisabledItemsRemain) { |
| 711 // Call start processing just to set up a scheduler callback. | 715 // Call start processing just to set up a scheduler callback. |
| 712 DeviceConditions device_conditions(false, 75, | 716 DeviceConditions device_conditions(false, 75, |
| 713 net::NetworkChangeNotifier::CONNECTION_3G); | 717 net::NetworkChangeNotifier::CONNECTION_3G); |
| 714 base::Callback<void(bool)> callback = base::Bind( | 718 base::Callback<void(bool)> callback = base::Bind( |
| 715 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this)); | 719 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this)); |
| 716 coordinator()->StartProcessing(device_conditions, callback); | 720 coordinator()->StartProcessing(kIsBackgroundScheduled, device_conditions, |
| 721 callback); |
| 717 EXPECT_TRUE(is_starting()); | 722 EXPECT_TRUE(is_starting()); |
| 718 | 723 |
| 719 // Call RequestNotPicked, simulating a request on the disabled list. | 724 // Call RequestNotPicked, simulating a request on the disabled list. |
| 720 CallRequestNotPicked(false, true); | 725 CallRequestNotPicked(false, true); |
| 721 PumpLoop(); | 726 PumpLoop(); |
| 722 | 727 |
| 723 EXPECT_FALSE(is_starting()); | 728 EXPECT_FALSE(is_starting()); |
| 724 | 729 |
| 725 // The scheduler should have been called to schedule the disabled task for | 730 // The scheduler should have been called to schedule the disabled task for |
| 726 // 5 minutes from now. | 731 // 5 minutes from now. |
| 727 SchedulerStub* scheduler_stub = | 732 SchedulerStub* scheduler_stub = |
| 728 reinterpret_cast<SchedulerStub*>(coordinator()->scheduler()); | 733 reinterpret_cast<SchedulerStub*>(coordinator()->scheduler()); |
| 729 EXPECT_TRUE(scheduler_stub->backup_schedule_called()); | 734 EXPECT_TRUE(scheduler_stub->backup_schedule_called()); |
| 730 EXPECT_TRUE(scheduler_stub->unschedule_called()); | 735 EXPECT_TRUE(scheduler_stub->unschedule_called()); |
| 731 } | 736 } |
| 732 | 737 |
| 733 // If one item completes, and there are no more user requeted items left, | 738 // If one item completes, and there are no more user requeted items left, |
| 734 // we should make a scheduler entry for a non-user requested item. | 739 // we should make a scheduler entry for a non-user requested item. |
| 735 TEST_F(RequestCoordinatorTest, RequestNotPickedNonUserRequestedItemsRemain) { | 740 TEST_F(RequestCoordinatorTest, RequestNotPickedNonUserRequestedItemsRemain) { |
| 736 // Call start processing just to set up a scheduler callback. | 741 // Call start processing just to set up a scheduler callback. |
| 737 DeviceConditions device_conditions(false, 75, | 742 DeviceConditions device_conditions(false, 75, |
| 738 net::NetworkChangeNotifier::CONNECTION_3G); | 743 net::NetworkChangeNotifier::CONNECTION_3G); |
| 739 base::Callback<void(bool)> callback = base::Bind( | 744 base::Callback<void(bool)> callback = base::Bind( |
| 740 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this)); | 745 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this)); |
| 741 coordinator()->StartProcessing(device_conditions, callback); | 746 coordinator()->StartProcessing(kIsBackgroundScheduled, device_conditions, |
| 747 callback); |
| 742 EXPECT_TRUE(is_starting()); | 748 EXPECT_TRUE(is_starting()); |
| 743 | 749 |
| 744 // Call RequestNotPicked, and make sure we pick schedule a task for non user | 750 // Call RequestNotPicked, and make sure we pick schedule a task for non user |
| 745 // requested conditions, with no tasks on the disabled list. | 751 // requested conditions, with no tasks on the disabled list. |
| 746 CallRequestNotPicked(true, false); | 752 CallRequestNotPicked(true, false); |
| 747 PumpLoop(); | 753 PumpLoop(); |
| 748 | 754 |
| 749 EXPECT_FALSE(is_starting()); | 755 EXPECT_FALSE(is_starting()); |
| 750 | 756 |
| 751 // The scheduler should have been called to schedule the non-user requested | 757 // The scheduler should have been called to schedule the non-user requested |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 base::Unretained(this))); | 813 base::Unretained(this))); |
| 808 PumpLoop(); | 814 PumpLoop(); |
| 809 | 815 |
| 810 DeviceConditions device_conditions(false, 75, | 816 DeviceConditions device_conditions(false, 75, |
| 811 net::NetworkChangeNotifier::CONNECTION_3G); | 817 net::NetworkChangeNotifier::CONNECTION_3G); |
| 812 DisableLoading(); | 818 DisableLoading(); |
| 813 base::Callback<void(bool)> callback = | 819 base::Callback<void(bool)> callback = |
| 814 base::Bind( | 820 base::Bind( |
| 815 &RequestCoordinatorTest::EmptyCallbackFunction, | 821 &RequestCoordinatorTest::EmptyCallbackFunction, |
| 816 base::Unretained(this)); | 822 base::Unretained(this)); |
| 817 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); | 823 EXPECT_TRUE(coordinator()->StartProcessing(kIsBackgroundScheduled, |
| 824 device_conditions, callback)); |
| 818 | 825 |
| 819 // Let the async callbacks in the request coordinator run. | 826 // Let the async callbacks in the request coordinator run. |
| 820 PumpLoop(); | 827 PumpLoop(); |
| 821 | 828 |
| 822 EXPECT_FALSE(is_starting()); | 829 EXPECT_FALSE(is_starting()); |
| 823 EXPECT_EQ(Offliner::PRERENDERING_NOT_STARTED, last_offlining_status()); | 830 EXPECT_EQ(Offliner::PRERENDERING_NOT_STARTED, last_offlining_status()); |
| 824 } | 831 } |
| 825 | 832 |
| 826 // This tests a StopProcessing call before we have actually started the | 833 // This tests a StopProcessing call before we have actually started the |
| 827 // prerenderer. | 834 // prerenderer. |
| 828 TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingImmediately) { | 835 TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingImmediately) { |
| 829 // Add a request to the queue, wait for callbacks to finish. | 836 // Add a request to the queue, wait for callbacks to finish. |
| 830 offline_pages::SavePageRequest request( | 837 offline_pages::SavePageRequest request( |
| 831 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); | 838 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); |
| 832 coordinator()->queue()->AddRequest( | 839 coordinator()->queue()->AddRequest( |
| 833 request, | 840 request, |
| 834 base::Bind(&RequestCoordinatorTest::AddRequestDone, | 841 base::Bind(&RequestCoordinatorTest::AddRequestDone, |
| 835 base::Unretained(this))); | 842 base::Unretained(this))); |
| 836 PumpLoop(); | 843 PumpLoop(); |
| 837 | 844 |
| 838 DeviceConditions device_conditions(false, 75, | 845 DeviceConditions device_conditions(false, 75, |
| 839 net::NetworkChangeNotifier::CONNECTION_3G); | 846 net::NetworkChangeNotifier::CONNECTION_3G); |
| 840 base::Callback<void(bool)> callback = | 847 base::Callback<void(bool)> callback = |
| 841 base::Bind( | 848 base::Bind( |
| 842 &RequestCoordinatorTest::EmptyCallbackFunction, | 849 &RequestCoordinatorTest::EmptyCallbackFunction, |
| 843 base::Unretained(this)); | 850 base::Unretained(this)); |
| 844 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); | 851 EXPECT_TRUE(coordinator()->StartProcessing(kIsBackgroundScheduled, |
| 852 device_conditions, callback)); |
| 845 EXPECT_TRUE(is_starting()); | 853 EXPECT_TRUE(is_starting()); |
| 846 | 854 |
| 847 // Now, quick, before it can do much (we haven't called PumpLoop), cancel it. | 855 // Now, quick, before it can do much (we haven't called PumpLoop), cancel it. |
| 848 coordinator()->StopProcessing(Offliner::REQUEST_COORDINATOR_CANCELED); | 856 coordinator()->StopProcessing(Offliner::REQUEST_COORDINATOR_CANCELED); |
| 849 | 857 |
| 850 // Let the async callbacks in the request coordinator run. | 858 // Let the async callbacks in the request coordinator run. |
| 851 PumpLoop(); | 859 PumpLoop(); |
| 852 | 860 |
| 853 EXPECT_FALSE(is_starting()); | 861 EXPECT_FALSE(is_starting()); |
| 854 | 862 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 874 | 882 |
| 875 // Ensure the start processing request stops before the completion callback. | 883 // Ensure the start processing request stops before the completion callback. |
| 876 EnableOfflinerCallback(false); | 884 EnableOfflinerCallback(false); |
| 877 | 885 |
| 878 DeviceConditions device_conditions(false, 75, | 886 DeviceConditions device_conditions(false, 75, |
| 879 net::NetworkChangeNotifier::CONNECTION_3G); | 887 net::NetworkChangeNotifier::CONNECTION_3G); |
| 880 base::Callback<void(bool)> callback = | 888 base::Callback<void(bool)> callback = |
| 881 base::Bind( | 889 base::Bind( |
| 882 &RequestCoordinatorTest::EmptyCallbackFunction, | 890 &RequestCoordinatorTest::EmptyCallbackFunction, |
| 883 base::Unretained(this)); | 891 base::Unretained(this)); |
| 884 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); | 892 EXPECT_TRUE(coordinator()->StartProcessing(kIsBackgroundScheduled, |
| 893 device_conditions, callback)); |
| 885 EXPECT_TRUE(is_starting()); | 894 EXPECT_TRUE(is_starting()); |
| 886 | 895 |
| 887 // Let all the async parts of the start processing pipeline run to completion. | 896 // Let all the async parts of the start processing pipeline run to completion. |
| 888 PumpLoop(); | 897 PumpLoop(); |
| 889 | 898 |
| 890 // Coordinator should now be busy. | 899 // Coordinator should now be busy. |
| 891 EXPECT_TRUE(is_busy()); | 900 EXPECT_TRUE(is_busy()); |
| 892 EXPECT_FALSE(is_starting()); | 901 EXPECT_FALSE(is_starting()); |
| 893 | 902 |
| 894 // Now we cancel it while the prerenderer is busy. | 903 // Now we cancel it while the prerenderer is busy. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 919 base::Unretained(this))); | 928 base::Unretained(this))); |
| 920 PumpLoop(); | 929 PumpLoop(); |
| 921 | 930 |
| 922 // Ensure the start processing request stops before the completion callback. | 931 // Ensure the start processing request stops before the completion callback. |
| 923 EnableOfflinerCallback(false); | 932 EnableOfflinerCallback(false); |
| 924 | 933 |
| 925 DeviceConditions device_conditions(false, 75, | 934 DeviceConditions device_conditions(false, 75, |
| 926 net::NetworkChangeNotifier::CONNECTION_3G); | 935 net::NetworkChangeNotifier::CONNECTION_3G); |
| 927 base::Callback<void(bool)> callback = base::Bind( | 936 base::Callback<void(bool)> callback = base::Bind( |
| 928 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this)); | 937 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this)); |
| 929 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); | 938 EXPECT_TRUE(coordinator()->StartProcessing(kIsBackgroundScheduled, |
| 939 device_conditions, callback)); |
| 930 | 940 |
| 931 // Let all the async parts of the start processing pipeline run to completion. | 941 // Let all the async parts of the start processing pipeline run to completion. |
| 932 PumpLoop(); | 942 PumpLoop(); |
| 933 | 943 |
| 934 // Remove the request while it is processing. | 944 // Remove the request while it is processing. |
| 935 std::vector<int64_t> request_ids{kRequestId1}; | 945 std::vector<int64_t> request_ids{kRequestId1}; |
| 936 coordinator()->RemoveRequests( | 946 coordinator()->RemoveRequests( |
| 937 request_ids, base::Bind(&RequestCoordinatorTest::RemoveRequestsDone, | 947 request_ids, base::Bind(&RequestCoordinatorTest::RemoveRequestsDone, |
| 938 base::Unretained(this))); | 948 base::Unretained(this))); |
| 939 | 949 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 953 base::Unretained(this))); | 963 base::Unretained(this))); |
| 954 PumpLoop(); | 964 PumpLoop(); |
| 955 | 965 |
| 956 // Ensure the start processing request stops before the completion callback. | 966 // Ensure the start processing request stops before the completion callback. |
| 957 EnableOfflinerCallback(false); | 967 EnableOfflinerCallback(false); |
| 958 | 968 |
| 959 DeviceConditions device_conditions(false, 75, | 969 DeviceConditions device_conditions(false, 75, |
| 960 net::NetworkChangeNotifier::CONNECTION_3G); | 970 net::NetworkChangeNotifier::CONNECTION_3G); |
| 961 base::Callback<void(bool)> callback = base::Bind( | 971 base::Callback<void(bool)> callback = base::Bind( |
| 962 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this)); | 972 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this)); |
| 963 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); | 973 EXPECT_TRUE(coordinator()->StartProcessing(kIsBackgroundScheduled, |
| 974 device_conditions, callback)); |
| 964 | 975 |
| 965 // Call the method under test, making sure we send SUCCESS to the observer. | 976 // Call the method under test, making sure we send SUCCESS to the observer. |
| 966 coordinator()->MarkRequestCompleted(kRequestId1); | 977 coordinator()->MarkRequestCompleted(kRequestId1); |
| 967 PumpLoop(); | 978 PumpLoop(); |
| 968 | 979 |
| 969 // Our observer should have seen SUCCESS instead of REMOVED. | 980 // Our observer should have seen SUCCESS instead of REMOVED. |
| 970 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::SUCCESS, | 981 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::SUCCESS, |
| 971 observer().last_status()); | 982 observer().last_status()); |
| 972 EXPECT_TRUE(observer().completed_called()); | 983 EXPECT_TRUE(observer().completed_called()); |
| 973 } | 984 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 992 | 1003 |
| 993 // Ensure that the new request does not finish - we simulate it being | 1004 // Ensure that the new request does not finish - we simulate it being |
| 994 // in progress by asking it to skip making the completion callback. | 1005 // in progress by asking it to skip making the completion callback. |
| 995 EnableOfflinerCallback(false); | 1006 EnableOfflinerCallback(false); |
| 996 | 1007 |
| 997 // Ask RequestCoordinator to stop waiting for the offliner after this many | 1008 // Ask RequestCoordinator to stop waiting for the offliner after this many |
| 998 // seconds. | 1009 // seconds. |
| 999 SetOfflinerTimeoutForTest(base::TimeDelta::FromSeconds(kTestTimeoutSeconds)); | 1010 SetOfflinerTimeoutForTest(base::TimeDelta::FromSeconds(kTestTimeoutSeconds)); |
| 1000 | 1011 |
| 1001 // Sending the request to the offliner. | 1012 // Sending the request to the offliner. |
| 1002 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); | 1013 EXPECT_TRUE(coordinator()->StartProcessing(kIsBackgroundScheduled, |
| 1014 device_conditions, callback)); |
| 1003 PumpLoop(); | 1015 PumpLoop(); |
| 1004 | 1016 |
| 1005 // Advance the mock clock far enough to cause a watchdog timeout | 1017 // Advance the mock clock far enough to cause a watchdog timeout |
| 1006 AdvanceClockBy(base::TimeDelta::FromSeconds(kTestTimeoutSeconds + 1)); | 1018 AdvanceClockBy(base::TimeDelta::FromSeconds(kTestTimeoutSeconds + 1)); |
| 1007 PumpLoop(); | 1019 PumpLoop(); |
| 1008 | 1020 |
| 1009 // Wait for timeout to expire. Use a TaskRunner with a DelayedTaskRunner | 1021 // Wait for timeout to expire. Use a TaskRunner with a DelayedTaskRunner |
| 1010 // which won't time out immediately, so the watchdog thread doesn't kill valid | 1022 // which won't time out immediately, so the watchdog thread doesn't kill valid |
| 1011 // tasks too soon. | 1023 // tasks too soon. |
| 1012 WaitForCallback(); | 1024 WaitForCallback(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1037 | 1049 |
| 1038 // Set up for the call to StartProcessing. | 1050 // Set up for the call to StartProcessing. |
| 1039 DeviceConditions device_conditions( | 1051 DeviceConditions device_conditions( |
| 1040 !kPowerRequired, kBatteryPercentageHigh, | 1052 !kPowerRequired, kBatteryPercentageHigh, |
| 1041 net::NetworkChangeNotifier::CONNECTION_3G); | 1053 net::NetworkChangeNotifier::CONNECTION_3G); |
| 1042 base::Callback<void(bool)> callback = | 1054 base::Callback<void(bool)> callback = |
| 1043 base::Bind(&RequestCoordinatorTest::WaitingCallbackFunction, | 1055 base::Bind(&RequestCoordinatorTest::WaitingCallbackFunction, |
| 1044 base::Unretained(this)); | 1056 base::Unretained(this)); |
| 1045 | 1057 |
| 1046 // Sending the request to the offliner. | 1058 // Sending the request to the offliner. |
| 1047 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); | 1059 EXPECT_TRUE(coordinator()->StartProcessing(kIsBackgroundScheduled, |
| 1060 device_conditions, callback)); |
| 1048 PumpLoop(); | 1061 PumpLoop(); |
| 1049 | 1062 |
| 1050 // Advance the mock clock far enough to exceed our time budget. | 1063 // Advance the mock clock far enough to exceed our time budget. |
| 1051 AdvanceClockBy(base::TimeDelta::FromSeconds(kTestTimeBudgetSeconds)); | 1064 AdvanceClockBy(base::TimeDelta::FromSeconds(kTestTimeBudgetSeconds)); |
| 1052 PumpLoop(); | 1065 PumpLoop(); |
| 1053 | 1066 |
| 1054 // TryNextRequest should decide that there is no more work to be done, | 1067 // TryNextRequest should decide that there is no more work to be done, |
| 1055 // and call back to the scheduler, even though there is another request in the | 1068 // and call back to the scheduler, even though there is another request in the |
| 1056 // queue. There should be one request left in the queue. | 1069 // queue. There should be one request left in the queue. |
| 1057 // Verify the request gets removed from the queue, and wait for callbacks. | 1070 // Verify the request gets removed from the queue, and wait for callbacks. |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1228 // Now whether processing triggered immediately depends on whether test | 1241 // Now whether processing triggered immediately depends on whether test |
| 1229 // is run on svelte device or not. | 1242 // is run on svelte device or not. |
| 1230 if (base::SysInfo::IsLowEndDevice()) { | 1243 if (base::SysInfo::IsLowEndDevice()) { |
| 1231 EXPECT_FALSE(is_busy()); | 1244 EXPECT_FALSE(is_busy()); |
| 1232 } else { | 1245 } else { |
| 1233 EXPECT_TRUE(is_busy()); | 1246 EXPECT_TRUE(is_busy()); |
| 1234 } | 1247 } |
| 1235 } | 1248 } |
| 1236 | 1249 |
| 1237 } // namespace offline_pages | 1250 } // namespace offline_pages |
| OLD | NEW |