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 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 599 | 599 |
| 600 // OfflinerDoneCallback will not end up getting called with status SAVED, | 600 // OfflinerDoneCallback will not end up getting called with status SAVED, |
| 601 // since we cancelled the event before the LoadAndSave completed. | 601 // since we cancelled the event before the LoadAndSave completed. |
| 602 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED, | 602 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED, |
| 603 last_offlining_status()); | 603 last_offlining_status()); |
| 604 | 604 |
| 605 // Since offliner was started, it will have seen cancel call. | 605 // Since offliner was started, it will have seen cancel call. |
| 606 EXPECT_TRUE(OfflinerWasCanceled()); | 606 EXPECT_TRUE(OfflinerWasCanceled()); |
| 607 } | 607 } |
| 608 | 608 |
| 609 // This tests that canceling a request will result in TryNextRequest() getting | |
| 610 // called. | |
| 611 TEST_F(RequestCoordinatorTest, RemoveInflightRequest) { | |
| 612 // Add a request to the queue, wait for callbacks to finish. | |
| 613 offline_pages::SavePageRequest request1(kRequestId1, kUrl1, kClientId1, | |
| 614 base::Time::Now(), kUserRequested); | |
| 615 coordinator()->queue()->AddRequest( | |
| 616 request1, base::Bind(&RequestCoordinatorTest::AddRequestDone, | |
| 617 base::Unretained(this))); | |
| 618 PumpLoop(); | |
| 619 | |
| 620 // Ensure the start processing request stops before the completion callback. | |
| 621 EnableOfflinerCallback(false); | |
| 622 | |
| 623 DeviceConditions device_conditions(false, 75, | |
| 624 net::NetworkChangeNotifier::CONNECTION_3G); | |
| 625 base::Callback<void(bool)> callback = base::Bind( | |
| 626 &RequestCoordinatorTest::EmptyCallbackFunction, base::Unretained(this)); | |
| 627 EXPECT_TRUE(coordinator()->StartProcessing(device_conditions, callback)); | |
| 628 | |
| 629 // Let all the async parts of the start processing pipeline run to completion. | |
| 630 PumpLoop(); | |
|
dougarnett
2016/08/23 21:50:24
More PumpLoop() to get SendToOffliner to run (eg,
Pete Williamson
2016/08/23 21:57:00
A single PumpLoop() will run until the task queue
| |
| 631 | |
| 632 // Remove the request while it is processing. | |
| 633 std::vector<int64_t> request_ids{kRequestId1}; | |
| 634 coordinator()->RemoveRequests(request_ids); | |
| 635 | |
| 636 // Let the async callbacks in the cancel run. | |
| 637 PumpLoop(); | |
| 638 | |
| 639 // Since offliner was started, it will have seen cancel call. | |
| 640 EXPECT_TRUE(OfflinerWasCanceled()); | |
| 641 } | |
| 642 | |
| 609 TEST_F(RequestCoordinatorTest, WatchdogTimeout) { | 643 TEST_F(RequestCoordinatorTest, WatchdogTimeout) { |
| 610 // Build a request to use with the pre-renderer, and put it on the queue. | 644 // Build a request to use with the pre-renderer, and put it on the queue. |
| 611 offline_pages::SavePageRequest request( | 645 offline_pages::SavePageRequest request( |
| 612 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); | 646 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); |
| 613 coordinator()->queue()->AddRequest( | 647 coordinator()->queue()->AddRequest( |
| 614 request, | 648 request, |
| 615 base::Bind(&RequestCoordinatorTest::AddRequestDone, | 649 base::Bind(&RequestCoordinatorTest::AddRequestDone, |
| 616 base::Unretained(this))); | 650 base::Unretained(this))); |
| 617 PumpLoop(); | 651 PumpLoop(); |
| 618 | 652 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 769 request_ids.push_back(kRequestId1); | 803 request_ids.push_back(kRequestId1); |
| 770 coordinator()->RemoveRequests(request_ids); | 804 coordinator()->RemoveRequests(request_ids); |
| 771 PumpLoop(); | 805 PumpLoop(); |
| 772 | 806 |
| 773 EXPECT_TRUE(observer().completed_called()); | 807 EXPECT_TRUE(observer().completed_called()); |
| 774 EXPECT_EQ(RequestCoordinator::SavePageStatus::REMOVED, | 808 EXPECT_EQ(RequestCoordinator::SavePageStatus::REMOVED, |
| 775 observer().last_status()); | 809 observer().last_status()); |
| 776 } | 810 } |
| 777 | 811 |
| 778 } // namespace offline_pages | 812 } // namespace offline_pages |
| OLD | NEW |