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

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

Issue 2556613003: [OfflinePages] Restarts immediate processing if stopped due to no net (Closed)
Patch Set: 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
« no previous file with comments | « components/offline_pages/background/request_coordinator.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 SetEffectiveConnectionTypeForTest( 321 SetEffectiveConnectionTypeForTest(
322 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_3G); 322 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_3G);
323 } else { 323 } else {
324 SetNetworkConditionsForTest( 324 SetNetworkConditionsForTest(
325 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE); 325 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE);
326 SetEffectiveConnectionTypeForTest( 326 SetEffectiveConnectionTypeForTest(
327 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_OFFLINE); 327 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_OFFLINE);
328 } 328 }
329 } 329 }
330 330
331 void CallConnectionTypeObserver() {
332 if (coordinator()->connection_notifier_) {
333 coordinator()->connection_notifier_->OnConnectionTypeChanged(
334 GetConnectionType());
335 }
336 }
337
331 void SetIsLowEndDeviceForTest(bool is_low_end_device) { 338 void SetIsLowEndDeviceForTest(bool is_low_end_device) {
332 coordinator()->is_low_end_device_ = is_low_end_device; 339 coordinator()->is_low_end_device_ = is_low_end_device;
333 } 340 }
334 341
335 void SetProcessingStateForTest( 342 void SetProcessingStateForTest(
336 RequestCoordinator::ProcessingWindowState processing_state) { 343 RequestCoordinator::ProcessingWindowState processing_state) {
337 coordinator()->processing_state_ = processing_state; 344 coordinator()->processing_state_ = processing_state;
338 } 345 }
339 346
340 void SetOperationStartTimeForTest(base::Time start_time) { 347 void SetOperationStartTimeForTest(base::Time start_time) {
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 // RequestPicker should *not* have tried to start an additional job, 695 // RequestPicker should *not* have tried to start an additional job,
689 // because the request queue is empty now. 696 // because the request queue is empty now.
690 EXPECT_EQ(0UL, last_requests().size()); 697 EXPECT_EQ(0UL, last_requests().size());
691 // Check that the observer got the notification that we succeeded, and that 698 // Check that the observer got the notification that we succeeded, and that
692 // the request got removed from the queue. 699 // the request got removed from the queue.
693 EXPECT_TRUE(observer().completed_called()); 700 EXPECT_TRUE(observer().completed_called());
694 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::SUCCESS, 701 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::SUCCESS,
695 observer().last_status()); 702 observer().last_status());
696 } 703 }
697 704
705 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestSucceededButLostNetwork) {
706 // Add a request to the queue and set offliner done callback for it.
707 offline_pages::SavePageRequest request(kRequestId1, kUrl1, kClientId1,
708 base::Time::Now(), kUserRequested);
709 SetupForOfflinerDoneCallbackTest(&request);
710 EnableOfflinerCallback(false);
711
712 // Add a 2nd request to the queue.
713 AddRequest2();
714
715 // Disconnect network.
716 SetNetworkConnected(false);
717
718 // Call the OfflinerDoneCallback to simulate the page being completed, wait
719 // for callbacks.
720 SendOfflinerDoneCallback(request, Offliner::RequestStatus::SAVED);
721 PumpLoop();
722 EXPECT_TRUE(immediate_schedule_callback_called());
723
724 // Verify not busy with 2nd request (since no connection).
725 EXPECT_FALSE(is_busy());
726
727 // Now connect network and verify processing starts.
728 SetNetworkConnected(true);
729 CallConnectionTypeObserver();
730 PumpLoop();
731 EXPECT_TRUE(is_busy());
732 }
733
698 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailed) { 734 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailed) {
699 // Add a request to the queue, wait for callbacks to finish. 735 // Add a request to the queue, wait for callbacks to finish.
700 offline_pages::SavePageRequest request( 736 offline_pages::SavePageRequest request(
701 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); 737 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested);
702 request.set_completed_attempt_count(kMaxCompletedTries - 1); 738 request.set_completed_attempt_count(kMaxCompletedTries - 1);
703 SetupForOfflinerDoneCallbackTest(&request); 739 SetupForOfflinerDoneCallbackTest(&request);
704 // Stop processing before completing the second request on the queue. 740 // Stop processing before completing the second request on the queue.
705 EnableOfflinerCallback(false); 741 EnableOfflinerCallback(false);
706 742
707 // Add second request to the queue to check handling when first fails. 743 // Add second request to the queue to check handling when first fails.
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
1361 kUrl2, kClientId2, kUserRequested, 1397 kUrl2, kClientId2, kUserRequested,
1362 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), 1398 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER),
1363 0); 1399 0);
1364 PumpLoop(); 1400 PumpLoop();
1365 1401
1366 // Verify immediate processing did start this time. 1402 // Verify immediate processing did start this time.
1367 EXPECT_TRUE(is_busy()); 1403 EXPECT_TRUE(is_busy());
1368 } 1404 }
1369 1405
1370 TEST_F(RequestCoordinatorTest, SavePageDoesntStartProcessingWhenDisconnected) { 1406 TEST_F(RequestCoordinatorTest, SavePageDoesntStartProcessingWhenDisconnected) {
1407 // If low end device, pretend it is not so that immediate start allowed.
1408 SetIsLowEndDeviceForTest(false);
1409
1371 SetNetworkConnected(false); 1410 SetNetworkConnected(false);
1411 EnableOfflinerCallback(false);
1372 EXPECT_NE( 1412 EXPECT_NE(
1373 coordinator()->SavePageLater( 1413 coordinator()->SavePageLater(
1374 kUrl1, kClientId1, kUserRequested, 1414 kUrl1, kClientId1, kUserRequested,
1375 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), 0); 1415 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER), 0);
1376 PumpLoop(); 1416 PumpLoop();
1377 EXPECT_FALSE(is_busy()); 1417 EXPECT_FALSE(is_busy());
1418
1419 // Now connect network and verify processing starts.
1420 SetNetworkConnected(true);
1421 CallConnectionTypeObserver();
1422 PumpLoop();
1423 EXPECT_TRUE(is_busy());
1378 } 1424 }
1379 1425
1380 TEST_F(RequestCoordinatorTest, 1426 TEST_F(RequestCoordinatorTest,
1381 SavePageDoesStartProcessingWhenPoorlyConnected) { 1427 SavePageDoesStartProcessingWhenPoorlyConnected) {
1382 // Set specific network type for 2G with poor effective connection. 1428 // Set specific network type for 2G with poor effective connection.
1383 SetNetworkConditionsForTest( 1429 SetNetworkConditionsForTest(
1384 net::NetworkChangeNotifier::ConnectionType::CONNECTION_2G); 1430 net::NetworkChangeNotifier::ConnectionType::CONNECTION_2G);
1385 SetEffectiveConnectionTypeForTest( 1431 SetEffectiveConnectionTypeForTest(
1386 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_SLOW_2G); 1432 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_SLOW_2G);
1387 1433
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1437 // Now whether processing triggered immediately depends on whether test 1483 // Now whether processing triggered immediately depends on whether test
1438 // is run on svelte device or not. 1484 // is run on svelte device or not.
1439 if (base::SysInfo::IsLowEndDevice()) { 1485 if (base::SysInfo::IsLowEndDevice()) {
1440 EXPECT_FALSE(is_busy()); 1486 EXPECT_FALSE(is_busy());
1441 } else { 1487 } else {
1442 EXPECT_TRUE(is_busy()); 1488 EXPECT_TRUE(is_busy());
1443 } 1489 }
1444 } 1490 }
1445 1491
1446 } // namespace offline_pages 1492 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/background/request_coordinator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698