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 926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 request_ids, base::Bind(&RequestCoordinatorTest::RemoveRequestsDone, | 937 request_ids, base::Bind(&RequestCoordinatorTest::RemoveRequestsDone, |
938 base::Unretained(this))); | 938 base::Unretained(this))); |
939 | 939 |
940 // Let the async callbacks in the cancel run. | 940 // Let the async callbacks in the cancel run. |
941 PumpLoop(); | 941 PumpLoop(); |
942 | 942 |
943 // Since offliner was started, it will have seen cancel call. | 943 // Since offliner was started, it will have seen cancel call. |
944 EXPECT_TRUE(OfflinerWasCanceled()); | 944 EXPECT_TRUE(OfflinerWasCanceled()); |
945 } | 945 } |
946 | 946 |
| 947 TEST_F(RequestCoordinatorTest, MarkRequestCompleted) { |
| 948 // Add a request to the queue. |
| 949 offline_pages::SavePageRequest request1(kRequestId1, kUrl1, kClientId1, |
| 950 base::Time::Now(), kUserRequested); |
| 951 coordinator()->queue()->AddRequest( |
| 952 request1, base::Bind(&RequestCoordinatorTest::AddRequestDone, |
| 953 base::Unretained(this))); |
| 954 PumpLoop(); |
| 955 |
| 956 // Ensure the start processing request stops before the completion callback. |
| 957 EnableOfflinerCallback(false); |
| 958 |
| 959 DeviceConditions device_conditions(false, 75, |
| 960 net::NetworkChangeNotifier::CONNECTION_3G); |
| 961 base::Callback<void(bool)> callback = base::Bind( |
| 962 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this)); |
| 963 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); |
| 964 |
| 965 // Call the method under test, making sure we send SUCCESS to the observer. |
| 966 coordinator()->MarkRequestCompleted(kRequestId1); |
| 967 PumpLoop(); |
| 968 |
| 969 // Our observer should have seen SUCCESS instead of REMOVED. |
| 970 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::SUCCESS, |
| 971 observer().last_status()); |
| 972 EXPECT_TRUE(observer().completed_called()); |
| 973 } |
| 974 |
947 TEST_F(RequestCoordinatorTest, WatchdogTimeout) { | 975 TEST_F(RequestCoordinatorTest, WatchdogTimeout) { |
948 // Build a request to use with the pre-renderer, and put it on the queue. | 976 // Build a request to use with the pre-renderer, and put it on the queue. |
949 offline_pages::SavePageRequest request( | 977 offline_pages::SavePageRequest request( |
950 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); | 978 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); |
951 coordinator()->queue()->AddRequest( | 979 coordinator()->queue()->AddRequest( |
952 request, | 980 request, |
953 base::Bind(&RequestCoordinatorTest::AddRequestDone, | 981 base::Bind(&RequestCoordinatorTest::AddRequestDone, |
954 base::Unretained(this))); | 982 base::Unretained(this))); |
955 PumpLoop(); | 983 PumpLoop(); |
956 | 984 |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1200 // Now whether processing triggered immediately depends on whether test | 1228 // Now whether processing triggered immediately depends on whether test |
1201 // is run on svelte device or not. | 1229 // is run on svelte device or not. |
1202 if (base::SysInfo::IsLowEndDevice()) { | 1230 if (base::SysInfo::IsLowEndDevice()) { |
1203 EXPECT_FALSE(is_busy()); | 1231 EXPECT_FALSE(is_busy()); |
1204 } else { | 1232 } else { |
1205 EXPECT_TRUE(is_busy()); | 1233 EXPECT_TRUE(is_busy()); |
1206 } | 1234 } |
1207 } | 1235 } |
1208 | 1236 |
1209 } // namespace offline_pages | 1237 } // namespace offline_pages |
OLD | NEW |