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

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

Issue 2279913002: Start processing immediately if there is network (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 3 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
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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 234
235 const RequestQueue::UpdateMultipleRequestResults& last_remove_results() 235 const RequestQueue::UpdateMultipleRequestResults& last_remove_results()
236 const { 236 const {
237 return last_remove_results_; 237 return last_remove_results_;
238 } 238 }
239 239
240 void EnableOfflinerCallback(bool enable) { 240 void EnableOfflinerCallback(bool enable) {
241 offliner_->enable_callback(enable); 241 offliner_->enable_callback(enable);
242 } 242 }
243 243
244 void SetNetworkConditionsForTest(
245 net::NetworkChangeNotifier::ConnectionType connection) {
246 coordinator()->SetNetworkConditionsForTest(connection);
247 }
248
244 void SetOfflinerTimeoutForTest(const base::TimeDelta& timeout) { 249 void SetOfflinerTimeoutForTest(const base::TimeDelta& timeout) {
245 coordinator_->SetOfflinerTimeoutForTest(timeout); 250 coordinator_->SetOfflinerTimeoutForTest(timeout);
246 } 251 }
247 252
248 void SetDeviceConditionsForTest(DeviceConditions device_conditions) { 253 void SetDeviceConditionsForTest(DeviceConditions device_conditions) {
249 coordinator_->SetDeviceConditionsForTest(device_conditions); 254 coordinator_->SetDeviceConditionsForTest(device_conditions);
250 } 255 }
251 256
252 void WaitForCallback() { 257 void WaitForCallback() {
253 waiter_.Wait(); 258 waiter_.Wait();
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 DeviceConditions device_conditions(false, 75, 345 DeviceConditions device_conditions(false, 75,
341 net::NetworkChangeNotifier::CONNECTION_3G); 346 net::NetworkChangeNotifier::CONNECTION_3G);
342 base::Callback<void(bool)> callback = 347 base::Callback<void(bool)> callback =
343 base::Bind( 348 base::Bind(
344 &RequestCoordinatorTest::EmptyCallbackFunction, 349 &RequestCoordinatorTest::EmptyCallbackFunction,
345 base::Unretained(this)); 350 base::Unretained(this));
346 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); 351 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback));
347 } 352 }
348 353
349 TEST_F(RequestCoordinatorTest, StartProcessingWithRequestInProgress) { 354 TEST_F(RequestCoordinatorTest, StartProcessingWithRequestInProgress) {
355 SetNetworkConditionsForTest(
356 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE);
350 // Put the request on the queue. 357 // Put the request on the queue.
351 EXPECT_TRUE(coordinator()->SavePageLater(kUrl1, kClientId1, kUserRequested)); 358 EXPECT_TRUE(coordinator()->SavePageLater(kUrl1, kClientId1, kUserRequested));
352 359
353 // Set up for the call to StartProcessing by building arguments. 360 // Set up for the call to StartProcessing by building arguments.
354 DeviceConditions device_conditions(false, 75, 361 DeviceConditions device_conditions(
355 net::NetworkChangeNotifier::CONNECTION_3G); 362 false, 75, net::NetworkChangeNotifier::CONNECTION_3G);
356 base::Callback<void(bool)> callback = 363 base::Callback<void(bool)> callback =
357 base::Bind(&RequestCoordinatorTest::EmptyCallbackFunction, 364 base::Bind(&RequestCoordinatorTest::EmptyCallbackFunction,
358 base::Unretained(this)); 365 base::Unretained(this));
359 366
360 // Ensure that the forthcoming request does not finish - we simulate it being 367 // Ensure that the forthcoming request does not finish - we simulate it being
361 // in progress by asking it to skip making the completion callback. 368 // in progress by asking it to skip making the completion callback.
362 EnableOfflinerCallback(false); 369 EnableOfflinerCallback(false);
363 370
364 // Sending the request to the offliner should make it busy. 371 // Sending the request to the offliner should make it busy.
365 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); 372 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback));
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 WaitForCallback(); 834 WaitForCallback();
828 PumpLoop(); 835 PumpLoop();
829 836
830 EXPECT_TRUE(observer().completed_called()); 837 EXPECT_TRUE(observer().completed_called());
831 EXPECT_EQ(RequestCoordinator::SavePageStatus::REMOVED, 838 EXPECT_EQ(RequestCoordinator::SavePageStatus::REMOVED,
832 observer().last_status()); 839 observer().last_status());
833 EXPECT_EQ(1UL, last_remove_results().size()); 840 EXPECT_EQ(1UL, last_remove_results().size());
834 EXPECT_EQ(kRequestId1, std::get<0>(last_remove_results().at(0))); 841 EXPECT_EQ(kRequestId1, std::get<0>(last_remove_results().at(0)));
835 } 842 }
836 843
844 TEST_F(RequestCoordinatorTest, SavePageStartsProcessingWhenConnected) {
845 SetNetworkConditionsForTest(
846 net::NetworkChangeNotifier::ConnectionType::CONNECTION_3G);
847 EXPECT_TRUE(coordinator()->SavePageLater(kUrl1, kClientId1, kUserRequested));
848 PumpLoop();
849 EXPECT_TRUE(is_busy());
850 }
851
852 TEST_F(RequestCoordinatorTest, SavePageDoesntStartProcessingWhenDisconnected) {
853 SetNetworkConditionsForTest(
854 net::NetworkChangeNotifier::ConnectionType::CONNECTION_NONE);
855 EXPECT_TRUE(coordinator()->SavePageLater(kUrl1, kClientId1, kUserRequested));
856 PumpLoop();
857 EXPECT_FALSE(is_busy());
858 }
859
837 } // namespace offline_pages 860 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698