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

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

Issue 2395903002: API changes to support suspending requests (Closed)
Patch Set: Keep the JS with a boolean instead of forcing a double. Created 4 years, 2 months 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 <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 net::NetworkChangeNotifier::CONNECTION_3G); 394 net::NetworkChangeNotifier::CONNECTION_3G);
395 base::Callback<void(bool)> callback = 395 base::Callback<void(bool)> callback =
396 base::Bind( 396 base::Bind(
397 &RequestCoordinatorTest::EmptyCallbackFunction, 397 &RequestCoordinatorTest::EmptyCallbackFunction,
398 base::Unretained(this)); 398 base::Unretained(this));
399 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); 399 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback));
400 } 400 }
401 401
402 TEST_F(RequestCoordinatorTest, StartProcessingWithRequestInProgress) { 402 TEST_F(RequestCoordinatorTest, StartProcessingWithRequestInProgress) {
403 // Put the request on the queue. 403 // Put the request on the queue.
404 EXPECT_TRUE(coordinator()->SavePageLater(kUrl1, kClientId1, kUserRequested)); 404 EXPECT_TRUE(
405 coordinator()->SavePageLater(
406 kUrl1, kClientId1, kUserRequested,
407 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER) != 0);
405 408
406 // Set up for the call to StartProcessing by building arguments. 409 // Set up for the call to StartProcessing by building arguments.
407 DeviceConditions device_conditions( 410 DeviceConditions device_conditions(
408 false, 75, net::NetworkChangeNotifier::CONNECTION_3G); 411 false, 75, net::NetworkChangeNotifier::CONNECTION_3G);
409 base::Callback<void(bool)> callback = 412 base::Callback<void(bool)> callback =
410 base::Bind(&RequestCoordinatorTest::EmptyCallbackFunction, 413 base::Bind(&RequestCoordinatorTest::EmptyCallbackFunction,
411 base::Unretained(this)); 414 base::Unretained(this));
412 415
413 // Ensure that the forthcoming request does not finish - we simulate it being 416 // Ensure that the forthcoming request does not finish - we simulate it being
414 // in progress by asking it to skip making the completion callback. 417 // in progress by asking it to skip making the completion callback.
415 EnableOfflinerCallback(false); 418 EnableOfflinerCallback(false);
416 419
417 // Sending the request to the offliner should make it busy. 420 // Sending the request to the offliner should make it busy.
418 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); 421 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback));
419 PumpLoop(); 422 PumpLoop();
420 EXPECT_TRUE(is_busy()); 423 EXPECT_TRUE(is_busy());
421 424
422 // Now trying to start processing on another request should return false. 425 // Now trying to start processing on another request should return false.
423 EXPECT_FALSE(coordinator()->StartProcessing(device_conditions, callback)); 426 EXPECT_FALSE(coordinator()->StartProcessing(device_conditions, callback));
424 } 427 }
425 428
426 TEST_F(RequestCoordinatorTest, SavePageLater) { 429 TEST_F(RequestCoordinatorTest, SavePageLater) {
427 EXPECT_TRUE(coordinator()->SavePageLater(kUrl1, kClientId1, kUserRequested)); 430 EXPECT_TRUE(
431 coordinator()->SavePageLater(
432 kUrl1, kClientId1, kUserRequested,
433 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER) != 0);
428 434
429 // Expect that a request got placed on the queue. 435 // Expect that a request got placed on the queue.
430 coordinator()->queue()->GetRequests( 436 coordinator()->queue()->GetRequests(
431 base::Bind(&RequestCoordinatorTest::GetRequestsDone, 437 base::Bind(&RequestCoordinatorTest::GetRequestsDone,
432 base::Unretained(this))); 438 base::Unretained(this)));
433 439
434 // Wait for callbacks to finish, both request queue and offliner. 440 // Wait for callbacks to finish, both request queue and offliner.
435 PumpLoop(); 441 PumpLoop();
436 442
437 // Check the request queue is as expected. 443 // Check the request queue is as expected.
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::REMOVED, 1029 EXPECT_EQ(RequestCoordinator::BackgroundSavePageResult::REMOVED,
1024 observer().last_status()); 1030 observer().last_status());
1025 EXPECT_EQ(1UL, last_remove_results().size()); 1031 EXPECT_EQ(1UL, last_remove_results().size());
1026 EXPECT_EQ(kRequestId1, std::get<0>(last_remove_results().at(0))); 1032 EXPECT_EQ(kRequestId1, std::get<0>(last_remove_results().at(0)));
1027 } 1033 }
1028 1034
1029 TEST_F(RequestCoordinatorTest, 1035 TEST_F(RequestCoordinatorTest,
1030 SavePageStartsProcessingWhenConnectedAndNotLowEndDevice) { 1036 SavePageStartsProcessingWhenConnectedAndNotLowEndDevice) {
1031 SetEffectiveConnectionTypeForTest( 1037 SetEffectiveConnectionTypeForTest(
1032 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_3G); 1038 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_3G);
1033 EXPECT_TRUE(coordinator()->SavePageLater(kUrl1, kClientId1, kUserRequested)); 1039 EXPECT_TRUE(
1040 coordinator()->SavePageLater(
1041 kUrl1, kClientId1, kUserRequested,
1042 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER) != 0);
1034 PumpLoop(); 1043 PumpLoop();
1035 1044
1036 // Now whether processing triggered immediately depends on whether test 1045 // Now whether processing triggered immediately depends on whether test
1037 // is run on svelte device or not. 1046 // is run on svelte device or not.
1038 if (base::SysInfo::IsLowEndDevice()) { 1047 if (base::SysInfo::IsLowEndDevice()) {
1039 EXPECT_FALSE(is_busy()); 1048 EXPECT_FALSE(is_busy());
1040 } else { 1049 } else {
1041 EXPECT_TRUE(is_busy()); 1050 EXPECT_TRUE(is_busy());
1042 } 1051 }
1043 } 1052 }
1044 1053
1045 TEST_F(RequestCoordinatorTest, SavePageDoesntStartProcessingWhenDisconnected) { 1054 TEST_F(RequestCoordinatorTest, SavePageDoesntStartProcessingWhenDisconnected) {
1046 EXPECT_TRUE(coordinator()->SavePageLater(kUrl1, kClientId1, kUserRequested)); 1055 EXPECT_TRUE(
1056 coordinator()->SavePageLater(
1057 kUrl1, kClientId1, kUserRequested,
1058 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER) != 0);
1047 PumpLoop(); 1059 PumpLoop();
1048 EXPECT_FALSE(is_busy()); 1060 EXPECT_FALSE(is_busy());
1049 } 1061 }
1050 1062
1051 TEST_F(RequestCoordinatorTest, 1063 TEST_F(RequestCoordinatorTest,
1052 SavePageDoesntStartProcessingWhenPoorlyConnected) { 1064 SavePageDoesntStartProcessingWhenPoorlyConnected) {
1053 SetEffectiveConnectionTypeForTest( 1065 SetEffectiveConnectionTypeForTest(
1054 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_SLOW_2G); 1066 net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_SLOW_2G);
1055 EXPECT_TRUE(coordinator()->SavePageLater(kUrl1, kClientId1, kUserRequested)); 1067 EXPECT_TRUE(
1068 coordinator()->SavePageLater(
1069 kUrl1, kClientId1, kUserRequested,
1070 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER) != 0);
1056 PumpLoop(); 1071 PumpLoop();
1057 EXPECT_FALSE(is_busy()); 1072 EXPECT_FALSE(is_busy());
1058 } 1073 }
1059 1074
1060 TEST_F(RequestCoordinatorTest, 1075 TEST_F(RequestCoordinatorTest,
1061 ResumeStartsProcessingWhenConnectedAndNotLowEndDevice) { 1076 ResumeStartsProcessingWhenConnectedAndNotLowEndDevice) {
1062 1077
1063 // Add a request to the queue. 1078 // Add a request to the queue.
1064 offline_pages::SavePageRequest request1(kRequestId1, kUrl1, kClientId1, 1079 offline_pages::SavePageRequest request1(kRequestId1, kUrl1, kClientId1,
1065 base::Time::Now(), kUserRequested); 1080 base::Time::Now(), kUserRequested);
(...skipping 30 matching lines...) Expand all
1096 // Now whether processing triggered immediately depends on whether test 1111 // Now whether processing triggered immediately depends on whether test
1097 // is run on svelte device or not. 1112 // is run on svelte device or not.
1098 if (base::SysInfo::IsLowEndDevice()) { 1113 if (base::SysInfo::IsLowEndDevice()) {
1099 EXPECT_FALSE(is_busy()); 1114 EXPECT_FALSE(is_busy());
1100 } else { 1115 } else {
1101 EXPECT_TRUE(is_busy()); 1116 EXPECT_TRUE(is_busy());
1102 } 1117 }
1103 } 1118 }
1104 1119
1105 } // namespace offline_pages 1120 } // 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