Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Side by Side Diff: components/offline_pages/background/request_coordinator_unittest.cc

Issue 2483463002: [Offline Pages] Feature flag to allow concurrent background loading on svelte (Closed)
Patch Set: Address petewil@ comment Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1285 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 1325
1324 // Now whether processing triggered immediately depends on whether test 1326 // Now whether processing triggered immediately depends on whether test
1325 // is run on svelte device or not. 1327 // is run on svelte device or not.
1326 if (base::SysInfo::IsLowEndDevice()) { 1328 if (base::SysInfo::IsLowEndDevice()) {
1327 EXPECT_FALSE(is_busy()); 1329 EXPECT_FALSE(is_busy());
1328 } else { 1330 } else {
1329 EXPECT_TRUE(is_busy()); 1331 EXPECT_TRUE(is_busy());
1330 } 1332 }
1331 } 1333 }
1332 1334
1335 TEST_F(RequestCoordinatorTest,
1336 SavePageStartsProcessingWhenConnectedOnLowEndDeviceIfFlagEnabled) {
1337 // Set up the fake network conditions for the NetworkConnectionNotifier.
1338 SetNetworkConditionsForTest(
1339 net::NetworkChangeNotifier::ConnectionType::CONNECTION_3G);
1340 // Set up the fake network conditions for the network quality estimator.
1341 SetEffectiveConnectionTypeForTest(
1342 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_3G);
1343 // Mark device as low-end device.
1344 SetIsLowEndDeviceForTest(true);
1345 EXPECT_FALSE(offline_pages::IsOfflinePagesSvelteConcurrentLoadingEnabled());
1346
1347 // Make a request.
1348 EXPECT_NE(coordinator()->SavePageLater(
1349 kUrl1, kClientId1, kUserRequested,
1350 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER),
1351 0);
1352 PumpLoop();
1353
1354 // Verify not immediately busy (since low-end device).
1355 EXPECT_FALSE(is_busy());
1356
1357 // Set feature flag to allow concurrent loads.
1358 base::test::ScopedFeatureList scoped_feature_list;
1359 scoped_feature_list.InitAndEnableFeature(
1360 kOfflinePagesSvelteConcurrentLoadingFeature);
1361 EXPECT_TRUE(offline_pages::IsOfflinePagesSvelteConcurrentLoadingEnabled());
1362
1363 // Make another request.
1364 EXPECT_NE(coordinator()->SavePageLater(
1365 kUrl2, kClientId2, kUserRequested,
1366 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER),
1367 0);
1368 PumpLoop();
1369
1370 // Verify immediate processing did start this time.
1371 EXPECT_TRUE(is_busy());
1372 }
1373
1333 TEST_F(RequestCoordinatorTest, SavePageDoesntStartProcessingWhenDisconnected) { 1374 TEST_F(RequestCoordinatorTest, SavePageDoesntStartProcessingWhenDisconnected) {
1334 SetNetworkConnected(false); 1375 SetNetworkConnected(false);
1335 EXPECT_NE( 1376 EXPECT_NE(
1336 coordinator()->SavePageLater( 1377 coordinator()->SavePageLater(
1337 kUrl1, kClientId1, kUserRequested, 1378 kUrl1, kClientId1, kUserRequested,
1338 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), 0); 1379 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), 0);
1339 PumpLoop(); 1380 PumpLoop();
1340 EXPECT_FALSE(is_busy()); 1381 EXPECT_FALSE(is_busy());
1341 } 1382 }
1342 1383
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1395 // Now whether processing triggered immediately depends on whether test 1436 // Now whether processing triggered immediately depends on whether test
1396 // is run on svelte device or not. 1437 // is run on svelte device or not.
1397 if (base::SysInfo::IsLowEndDevice()) { 1438 if (base::SysInfo::IsLowEndDevice()) {
1398 EXPECT_FALSE(is_busy()); 1439 EXPECT_FALSE(is_busy());
1399 } else { 1440 } else {
1400 EXPECT_TRUE(is_busy()); 1441 EXPECT_TRUE(is_busy());
1401 } 1442 }
1402 } 1443 }
1403 1444
1404 } // namespace offline_pages 1445 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698