| 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 1302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1340 | 1342 |
| 1341 // Now whether processing triggered immediately depends on whether test | 1343 // Now whether processing triggered immediately depends on whether test |
| 1342 // is run on svelte device or not. | 1344 // is run on svelte device or not. |
| 1343 if (base::SysInfo::IsLowEndDevice()) { | 1345 if (base::SysInfo::IsLowEndDevice()) { |
| 1344 EXPECT_FALSE(is_busy()); | 1346 EXPECT_FALSE(is_busy()); |
| 1345 } else { | 1347 } else { |
| 1346 EXPECT_TRUE(is_busy()); | 1348 EXPECT_TRUE(is_busy()); |
| 1347 } | 1349 } |
| 1348 } | 1350 } |
| 1349 | 1351 |
| 1352 TEST_F(RequestCoordinatorTest, |
| 1353 SavePageStartsProcessingWhenConnectedOnLowEndDeviceIfFlagEnabled) { |
| 1354 // Set up the fake network conditions for the NetworkConnectionNotifier. |
| 1355 SetNetworkConditionsForTest( |
| 1356 net::NetworkChangeNotifier::ConnectionType::CONNECTION_3G); |
| 1357 // Set up the fake network conditions for the network quality estimator. |
| 1358 SetEffectiveConnectionTypeForTest( |
| 1359 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_3G); |
| 1360 // Mark device as low-end device. |
| 1361 SetIsLowEndDeviceForTest(true); |
| 1362 EXPECT_FALSE(offline_pages::IsOfflinePagesSvelteConcurrentLoadingEnabled()); |
| 1363 |
| 1364 // Make a request. |
| 1365 EXPECT_NE(coordinator()->SavePageLater( |
| 1366 kUrl1, kClientId1, kUserRequested, |
| 1367 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), |
| 1368 0); |
| 1369 PumpLoop(); |
| 1370 |
| 1371 // Verify not immediately busy (since low-end device). |
| 1372 EXPECT_FALSE(is_busy()); |
| 1373 |
| 1374 // Set feature flag to allow concurrent loads. |
| 1375 base::test::ScopedFeatureList scoped_feature_list; |
| 1376 scoped_feature_list.InitAndEnableFeature( |
| 1377 kOfflinePagesSvelteConcurrentLoadingFeature); |
| 1378 EXPECT_TRUE(offline_pages::IsOfflinePagesSvelteConcurrentLoadingEnabled()); |
| 1379 |
| 1380 // Make another request. |
| 1381 EXPECT_NE(coordinator()->SavePageLater( |
| 1382 kUrl2, kClientId2, kUserRequested, |
| 1383 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), |
| 1384 0); |
| 1385 PumpLoop(); |
| 1386 |
| 1387 // Verify immediate processing did start this time. |
| 1388 EXPECT_TRUE(is_busy()); |
| 1389 } |
| 1390 |
| 1350 TEST_F(RequestCoordinatorTest, SavePageDoesntStartProcessingWhenDisconnected) { | 1391 TEST_F(RequestCoordinatorTest, SavePageDoesntStartProcessingWhenDisconnected) { |
| 1351 SetNetworkConnected(false); | 1392 SetNetworkConnected(false); |
| 1352 EXPECT_NE( | 1393 EXPECT_NE( |
| 1353 coordinator()->SavePageLater( | 1394 coordinator()->SavePageLater( |
| 1354 kUrl1, kClientId1, kUserRequested, | 1395 kUrl1, kClientId1, kUserRequested, |
| 1355 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), 0); | 1396 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), 0); |
| 1356 PumpLoop(); | 1397 PumpLoop(); |
| 1357 EXPECT_FALSE(is_busy()); | 1398 EXPECT_FALSE(is_busy()); |
| 1358 } | 1399 } |
| 1359 | 1400 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1412 // Now whether processing triggered immediately depends on whether test | 1453 // Now whether processing triggered immediately depends on whether test |
| 1413 // is run on svelte device or not. | 1454 // is run on svelte device or not. |
| 1414 if (base::SysInfo::IsLowEndDevice()) { | 1455 if (base::SysInfo::IsLowEndDevice()) { |
| 1415 EXPECT_FALSE(is_busy()); | 1456 EXPECT_FALSE(is_busy()); |
| 1416 } else { | 1457 } else { |
| 1417 EXPECT_TRUE(is_busy()); | 1458 EXPECT_TRUE(is_busy()); |
| 1418 } | 1459 } |
| 1419 } | 1460 } |
| 1420 | 1461 |
| 1421 } // namespace offline_pages | 1462 } // namespace offline_pages |
| OLD | NEW |