| OLD | NEW |
| 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 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 base::Unretained(this))); | 356 base::Unretained(this))); |
| 357 PumpLoop(); | 357 PumpLoop(); |
| 358 | 358 |
| 359 // We need to give a callback to the request. | 359 // We need to give a callback to the request. |
| 360 base::Callback<void(bool)> callback = | 360 base::Callback<void(bool)> callback = |
| 361 base::Bind( | 361 base::Bind( |
| 362 &RequestCoordinatorTest::EmptyCallbackFunction, | 362 &RequestCoordinatorTest::EmptyCallbackFunction, |
| 363 base::Unretained(this)); | 363 base::Unretained(this)); |
| 364 coordinator()->SetProcessingCallbackForTest(callback); | 364 coordinator()->SetProcessingCallbackForTest(callback); |
| 365 | 365 |
| 366 // Set up device conditions for the test. |
| 367 DeviceConditions device_conditions( |
| 368 false, 75, net::NetworkChangeNotifier::CONNECTION_3G); |
| 369 SetDeviceConditionsForTest(device_conditions); |
| 370 |
| 366 // Call the OfflinerDoneCallback to simulate the request failed, wait | 371 // Call the OfflinerDoneCallback to simulate the request failed, wait |
| 367 // for callbacks. | 372 // for callbacks. |
| 368 EnableOfflinerCallback(true); | 373 EnableOfflinerCallback(true); |
| 369 SendOfflinerDoneCallback(request, | 374 SendOfflinerDoneCallback(request, |
| 370 Offliner::RequestStatus::PRERENDERING_FAILED); | 375 Offliner::RequestStatus::PRERENDERING_FAILED); |
| 376 // There will be one request left in the queue after the prerender fails, stop |
| 377 // processing now so that it will remain in the queue for us to check. This |
| 378 // won't affect the offliner done callback other than preventing |
| 379 // TryNextRequest from doing anything. |
| 380 coordinator()->StopProcessing(); |
| 381 |
| 371 PumpLoop(); | 382 PumpLoop(); |
| 372 | 383 |
| 373 // Verify the request is not removed from the queue, and wait for callbacks. | 384 // Verify the request is not removed from the queue, and wait for callbacks. |
| 374 coordinator()->queue()->GetRequests( | 385 coordinator()->queue()->GetRequests( |
| 375 base::Bind(&RequestCoordinatorTest::GetRequestsDone, | 386 base::Bind(&RequestCoordinatorTest::GetRequestsDone, |
| 376 base::Unretained(this))); | 387 base::Unretained(this))); |
| 377 PumpLoop(); | 388 PumpLoop(); |
| 378 | 389 |
| 379 // Still one request in the queue. | 390 // Still one request in the queue. |
| 380 EXPECT_EQ(1UL, last_requests().size()); | 391 EXPECT_EQ(1UL, last_requests().size()); |
| 381 // TODO(dougarnett): Verify retry count gets incremented. | 392 // Verify retry count was incremented. |
| 393 const SavePageRequest& found_request = last_requests().front(); |
| 394 EXPECT_EQ(1L, found_request.attempt_count()); |
| 382 } | 395 } |
| 383 | 396 |
| 384 // This tests a StopProcessing call before we have actually started the | 397 // This tests a StopProcessing call before we have actually started the |
| 385 // prerenderer. | 398 // prerenderer. |
| 386 TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingImmediately) { | 399 TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingImmediately) { |
| 387 // Add a request to the queue, wait for callbacks to finish. | 400 // Add a request to the queue, wait for callbacks to finish. |
| 388 offline_pages::SavePageRequest request( | 401 offline_pages::SavePageRequest request( |
| 389 kRequestId, kUrl, kClientId, base::Time::Now(), kUserRequested); | 402 kRequestId, kUrl, kClientId, base::Time::Now(), kUserRequested); |
| 390 coordinator()->queue()->AddRequest( | 403 coordinator()->queue()->AddRequest( |
| 391 request, | 404 request, |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 // tasks too soon. | 508 // tasks too soon. |
| 496 WaitForCallback(); | 509 WaitForCallback(); |
| 497 PumpLoop(); | 510 PumpLoop(); |
| 498 | 511 |
| 499 EXPECT_TRUE(OfflinerWasCanceled()); | 512 EXPECT_TRUE(OfflinerWasCanceled()); |
| 500 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED, | 513 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED, |
| 501 last_offlining_status()); | 514 last_offlining_status()); |
| 502 } | 515 } |
| 503 | 516 |
| 504 } // namespace offline_pages | 517 } // namespace offline_pages |
| OLD | NEW |