| 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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
| 16 #include "base/sys_info.h" | 16 #include "base/sys_info.h" |
| 17 #include "base/test/scoped_feature_list.h" |
| 17 #include "base/test/test_mock_time_task_runner.h" | 18 #include "base/test/test_mock_time_task_runner.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 20 #include "components/offline_pages/background/device_conditions.h" | 21 #include "components/offline_pages/background/device_conditions.h" |
| 21 #include "components/offline_pages/background/offliner.h" | 22 #include "components/offline_pages/background/offliner.h" |
| 22 #include "components/offline_pages/background/offliner_factory.h" | 23 #include "components/offline_pages/background/offliner_factory.h" |
| 23 #include "components/offline_pages/background/offliner_policy.h" | 24 #include "components/offline_pages/background/offliner_policy.h" |
| 24 #include "components/offline_pages/background/request_queue.h" | 25 #include "components/offline_pages/background/request_queue.h" |
| 25 #include "components/offline_pages/background/request_queue_in_memory_store.h" | 26 #include "components/offline_pages/background/request_queue_in_memory_store.h" |
| 26 #include "components/offline_pages/background/save_page_request.h" | 27 #include "components/offline_pages/background/save_page_request.h" |
| 27 #include "components/offline_pages/background/scheduler.h" | 28 #include "components/offline_pages/background/scheduler.h" |
| 29 #include "components/offline_pages/offline_page_feature.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 31 |
| 30 namespace offline_pages { | 32 namespace offline_pages { |
| 31 | 33 |
| 32 namespace { | 34 namespace { |
| 33 // put test constants here | 35 // put test constants here |
| 34 const GURL kUrl1("http://universe.com/everything"); | 36 const GURL kUrl1("http://universe.com/everything"); |
| 35 const GURL kUrl2("http://universe.com/toinfinityandbeyond"); | 37 const GURL kUrl2("http://universe.com/toinfinityandbeyond"); |
| 36 const std::string kClientNamespace("bookmark"); | 38 const std::string kClientNamespace("bookmark"); |
| 37 const std::string kId1("42"); | 39 const std::string kId1("42"); |
| (...skipping 1244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1282 | 1284 |
| 1283 // Now whether processing triggered immediately depends on whether test | 1285 // Now whether processing triggered immediately depends on whether test |
| 1284 // is run on svelte device or not. | 1286 // is run on svelte device or not. |
| 1285 if (base::SysInfo::IsLowEndDevice()) { | 1287 if (base::SysInfo::IsLowEndDevice()) { |
| 1286 EXPECT_FALSE(is_busy()); | 1288 EXPECT_FALSE(is_busy()); |
| 1287 } else { | 1289 } else { |
| 1288 EXPECT_TRUE(is_busy()); | 1290 EXPECT_TRUE(is_busy()); |
| 1289 } | 1291 } |
| 1290 } | 1292 } |
| 1291 | 1293 |
| 1294 TEST_F(RequestCoordinatorTest, |
| 1295 SavePageStartsProcessingWhenConnectedOnLowEndDeviceIfFlagEnabled) { |
| 1296 // Set up the fake network conditions for the NetworkConnectionNotifier. |
| 1297 SetNetworkConditionsForTest( |
| 1298 net::NetworkChangeNotifier::ConnectionType::CONNECTION_3G); |
| 1299 // Set up the fake network conditions for the network quality estimator. |
| 1300 SetEffectiveConnectionTypeForTest( |
| 1301 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_3G); |
| 1302 // Mark device as low-end device. |
| 1303 SetIsLowEndDeviceForTest(true); |
| 1304 EXPECT_FALSE(offline_pages::IsOfflinePagesSvelteConcurrentLoadingEnabled()); |
| 1305 |
| 1306 // Make a request. |
| 1307 EXPECT_NE(coordinator()->SavePageLater( |
| 1308 kUrl1, kClientId1, kUserRequested, |
| 1309 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), |
| 1310 0); |
| 1311 PumpLoop(); |
| 1312 |
| 1313 // Verify not immediately busy (since low-end device). |
| 1314 EXPECT_FALSE(is_busy()); |
| 1315 |
| 1316 // Set feature flag to allow concurrent loads. |
| 1317 base::test::ScopedFeatureList scoped_feature_list; |
| 1318 scoped_feature_list.InitAndEnableFeature( |
| 1319 kOfflinePagesSvelteConcurrentLoadingFeature); |
| 1320 EXPECT_TRUE(offline_pages::IsOfflinePagesSvelteConcurrentLoadingEnabled()); |
| 1321 |
| 1322 // Make another request. |
| 1323 EXPECT_NE(coordinator()->SavePageLater( |
| 1324 kUrl2, kClientId2, kUserRequested, |
| 1325 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), |
| 1326 0); |
| 1327 PumpLoop(); |
| 1328 |
| 1329 // Verify immediate processing did start this time. |
| 1330 EXPECT_TRUE(is_busy()); |
| 1331 } |
| 1332 |
| 1292 TEST_F(RequestCoordinatorTest, SavePageDoesntStartProcessingWhenDisconnected) { | 1333 TEST_F(RequestCoordinatorTest, SavePageDoesntStartProcessingWhenDisconnected) { |
| 1293 EXPECT_NE( | 1334 EXPECT_NE( |
| 1294 coordinator()->SavePageLater( | 1335 coordinator()->SavePageLater( |
| 1295 kUrl1, kClientId1, kUserRequested, | 1336 kUrl1, kClientId1, kUserRequested, |
| 1296 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), 0); | 1337 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), 0); |
| 1297 PumpLoop(); | 1338 PumpLoop(); |
| 1298 EXPECT_FALSE(is_busy()); | 1339 EXPECT_FALSE(is_busy()); |
| 1299 } | 1340 } |
| 1300 | 1341 |
| 1301 TEST_F(RequestCoordinatorTest, | 1342 TEST_F(RequestCoordinatorTest, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1350 // Now whether processing triggered immediately depends on whether test | 1391 // Now whether processing triggered immediately depends on whether test |
| 1351 // is run on svelte device or not. | 1392 // is run on svelte device or not. |
| 1352 if (base::SysInfo::IsLowEndDevice()) { | 1393 if (base::SysInfo::IsLowEndDevice()) { |
| 1353 EXPECT_FALSE(is_busy()); | 1394 EXPECT_FALSE(is_busy()); |
| 1354 } else { | 1395 } else { |
| 1355 EXPECT_TRUE(is_busy()); | 1396 EXPECT_TRUE(is_busy()); |
| 1356 } | 1397 } |
| 1357 } | 1398 } |
| 1358 | 1399 |
| 1359 } // namespace offline_pages | 1400 } // namespace offline_pages |
| OLD | NEW |