Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: components/offline_pages/background/request_coordinator_unittest.cc

Issue 2266323002: Cancel prerendering when a request is paused or removed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR feedback per DougArnett Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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();
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 // Simulate the offliner responding to the cancel request
640 SendOfflinerDoneCallback(request1,
dougarnett 2016/08/23 20:59:45 as discussed, we may seeing that SendToOffliner wa
641 Offliner::RequestStatus::PRERENDERING_CANCELED);
642 PumpLoop();
643
644 // OfflinerDoneCallback will not end up getting called with status SAVED,
645 // since we cancelled the event before the LoadAndSave completed.
646 EXPECT_EQ(Offliner::RequestStatus::PRERENDERING_CANCELED,
647 last_offlining_status());
648
649 // Since offliner was started, it will have seen cancel call.
650 EXPECT_TRUE(OfflinerWasCanceled());
651 }
652
609 TEST_F(RequestCoordinatorTest, WatchdogTimeout) { 653 TEST_F(RequestCoordinatorTest, WatchdogTimeout) {
610 // Build a request to use with the pre-renderer, and put it on the queue. 654 // Build a request to use with the pre-renderer, and put it on the queue.
611 offline_pages::SavePageRequest request( 655 offline_pages::SavePageRequest request(
612 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested); 656 kRequestId1, kUrl1, kClientId1, base::Time::Now(), kUserRequested);
613 coordinator()->queue()->AddRequest( 657 coordinator()->queue()->AddRequest(
614 request, 658 request,
615 base::Bind(&RequestCoordinatorTest::AddRequestDone, 659 base::Bind(&RequestCoordinatorTest::AddRequestDone,
616 base::Unretained(this))); 660 base::Unretained(this)));
617 PumpLoop(); 661 PumpLoop();
618 662
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 request_ids.push_back(kRequestId1); 813 request_ids.push_back(kRequestId1);
770 coordinator()->RemoveRequests(request_ids); 814 coordinator()->RemoveRequests(request_ids);
771 PumpLoop(); 815 PumpLoop();
772 816
773 EXPECT_TRUE(observer().completed_called()); 817 EXPECT_TRUE(observer().completed_called());
774 EXPECT_EQ(RequestCoordinator::SavePageStatus::REMOVED, 818 EXPECT_EQ(RequestCoordinator::SavePageStatus::REMOVED,
775 observer().last_status()); 819 observer().last_status());
776 } 820 }
777 821
778 } // namespace offline_pages 822 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698