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/core/background/request_coordinator.h" | 5 #include "components/offline_pages/core/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 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 EXPECT_NE(request_id, 0l); | 1098 EXPECT_NE(request_id, 0l); |
1099 | 1099 |
1100 // Verify request added in OFFLINING state. | 1100 // Verify request added in OFFLINING state. |
1101 EXPECT_TRUE(observer().added_called()); | 1101 EXPECT_TRUE(observer().added_called()); |
1102 EXPECT_EQ(SavePageRequest::RequestState::OFFLINING, observer().state()); | 1102 EXPECT_EQ(SavePageRequest::RequestState::OFFLINING, observer().state()); |
1103 | 1103 |
1104 // Call the method under test, making sure we send SUCCESS to the observer. | 1104 // Call the method under test, making sure we send SUCCESS to the observer. |
1105 coordinator()->MarkRequestCompleted(request_id); | 1105 coordinator()->MarkRequestCompleted(request_id); |
1106 PumpLoop(); | 1106 PumpLoop(); |
1107 | 1107 |
1108 // Our observer should have seen SUCCESS instead of REMOVED. | 1108 // Our observer should have seen SUCCESS instead of USER_CANCELED. |
1109 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::SUCCESS, | 1109 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::SUCCESS, |
1110 observer().last_status()); | 1110 observer().last_status()); |
1111 EXPECT_TRUE(observer().completed_called()); | 1111 EXPECT_TRUE(observer().completed_called()); |
1112 } | 1112 } |
1113 | 1113 |
1114 TEST_F(RequestCoordinatorTest, EnableForOffliner) { | 1114 TEST_F(RequestCoordinatorTest, EnableForOffliner) { |
1115 // Pretend we are on low-end device so immediate start won't happen. | 1115 // Pretend we are on low-end device so immediate start won't happen. |
1116 SetIsLowEndDeviceForTest(true); | 1116 SetIsLowEndDeviceForTest(true); |
1117 | 1117 |
1118 int64_t request_id = SavePageLaterWithAvailability( | 1118 int64_t request_id = SavePageLaterWithAvailability( |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1352 request_ids.push_back(kRequestId1); | 1352 request_ids.push_back(kRequestId1); |
1353 coordinator()->RemoveRequests( | 1353 coordinator()->RemoveRequests( |
1354 request_ids, base::Bind(&RequestCoordinatorTest::RemoveRequestsDone, | 1354 request_ids, base::Bind(&RequestCoordinatorTest::RemoveRequestsDone, |
1355 base::Unretained(this))); | 1355 base::Unretained(this))); |
1356 | 1356 |
1357 PumpLoop(); | 1357 PumpLoop(); |
1358 WaitForCallback(); | 1358 WaitForCallback(); |
1359 PumpLoop(); | 1359 PumpLoop(); |
1360 | 1360 |
1361 EXPECT_TRUE(observer().completed_called()); | 1361 EXPECT_TRUE(observer().completed_called()); |
1362 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::REMOVED, | 1362 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::USER_CANCELED, |
1363 observer().last_status()); | 1363 observer().last_status()); |
1364 EXPECT_EQ(1UL, last_remove_results().size()); | 1364 EXPECT_EQ(1UL, last_remove_results().size()); |
1365 EXPECT_EQ(kRequestId1, std::get<0>(last_remove_results().at(0))); | 1365 EXPECT_EQ(kRequestId1, std::get<0>(last_remove_results().at(0))); |
1366 } | 1366 } |
1367 | 1367 |
1368 TEST_F(RequestCoordinatorTest, | 1368 TEST_F(RequestCoordinatorTest, |
1369 SavePageStartsProcessingWhenConnectedAndNotLowEndDevice) { | 1369 SavePageStartsProcessingWhenConnectedAndNotLowEndDevice) { |
1370 // Turn off the callback so that the request stops before processing in | 1370 // Turn off the callback so that the request stops before processing in |
1371 // PumpLoop. | 1371 // PumpLoop. |
1372 EnableOfflinerCallback(false); | 1372 EnableOfflinerCallback(false); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1579 PumpLoop(); | 1579 PumpLoop(); |
1580 | 1580 |
1581 // The last time would trigger the snapshot on last retry and succeed. | 1581 // The last time would trigger the snapshot on last retry and succeed. |
1582 EXPECT_FALSE(OfflinerWasCanceled()); | 1582 EXPECT_FALSE(OfflinerWasCanceled()); |
1583 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::SUCCESS, | 1583 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::SUCCESS, |
1584 observer().last_status()); | 1584 observer().last_status()); |
1585 EXPECT_TRUE(observer().completed_called()); | 1585 EXPECT_TRUE(observer().completed_called()); |
1586 } | 1586 } |
1587 | 1587 |
1588 } // namespace offline_pages | 1588 } // namespace offline_pages |
OLD | NEW |