| 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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 base::Bind( | 350 base::Bind( |
| 351 &RequestCoordinatorTest::EmptyCallbackFunction, | 351 &RequestCoordinatorTest::EmptyCallbackFunction, |
| 352 base::Unretained(this)); | 352 base::Unretained(this)); |
| 353 coordinator()->SetProcessingCallbackForTest(callback); | 353 coordinator()->SetProcessingCallbackForTest(callback); |
| 354 | 354 |
| 355 // Call the OfflinerDoneCallback to simulate the request failed, wait | 355 // Call the OfflinerDoneCallback to simulate the request failed, wait |
| 356 // for callbacks. | 356 // for callbacks. |
| 357 EnableOfflinerCallback(true); | 357 EnableOfflinerCallback(true); |
| 358 SendOfflinerDoneCallback(request, | 358 SendOfflinerDoneCallback(request, |
| 359 Offliner::RequestStatus::PRERENDERING_FAILED); | 359 Offliner::RequestStatus::PRERENDERING_FAILED); |
| 360 // There will be one request left in the queue after the prerender fails, stop |
| 361 // processing now so that it will remain in the queue for us to check. This |
| 362 // won't affect the offliner done callback other than preventing |
| 363 // TryNextRequest from doing anything. |
| 364 coordinator()->StopProcessing(); |
| 365 |
| 360 PumpLoop(); | 366 PumpLoop(); |
| 361 | 367 |
| 362 // Verify the request is not removed from the queue, and wait for callbacks. | 368 // Verify the request is not removed from the queue, and wait for callbacks. |
| 363 coordinator()->queue()->GetRequests( | 369 coordinator()->queue()->GetRequests( |
| 364 base::Bind(&RequestCoordinatorTest::GetRequestsDone, | 370 base::Bind(&RequestCoordinatorTest::GetRequestsDone, |
| 365 base::Unretained(this))); | 371 base::Unretained(this))); |
| 366 PumpLoop(); | 372 PumpLoop(); |
| 367 | 373 |
| 368 // Still one request in the queue. | 374 // Still one request in the queue. |
| 369 EXPECT_EQ(1UL, last_requests().size()); | 375 EXPECT_EQ(1UL, last_requests().size()); |
| 370 // TODO(dougarnett): Verify retry count gets incremented. | 376 // Verify retry count was incremented. |
| 377 const SavePageRequest& found_request = last_requests().front(); |
| 378 EXPECT_EQ(1L, found_request.attempt_count()); |
| 371 } | 379 } |
| 372 | 380 |
| 373 // This tests a StopProcessing call before we have actually started the | 381 // This tests a StopProcessing call before we have actually started the |
| 374 // prerenderer. | 382 // prerenderer. |
| 375 TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingImmediately) { | 383 TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingImmediately) { |
| 376 // Add a request to the queue, wait for callbacks to finish. | 384 // Add a request to the queue, wait for callbacks to finish. |
| 377 offline_pages::SavePageRequest request( | 385 offline_pages::SavePageRequest request( |
| 378 kRequestId, kUrl, kClientId, base::Time::Now()); | 386 kRequestId, kUrl, kClientId, base::Time::Now()); |
| 379 coordinator()->queue()->AddRequest( | 387 coordinator()->queue()->AddRequest( |
| 380 request, | 388 request, |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 // tasks too soon. | 492 // tasks too soon. |
| 485 WaitForCallback(); | 493 WaitForCallback(); |
| 486 PumpLoop(); | 494 PumpLoop(); |
| 487 | 495 |
| 488 EXPECT_TRUE(OfflinerWasCanceled()); | 496 EXPECT_TRUE(OfflinerWasCanceled()); |
| 489 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED, | 497 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED, |
| 490 last_offlining_status()); | 498 last_offlining_status()); |
| 491 } | 499 } |
| 492 | 500 |
| 493 } // namespace offline_pages | 501 } // namespace offline_pages |
| OLD | NEW |