| 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 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this))); | 536 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this))); |
| 537 PumpLoop(); | 537 PumpLoop(); |
| 538 | 538 |
| 539 // Request no longer in the queue (for single attempt policy). | 539 // Request no longer in the queue (for single attempt policy). |
| 540 EXPECT_EQ(1UL, last_requests().size()); | 540 EXPECT_EQ(1UL, last_requests().size()); |
| 541 // Verify foreground cancel not counted as an attempt after all. | 541 // Verify foreground cancel not counted as an attempt after all. |
| 542 const SavePageRequest& found_request = last_requests().front(); | 542 const SavePageRequest& found_request = last_requests().front(); |
| 543 EXPECT_EQ(0L, found_request.completed_attempt_count()); | 543 EXPECT_EQ(0L, found_request.completed_attempt_count()); |
| 544 } | 544 } |
| 545 | 545 |
| 546 TEST_F(RequestCoordinatorTest, OfflinerDonePrerenderingCancel) { |
| 547 // Add a request to the queue, wait for callbacks to finish. |
| 548 offline_pages::SavePageRequest request(kRequestId1, kUrl1, kClientId1, |
| 549 base::Time::Now(), kUserRequested); |
| 550 request.MarkAttemptStarted(base::Time::Now()); |
| 551 coordinator()->queue()->AddRequest( |
| 552 request, base::Bind(&RequestCoordinatorTest::AddRequestDone, |
| 553 base::Unretained(this))); |
| 554 PumpLoop(); |
| 555 |
| 556 // We need to give a callback to the request. |
| 557 base::Callback<void(bool)> callback = base::Bind( |
| 558 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this)); |
| 559 coordinator()->SetProcessingCallbackForTest(callback); |
| 560 |
| 561 // Set up device conditions for the test. |
| 562 DeviceConditions device_conditions(false, 75, |
| 563 net::NetworkChangeNotifier::CONNECTION_3G); |
| 564 SetDeviceConditionsForTest(device_conditions); |
| 565 |
| 566 // Call the OfflinerDoneCallback to simulate the request failed, wait |
| 567 // for callbacks. |
| 568 EnableOfflinerCallback(true); |
| 569 SendOfflinerDoneCallback(request, |
| 570 Offliner::RequestStatus::PRERENDERING_CANCELED); |
| 571 PumpLoop(); |
| 572 |
| 573 // Verify the request is not removed from the queue, and wait for callbacks. |
| 574 coordinator()->queue()->GetRequests(base::Bind( |
| 575 &RequestCoordinatorTest::GetRequestsDone, base::Unretained(this))); |
| 576 PumpLoop(); |
| 577 |
| 578 // Request still in the queue. |
| 579 EXPECT_EQ(1UL, last_requests().size()); |
| 580 // Verify prerendering cancel not counted as an attempt after all. |
| 581 const SavePageRequest& found_request = last_requests().front(); |
| 582 EXPECT_EQ(0L, found_request.completed_attempt_count()); |
| 583 } |
| 584 |
| 546 // This tests a StopProcessing call before we have actually started the | 585 // This tests a StopProcessing call before we have actually started the |
| 547 // prerenderer. | 586 // prerenderer. |
| 548 TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingImmediately) { | 587 TEST_F(RequestCoordinatorTest, StartProcessingThenStopProcessingImmediately) { |
| 549 // Add a request to the queue, wait for callbacks to finish. | 588 // Add a request to the queue, wait for callbacks to finish. |
| 550 offline_pages::SavePageRequest request( | 589 offline_pages::SavePageRequest request( |
| 551 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); | 590 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); |
| 552 coordinator()->queue()->AddRequest( | 591 coordinator()->queue()->AddRequest( |
| 553 request, | 592 request, |
| 554 base::Bind(&RequestCoordinatorTest::AddRequestDone, | 593 base::Bind(&RequestCoordinatorTest::AddRequestDone, |
| 555 base::Unretained(this))); | 594 base::Unretained(this))); |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 net::NetworkChangeNotifier::ConnectionType::CONNECTION_3G); | 923 net::NetworkChangeNotifier::ConnectionType::CONNECTION_3G); |
| 885 | 924 |
| 886 // Resume the request while connected. | 925 // Resume the request while connected. |
| 887 coordinator()->ResumeRequests(request_ids); | 926 coordinator()->ResumeRequests(request_ids); |
| 888 EXPECT_FALSE(is_busy()); | 927 EXPECT_FALSE(is_busy()); |
| 889 PumpLoop(); | 928 PumpLoop(); |
| 890 EXPECT_TRUE(is_busy()); | 929 EXPECT_TRUE(is_busy()); |
| 891 } | 930 } |
| 892 | 931 |
| 893 } // namespace offline_pages | 932 } // namespace offline_pages |
| OLD | NEW |