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

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

Issue 2087633002: Defines TriggerConditions and plumbs up to BackgroundScheduler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Exposed TriggerConditions object for test Created 4 years, 6 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 15 matching lines...) Expand all
26 26
27 namespace { 27 namespace {
28 // put test constants here 28 // put test constants here
29 const GURL kUrl("http://universe.com/everything"); 29 const GURL kUrl("http://universe.com/everything");
30 const ClientId kClientId("bookmark", "42"); 30 const ClientId kClientId("bookmark", "42");
31 const int kRequestId(1); 31 const int kRequestId(1);
32 } // namespace 32 } // namespace
33 33
34 class SchedulerStub : public Scheduler { 34 class SchedulerStub : public Scheduler {
35 public: 35 public:
36 SchedulerStub() : schedule_called_(false), unschedule_called_(false) {} 36 SchedulerStub()
37 : schedule_called_(false),
38 unschedule_called_(false),
39 conditions_(false, 0, false) {}
37 40
38 void Schedule(const TriggerCondition& trigger_condition) override { 41 void Schedule(const TriggerConditions& trigger_conditions) override {
39 schedule_called_ = true; 42 schedule_called_ = true;
43 conditions_ = trigger_conditions;
40 } 44 }
41 45
42 // Unschedules the currently scheduled task, if any. 46 // Unschedules the currently scheduled task, if any.
43 void Unschedule() override { 47 void Unschedule() override {
44 unschedule_called_ = true; 48 unschedule_called_ = true;
45 } 49 }
46 50
47 bool schedule_called() const { return schedule_called_; } 51 bool schedule_called() const { return schedule_called_; }
48 52
49 bool unschedule_called() const { return unschedule_called_; } 53 bool unschedule_called() const { return unschedule_called_; }
50 54
55 TriggerConditions const* conditions() const { return &conditions_; }
56
51 private: 57 private:
52 bool schedule_called_; 58 bool schedule_called_;
53 bool unschedule_called_; 59 bool unschedule_called_;
60 TriggerConditions conditions_;
54 }; 61 };
55 62
56 class OfflinerStub : public Offliner { 63 class OfflinerStub : public Offliner {
57 bool LoadAndSave(const SavePageRequest& request, 64 bool LoadAndSave(const SavePageRequest& request,
58 const CompletionCallback& callback) override { 65 const CompletionCallback& callback) override {
59 // Post the callback on the run loop. 66 // Post the callback on the run loop.
60 base::ThreadTaskRunnerHandle::Get()->PostTask( 67 base::ThreadTaskRunnerHandle::Get()->PostTask(
61 FROM_HERE, 68 FROM_HERE,
62 base::Bind(callback, request, Offliner::RequestStatus::SAVED)); 69 base::Bind(callback, request, Offliner::RequestStatus::SAVED));
63 return true; 70 return true;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 195
189 // Check the request queue is as expected. 196 // Check the request queue is as expected.
190 EXPECT_EQ(1UL, last_requests().size()); 197 EXPECT_EQ(1UL, last_requests().size());
191 EXPECT_EQ(kUrl, last_requests()[0].url()); 198 EXPECT_EQ(kUrl, last_requests()[0].url());
192 EXPECT_EQ(kClientId, last_requests()[0].client_id()); 199 EXPECT_EQ(kClientId, last_requests()[0].client_id());
193 200
194 // Expect that the scheduler got notified. 201 // Expect that the scheduler got notified.
195 SchedulerStub* scheduler_stub = reinterpret_cast<SchedulerStub*>( 202 SchedulerStub* scheduler_stub = reinterpret_cast<SchedulerStub*>(
196 coordinator()->scheduler()); 203 coordinator()->scheduler());
197 EXPECT_TRUE(scheduler_stub->schedule_called()); 204 EXPECT_TRUE(scheduler_stub->schedule_called());
205 EXPECT_EQ(coordinator()
206 ->GetTriggerConditionsForUserRequest()
207 .minimum_battery_percentage,
208 scheduler_stub->conditions()->minimum_battery_percentage);
198 } 209 }
199 210
200 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestSucceeded) { 211 TEST_F(RequestCoordinatorTest, OfflinerDoneRequestSucceeded) {
201 // Add a request to the queue, wait for callbacks to finish. 212 // Add a request to the queue, wait for callbacks to finish.
202 offline_pages::SavePageRequest request( 213 offline_pages::SavePageRequest request(
203 kRequestId, kUrl, kClientId, base::Time::Now()); 214 kRequestId, kUrl, kClientId, base::Time::Now());
204 coordinator()->queue()->AddRequest( 215 coordinator()->queue()->AddRequest(
205 request, 216 request,
206 base::Bind(&RequestCoordinatorTest::AddRequestDone, 217 base::Bind(&RequestCoordinatorTest::AddRequestDone,
207 base::Unretained(this))); 218 base::Unretained(this)));
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 base::Bind(&RequestCoordinatorTest::GetRequestsDone, 269 base::Bind(&RequestCoordinatorTest::GetRequestsDone,
259 base::Unretained(this))); 270 base::Unretained(this)));
260 PumpLoop(); 271 PumpLoop();
261 272
262 // Still one request in the queue. 273 // Still one request in the queue.
263 EXPECT_EQ(1UL, last_requests().size()); 274 EXPECT_EQ(1UL, last_requests().size());
264 // TODO(dougarnett): Verify retry count gets incremented. 275 // TODO(dougarnett): Verify retry count gets incremented.
265 } 276 }
266 277
267 } // namespace offline_pages 278 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/background/request_coordinator.cc ('k') | components/offline_pages/background/scheduler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698