| 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 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 | 452 |
| 453 // Verify the request is not removed from the queue, and wait for callbacks. | 453 // Verify the request is not removed from the queue, and wait for callbacks. |
| 454 coordinator()->queue()->GetRequests(base::Bind( | 454 coordinator()->queue()->GetRequests(base::Bind( |
| 455 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this))); | 455 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this))); |
| 456 PumpLoop(); | 456 PumpLoop(); |
| 457 | 457 |
| 458 // Request no longer in the queue (for single attempt policy). | 458 // Request no longer in the queue (for single attempt policy). |
| 459 EXPECT_EQ(1UL, last_requests().size()); | 459 EXPECT_EQ(1UL, last_requests().size()); |
| 460 // Verify foreground cancel not counted as an attempt after all. | 460 // Verify foreground cancel not counted as an attempt after all. |
| 461 const SavePageRequest& found_request = last_requests().front(); | 461 const SavePageRequest& found_request = last_requests().front(); |
| 462 EXPECT_EQ(0L, found_request.attempt_count()); | 462 EXPECT_EQ(0L, found_request.completed_attempt_count()); |
| 463 } | 463 } |
| 464 | 464 |
| 465 // This tests a StopProcessing call before we have actually started the | 465 // This tests a StopProcessing call before we have actually started the |
| 466 // prerenderer. | 466 // prerenderer. |
| 467 TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingImmediately) { | 467 TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingImmediately) { |
| 468 // Add a request to the queue, wait for callbacks to finish. | 468 // Add a request to the queue, wait for callbacks to finish. |
| 469 offline_pages::SavePageRequest request( | 469 offline_pages::SavePageRequest request( |
| 470 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); | 470 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); |
| 471 coordinator()->queue()->AddRequest( | 471 coordinator()->queue()->AddRequest( |
| 472 request, | 472 request, |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED, | 581 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED, |
| 582 last_offlining_status()); | 582 last_offlining_status()); |
| 583 } | 583 } |
| 584 | 584 |
| 585 TEST_F(RequestCoordinatorTest, TimeBudgetExceeded) { | 585 TEST_F(RequestCoordinatorTest, TimeBudgetExceeded) { |
| 586 // Build two requests to use with the pre-renderer, and put it on the queue. | 586 // Build two requests to use with the pre-renderer, and put it on the queue. |
| 587 offline_pages::SavePageRequest request1( | 587 offline_pages::SavePageRequest request1( |
| 588 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); | 588 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); |
| 589 offline_pages::SavePageRequest request2( | 589 offline_pages::SavePageRequest request2( |
| 590 kRequestId1 + 1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); | 590 kRequestId1 + 1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); |
| 591 request2.set_attempt_count(kAttemptCount); | 591 request2.set_completed_attempt_count(kAttemptCount); |
| 592 coordinator()->queue()->AddRequest( | 592 coordinator()->queue()->AddRequest( |
| 593 request1, | 593 request1, |
| 594 base::Bind(&RequestCoordinatorTest::AddRequestDone, | 594 base::Bind(&RequestCoordinatorTest::AddRequestDone, |
| 595 base::Unretained(this))); | 595 base::Unretained(this))); |
| 596 coordinator()->queue()->AddRequest( | 596 coordinator()->queue()->AddRequest( |
| 597 request1, // TODO(petewil): This is a bug, should be request2. | 597 request1, // TODO(petewil): This is a bug, should be request2. |
| 598 base::Bind(&RequestCoordinatorTest::AddRequestDone, | 598 base::Bind(&RequestCoordinatorTest::AddRequestDone, |
| 599 base::Unretained(this))); | 599 base::Unretained(this))); |
| 600 PumpLoop(); | 600 PumpLoop(); |
| 601 | 601 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 WaitForCallback(); | 653 WaitForCallback(); |
| 654 PumpLoop(); | 654 PumpLoop(); |
| 655 | 655 |
| 656 // Check that the statuses found in the callback match what we expect. | 656 // Check that the statuses found in the callback match what we expect. |
| 657 EXPECT_EQ(2UL, last_client_ids().size()); | 657 EXPECT_EQ(2UL, last_client_ids().size()); |
| 658 EXPECT_EQ(kId1, last_client_ids().at(0).id); | 658 EXPECT_EQ(kId1, last_client_ids().at(0).id); |
| 659 EXPECT_EQ(kId2, last_client_ids().at(1).id); | 659 EXPECT_EQ(kId2, last_client_ids().at(1).id); |
| 660 } | 660 } |
| 661 | 661 |
| 662 } // namespace offline_pages | 662 } // namespace offline_pages |
| OLD | NEW |