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

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

Issue 2546433004: [OfflinePages] Restarts immediate processing if stopped due to no net (Closed)
Patch Set: Added some unittests Created 4 years 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>
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 // RequestPicker should *not* have tried to start an additional job, 563 // RequestPicker should *not* have tried to start an additional job,
564 // because the request queue is empty now. 564 // because the request queue is empty now.
565 EXPECT_EQ(0UL, last_requests().size()); 565 EXPECT_EQ(0UL, last_requests().size());
566 // Check that the observer got the notification that we succeeded, and that 566 // Check that the observer got the notification that we succeeded, and that
567 // the request got removed from the queue. 567 // the request got removed from the queue.
568 EXPECT_TRUE(observer().completed_called()); 568 EXPECT_TRUE(observer().completed_called());
569 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::SUCCESS, 569 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::SUCCESS,
570 observer().last_status()); 570 observer().last_status());
571 } 571 }
572 572
573 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestSucceededButLostNetwork) {
574 // Add a request to the queue and set offliner done callback for it.
575 offline_pages::SavePageRequest request(kRequestId1, kUrl1, kClientId1,
576 base::Time::Now(), kUserRequested);
577 SetupForOfflinerDoneCallbackTest(&request);
578 EnableOfflinerCallback(false);
579
580 // Add a 2nd request to the queue.
581 AddRequest2();
582
583 // Disconnect network.
584 SetNetworkConnected(false);
585
586 // Call the OfflinerDoneCallback to simulate the page being completed, wait
587 // for callbacks.
588 SendOfflinerDoneCallback(request, Offliner::RequestStatus::SAVED);
589 PumpLoop();
590 EXPECT_TRUE(immediate_schedule_callback_called());
591
592 // Verify not busy with 2nd request (since no connection).
593 EXPECT_FALSE(is_busy());
594
595 // Now connect network and verify processing starts.
596 SetNetworkConnected(true);
597 PumpLoop();
598 EXPECT_TRUE(is_busy());
599 }
600
573 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailed) { 601 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailed) {
574 // Add a request to the queue, wait for callbacks to finish. 602 // Add a request to the queue, wait for callbacks to finish.
575 offline_pages::SavePageRequest request( 603 offline_pages::SavePageRequest request(
576 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); 604 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested);
577 request.set_completed_attempt_count(kMaxCompletedTries - 1); 605 request.set_completed_attempt_count(kMaxCompletedTries - 1);
578 SetupForOfflinerDoneCallbackTest(&request); 606 SetupForOfflinerDoneCallbackTest(&request);
579 // Stop processing before completing the second request on the queue. 607 // Stop processing before completing the second request on the queue.
580 EnableOfflinerCallback(false); 608 EnableOfflinerCallback(false);
581 609
582 // Add second request to the queue to check handling when first fails. 610 // Add second request to the queue to check handling when first fails.
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 kUrl2, kClientId2, kUserRequested, 1264 kUrl2, kClientId2, kUserRequested,
1237 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), 1265 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER),
1238 0); 1266 0);
1239 PumpLoop(); 1267 PumpLoop();
1240 1268
1241 // Verify immediate processing did start this time. 1269 // Verify immediate processing did start this time.
1242 EXPECT_TRUE(is_busy()); 1270 EXPECT_TRUE(is_busy());
1243 } 1271 }
1244 1272
1245 TEST_F(RequestCoordinatorTest, SavePageDoesntStartProcessingWhenDisconnected) { 1273 TEST_F(RequestCoordinatorTest, SavePageDoesntStartProcessingWhenDisconnected) {
1274 // If low end device, pretend it is not so that immediate start allowed.
1275 SetIsLowEndDeviceForTest(false);
1276
1246 SetNetworkConnected(false); 1277 SetNetworkConnected(false);
1278 EnableOfflinerCallback(false);
1247 EXPECT_NE( 1279 EXPECT_NE(
1248 coordinator()->SavePageLater( 1280 coordinator()->SavePageLater(
1249 kUrl1, kClientId1, kUserRequested, 1281 kUrl1, kClientId1, kUserRequested,
1250 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), 0); 1282 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), 0);
1251 PumpLoop(); 1283 PumpLoop();
1252 EXPECT_FALSE(is_busy()); 1284 EXPECT_FALSE(is_busy());
1285
1286 // Now connect network and verify processing starts.
1287 SetNetworkConnected(true);
1288 PumpLoop();
1289 EXPECT_TRUE(is_busy());
1253 } 1290 }
1254 1291
1255 TEST_F(RequestCoordinatorTest, 1292 TEST_F(RequestCoordinatorTest,
1256 SavePageDoesStartProcessingWhenPoorlyConnected) { 1293 SavePageDoesStartProcessingWhenPoorlyConnected) {
1257 // Set specific network type for 2G with poor effective connection. 1294 // Set specific network type for 2G with poor effective connection.
1258 SetNetworkConditionsForTest( 1295 SetNetworkConditionsForTest(
1259 net::NetworkChangeNotifier::ConnectionType::CONNECTION_2G); 1296 net::NetworkChangeNotifier::ConnectionType::CONNECTION_2G);
1260 SetEffectiveConnectionTypeForTest( 1297 SetEffectiveConnectionTypeForTest(
1261 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_SLOW_2G); 1298 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_SLOW_2G);
1262 1299
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 // Now whether processing triggered immediately depends on whether test 1349 // Now whether processing triggered immediately depends on whether test
1313 // is run on svelte device or not. 1350 // is run on svelte device or not.
1314 if (base::SysInfo::IsLowEndDevice()) { 1351 if (base::SysInfo::IsLowEndDevice()) {
1315 EXPECT_FALSE(is_busy()); 1352 EXPECT_FALSE(is_busy());
1316 } else { 1353 } else {
1317 EXPECT_TRUE(is_busy()); 1354 EXPECT_TRUE(is_busy());
1318 } 1355 }
1319 } 1356 }
1320 1357
1321 } // namespace offline_pages 1358 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698