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

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

Issue 1971033002: Call scheduler when we get a save page later request. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/test/test_simple_task_runner.h" 11 #include "base/test/test_simple_task_runner.h"
12 #include "base/thread_task_runner_handle.h" 12 #include "base/thread_task_runner_handle.h"
13 #include "components/offline_pages/background/offliner_factory.h" 13 #include "components/offline_pages/background/offliner_factory.h"
14 #include "components/offline_pages/background/offliner_policy.h" 14 #include "components/offline_pages/background/offliner_policy.h"
15 #include "components/offline_pages/background/request_queue.h" 15 #include "components/offline_pages/background/request_queue.h"
16 #include "components/offline_pages/background/request_queue_in_memory_store.h" 16 #include "components/offline_pages/background/request_queue_in_memory_store.h"
17 #include "components/offline_pages/background/save_page_request.h" 17 #include "components/offline_pages/background/save_page_request.h"
18 #include "components/offline_pages/background/scheduler.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 20
20 namespace offline_pages { 21 namespace offline_pages {
21 22
22 namespace { 23 namespace {
23 // put test constants here 24 // put test constants here
24 const GURL kUrl("http://universe.com/everything"); 25 const GURL kUrl("http://universe.com/everything");
25 const ClientId kClientId("bookmark", "42"); 26 const ClientId kClientId("bookmark", "42");
26 } // namespace 27 } // namespace
27 28
29 class SchedulerStub : public Scheduler {
30 public:
31 SchedulerStub() {
32 schedule_called_ = false;
fgorski 2016/05/12 14:32:35 C++ again, use initializer list, please.
Pete Williamson 2016/05/12 17:21:19 Done.
33 unschedule_called_ = false;
34 }
35
36 void Schedule(const TriggerCondition& trigger_condition) override {
37 schedule_called_ = true;
38 }
39
40 // Unschedules the currently scheduled task, if any.
41 void Unschedule() override {
42 unschedule_called_ = true;
43 }
44
45 bool WasScheduleCalled() { return schedule_called_; }
fgorski 2016/05/12 14:32:35 can this be a const method? Did you consider simpl
Pete Williamson 2016/05/12 17:21:19 Done.
46
47 bool WasUnscheduleCalled() { return unschedule_called_; }
fgorski 2016/05/12 14:32:35 ditto.
Pete Williamson 2016/05/12 17:21:19 Done.
48
49 private:
50 bool schedule_called_;
51 bool unschedule_called_;
52 };
53
28 class RequestCoordinatorTest 54 class RequestCoordinatorTest
29 : public testing::Test { 55 : public testing::Test {
30 public: 56 public:
31 RequestCoordinatorTest(); 57 RequestCoordinatorTest();
32 ~RequestCoordinatorTest() override; 58 ~RequestCoordinatorTest() override;
33 59
34 void SetUp() override; 60 void SetUp() override;
35 61
36 void PumpLoop(); 62 void PumpLoop();
37 63
38 RequestCoordinator* getCoordinator() { 64 RequestCoordinator* getCoordinator() {
fgorski 2016/05/12 14:32:35 nit: can you rename it to coordinator() or GetCoor
Pete Williamson 2016/05/12 17:21:18 Done.
39 return coordinator_.get(); 65 return coordinator_.get();
40 } 66 }
41 67
42 // Empty callback function 68 // Empty callback function
43 void EmptyCallbackFunction() { 69 void EmptyCallbackFunction() {
44 } 70 }
45 71
46 // Callback for getting requests. 72 // Callback for getting requests.
47 void GetRequestsDone(RequestQueue::GetRequestsResult result, 73 void GetRequestsDone(RequestQueue::GetRequestsResult result,
48 const std::vector<SavePageRequest>& requests); 74 const std::vector<SavePageRequest>& requests);
(...skipping 20 matching lines...) Expand all
69 task_runner_handle_(task_runner_) {} 95 task_runner_handle_(task_runner_) {}
70 96
71 RequestCoordinatorTest::~RequestCoordinatorTest() {} 97 RequestCoordinatorTest::~RequestCoordinatorTest() {}
72 98
73 void RequestCoordinatorTest::SetUp() { 99 void RequestCoordinatorTest::SetUp() {
74 std::unique_ptr<OfflinerPolicy> policy(new OfflinerPolicy()); 100 std::unique_ptr<OfflinerPolicy> policy(new OfflinerPolicy());
75 std::unique_ptr<OfflinerFactory> factory; 101 std::unique_ptr<OfflinerFactory> factory;
76 std::unique_ptr<RequestQueueInMemoryStore> 102 std::unique_ptr<RequestQueueInMemoryStore>
77 store(new RequestQueueInMemoryStore()); 103 store(new RequestQueueInMemoryStore());
78 std::unique_ptr<RequestQueue> queue(new RequestQueue(std::move(store))); 104 std::unique_ptr<RequestQueue> queue(new RequestQueue(std::move(store)));
105 std::unique_ptr<Scheduler> schedulerStub(new SchedulerStub());
fgorski 2016/05/12 14:32:35 nit: alignment
dougarnett 2016/05/12 15:33:33 scheduler_stub I suppose
Pete Williamson 2016/05/12 17:21:18 Done.
Pete Williamson 2016/05/12 17:21:19 Done.
79 coordinator_.reset(new RequestCoordinator( 106 coordinator_.reset(new RequestCoordinator(
80 std::move(policy), std::move(factory), std::move(queue))); 107 std::move(policy), std::move(factory), std::move(queue),
108 std::move(schedulerStub)));
81 } 109 }
82 110
83 111
84 void RequestCoordinatorTest::PumpLoop() { 112 void RequestCoordinatorTest::PumpLoop() {
85 task_runner_->RunUntilIdle(); 113 task_runner_->RunUntilIdle();
86 } 114 }
87 115
88 void RequestCoordinatorTest::GetRequestsDone( 116 void RequestCoordinatorTest::GetRequestsDone(
89 RequestQueue::GetRequestsResult result, 117 RequestQueue::GetRequestsResult result,
90 const std::vector<SavePageRequest>& requests) { 118 const std::vector<SavePageRequest>& requests) {
(...skipping 18 matching lines...) Expand all
109 base::Unretained(this))); 137 base::Unretained(this)));
110 138
111 // Wait for callback to finish. 139 // Wait for callback to finish.
112 PumpLoop(); 140 PumpLoop();
113 141
114 // Check the results are as expected. 142 // Check the results are as expected.
115 EXPECT_EQ(1UL, last_requests().size()); 143 EXPECT_EQ(1UL, last_requests().size());
116 EXPECT_EQ(kUrl, last_requests()[0].url()); 144 EXPECT_EQ(kUrl, last_requests()[0].url());
117 EXPECT_EQ(kClientId, last_requests()[0].client_id()); 145 EXPECT_EQ(kClientId, last_requests()[0].client_id());
118 146
119 // TODO(petewil): Expect that the scheduler got notified. 147 // Expect that the scheduler got notified.
148 SchedulerStub* stub = reinterpret_cast<SchedulerStub*>(
149 getCoordinator()->GetSchedulerForTesting());
150 EXPECT_TRUE(stub->WasScheduleCalled());
151
fgorski 2016/05/12 14:32:35 nit: empty lines.
Pete Williamson 2016/05/12 17:21:19 Done.
120 } 152 }
121 153
122 } // namespace offline_pages 154 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698