Chromium Code Reviews| 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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 EXPECT_EQ(coordinator() | 308 EXPECT_EQ(coordinator() |
| 309 ->GetTriggerConditionsForUserRequest() | 309 ->GetTriggerConditionsForUserRequest() |
| 310 .minimum_battery_percentage, | 310 .minimum_battery_percentage, |
| 311 scheduler_stub->conditions()->minimum_battery_percentage); | 311 scheduler_stub->conditions()->minimum_battery_percentage); |
| 312 } | 312 } |
| 313 | 313 |
| 314 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestSucceeded) { | 314 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestSucceeded) { |
| 315 // Add a request to the queue, wait for callbacks to finish. | 315 // Add a request to the queue, wait for callbacks to finish. |
| 316 offline_pages::SavePageRequest request( | 316 offline_pages::SavePageRequest request( |
| 317 kRequestId, kUrl, kClientId, base::Time::Now(), kUserRequested); | 317 kRequestId, kUrl, kClientId, base::Time::Now(), kUserRequested); |
| 318 request.MarkAttemptStarted(base::Time::Now()); | |
| 318 coordinator()->queue()->AddRequest( | 319 coordinator()->queue()->AddRequest( |
| 319 request, | 320 request, |
| 320 base::Bind(&RequestCoordinatorTest::AddRequestDone, | 321 base::Bind(&RequestCoordinatorTest::AddRequestDone, |
| 321 base::Unretained(this))); | 322 base::Unretained(this))); |
| 322 PumpLoop(); | 323 PumpLoop(); |
| 323 | 324 |
| 324 // We need to give a callback to the request. | 325 // We need to give a callback to the request. |
| 325 base::Callback<void(bool)> callback = | 326 base::Callback<void(bool)> callback = |
| 326 base::Bind( | 327 base::Bind( |
| 327 &RequestCoordinatorTest::EmptyCallbackFunction, | 328 &RequestCoordinatorTest::EmptyCallbackFunction, |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 348 // We should not find any requests in the queue anymore. | 349 // We should not find any requests in the queue anymore. |
| 349 // RequestPicker should *not* have tried to start an additional job, | 350 // RequestPicker should *not* have tried to start an additional job, |
| 350 // because the request queue is empty now. | 351 // because the request queue is empty now. |
| 351 EXPECT_EQ(0UL, last_requests().size()); | 352 EXPECT_EQ(0UL, last_requests().size()); |
| 352 } | 353 } |
| 353 | 354 |
| 354 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailed) { | 355 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailed) { |
| 355 // Add a request to the queue, wait for callbacks to finish. | 356 // Add a request to the queue, wait for callbacks to finish. |
| 356 offline_pages::SavePageRequest request( | 357 offline_pages::SavePageRequest request( |
| 357 kRequestId, kUrl, kClientId, base::Time::Now(), kUserRequested); | 358 kRequestId, kUrl, kClientId, base::Time::Now(), kUserRequested); |
| 359 request.MarkAttemptStarted(base::Time::Now()); | |
| 358 coordinator()->queue()->AddRequest( | 360 coordinator()->queue()->AddRequest( |
| 359 request, | 361 request, |
| 360 base::Bind(&RequestCoordinatorTest::AddRequestDone, | 362 base::Bind(&RequestCoordinatorTest::AddRequestDone, |
| 361 base::Unretained(this))); | 363 base::Unretained(this))); |
| 362 PumpLoop(); | 364 PumpLoop(); |
| 363 | 365 |
| 364 // Add second request to the queue to check handling when first fails. | 366 // Add second request to the queue to check handling when first fails. |
| 365 offline_pages::SavePageRequest request2( | 367 offline_pages::SavePageRequest request2( |
| 366 kRequestId2, kUrl2, kClientId2, base::Time::Now(), kUserRequested); | 368 kRequestId2, kUrl2, kClientId2, base::Time::Now(), kUserRequested); |
| 367 coordinator()->queue()->AddRequest( | 369 coordinator()->queue()->AddRequest( |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 392 // TODO(dougarnett): Consider injecting mock RequestPicker for this test | 394 // TODO(dougarnett): Consider injecting mock RequestPicker for this test |
| 393 // and verifying that there is no attempt to pick another request following | 395 // and verifying that there is no attempt to pick another request following |
| 394 // this failure code. | 396 // this failure code. |
| 395 | 397 |
| 396 // Verify neither request is removed from the queue; wait for callbacks. | 398 // Verify neither request is removed from the queue; wait for callbacks. |
| 397 coordinator()->queue()->GetRequests( | 399 coordinator()->queue()->GetRequests( |
| 398 base::Bind(&RequestCoordinatorTest::GetRequestsDone, | 400 base::Bind(&RequestCoordinatorTest::GetRequestsDone, |
| 399 base::Unretained(this))); | 401 base::Unretained(this))); |
| 400 PumpLoop(); | 402 PumpLoop(); |
| 401 | 403 |
| 402 // Still two requests in the queue. | 404 // Now just one request in the queue since failed request removed |
|
Pete Williamson
2016/08/03 20:44:56
Huh? I didnt' see code to remove the failed reque
dougarnett
2016/08/03 21:40:01
Greater Than or Equal check in Coordinater line 23
| |
| 403 EXPECT_EQ(2UL, last_requests().size()); | 405 // (for single attempt policy). |
| 404 // Verify retry count was incremented for first request. | 406 EXPECT_EQ(1UL, last_requests().size()); |
| 407 } | |
| 408 | |
| 409 TEST_F(RequestCoordinatorTest, OfflinerDoneForegroundCancel) { | |
| 410 // Add a request to the queue, wait for callbacks to finish. | |
| 411 offline_pages::SavePageRequest request( | |
| 412 kRequestId, kUrl, kClientId, base::Time::Now(), kUserRequested); | |
| 413 request.MarkAttemptStarted(base::Time::Now()); | |
| 414 coordinator()->queue()->AddRequest( | |
| 415 request, | |
| 416 base::Bind(&RequestCoordinatorTest::AddRequestDone, | |
| 417 base::Unretained(this))); | |
| 418 PumpLoop(); | |
| 419 | |
| 420 // We need to give a callback to the request. | |
| 421 base::Callback<void(bool)> callback = | |
| 422 base::Bind( | |
| 423 &RequestCoordinatorTest::EmptyCallbackFunction, | |
| 424 base::Unretained(this)); | |
| 425 coordinator()->SetProcessingCallbackForTest(callback); | |
| 426 | |
| 427 // Set up device conditions for the test. | |
| 428 DeviceConditions device_conditions( | |
| 429 false, 75, net::NetworkChangeNotifier::CONNECTION_3G); | |
| 430 SetDeviceConditionsForTest(device_conditions); | |
| 431 | |
| 432 // Call the OfflinerDoneCallback to simulate the request failed, wait | |
| 433 // for callbacks. | |
| 434 EnableOfflinerCallback(true); | |
| 435 SendOfflinerDoneCallback(request, | |
| 436 Offliner::RequestStatus::FOREGROUND_CANCELED); | |
| 437 PumpLoop(); | |
| 438 | |
| 439 // Verify the request is not removed from the queue, and wait for callbacks. | |
| 440 coordinator()->queue()->GetRequests( | |
| 441 base::Bind(&RequestCoordinatorTest::GetRequestsDone, | |
| 442 base::Unretained(this))); | |
| 443 PumpLoop(); | |
| 444 | |
| 445 // Request no longer in the queue (for single attempt policy). | |
| 446 EXPECT_EQ(1UL, last_requests().size()); | |
| 447 // Verify foreground cancel not counted as an attempt after all. | |
| 405 const SavePageRequest& found_request = last_requests().front(); | 448 const SavePageRequest& found_request = last_requests().front(); |
| 406 EXPECT_EQ(1L, found_request.attempt_count()); | 449 EXPECT_EQ(0L, found_request.attempt_count()); |
| 407 } | 450 } |
| 408 | 451 |
| 409 // This tests a StopProcessing call before we have actually started the | 452 // This tests a StopProcessing call before we have actually started the |
| 410 // prerenderer. | 453 // prerenderer. |
| 411 TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingImmediately) { | 454 TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingImmediately) { |
| 412 // Add a request to the queue, wait for callbacks to finish. | 455 // Add a request to the queue, wait for callbacks to finish. |
| 413 offline_pages::SavePageRequest request( | 456 offline_pages::SavePageRequest request( |
| 414 kRequestId, kUrl, kClientId, base::Time::Now(), kUserRequested); | 457 kRequestId, kUrl, kClientId, base::Time::Now(), kUserRequested); |
| 415 coordinator()->queue()->AddRequest( | 458 coordinator()->queue()->AddRequest( |
| 416 request, | 459 request, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 474 | 517 |
| 475 // OfflinerDoneCallback will not end up getting called with status SAVED, | 518 // OfflinerDoneCallback will not end up getting called with status SAVED, |
| 476 // since we cancelled the event before the LoadAndSave completed. | 519 // since we cancelled the event before the LoadAndSave completed. |
| 477 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED, | 520 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED, |
| 478 last_offlining_status()); | 521 last_offlining_status()); |
| 479 | 522 |
| 480 // Since offliner was started, it will have seen cancel call. | 523 // Since offliner was started, it will have seen cancel call. |
| 481 EXPECT_TRUE(OfflinerWasCanceled()); | 524 EXPECT_TRUE(OfflinerWasCanceled()); |
| 482 } | 525 } |
| 483 | 526 |
| 484 TEST_F(RequestCoordinatorTest, PrerendererTimeout) { | 527 TEST_F(RequestCoordinatorTest, WatchdogTimeout) { |
| 485 // Build a request to use with the pre-renderer, and put it on the queue. | 528 // Build a request to use with the pre-renderer, and put it on the queue. |
| 486 offline_pages::SavePageRequest request( | 529 offline_pages::SavePageRequest request( |
| 487 kRequestId, kUrl, kClientId, base::Time::Now(), kUserRequested); | 530 kRequestId, kUrl, kClientId, base::Time::Now(), kUserRequested); |
| 488 coordinator()->queue()->AddRequest( | 531 coordinator()->queue()->AddRequest( |
| 489 request, | 532 request, |
| 490 base::Bind(&RequestCoordinatorTest::AddRequestDone, | 533 base::Bind(&RequestCoordinatorTest::AddRequestDone, |
| 491 base::Unretained(this))); | 534 base::Unretained(this))); |
| 492 PumpLoop(); | 535 PumpLoop(); |
| 493 | 536 |
| 494 // Set up for the call to StartProcessing. | 537 // Set up for the call to StartProcessing. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 566 coordinator()->queue()->GetRequests( | 609 coordinator()->queue()->GetRequests( |
| 567 base::Bind(&RequestCoordinatorTest::GetRequestsDone, | 610 base::Bind(&RequestCoordinatorTest::GetRequestsDone, |
| 568 base::Unretained(this))); | 611 base::Unretained(this))); |
| 569 PumpLoop(); | 612 PumpLoop(); |
| 570 | 613 |
| 571 // We should find one request in the queue. | 614 // We should find one request in the queue. |
| 572 EXPECT_EQ(1UL, last_requests().size()); | 615 EXPECT_EQ(1UL, last_requests().size()); |
| 573 } | 616 } |
| 574 | 617 |
| 575 } // namespace offline_pages | 618 } // namespace offline_pages |
| OLD | NEW |