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

Side by Side Diff: cc/scheduler/scheduler_unittest.cc

Issue 844763008: Refactor and cleanup scheduler_unittest.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move member of FakeSchedulerClient to SchedulerTest Created 5 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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 "cc/scheduler/scheduler.h" 5 #include "cc/scheduler/scheduler.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/power_monitor/power_monitor.h" 14 #include "base/power_monitor/power_monitor.h"
15 #include "base/power_monitor/power_monitor_source.h" 15 #include "base/power_monitor/power_monitor_source.h"
16 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "cc/test/begin_frame_args_test.h" 18 #include "cc/test/begin_frame_args_test.h"
19 #include "cc/test/ordered_simple_task_runner.h" 19 #include "cc/test/ordered_simple_task_runner.h"
20 #include "cc/test/scheduler_test_common.h" 20 #include "cc/test/scheduler_test_common.h"
21 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 23
24 #define EXPECT_ACTION(action, client, action_index, expected_num_actions) \ 24 #define EXPECT_ACTION(action, client, action_index, expected_num_actions) \
25 do { \ 25 client->ExpectAction(action, action_index, expected_num_actions, \
26 EXPECT_EQ(expected_num_actions, client.num_actions_()); \ 26 scheduler_.get());
27 if (action_index >= 0) { \
28 ASSERT_LT(action_index, client.num_actions_()) << scheduler; \
29 EXPECT_STREQ(action, client.Action(action_index)); \
30 } \
31 for (int i = expected_num_actions; i < client.num_actions_(); ++i) \
32 ADD_FAILURE() << "Unexpected action: " << client.Action(i) \
33 << " with state:\n" << client.StateForAction(i); \
34 } while (false)
35 27
36 #define EXPECT_NO_ACTION(client) EXPECT_ACTION("", client, -1, 0) 28 #define EXPECT_NO_ACTION(client) EXPECT_ACTION("", client, -1, 0)
37 29
38 #define EXPECT_SINGLE_ACTION(action, client) \ 30 #define EXPECT_SINGLE_ACTION(action, client) \
39 EXPECT_ACTION(action, client, 0, 1) 31 EXPECT_ACTION(action, client, 0, 1)
40 32
41 #define EXPECT_SCOPED(statements) \ 33 #define EXPECT_SCOPED(statements) \
42 { \ 34 { \
43 SCOPED_TRACE(""); \ 35 SCOPED_TRACE(""); \
44 statements; \ 36 statements; \
45 } 37 }
46 38
47 #define CREATE_SCHEDULER_AND_INIT_SURFACE(settings) \
48 TestScheduler* scheduler = client.CreateScheduler(settings); \
49 EXPECT_SCOPED(client.InitializeOutputSurfaceAndFirstCommit(scheduler));
50
51 namespace cc { 39 namespace cc {
52 namespace { 40 namespace {
53 41
54 class FakeSchedulerClient;
55
56 class FakeSchedulerClient : public SchedulerClient { 42 class FakeSchedulerClient : public SchedulerClient {
57 public: 43 public:
58 class FakeExternalBeginFrameSource : public BeginFrameSourceMixIn {
59 public:
60 explicit FakeExternalBeginFrameSource(FakeSchedulerClient* client)
61 : client_(client) {}
62 ~FakeExternalBeginFrameSource() override {}
63
64 void OnNeedsBeginFramesChange(bool needs_begin_frames) override {
65 if (needs_begin_frames) {
66 client_->PushAction("SetNeedsBeginFrames(true)");
67 } else {
68 client_->PushAction("SetNeedsBeginFrames(false)");
69 }
70 client_->states_.push_back(client_->scheduler_->AsValue());
71 }
72
73 void TestOnBeginFrame(const BeginFrameArgs& args) {
74 return CallOnBeginFrame(args);
75 }
76
77 private:
78 FakeSchedulerClient* client_;
79 };
80
81 class FakePowerMonitorSource : public base::PowerMonitorSource {
82 public:
83 FakePowerMonitorSource() {}
84 ~FakePowerMonitorSource() override {}
85 void GeneratePowerStateEvent(bool on_battery_power) {
86 on_battery_power_impl_ = on_battery_power;
87 ProcessPowerEvent(POWER_STATE_EVENT);
88 base::MessageLoop::current()->RunUntilIdle();
89 }
90 bool IsOnBatteryPowerImpl() override { return on_battery_power_impl_; }
91
92 private:
93 bool on_battery_power_impl_;
94 };
95
96 FakeSchedulerClient() 44 FakeSchedulerClient()
97 : automatic_swap_ack_(true), 45 : automatic_swap_ack_(true),
98 begin_frame_is_sent_to_children_(false), 46 begin_frame_is_sent_to_children_(false),
99 now_src_(TestNowSource::Create()), 47 now_src_(TestNowSource::Create()),
100 task_runner_(new OrderedSimpleTaskRunner(now_src_, true)), 48 task_runner_(new OrderedSimpleTaskRunner(now_src_, true)),
101 fake_external_begin_frame_source_(nullptr),
102 fake_power_monitor_source_(new FakePowerMonitorSource),
103 power_monitor_(make_scoped_ptr<base::PowerMonitorSource>(
104 fake_power_monitor_source_)),
105 scheduler_(nullptr) { 49 scheduler_(nullptr) {
106 // A bunch of tests require Now() to be > BeginFrameArgs::DefaultInterval() 50 // A bunch of tests require Now() to be > BeginFrameArgs::DefaultInterval()
107 now_src_->AdvanceNow(base::TimeDelta::FromMilliseconds(100)); 51 now_src_->AdvanceNow(base::TimeDelta::FromMilliseconds(100));
108 // Fail if we need to run 100 tasks in a row. 52 // Fail if we need to run 100 tasks in a row.
109 task_runner_->SetRunTaskLimit(100); 53 task_runner_->SetRunTaskLimit(100);
110 Reset(); 54 Reset();
111 } 55 }
112 56
113 void Reset() { 57 void Reset() {
114 actions_.clear(); 58 actions_.clear();
115 states_.clear(); 59 states_.clear();
116 draw_will_happen_ = true; 60 draw_will_happen_ = true;
117 swap_will_happen_if_draw_happens_ = true; 61 swap_will_happen_if_draw_happens_ = true;
118 num_draws_ = 0; 62 num_draws_ = 0;
119 log_anticipated_draw_time_change_ = false; 63 log_anticipated_draw_time_change_ = false;
120 begin_frame_is_sent_to_children_ = false; 64 begin_frame_is_sent_to_children_ = false;
121 } 65 }
122 66
123 TestScheduler* CreateScheduler(const SchedulerSettings& settings) { 67 void SetScheduler(TestScheduler* scheduler) { scheduler_ = scheduler; }
simonhong 2015/01/21 22:04:09 set_scheduler(...)
Jimmy Jo 2015/01/22 07:22:50 Done.
124 scoped_ptr<FakeExternalBeginFrameSource> fake_external_begin_frame_source;
125 if (settings.use_external_begin_frame_source) {
126 fake_external_begin_frame_source.reset(
127 new FakeExternalBeginFrameSource(this));
128 fake_external_begin_frame_source_ =
129 fake_external_begin_frame_source.get();
130 }
131 scheduler_ = TestScheduler::Create(now_src_,
132 this,
133 settings,
134 0,
135 task_runner_,
136 &power_monitor_,
137 fake_external_begin_frame_source.Pass());
138 DCHECK(scheduler_);
139 return scheduler_.get();
140 }
141 68
142 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it 69 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it
143 // for tests that do. 70 // for tests that do.
144 void set_log_anticipated_draw_time_change(bool log) { 71 void set_log_anticipated_draw_time_change(bool log) {
145 log_anticipated_draw_time_change_ = log; 72 log_anticipated_draw_time_change_ = log;
146 } 73 }
147 bool needs_begin_frames() { 74 bool needs_begin_frames() {
148 return scheduler_->frame_source().NeedsBeginFrames(); 75 return scheduler_->frame_source().NeedsBeginFrames();
149 } 76 }
150 int num_draws() const { return num_draws_; } 77 int num_draws() const { return num_draws_; }
151 int num_actions_() const { return static_cast<int>(actions_.size()); } 78 int num_actions_() const { return static_cast<int>(actions_.size()); }
152 const char* Action(int i) const { return actions_[i]; } 79 const char* Action(int i) const { return actions_[i]; }
153 std::string StateForAction(int i) const { return states_[i]->ToString(); } 80 std::string StateForAction(int i) const { return states_[i]->ToString(); }
154 base::TimeTicks posted_begin_impl_frame_deadline() const { 81 base::TimeTicks posted_begin_impl_frame_deadline() const {
155 return posted_begin_impl_frame_deadline_; 82 return posted_begin_impl_frame_deadline_;
156 } 83 }
157 84
158 FakeExternalBeginFrameSource* fake_external_begin_frame_source() const {
159 return fake_external_begin_frame_source_;
160 }
161
162 base::PowerMonitor* PowerMonitor() { return &power_monitor_; }
163
164 FakePowerMonitorSource* PowerMonitorSource() {
165 return fake_power_monitor_source_;
166 }
167
168 // As this function contains EXPECT macros, to allow debugging it should be
169 // called inside EXPECT_SCOPED like so;
170 // EXPECT_SCOPED(client.InitializeOutputSurfaceAndFirstCommit(scheduler));
171 void InitializeOutputSurfaceAndFirstCommit(TestScheduler* scheduler) {
172 TRACE_EVENT0("cc",
173 "SchedulerUnitTest::InitializeOutputSurfaceAndFirstCommit");
174 DCHECK(scheduler);
175
176 // Check the client doesn't have any actions queued when calling this
177 // function.
178 EXPECT_NO_ACTION((*this));
179 EXPECT_FALSE(needs_begin_frames());
180
181 // Start the initial output surface creation.
182 EXPECT_FALSE(scheduler->CanStart());
183 scheduler->SetCanStart();
184 scheduler->SetVisible(true);
185 scheduler->SetCanDraw(true);
186 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", (*this));
187 Reset();
188
189 // We don't see anything happening until the first impl frame.
190 scheduler->DidCreateAndInitializeOutputSurface();
191 scheduler->SetNeedsCommit();
192 EXPECT_TRUE(needs_begin_frames());
193 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
194 Reset();
195
196 {
197 SCOPED_TRACE("Do first frame to commit after initialize.");
198 AdvanceFrame();
199
200 scheduler->NotifyBeginMainFrameStarted();
201 scheduler->NotifyReadyToCommitThenActivateIfNeeded();
202
203 // Run the posted deadline task.
204 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
205 task_runner().RunTasksWhile(ImplFrameDeadlinePending(true));
206 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
207
208 EXPECT_FALSE(scheduler->CommitPending());
209 }
210
211 Reset();
212
213 {
214 SCOPED_TRACE(
215 "Run second frame so Scheduler calls SetNeedsBeginFrame(false).");
216 AdvanceFrame();
217
218 // Run the posted deadline task.
219 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
220 task_runner().RunTasksWhile(ImplFrameDeadlinePending(true));
221 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
222 }
223
224 EXPECT_FALSE(needs_begin_frames());
225 Reset();
226 }
227
228 // As this function contains EXPECT macros, to allow debugging it should be
229 // called inside EXPECT_SCOPED like so;
230 // EXPECT_SCOPED(client.AdvanceFrame());
231 void AdvanceFrame() {
232 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"),
233 "FakeSchedulerClient::AdvanceFrame");
234 // Consume any previous deadline first, if no deadline is currently
235 // pending, ImplFrameDeadlinePending will return false straight away and we
236 // will run no tasks.
237 task_runner().RunTasksWhile(ImplFrameDeadlinePending(true));
238 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
239
240 // Send the next BeginFrame message if using an external source, otherwise
241 // it will be already in the task queue.
242 if (scheduler_->settings().use_external_begin_frame_source &&
243 scheduler_->FrameProductionThrottled()) {
244 SendNextBeginFrame();
245 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
246 }
247
248 // Then run tasks until new deadline is scheduled.
249 EXPECT_TRUE(task_runner().RunTasksWhile(ImplFrameDeadlinePending(false)));
250 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
251 }
252
253 void SendNextBeginFrame() {
254 DCHECK(scheduler_->settings().use_external_begin_frame_source);
255 // Creep the time forward so that any BeginFrameArgs is not equal to the
256 // last one otherwise we violate the BeginFrameSource contract.
257 now_src_->AdvanceNow(BeginFrameArgs::DefaultInterval());
258 fake_external_begin_frame_source_->TestOnBeginFrame(
259 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src_));
260 }
261
262 OrderedSimpleTaskRunner& task_runner() { return *task_runner_; } 85 OrderedSimpleTaskRunner& task_runner() { return *task_runner_; }
263 TestNowSource* now_src() { return now_src_.get(); } 86 TestNowSource* now_src() { return now_src_.get(); }
264 87
265 int ActionIndex(const char* action) const { 88 int ActionIndex(const char* action) const {
266 for (size_t i = 0; i < actions_.size(); i++) 89 for (size_t i = 0; i < actions_.size(); i++)
267 if (!strcmp(actions_[i], action)) 90 if (!strcmp(actions_[i], action))
268 return i; 91 return i;
269 return -1; 92 return -1;
270 } 93 }
271 94
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 base::Callback<bool(void)> ImplFrameDeadlinePending(bool state) { 165 base::Callback<bool(void)> ImplFrameDeadlinePending(bool state) {
343 return base::Bind(&FakeSchedulerClient::ImplFrameDeadlinePendingCallback, 166 return base::Bind(&FakeSchedulerClient::ImplFrameDeadlinePendingCallback,
344 base::Unretained(this), 167 base::Unretained(this),
345 state); 168 state);
346 } 169 }
347 170
348 bool begin_frame_is_sent_to_children() const { 171 bool begin_frame_is_sent_to_children() const {
349 return begin_frame_is_sent_to_children_; 172 return begin_frame_is_sent_to_children_;
350 } 173 }
351 174
352 protected: 175 void ExpectAction(const char* action,
353 bool ImplFrameDeadlinePendingCallback(bool state) { 176 int action_index,
354 return scheduler_->BeginImplFrameDeadlinePending() == state; 177 int expected_num_actions,
178 const TestScheduler* scheduler) {
179 EXPECT_EQ(expected_num_actions, num_actions_());
180 if (action_index >= 0) {
181 ASSERT_LT(action_index, num_actions_()) << scheduler;
182 EXPECT_STREQ(action, Action(action_index));
183 }
184 for (int i = expected_num_actions; i < num_actions_(); ++i)
185 ADD_FAILURE() << "Unexpected action: " << Action(i) << " with state:\n"
186 << StateForAction(i);
355 } 187 }
356 188
357 void PushAction(const char* description) { 189 void PushAction(const char* description) {
358 actions_.push_back(description); 190 actions_.push_back(description);
359 states_.push_back(scheduler_->AsValue()); 191 states_.push_back(scheduler_->AsValue());
360 } 192 }
361 193
194 protected:
195 bool ImplFrameDeadlinePendingCallback(bool state) {
196 return scheduler_->BeginImplFrameDeadlinePending() == state;
197 }
198
362 bool draw_will_happen_; 199 bool draw_will_happen_;
363 bool swap_will_happen_if_draw_happens_; 200 bool swap_will_happen_if_draw_happens_;
364 bool automatic_swap_ack_; 201 bool automatic_swap_ack_;
365 int num_draws_; 202 int num_draws_;
366 bool log_anticipated_draw_time_change_; 203 bool log_anticipated_draw_time_change_;
367 bool begin_frame_is_sent_to_children_; 204 bool begin_frame_is_sent_to_children_;
368 base::TimeTicks posted_begin_impl_frame_deadline_; 205 base::TimeTicks posted_begin_impl_frame_deadline_;
369 std::vector<const char*> actions_; 206 std::vector<const char*> actions_;
370 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat>> states_; 207 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat>> states_;
371 scoped_refptr<TestNowSource> now_src_; 208 scoped_refptr<TestNowSource> now_src_;
372 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; 209 scoped_refptr<OrderedSimpleTaskRunner> task_runner_;
210 TestScheduler* scheduler_;
211 };
212
213 class SchedulerTest : public testing::Test {
214 public:
215 SchedulerTest()
216 : fake_power_monitor_source_(new FakePowerMonitorSource),
217 fake_external_begin_frame_source_(nullptr),
218 power_monitor_(make_scoped_ptr<base::PowerMonitorSource>(
219 fake_power_monitor_source_)) {}
220 ~SchedulerTest() override {}
221
222 class FakePowerMonitorSource : public base::PowerMonitorSource {
simonhong 2015/01/21 22:04:09 nit: How about moving these two class(FakePowerMon
Jimmy Jo 2015/01/22 07:22:50 Done.
223 public:
224 FakePowerMonitorSource() {}
225 ~FakePowerMonitorSource() override {}
226 void GeneratePowerStateEvent(bool on_battery_power) {
227 on_battery_power_impl_ = on_battery_power;
228 ProcessPowerEvent(POWER_STATE_EVENT);
229 base::MessageLoop::current()->RunUntilIdle();
230 }
231 bool IsOnBatteryPowerImpl() override { return on_battery_power_impl_; }
232
233 private:
234 bool on_battery_power_impl_;
235 };
236
237 class FakeExternalBeginFrameSource : public BeginFrameSourceMixIn {
238 public:
239 explicit FakeExternalBeginFrameSource(FakeSchedulerClient* client)
240 : client_(client) {}
241 ~FakeExternalBeginFrameSource() override {}
242
243 void OnNeedsBeginFramesChange(bool needs_begin_frames) override {
244 if (needs_begin_frames) {
245 client_->PushAction("SetNeedsBeginFrames(true)");
246 } else {
247 client_->PushAction("SetNeedsBeginFrames(false)");
248 }
249 }
250
251 void TestOnBeginFrame(const BeginFrameArgs& args) {
252 return CallOnBeginFrame(args);
253 }
254
255 private:
256 FakeSchedulerClient* client_;
257 };
258
259 protected:
260 TestScheduler* CreateScheduler() {
261 scoped_ptr<FakeExternalBeginFrameSource> fake_external_begin_frame_source;
262 if (scheduler_settings_.use_external_begin_frame_source) {
263 fake_external_begin_frame_source.reset(
264 new FakeExternalBeginFrameSource(client_.get()));
265 fake_external_begin_frame_source_ =
266 fake_external_begin_frame_source.get();
267 }
268 scheduler_ = TestScheduler::Create(
269 client_->now_src(), client_.get(), scheduler_settings_, 0,
270 make_scoped_refptr(&client_->task_runner()), &power_monitor_,
271 fake_external_begin_frame_source.Pass());
272 DCHECK(scheduler_);
273 client_->SetScheduler(scheduler_.get());
274 return scheduler_.get();
275 }
276
277 void CreateSchedulerAndInitSurface() {
278 CreateScheduler();
279 EXPECT_SCOPED(InitializeOutputSurfaceAndFirstCommit());
280 }
281
282 void SetUpScheduler(bool initSurface) {
283 SetUpScheduler((new FakeSchedulerClient), initSurface);
284 }
285
286 void SetUpScheduler(FakeSchedulerClient* client, bool initSurface) {
287 client_.reset(client);
288 if (initSurface)
289 CreateSchedulerAndInitSurface();
290 else
291 CreateScheduler();
292 }
293
294 // As this function contains EXPECT macros, to allow debugging it should be
295 // called inside EXPECT_SCOPED like so;
296 // EXPECT_SCOPED(client.InitializeOutputSurfaceAndFirstCommit(scheduler));
297 void InitializeOutputSurfaceAndFirstCommit() {
298 TRACE_EVENT0("cc",
299 "SchedulerUnitTest::InitializeOutputSurfaceAndFirstCommit");
300 DCHECK(scheduler_);
301
302 // Check the client doesn't have any actions queued when calling this
303 // function.
304 EXPECT_NO_ACTION(client_);
305 EXPECT_FALSE(client_->needs_begin_frames());
306
307 // Start the initial output surface creation.
308 EXPECT_FALSE(scheduler_->CanStart());
309 scheduler_->SetCanStart();
310 scheduler_->SetVisible(true);
311 scheduler_->SetCanDraw(true);
312 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_);
313
314 client_->Reset();
315
316 // We don't see anything happening until the first impl frame.
317 scheduler_->DidCreateAndInitializeOutputSurface();
318 scheduler_->SetNeedsCommit();
319 EXPECT_TRUE(client_->needs_begin_frames());
320 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
321 client_->Reset();
322
323 {
324 SCOPED_TRACE("Do first frame to commit after initialize.");
325 AdvanceFrame();
326
327 scheduler_->NotifyBeginMainFrameStarted();
328 scheduler_->NotifyReadyToCommitThenActivateIfNeeded();
329
330 // Run the posted deadline task.
331 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
332 client_->task_runner().RunTasksWhile(
333 client_->ImplFrameDeadlinePending(true));
334 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
335
336 EXPECT_FALSE(scheduler_->CommitPending());
337 }
338
339 client_->Reset();
340
341 {
342 SCOPED_TRACE(
343 "Run second frame so Scheduler calls SetNeedsBeginFrame(false).");
344 AdvanceFrame();
345
346 // Run the posted deadline task.
347 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
348 client_->task_runner().RunTasksWhile(
349 client_->ImplFrameDeadlinePending(true));
350 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
351 }
352
353 EXPECT_FALSE(client_->needs_begin_frames());
354 client_->Reset();
355 }
356
357 // As this function contains EXPECT macros, to allow debugging it should be
358 // called inside EXPECT_SCOPED like so;
359 // EXPECT_SCOPED(client.AdvanceFrame());
360 void AdvanceFrame() {
361 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"),
362 "FakeSchedulerClient::AdvanceFrame");
363 // Consume any previous deadline first, if no deadline is currently
364 // pending, ImplFrameDeadlinePending will return false straight away and we
365 // will run no tasks.
366 client_->task_runner().RunTasksWhile(
367 client_->ImplFrameDeadlinePending(true));
368 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
369
370 // Send the next BeginFrame message if using an external source, otherwise
371 // it will be already in the task queue.
372 if (scheduler_->settings().use_external_begin_frame_source &&
373 scheduler_->FrameProductionThrottled()) {
374 SendNextBeginFrame();
375 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
376 }
377
378 // Then run tasks until new deadline is scheduled.
379 EXPECT_TRUE(client_->task_runner().RunTasksWhile(
380 client_->ImplFrameDeadlinePending(false)));
381 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
382 }
383
384 void SendNextBeginFrame() {
385 DCHECK(scheduler_->settings().use_external_begin_frame_source);
386 // Creep the time forward so that any BeginFrameArgs is not equal to the
387 // last one otherwise we violate the BeginFrameSource contract.
388 client_->now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval());
389 fake_external_begin_frame_source_->TestOnBeginFrame(
390 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE,
391 client_->now_src()));
392 }
393
394 base::PowerMonitor* PowerMonitor() { return &power_monitor_; }
395 FakePowerMonitorSource* PowerMonitorSource() {
396 return fake_power_monitor_source_;
397 }
398
399 FakeExternalBeginFrameSource* fake_external_begin_frame_source() const {
400 return fake_external_begin_frame_source_;
401 }
402
403 void MainFrameInHighLatencyMode(
404 int64 begin_main_frame_to_commit_estimate_in_ms,
405 int64 commit_to_activate_estimate_in_ms,
406 bool impl_latency_takes_priority,
407 bool should_send_begin_main_frame);
408 void BeginFramesNotFromClient(bool use_external_begin_frame_source,
409 bool throttle_frame_production);
410 void BeginFramesNotFromClient_SwapThrottled(
411 bool use_external_begin_frame_source,
412 bool throttle_frame_production);
413 void DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency(
414 bool impl_side_painting);
415 void DidLoseOutputSurfaceAfterReadyToCommit(bool impl_side_painting);
416
417 FakePowerMonitorSource* fake_power_monitor_source_;
373 FakeExternalBeginFrameSource* fake_external_begin_frame_source_; 418 FakeExternalBeginFrameSource* fake_external_begin_frame_source_;
374 FakePowerMonitorSource* fake_power_monitor_source_;
375 base::PowerMonitor power_monitor_; 419 base::PowerMonitor power_monitor_;
420 SchedulerSettings scheduler_settings_;
421 scoped_ptr<FakeSchedulerClient> client_;
376 scoped_ptr<TestScheduler> scheduler_; 422 scoped_ptr<TestScheduler> scheduler_;
377 }; 423 };
378 424
379 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { 425 TEST_F(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) {
380 FakeSchedulerClient client; 426 scheduler_settings_.use_external_begin_frame_source = true;
381 SchedulerSettings scheduler_settings; 427 SetUpScheduler(false);
382 scheduler_settings.use_external_begin_frame_source = true; 428 scheduler_->SetCanStart();
383 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); 429 scheduler_->SetVisible(true);
384 scheduler->SetCanStart(); 430 scheduler_->SetCanDraw(true);
385 scheduler->SetVisible(true); 431
386 scheduler->SetCanDraw(true); 432 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_);
387 433 client_->Reset();
388 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 434 scheduler_->DidCreateAndInitializeOutputSurface();
389 client.Reset(); 435 EXPECT_NO_ACTION(client_);
390 scheduler->DidCreateAndInitializeOutputSurface(); 436 }
391 EXPECT_NO_ACTION(client); 437
392 } 438 TEST_F(SchedulerTest, SendBeginFramesToChildren) {
393 439 scheduler_settings_.use_external_begin_frame_source = true;
394 TEST(SchedulerTest, SendBeginFramesToChildren) { 440 scheduler_settings_.forward_begin_frames_to_children = true;
395 FakeSchedulerClient client; 441 SetUpScheduler(true);
396 SchedulerSettings scheduler_settings; 442
397 scheduler_settings.use_external_begin_frame_source = true; 443 EXPECT_FALSE(client_->begin_frame_is_sent_to_children());
398 scheduler_settings.forward_begin_frames_to_children = true; 444 scheduler_->SetNeedsCommit();
399 445 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
400 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); 446 EXPECT_TRUE(client_->needs_begin_frames());
401 447
402 EXPECT_FALSE(client.begin_frame_is_sent_to_children()); 448 scheduler_->SetChildrenNeedBeginFrames(true);
403 scheduler->SetNeedsCommit(); 449
404 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); 450 client_->Reset();
405 EXPECT_TRUE(client.needs_begin_frames()); 451 EXPECT_SCOPED(AdvanceFrame());
406 452 EXPECT_TRUE(client_->begin_frame_is_sent_to_children());
407 scheduler->SetChildrenNeedBeginFrames(true); 453 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
408 454 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
409 client.Reset(); 455 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
410 EXPECT_SCOPED(client.AdvanceFrame()); 456 EXPECT_TRUE(client_->needs_begin_frames());
411 EXPECT_TRUE(client.begin_frame_is_sent_to_children()); 457 }
412 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 458
413 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 459 TEST_F(SchedulerTest, SendBeginFramesToChildrenWithoutCommit) {
414 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 460 scheduler_settings_.use_external_begin_frame_source = true;
415 EXPECT_TRUE(client.needs_begin_frames()); 461 scheduler_settings_.forward_begin_frames_to_children = true;
416 } 462 SetUpScheduler(true);
417 463
418 TEST(SchedulerTest, SendBeginFramesToChildrenWithoutCommit) { 464 EXPECT_FALSE(client_->needs_begin_frames());
419 FakeSchedulerClient client; 465 scheduler_->SetChildrenNeedBeginFrames(true);
420 SchedulerSettings scheduler_settings; 466 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
421 scheduler_settings.use_external_begin_frame_source = true; 467 EXPECT_TRUE(client_->needs_begin_frames());
422 scheduler_settings.forward_begin_frames_to_children = true; 468
423 469 client_->Reset();
424 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); 470 EXPECT_SCOPED(AdvanceFrame());
425 471 EXPECT_TRUE(client_->begin_frame_is_sent_to_children());
426 EXPECT_FALSE(client.needs_begin_frames()); 472 }
427 scheduler->SetChildrenNeedBeginFrames(true); 473
428 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); 474 TEST_F(SchedulerTest, RequestCommit) {
429 EXPECT_TRUE(client.needs_begin_frames()); 475 scheduler_settings_.use_external_begin_frame_source = true;
430 476 SetUpScheduler(true);
431 client.Reset();
432 EXPECT_SCOPED(client.AdvanceFrame());
433 EXPECT_TRUE(client.begin_frame_is_sent_to_children());
434 }
435
436 TEST(SchedulerTest, RequestCommit) {
437 FakeSchedulerClient client;
438 SchedulerSettings scheduler_settings;
439 scheduler_settings.use_external_begin_frame_source = true;
440
441 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings);
442 477
443 // SetNeedsCommit should begin the frame on the next BeginImplFrame. 478 // SetNeedsCommit should begin the frame on the next BeginImplFrame.
444 scheduler->SetNeedsCommit(); 479 scheduler_->SetNeedsCommit();
445 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); 480 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
446 client.Reset(); 481 client_->Reset();
447 482
448 EXPECT_SCOPED(client.AdvanceFrame()); 483 EXPECT_SCOPED(AdvanceFrame());
449 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 484 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
450 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 485 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
451 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 486 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
452 EXPECT_TRUE(client.needs_begin_frames()); 487 EXPECT_TRUE(client_->needs_begin_frames());
453 client.Reset(); 488 client_->Reset();
454 489
455 // If we don't swap on the deadline, we wait for the next BeginFrame. 490 // If we don't swap on the deadline, we wait for the next BeginFrame.
456 client.task_runner().RunPendingTasks(); // Run posted deadline. 491 client_->task_runner().RunPendingTasks(); // Run posted deadline.
457 EXPECT_NO_ACTION(client); 492 EXPECT_NO_ACTION(client_);
458 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 493 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
459 EXPECT_TRUE(client.needs_begin_frames()); 494 EXPECT_TRUE(client_->needs_begin_frames());
460 client.Reset(); 495 client_->Reset();
461 496
462 // NotifyReadyToCommit should trigger the commit. 497 // NotifyReadyToCommit should trigger the commit.
463 scheduler->NotifyBeginMainFrameStarted(); 498 scheduler_->NotifyBeginMainFrameStarted();
464 scheduler->NotifyReadyToCommit(); 499 scheduler_->NotifyReadyToCommit();
465 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 500 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_);
466 EXPECT_TRUE(client.needs_begin_frames()); 501 EXPECT_TRUE(client_->needs_begin_frames());
467 client.Reset(); 502 client_->Reset();
468 503
469 // BeginImplFrame should prepare the draw. 504 // BeginImplFrame should prepare the draw.
470 EXPECT_SCOPED(client.AdvanceFrame()); 505 EXPECT_SCOPED(AdvanceFrame());
471 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 506 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
472 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 507 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2);
473 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 508 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
474 EXPECT_TRUE(client.needs_begin_frames()); 509 EXPECT_TRUE(client_->needs_begin_frames());
475 client.Reset(); 510 client_->Reset();
476 511
477 // BeginImplFrame deadline should draw. 512 // BeginImplFrame deadline should draw.
478 client.task_runner().RunPendingTasks(); // Run posted deadline. 513 client_->task_runner().RunPendingTasks(); // Run posted deadline.
479 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); 514 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1);
480 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 515 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
481 EXPECT_TRUE(client.needs_begin_frames()); 516 EXPECT_TRUE(client_->needs_begin_frames());
482 client.Reset(); 517 client_->Reset();
483 518
484 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) 519 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false)
485 // to avoid excessive toggles. 520 // to avoid excessive toggles.
486 EXPECT_SCOPED(client.AdvanceFrame()); 521 EXPECT_SCOPED(AdvanceFrame());
487 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); 522 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_);
488 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 523 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
489 client.Reset(); 524 client_->Reset();
490 525
491 client.task_runner().RunPendingTasks(); // Run posted deadline. 526 client_->task_runner().RunPendingTasks(); // Run posted deadline.
492 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); 527 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_);
493 client.Reset(); 528 client_->Reset();
494 } 529 }
495 530
496 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { 531 TEST_F(SchedulerTest, RequestCommitAfterBeginMainFrameSent) {
497 FakeSchedulerClient client; 532 scheduler_settings_.use_external_begin_frame_source = true;
498 SchedulerSettings scheduler_settings; 533 SetUpScheduler(true);
499 scheduler_settings.use_external_begin_frame_source = true;
500
501 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings);
502 534
503 // SetNeedsCommit should begin the frame. 535 // SetNeedsCommit should begin the frame.
504 scheduler->SetNeedsCommit(); 536 scheduler_->SetNeedsCommit();
505 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); 537 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
506 538
507 client.Reset(); 539 client_->Reset();
508 EXPECT_SCOPED(client.AdvanceFrame()); 540 EXPECT_SCOPED(AdvanceFrame());
509 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 541 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
510 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 542 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
511 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 543 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
512 544
513 EXPECT_TRUE(client.needs_begin_frames()); 545 EXPECT_TRUE(client_->needs_begin_frames());
514 client.Reset(); 546 client_->Reset();
515 547
516 // Now SetNeedsCommit again. Calling here means we need a second commit. 548 // Now SetNeedsCommit again. Calling here means we need a second commit.
517 scheduler->SetNeedsCommit(); 549 scheduler_->SetNeedsCommit();
518 EXPECT_EQ(client.num_actions_(), 0); 550 EXPECT_EQ(client_->num_actions_(), 0);
519 client.Reset(); 551 client_->Reset();
520 552
521 // Finish the first commit. 553 // Finish the first commit.
522 scheduler->NotifyBeginMainFrameStarted(); 554 scheduler_->NotifyBeginMainFrameStarted();
523 scheduler->NotifyReadyToCommit(); 555 scheduler_->NotifyReadyToCommit();
524 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 556 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_);
525 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 557 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
526 client.Reset(); 558 client_->Reset();
527 client.task_runner().RunPendingTasks(); // Run posted deadline. 559 client_->task_runner().RunPendingTasks(); // Run posted deadline.
528 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); 560 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2);
529 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); 561 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2);
530 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 562 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
531 563
532 // Because we just swapped, the Scheduler should also request the next 564 // Because we just swapped, the Scheduler should also request the next
533 // BeginImplFrame from the OutputSurface. 565 // BeginImplFrame from the OutputSurface.
534 EXPECT_TRUE(client.needs_begin_frames()); 566 EXPECT_TRUE(client_->needs_begin_frames());
535 client.Reset(); 567 client_->Reset();
536 // Since another commit is needed, the next BeginImplFrame should initiate 568 // Since another commit is needed, the next BeginImplFrame should initiate
537 // the second commit. 569 // the second commit.
538 EXPECT_SCOPED(client.AdvanceFrame()); 570 EXPECT_SCOPED(AdvanceFrame());
539 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 571 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
540 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 572 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
541 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 573 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
542 client.Reset(); 574 client_->Reset();
543 575
544 // Finishing the commit before the deadline should post a new deadline task 576 // Finishing the commit before the deadline should post a new deadline task
545 // to trigger the deadline early. 577 // to trigger the deadline early.
546 scheduler->NotifyBeginMainFrameStarted(); 578 scheduler_->NotifyBeginMainFrameStarted();
547 scheduler->NotifyReadyToCommit(); 579 scheduler_->NotifyReadyToCommit();
548 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 580 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_);
549 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 581 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
550 client.Reset(); 582 client_->Reset();
551 client.task_runner().RunPendingTasks(); // Run posted deadline. 583 client_->task_runner().RunPendingTasks(); // Run posted deadline.
552 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); 584 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2);
553 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); 585 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2);
554 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 586 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
555 EXPECT_TRUE(client.needs_begin_frames()); 587 EXPECT_TRUE(client_->needs_begin_frames());
556 client.Reset(); 588 client_->Reset();
557 589
558 // On the next BeginImplFrame, verify we go back to a quiescent state and 590 // On the next BeginImplFrame, verify we go back to a quiescent state and
559 // no longer request BeginImplFrames. 591 // no longer request BeginImplFrames.
560 EXPECT_SCOPED(client.AdvanceFrame()); 592 EXPECT_SCOPED(AdvanceFrame());
561 client.task_runner().RunPendingTasks(); // Run posted deadline. 593 client_->task_runner().RunPendingTasks(); // Run posted deadline.
562 EXPECT_FALSE(client.needs_begin_frames()); 594 EXPECT_FALSE(client_->needs_begin_frames());
563 client.Reset(); 595 client_->Reset();
564 } 596 }
565 597
566 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { 598 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient {
567 public: 599 public:
568 SchedulerClientThatsetNeedsDrawInsideDraw() 600 SchedulerClientThatsetNeedsDrawInsideDraw()
569 : FakeSchedulerClient(), request_redraws_(false) {} 601 : FakeSchedulerClient(), request_redraws_(false) {}
570 602
571 void ScheduledActionSendBeginMainFrame() override {} 603 void ScheduledActionSendBeginMainFrame() override {}
572 604
573 void SetRequestRedrawsInsideDraw(bool enable) { request_redraws_ = enable; } 605 void SetRequestRedrawsInsideDraw(bool enable) { request_redraws_ = enable; }
(...skipping 15 matching lines...) Expand all
589 void DidAnticipatedDrawTimeChange(base::TimeTicks) override {} 621 void DidAnticipatedDrawTimeChange(base::TimeTicks) override {}
590 622
591 private: 623 private:
592 bool request_redraws_; 624 bool request_redraws_;
593 }; 625 };
594 626
595 // Tests for two different situations: 627 // Tests for two different situations:
596 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside 628 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside
597 // a ScheduledActionDrawAndSwap 629 // a ScheduledActionDrawAndSwap
598 // 2. the scheduler drawing twice inside a single tick 630 // 2. the scheduler drawing twice inside a single tick
599 TEST(SchedulerTest, RequestRedrawInsideDraw) { 631 TEST_F(SchedulerTest, RequestRedrawInsideDraw) {
600 SchedulerClientThatsetNeedsDrawInsideDraw client; 632 SchedulerClientThatsetNeedsDrawInsideDraw* client =
601 SchedulerSettings scheduler_settings; 633 new SchedulerClientThatsetNeedsDrawInsideDraw;
602 scheduler_settings.use_external_begin_frame_source = true; 634 scheduler_settings_.use_external_begin_frame_source = true;
635 SetUpScheduler(client, true);
636 client->SetRequestRedrawsInsideDraw(true);
603 637
604 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); 638 scheduler_->SetNeedsRedraw();
605 client.SetRequestRedrawsInsideDraw(true); 639 EXPECT_TRUE(scheduler_->RedrawPending());
640 EXPECT_TRUE(client->needs_begin_frames());
641 EXPECT_EQ(0, client->num_draws());
606 642
607 scheduler->SetNeedsRedraw(); 643 EXPECT_SCOPED(AdvanceFrame());
608 EXPECT_TRUE(scheduler->RedrawPending()); 644 client->task_runner().RunPendingTasks(); // Run posted deadline.
609 EXPECT_TRUE(client.needs_begin_frames()); 645 EXPECT_EQ(1, client->num_draws());
610 EXPECT_EQ(0, client.num_draws()); 646 EXPECT_TRUE(scheduler_->RedrawPending());
647 EXPECT_TRUE(client->needs_begin_frames());
611 648
612 EXPECT_SCOPED(client.AdvanceFrame()); 649 client->SetRequestRedrawsInsideDraw(false);
613 client.task_runner().RunPendingTasks(); // Run posted deadline.
614 EXPECT_EQ(1, client.num_draws());
615 EXPECT_TRUE(scheduler->RedrawPending());
616 EXPECT_TRUE(client.needs_begin_frames());
617 650
618 client.SetRequestRedrawsInsideDraw(false); 651 EXPECT_SCOPED(AdvanceFrame());
619 652 client->task_runner().RunPendingTasks(); // Run posted deadline.
620 EXPECT_SCOPED(client.AdvanceFrame()); 653 EXPECT_EQ(2, client_->num_draws());
621 client.task_runner().RunPendingTasks(); // Run posted deadline. 654 EXPECT_FALSE(scheduler_->RedrawPending());
622 EXPECT_EQ(2, client.num_draws()); 655 EXPECT_TRUE(client->needs_begin_frames());
623 EXPECT_FALSE(scheduler->RedrawPending());
624 EXPECT_TRUE(client.needs_begin_frames());
625 656
626 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't 657 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't
627 // swap. 658 // swap.
628 EXPECT_SCOPED(client.AdvanceFrame()); 659 EXPECT_SCOPED(AdvanceFrame());
629 client.task_runner().RunPendingTasks(); // Run posted deadline. 660 client->task_runner().RunPendingTasks(); // Run posted deadline.
630 EXPECT_EQ(2, client.num_draws()); 661 EXPECT_EQ(2, client->num_draws());
631 EXPECT_FALSE(scheduler->RedrawPending()); 662 EXPECT_FALSE(scheduler_->RedrawPending());
632 EXPECT_FALSE(client.needs_begin_frames()); 663 EXPECT_FALSE(client->needs_begin_frames());
633 } 664 }
634 665
635 // Test that requesting redraw inside a failed draw doesn't lose the request. 666 // Test that requesting redraw inside a failed draw doesn't lose the request.
636 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { 667 TEST_F(SchedulerTest, RequestRedrawInsideFailedDraw) {
637 SchedulerClientThatsetNeedsDrawInsideDraw client; 668 SchedulerClientThatsetNeedsDrawInsideDraw* client =
638 SchedulerSettings scheduler_settings; 669 new SchedulerClientThatsetNeedsDrawInsideDraw;
639 scheduler_settings.use_external_begin_frame_source = true; 670 scheduler_settings_.use_external_begin_frame_source = true;
671 SetUpScheduler(client, true);
640 672
641 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); 673 client->SetRequestRedrawsInsideDraw(true);
642 client.SetRequestRedrawsInsideDraw(true); 674 client->SetDrawWillHappen(false);
643 client.SetDrawWillHappen(false);
644 675
645 scheduler->SetNeedsRedraw(); 676 scheduler_->SetNeedsRedraw();
646 EXPECT_TRUE(scheduler->RedrawPending()); 677 EXPECT_TRUE(scheduler_->RedrawPending());
647 EXPECT_TRUE(client.needs_begin_frames()); 678 EXPECT_TRUE(client->needs_begin_frames());
648 EXPECT_EQ(0, client.num_draws()); 679 EXPECT_EQ(0, client->num_draws());
649 680
650 // Fail the draw. 681 // Fail the draw.
651 EXPECT_SCOPED(client.AdvanceFrame()); 682 EXPECT_SCOPED(AdvanceFrame());
652 client.task_runner().RunPendingTasks(); // Run posted deadline. 683 client->task_runner().RunPendingTasks(); // Run posted deadline.
653 EXPECT_EQ(1, client.num_draws()); 684 EXPECT_EQ(1, client->num_draws());
654 685
655 // We have a commit pending and the draw failed, and we didn't lose the redraw 686 // We have a commit pending and the draw failed, and we didn't lose the redraw
656 // request. 687 // request.
657 EXPECT_TRUE(scheduler->CommitPending()); 688 EXPECT_TRUE(scheduler_->CommitPending());
658 EXPECT_TRUE(scheduler->RedrawPending()); 689 EXPECT_TRUE(scheduler_->RedrawPending());
659 EXPECT_TRUE(client.needs_begin_frames()); 690 EXPECT_TRUE(client->needs_begin_frames());
660 691
661 client.SetRequestRedrawsInsideDraw(false); 692 client->SetRequestRedrawsInsideDraw(false);
662 693
663 // Fail the draw again. 694 // Fail the draw again.
664 EXPECT_SCOPED(client.AdvanceFrame()); 695 EXPECT_SCOPED(AdvanceFrame());
665 client.task_runner().RunPendingTasks(); // Run posted deadline. 696 client->task_runner().RunPendingTasks(); // Run posted deadline.
666 EXPECT_EQ(2, client.num_draws()); 697 EXPECT_EQ(2, client->num_draws());
667 EXPECT_TRUE(scheduler->CommitPending()); 698 EXPECT_TRUE(scheduler_->CommitPending());
668 EXPECT_TRUE(scheduler->RedrawPending()); 699 EXPECT_TRUE(scheduler_->RedrawPending());
669 EXPECT_TRUE(client.needs_begin_frames()); 700 EXPECT_TRUE(client->needs_begin_frames());
670 701
671 // Draw successfully. 702 // Draw successfully.
672 client.SetDrawWillHappen(true); 703 client->SetDrawWillHappen(true);
673 EXPECT_SCOPED(client.AdvanceFrame()); 704 EXPECT_SCOPED(AdvanceFrame());
674 client.task_runner().RunPendingTasks(); // Run posted deadline. 705 client->task_runner().RunPendingTasks(); // Run posted deadline.
675 EXPECT_EQ(3, client.num_draws()); 706 EXPECT_EQ(3, client->num_draws());
676 EXPECT_TRUE(scheduler->CommitPending()); 707 EXPECT_TRUE(scheduler_->CommitPending());
677 EXPECT_FALSE(scheduler->RedrawPending()); 708 EXPECT_FALSE(scheduler_->RedrawPending());
678 EXPECT_TRUE(client.needs_begin_frames()); 709 EXPECT_TRUE(client->needs_begin_frames());
679 } 710 }
680 711
681 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { 712 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient {
682 public: 713 public:
683 SchedulerClientThatSetNeedsCommitInsideDraw() 714 SchedulerClientThatSetNeedsCommitInsideDraw()
684 : set_needs_commit_on_next_draw_(false) {} 715 : set_needs_commit_on_next_draw_(false) {}
685 716
686 void ScheduledActionSendBeginMainFrame() override {} 717 void ScheduledActionSendBeginMainFrame() override {}
687 DrawResult ScheduledActionDrawAndSwapIfPossible() override { 718 DrawResult ScheduledActionDrawAndSwapIfPossible() override {
688 // Only SetNeedsCommit the first time this is called 719 // Only SetNeedsCommit the first time this is called
(...skipping 13 matching lines...) Expand all
702 void DidAnticipatedDrawTimeChange(base::TimeTicks) override {} 733 void DidAnticipatedDrawTimeChange(base::TimeTicks) override {}
703 734
704 void SetNeedsCommitOnNextDraw() { set_needs_commit_on_next_draw_ = true; } 735 void SetNeedsCommitOnNextDraw() { set_needs_commit_on_next_draw_ = true; }
705 736
706 private: 737 private:
707 bool set_needs_commit_on_next_draw_; 738 bool set_needs_commit_on_next_draw_;
708 }; 739 };
709 740
710 // Tests for the scheduler infinite-looping on SetNeedsCommit requests that 741 // Tests for the scheduler infinite-looping on SetNeedsCommit requests that
711 // happen inside a ScheduledActionDrawAndSwap 742 // happen inside a ScheduledActionDrawAndSwap
712 TEST(SchedulerTest, RequestCommitInsideDraw) { 743 TEST_F(SchedulerTest, RequestCommitInsideDraw) {
713 SchedulerClientThatSetNeedsCommitInsideDraw client; 744 SchedulerClientThatSetNeedsCommitInsideDraw* client =
714 SchedulerSettings scheduler_settings; 745 new SchedulerClientThatSetNeedsCommitInsideDraw;
715 scheduler_settings.use_external_begin_frame_source = true;
716 746
717 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); 747 scheduler_settings_.use_external_begin_frame_source = true;
748 SetUpScheduler(client, true);
718 749
719 EXPECT_FALSE(client.needs_begin_frames()); 750 EXPECT_FALSE(client->needs_begin_frames());
720 scheduler->SetNeedsRedraw(); 751 scheduler_->SetNeedsRedraw();
721 EXPECT_TRUE(scheduler->RedrawPending()); 752 EXPECT_TRUE(scheduler_->RedrawPending());
722 EXPECT_EQ(0, client.num_draws()); 753 EXPECT_EQ(0, client->num_draws());
723 EXPECT_TRUE(client.needs_begin_frames()); 754 EXPECT_TRUE(client->needs_begin_frames());
724 755
725 client.SetNeedsCommitOnNextDraw(); 756 client->SetNeedsCommitOnNextDraw();
726 EXPECT_SCOPED(client.AdvanceFrame()); 757 EXPECT_SCOPED(AdvanceFrame());
727 client.SetNeedsCommitOnNextDraw(); 758 client->SetNeedsCommitOnNextDraw();
728 client.task_runner().RunPendingTasks(); // Run posted deadline. 759 client->task_runner().RunPendingTasks(); // Run posted deadline.
729 EXPECT_EQ(1, client.num_draws()); 760 EXPECT_EQ(1, client->num_draws());
730 EXPECT_TRUE(scheduler->CommitPending()); 761 EXPECT_TRUE(scheduler_->CommitPending());
731 EXPECT_TRUE(client.needs_begin_frames()); 762 EXPECT_TRUE(client->needs_begin_frames());
732 scheduler->NotifyBeginMainFrameStarted(); 763 scheduler_->NotifyBeginMainFrameStarted();
733 scheduler->NotifyReadyToCommit(); 764 scheduler_->NotifyReadyToCommit();
734 765
735 EXPECT_SCOPED(client.AdvanceFrame()); 766 EXPECT_SCOPED(AdvanceFrame());
736 client.task_runner().RunPendingTasks(); // Run posted deadline. 767 client->task_runner().RunPendingTasks(); // Run posted deadline.
737 EXPECT_EQ(2, client.num_draws()); 768 EXPECT_EQ(2, client->num_draws());
738 769
739 EXPECT_FALSE(scheduler->RedrawPending()); 770 EXPECT_FALSE(scheduler_->RedrawPending());
740 EXPECT_FALSE(scheduler->CommitPending()); 771 EXPECT_FALSE(scheduler_->CommitPending());
741 EXPECT_TRUE(client.needs_begin_frames()); 772 EXPECT_TRUE(client->needs_begin_frames());
742 773
743 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't 774 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't
744 // swap. 775 // swap.
745 EXPECT_SCOPED(client.AdvanceFrame()); 776 EXPECT_SCOPED(AdvanceFrame());
746 client.task_runner().RunPendingTasks(); // Run posted deadline. 777 client->task_runner().RunPendingTasks(); // Run posted deadline.
747 EXPECT_EQ(2, client.num_draws()); 778 EXPECT_EQ(2, client->num_draws());
748 EXPECT_FALSE(scheduler->RedrawPending()); 779 EXPECT_FALSE(scheduler_->RedrawPending());
749 EXPECT_FALSE(scheduler->CommitPending()); 780 EXPECT_FALSE(scheduler_->CommitPending());
750 EXPECT_FALSE(client.needs_begin_frames()); 781 EXPECT_FALSE(client->needs_begin_frames());
751 } 782 }
752 783
753 // Tests that when a draw fails then the pending commit should not be dropped. 784 // Tests that when a draw fails then the pending commit should not be dropped.
754 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { 785 TEST_F(SchedulerTest, RequestCommitInsideFailedDraw) {
755 SchedulerClientThatsetNeedsDrawInsideDraw client; 786 SchedulerClientThatsetNeedsDrawInsideDraw* client =
756 SchedulerSettings scheduler_settings; 787 new SchedulerClientThatsetNeedsDrawInsideDraw;
757 scheduler_settings.use_external_begin_frame_source = true; 788 scheduler_settings_.use_external_begin_frame_source = true;
789 SetUpScheduler(client, true);
758 790
759 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); 791 client->SetDrawWillHappen(false);
760 792
761 client.SetDrawWillHappen(false); 793 scheduler_->SetNeedsRedraw();
762 794 EXPECT_TRUE(scheduler_->RedrawPending());
763 scheduler->SetNeedsRedraw(); 795 EXPECT_TRUE(client->needs_begin_frames());
764 EXPECT_TRUE(scheduler->RedrawPending()); 796 EXPECT_EQ(0, client->num_draws());
765 EXPECT_TRUE(client.needs_begin_frames());
766 EXPECT_EQ(0, client.num_draws());
767 797
768 // Fail the draw. 798 // Fail the draw.
769 EXPECT_SCOPED(client.AdvanceFrame()); 799 EXPECT_SCOPED(AdvanceFrame());
770 client.task_runner().RunPendingTasks(); // Run posted deadline. 800 client->task_runner().RunPendingTasks(); // Run posted deadline.
771 EXPECT_EQ(1, client.num_draws()); 801 EXPECT_EQ(1, client->num_draws());
772 802
773 // We have a commit pending and the draw failed, and we didn't lose the commit 803 // We have a commit pending and the draw failed, and we didn't lose the commit
774 // request. 804 // request.
775 EXPECT_TRUE(scheduler->CommitPending()); 805 EXPECT_TRUE(scheduler_->CommitPending());
776 EXPECT_TRUE(scheduler->RedrawPending()); 806 EXPECT_TRUE(scheduler_->RedrawPending());
777 EXPECT_TRUE(client.needs_begin_frames()); 807 EXPECT_TRUE(client->needs_begin_frames());
778 808
779 // Fail the draw again. 809 // Fail the draw again.
780 EXPECT_SCOPED(client.AdvanceFrame()); 810 EXPECT_SCOPED(AdvanceFrame());
781 811
782 client.task_runner().RunPendingTasks(); // Run posted deadline. 812 client->task_runner().RunPendingTasks(); // Run posted deadline.
783 EXPECT_EQ(2, client.num_draws()); 813 EXPECT_EQ(2, client->num_draws());
784 EXPECT_TRUE(scheduler->CommitPending()); 814 EXPECT_TRUE(scheduler_->CommitPending());
785 EXPECT_TRUE(scheduler->RedrawPending()); 815 EXPECT_TRUE(scheduler_->RedrawPending());
786 EXPECT_TRUE(client.needs_begin_frames()); 816 EXPECT_TRUE(client->needs_begin_frames());
787 817
788 // Draw successfully. 818 // Draw successfully.
789 client.SetDrawWillHappen(true); 819 client->SetDrawWillHappen(true);
790 EXPECT_SCOPED(client.AdvanceFrame()); 820 EXPECT_SCOPED(AdvanceFrame());
791 client.task_runner().RunPendingTasks(); // Run posted deadline. 821 client->task_runner().RunPendingTasks(); // Run posted deadline.
792 EXPECT_EQ(3, client.num_draws()); 822 EXPECT_EQ(3, client->num_draws());
793 EXPECT_TRUE(scheduler->CommitPending()); 823 EXPECT_TRUE(scheduler_->CommitPending());
794 EXPECT_FALSE(scheduler->RedrawPending()); 824 EXPECT_FALSE(scheduler_->RedrawPending());
795 EXPECT_TRUE(client.needs_begin_frames()); 825 EXPECT_TRUE(client->needs_begin_frames());
796 } 826 }
797 827
798 TEST(SchedulerTest, NoSwapWhenDrawFails) { 828 TEST_F(SchedulerTest, NoSwapWhenDrawFails) {
799 SchedulerClientThatSetNeedsCommitInsideDraw client; 829 SchedulerClientThatSetNeedsCommitInsideDraw* client =
800 SchedulerSettings scheduler_settings; 830 new SchedulerClientThatSetNeedsCommitInsideDraw;
801 scheduler_settings.use_external_begin_frame_source = true; 831 scheduler_settings_.use_external_begin_frame_source = true;
832 SetUpScheduler(client, true);
802 833
803 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); 834 scheduler_->SetNeedsRedraw();
804 835 EXPECT_TRUE(scheduler_->RedrawPending());
805 scheduler->SetNeedsRedraw(); 836 EXPECT_TRUE(client->needs_begin_frames());
806 EXPECT_TRUE(scheduler->RedrawPending()); 837 EXPECT_EQ(0, client->num_draws());
807 EXPECT_TRUE(client.needs_begin_frames());
808 EXPECT_EQ(0, client.num_draws());
809 838
810 // Draw successfully, this starts a new frame. 839 // Draw successfully, this starts a new frame.
811 client.SetNeedsCommitOnNextDraw(); 840 client->SetNeedsCommitOnNextDraw();
812 EXPECT_SCOPED(client.AdvanceFrame()); 841 EXPECT_SCOPED(AdvanceFrame());
813 client.task_runner().RunPendingTasks(); // Run posted deadline. 842 client->task_runner().RunPendingTasks(); // Run posted deadline.
814 EXPECT_EQ(1, client.num_draws()); 843 EXPECT_EQ(1, client->num_draws());
815 844
816 scheduler->SetNeedsRedraw(); 845 scheduler_->SetNeedsRedraw();
817 EXPECT_TRUE(scheduler->RedrawPending()); 846 EXPECT_TRUE(scheduler_->RedrawPending());
818 EXPECT_TRUE(client.needs_begin_frames()); 847 EXPECT_TRUE(client->needs_begin_frames());
819 848
820 // Fail to draw, this should not start a frame. 849 // Fail to draw, this should not start a frame.
821 client.SetDrawWillHappen(false); 850 client->SetDrawWillHappen(false);
822 client.SetNeedsCommitOnNextDraw(); 851 client->SetNeedsCommitOnNextDraw();
823 EXPECT_SCOPED(client.AdvanceFrame()); 852 EXPECT_SCOPED(AdvanceFrame());
824 client.task_runner().RunPendingTasks(); // Run posted deadline. 853 client->task_runner().RunPendingTasks(); // Run posted deadline.
825 EXPECT_EQ(2, client.num_draws()); 854 EXPECT_EQ(2, client->num_draws());
826 } 855 }
827 856
828 class SchedulerClientNeedsPrepareTilesInDraw : public FakeSchedulerClient { 857 class SchedulerClientNeedsPrepareTilesInDraw : public FakeSchedulerClient {
829 public: 858 public:
830 DrawResult ScheduledActionDrawAndSwapIfPossible() override { 859 DrawResult ScheduledActionDrawAndSwapIfPossible() override {
831 scheduler_->SetNeedsPrepareTiles(); 860 scheduler_->SetNeedsPrepareTiles();
832 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); 861 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible();
833 } 862 }
834 }; 863 };
835 864
836 // Test prepare tiles is independant of draws. 865 // Test prepare tiles is independant of draws.
837 TEST(SchedulerTest, PrepareTiles) { 866 TEST_F(SchedulerTest, PrepareTiles) {
838 SchedulerClientNeedsPrepareTilesInDraw client; 867 SchedulerClientNeedsPrepareTilesInDraw* client =
839 SchedulerSettings scheduler_settings; 868 new SchedulerClientNeedsPrepareTilesInDraw;
840 scheduler_settings.use_external_begin_frame_source = true; 869 scheduler_settings_.use_external_begin_frame_source = true;
841 870 SetUpScheduler(client, true);
842 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings);
843 871
844 // Request both draw and prepare tiles. PrepareTiles shouldn't 872 // Request both draw and prepare tiles. PrepareTiles shouldn't
845 // be trigged until BeginImplFrame. 873 // be trigged until BeginImplFrame.
846 client.Reset(); 874 client->Reset();
847 scheduler->SetNeedsPrepareTiles(); 875 scheduler_->SetNeedsPrepareTiles();
848 scheduler->SetNeedsRedraw(); 876 scheduler_->SetNeedsRedraw();
849 EXPECT_TRUE(scheduler->RedrawPending()); 877 EXPECT_TRUE(scheduler_->RedrawPending());
850 EXPECT_TRUE(scheduler->PrepareTilesPending()); 878 EXPECT_TRUE(scheduler_->PrepareTilesPending());
851 EXPECT_TRUE(client.needs_begin_frames()); 879 EXPECT_TRUE(client->needs_begin_frames());
852 EXPECT_EQ(0, client.num_draws()); 880 EXPECT_EQ(0, client->num_draws());
853 EXPECT_FALSE(client.HasAction("ScheduledActionPrepareTiles")); 881 EXPECT_FALSE(client->HasAction("ScheduledActionPrepareTiles"));
854 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 882 EXPECT_FALSE(client->HasAction("ScheduledActionDrawAndSwapIfPossible"));
855 883
856 // We have no immediate actions to perform, so the BeginImplFrame should post 884 // We have no immediate actions to perform, so the BeginImplFrame should post
857 // the deadline task. 885 // the deadline task.
858 client.Reset(); 886 client->Reset();
859 EXPECT_SCOPED(client.AdvanceFrame()); 887 EXPECT_SCOPED(AdvanceFrame());
860 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 888 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
861 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 889 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2);
862 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 890 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
863 891
864 // On the deadline, he actions should have occured in the right order. 892 // On the deadline, he actions should have occured in the right order.
865 client.Reset(); 893 client->Reset();
866 client.task_runner().RunPendingTasks(); // Run posted deadline. 894 client->task_runner().RunPendingTasks(); // Run posted deadline.
867 EXPECT_EQ(1, client.num_draws()); 895 EXPECT_EQ(1, client->num_draws());
868 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 896 EXPECT_TRUE(client->HasAction("ScheduledActionDrawAndSwapIfPossible"));
869 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); 897 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles"));
870 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), 898 EXPECT_LT(client->ActionIndex("ScheduledActionDrawAndSwapIfPossible"),
871 client.ActionIndex("ScheduledActionPrepareTiles")); 899 client->ActionIndex("ScheduledActionPrepareTiles"));
872 EXPECT_FALSE(scheduler->RedrawPending()); 900 EXPECT_FALSE(scheduler_->RedrawPending());
873 EXPECT_FALSE(scheduler->PrepareTilesPending()); 901 EXPECT_FALSE(scheduler_->PrepareTilesPending());
874 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 902 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
875 903
876 // Request a draw. We don't need a PrepareTiles yet. 904 // Request a draw. We don't need a PrepareTiles yet.
877 client.Reset(); 905 client->Reset();
878 scheduler->SetNeedsRedraw(); 906 scheduler_->SetNeedsRedraw();
879 EXPECT_TRUE(scheduler->RedrawPending()); 907 EXPECT_TRUE(scheduler_->RedrawPending());
880 EXPECT_FALSE(scheduler->PrepareTilesPending()); 908 EXPECT_FALSE(scheduler_->PrepareTilesPending());
881 EXPECT_TRUE(client.needs_begin_frames()); 909 EXPECT_TRUE(client->needs_begin_frames());
882 EXPECT_EQ(0, client.num_draws()); 910 EXPECT_EQ(0, client->num_draws());
883 911
884 // We have no immediate actions to perform, so the BeginImplFrame should post 912 // We have no immediate actions to perform, so the BeginImplFrame should post
885 // the deadline task. 913 // the deadline task.
886 client.Reset(); 914 client->Reset();
887 EXPECT_SCOPED(client.AdvanceFrame()); 915 EXPECT_SCOPED(AdvanceFrame());
888 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 916 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
889 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 917 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2);
890 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 918 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
891 919
892 // Draw. The draw will trigger SetNeedsPrepareTiles, and 920 // Draw. The draw will trigger SetNeedsPrepareTiles, and
893 // then the PrepareTiles action will be triggered after the Draw. 921 // then the PrepareTiles action will be triggered after the Draw.
894 // Afterwards, neither a draw nor PrepareTiles are pending. 922 // Afterwards, neither a draw nor PrepareTiles are pending.
895 client.Reset(); 923 client->Reset();
896 client.task_runner().RunPendingTasks(); // Run posted deadline. 924 client->task_runner().RunPendingTasks(); // Run posted deadline.
897 EXPECT_EQ(1, client.num_draws()); 925 EXPECT_EQ(1, client->num_draws());
898 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 926 EXPECT_TRUE(client->HasAction("ScheduledActionDrawAndSwapIfPossible"));
899 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); 927 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles"));
900 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), 928 EXPECT_LT(client->ActionIndex("ScheduledActionDrawAndSwapIfPossible"),
901 client.ActionIndex("ScheduledActionPrepareTiles")); 929 client->ActionIndex("ScheduledActionPrepareTiles"));
902 EXPECT_FALSE(scheduler->RedrawPending()); 930 EXPECT_FALSE(scheduler_->RedrawPending());
903 EXPECT_FALSE(scheduler->PrepareTilesPending()); 931 EXPECT_FALSE(scheduler_->PrepareTilesPending());
904 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 932 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
905 933
906 // We need a BeginImplFrame where we don't swap to go idle. 934 // We need a BeginImplFrame where we don't swap to go idle.
907 client.Reset(); 935 client->Reset();
908 EXPECT_SCOPED(client.AdvanceFrame()); 936 EXPECT_SCOPED(AdvanceFrame());
909 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); 937 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
910 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 938 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
911 client.Reset(); 939 client->Reset();
912 client.task_runner().RunPendingTasks(); // Run posted deadline. 940 client->task_runner().RunPendingTasks(); // Run posted deadline.
913 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); 941 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client);
914 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 942 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
915 EXPECT_EQ(0, client.num_draws()); 943 EXPECT_EQ(0, client->num_draws());
916 944
917 // Now trigger a PrepareTiles outside of a draw. We will then need 945 // Now trigger a PrepareTiles outside of a draw. We will then need
918 // a begin-frame for the PrepareTiles, but we don't need a draw. 946 // a begin-frame for the PrepareTiles, but we don't need a draw.
919 client.Reset(); 947 client->Reset();
920 EXPECT_FALSE(client.needs_begin_frames()); 948 EXPECT_FALSE(client->needs_begin_frames());
921 scheduler->SetNeedsPrepareTiles(); 949 scheduler_->SetNeedsPrepareTiles();
922 EXPECT_TRUE(client.needs_begin_frames()); 950 EXPECT_TRUE(client->needs_begin_frames());
923 EXPECT_TRUE(scheduler->PrepareTilesPending()); 951 EXPECT_TRUE(scheduler_->PrepareTilesPending());
924 EXPECT_FALSE(scheduler->RedrawPending()); 952 EXPECT_FALSE(scheduler_->RedrawPending());
925 953
926 // BeginImplFrame. There will be no draw, only PrepareTiles. 954 // BeginImplFrame. There will be no draw, only PrepareTiles.
927 client.Reset(); 955 client->Reset();
928 EXPECT_SCOPED(client.AdvanceFrame()); 956 EXPECT_SCOPED(AdvanceFrame());
929 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); 957 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
930 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 958 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
931 client.Reset(); 959 client->Reset();
932 client.task_runner().RunPendingTasks(); // Run posted deadline. 960 client->task_runner().RunPendingTasks(); // Run posted deadline.
933 EXPECT_EQ(0, client.num_draws()); 961 EXPECT_EQ(0, client->num_draws());
934 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 962 EXPECT_FALSE(client->HasAction("ScheduledActionDrawAndSwapIfPossible"));
935 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); 963 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles"));
936 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 964 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
937 } 965 }
938 966
939 // Test that PrepareTiles only happens once per frame. If an external caller 967 // Test that PrepareTiles only happens once per frame. If an external caller
940 // initiates it, then the state machine should not PrepareTiles on that frame. 968 // initiates it, then the state machine should not PrepareTiles on that frame.
941 TEST(SchedulerTest, PrepareTilesOncePerFrame) { 969 TEST_F(SchedulerTest, PrepareTilesOncePerFrame) {
942 FakeSchedulerClient client; 970 scheduler_settings_.use_external_begin_frame_source = true;
943 SchedulerSettings scheduler_settings; 971 SetUpScheduler(true);
944 scheduler_settings.use_external_begin_frame_source = true;
945
946 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings);
947 972
948 // If DidPrepareTiles during a frame, then PrepareTiles should not occur 973 // If DidPrepareTiles during a frame, then PrepareTiles should not occur
949 // again. 974 // again.
950 scheduler->SetNeedsPrepareTiles(); 975 scheduler_->SetNeedsPrepareTiles();
951 scheduler->SetNeedsRedraw(); 976 scheduler_->SetNeedsRedraw();
952 client.Reset(); 977 client_->Reset();
953 EXPECT_SCOPED(client.AdvanceFrame()); 978 EXPECT_SCOPED(AdvanceFrame());
954 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 979 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
955 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 980 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2);
956 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 981 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
957 982
958 EXPECT_TRUE(scheduler->PrepareTilesPending()); 983 EXPECT_TRUE(scheduler_->PrepareTilesPending());
959 scheduler->DidPrepareTiles(); // An explicit PrepareTiles. 984 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles.
960 EXPECT_FALSE(scheduler->PrepareTilesPending()); 985 EXPECT_FALSE(scheduler_->PrepareTilesPending());
961 986
962 client.Reset(); 987 client_->Reset();
963 client.task_runner().RunPendingTasks(); // Run posted deadline. 988 client_->task_runner().RunPendingTasks(); // Run posted deadline.
964 EXPECT_EQ(1, client.num_draws()); 989 EXPECT_EQ(1, client_->num_draws());
965 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 990 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible"));
966 EXPECT_FALSE(client.HasAction("ScheduledActionPrepareTiles")); 991 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles"));
967 EXPECT_FALSE(scheduler->RedrawPending()); 992 EXPECT_FALSE(scheduler_->RedrawPending());
968 EXPECT_FALSE(scheduler->PrepareTilesPending()); 993 EXPECT_FALSE(scheduler_->PrepareTilesPending());
969 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 994 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
970 995
971 // Next frame without DidPrepareTiles should PrepareTiles with draw. 996 // Next frame without DidPrepareTiles should PrepareTiles with draw.
972 scheduler->SetNeedsPrepareTiles(); 997 scheduler_->SetNeedsPrepareTiles();
973 scheduler->SetNeedsRedraw(); 998 scheduler_->SetNeedsRedraw();
974 client.Reset(); 999 client_->Reset();
975 EXPECT_SCOPED(client.AdvanceFrame()); 1000 EXPECT_SCOPED(AdvanceFrame());
976 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1001 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
977 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 1002 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2);
978 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1003 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
979 1004
980 client.Reset(); 1005 client_->Reset();
981 client.task_runner().RunPendingTasks(); // Run posted deadline. 1006 client_->task_runner().RunPendingTasks(); // Run posted deadline.
982 EXPECT_EQ(1, client.num_draws()); 1007 EXPECT_EQ(1, client_->num_draws());
983 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 1008 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible"));
984 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); 1009 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles"));
985 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), 1010 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawAndSwapIfPossible"),
986 client.ActionIndex("ScheduledActionPrepareTiles")); 1011 client_->ActionIndex("ScheduledActionPrepareTiles"));
987 EXPECT_FALSE(scheduler->RedrawPending()); 1012 EXPECT_FALSE(scheduler_->RedrawPending());
988 EXPECT_FALSE(scheduler->PrepareTilesPending()); 1013 EXPECT_FALSE(scheduler_->PrepareTilesPending());
989 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1014 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
990 scheduler->DidPrepareTiles(); // Corresponds to ScheduledActionPrepareTiles 1015 scheduler_->DidPrepareTiles(); // Corresponds to ScheduledActionPrepareTiles
991 1016
992 // If we get another DidPrepareTiles within the same frame, we should 1017 // If we get another DidPrepareTiles within the same frame, we should
993 // not PrepareTiles on the next frame. 1018 // not PrepareTiles on the next frame.
994 scheduler->DidPrepareTiles(); // An explicit PrepareTiles. 1019 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles.
995 scheduler->SetNeedsPrepareTiles(); 1020 scheduler_->SetNeedsPrepareTiles();
996 scheduler->SetNeedsRedraw(); 1021 scheduler_->SetNeedsRedraw();
997 client.Reset(); 1022 client_->Reset();
998 EXPECT_SCOPED(client.AdvanceFrame()); 1023 EXPECT_SCOPED(AdvanceFrame());
999 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1024 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1000 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 1025 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2);
1001 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1026 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1002 1027
1003 EXPECT_TRUE(scheduler->PrepareTilesPending()); 1028 EXPECT_TRUE(scheduler_->PrepareTilesPending());
1004 1029
1005 client.Reset(); 1030 client_->Reset();
1006 client.task_runner().RunPendingTasks(); // Run posted deadline. 1031 client_->task_runner().RunPendingTasks(); // Run posted deadline.
1007 EXPECT_EQ(1, client.num_draws()); 1032 EXPECT_EQ(1, client_->num_draws());
1008 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 1033 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible"));
1009 EXPECT_FALSE(client.HasAction("ScheduledActionPrepareTiles")); 1034 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles"));
1010 EXPECT_FALSE(scheduler->RedrawPending()); 1035 EXPECT_FALSE(scheduler_->RedrawPending());
1011 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1036 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
1012 1037
1013 // If we get another DidPrepareTiles, we should not PrepareTiles on the next 1038 // If we get another DidPrepareTiles, we should not PrepareTiles on the next
1014 // frame. This verifies we don't alternate calling PrepareTiles once and 1039 // frame. This verifies we don't alternate calling PrepareTiles once and
1015 // twice. 1040 // twice.
1016 EXPECT_TRUE(scheduler->PrepareTilesPending()); 1041 EXPECT_TRUE(scheduler_->PrepareTilesPending());
1017 scheduler->DidPrepareTiles(); // An explicit PrepareTiles. 1042 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles.
1018 EXPECT_FALSE(scheduler->PrepareTilesPending()); 1043 EXPECT_FALSE(scheduler_->PrepareTilesPending());
1019 scheduler->SetNeedsPrepareTiles(); 1044 scheduler_->SetNeedsPrepareTiles();
1020 scheduler->SetNeedsRedraw(); 1045 scheduler_->SetNeedsRedraw();
1021 client.Reset(); 1046 client_->Reset();
1022 EXPECT_SCOPED(client.AdvanceFrame()); 1047 EXPECT_SCOPED(AdvanceFrame());
1023 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1048 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1024 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 1049 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2);
1025 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1050 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1026 1051
1027 EXPECT_TRUE(scheduler->PrepareTilesPending()); 1052 EXPECT_TRUE(scheduler_->PrepareTilesPending());
1028 1053
1029 client.Reset(); 1054 client_->Reset();
1030 client.task_runner().RunPendingTasks(); // Run posted deadline. 1055 client_->task_runner().RunPendingTasks(); // Run posted deadline.
1031 EXPECT_EQ(1, client.num_draws()); 1056 EXPECT_EQ(1, client_->num_draws());
1032 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 1057 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible"));
1033 EXPECT_FALSE(client.HasAction("ScheduledActionPrepareTiles")); 1058 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles"));
1034 EXPECT_FALSE(scheduler->RedrawPending()); 1059 EXPECT_FALSE(scheduler_->RedrawPending());
1035 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1060 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
1036 1061
1037 // Next frame without DidPrepareTiles should PrepareTiles with draw. 1062 // Next frame without DidPrepareTiles should PrepareTiles with draw.
1038 scheduler->SetNeedsPrepareTiles(); 1063 scheduler_->SetNeedsPrepareTiles();
1039 scheduler->SetNeedsRedraw(); 1064 scheduler_->SetNeedsRedraw();
1040 client.Reset(); 1065 client_->Reset();
1041 EXPECT_SCOPED(client.AdvanceFrame()); 1066 EXPECT_SCOPED(AdvanceFrame());
1042 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1067 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1043 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 1068 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2);
1044 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1069 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1045 1070
1046 client.Reset(); 1071 client_->Reset();
1047 client.task_runner().RunPendingTasks(); // Run posted deadline. 1072 client_->task_runner().RunPendingTasks(); // Run posted deadline.
1048 EXPECT_EQ(1, client.num_draws()); 1073 EXPECT_EQ(1, client_->num_draws());
1049 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 1074 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible"));
1050 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); 1075 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles"));
1051 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), 1076 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawAndSwapIfPossible"),
1052 client.ActionIndex("ScheduledActionPrepareTiles")); 1077 client_->ActionIndex("ScheduledActionPrepareTiles"));
1053 EXPECT_FALSE(scheduler->RedrawPending()); 1078 EXPECT_FALSE(scheduler_->RedrawPending());
1054 EXPECT_FALSE(scheduler->PrepareTilesPending()); 1079 EXPECT_FALSE(scheduler_->PrepareTilesPending());
1055 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1080 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
1056 scheduler->DidPrepareTiles(); // Corresponds to ScheduledActionPrepareTiles 1081 scheduler_->DidPrepareTiles(); // Corresponds to ScheduledActionPrepareTiles
1057 } 1082 }
1058 1083
1059 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { 1084 TEST_F(SchedulerTest, TriggerBeginFrameDeadlineEarly) {
1060 SchedulerClientNeedsPrepareTilesInDraw client; 1085 SchedulerClientNeedsPrepareTilesInDraw* client =
1061 SchedulerSettings scheduler_settings; 1086 new SchedulerClientNeedsPrepareTilesInDraw;
1062 scheduler_settings.use_external_begin_frame_source = true; 1087 scheduler_settings_.use_external_begin_frame_source = true;
1063 1088 SetUpScheduler(client, true);
1064 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); 1089
1065 1090 scheduler_->SetNeedsRedraw();
1066 scheduler->SetNeedsRedraw(); 1091 EXPECT_SCOPED(AdvanceFrame());
1067 EXPECT_SCOPED(client.AdvanceFrame());
1068 1092
1069 // The deadline should be zero since there is no work other than drawing 1093 // The deadline should be zero since there is no work other than drawing
1070 // pending. 1094 // pending.
1071 EXPECT_EQ(base::TimeTicks(), client.posted_begin_impl_frame_deadline()); 1095 EXPECT_EQ(base::TimeTicks(), client->posted_begin_impl_frame_deadline());
1072 } 1096 }
1073 1097
1074 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { 1098 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient {
1075 public: 1099 public:
1076 SchedulerClientWithFixedEstimates( 1100 SchedulerClientWithFixedEstimates(
1077 base::TimeDelta draw_duration, 1101 base::TimeDelta draw_duration,
1078 base::TimeDelta begin_main_frame_to_commit_duration, 1102 base::TimeDelta begin_main_frame_to_commit_duration,
1079 base::TimeDelta commit_to_activate_duration) 1103 base::TimeDelta commit_to_activate_duration)
1080 : draw_duration_(draw_duration), 1104 : draw_duration_(draw_duration),
1081 begin_main_frame_to_commit_duration_( 1105 begin_main_frame_to_commit_duration_(
1082 begin_main_frame_to_commit_duration), 1106 begin_main_frame_to_commit_duration),
1083 commit_to_activate_duration_(commit_to_activate_duration) {} 1107 commit_to_activate_duration_(commit_to_activate_duration) {}
1084 1108
1085 base::TimeDelta DrawDurationEstimate() override { return draw_duration_; } 1109 base::TimeDelta DrawDurationEstimate() override { return draw_duration_; }
1086 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override { 1110 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override {
1087 return begin_main_frame_to_commit_duration_; 1111 return begin_main_frame_to_commit_duration_;
1088 } 1112 }
1089 base::TimeDelta CommitToActivateDurationEstimate() override { 1113 base::TimeDelta CommitToActivateDurationEstimate() override {
1090 return commit_to_activate_duration_; 1114 return commit_to_activate_duration_;
1091 } 1115 }
1092 1116
1093 private: 1117 private:
1094 base::TimeDelta draw_duration_; 1118 base::TimeDelta draw_duration_;
1095 base::TimeDelta begin_main_frame_to_commit_duration_; 1119 base::TimeDelta begin_main_frame_to_commit_duration_;
1096 base::TimeDelta commit_to_activate_duration_; 1120 base::TimeDelta commit_to_activate_duration_;
1097 }; 1121 };
1098 1122
1099 void MainFrameInHighLatencyMode(int64 begin_main_frame_to_commit_estimate_in_ms, 1123 void SchedulerTest::MainFrameInHighLatencyMode(
1100 int64 commit_to_activate_estimate_in_ms, 1124 int64 begin_main_frame_to_commit_estimate_in_ms,
1101 bool impl_latency_takes_priority, 1125 int64 commit_to_activate_estimate_in_ms,
1102 bool should_send_begin_main_frame) { 1126 bool impl_latency_takes_priority,
1127 bool should_send_begin_main_frame) {
1103 // Set up client with specified estimates (draw duration is set to 1). 1128 // Set up client with specified estimates (draw duration is set to 1).
1104 SchedulerClientWithFixedEstimates client( 1129 SchedulerClientWithFixedEstimates* client =
1105 base::TimeDelta::FromMilliseconds(1), 1130 new SchedulerClientWithFixedEstimates(
1106 base::TimeDelta::FromMilliseconds( 1131 base::TimeDelta::FromMilliseconds(1),
1107 begin_main_frame_to_commit_estimate_in_ms), 1132 base::TimeDelta::FromMilliseconds(
1108 base::TimeDelta::FromMilliseconds(commit_to_activate_estimate_in_ms)); 1133 begin_main_frame_to_commit_estimate_in_ms),
1109 SchedulerSettings scheduler_settings; 1134 base::TimeDelta::FromMilliseconds(commit_to_activate_estimate_in_ms));
1110 scheduler_settings.use_external_begin_frame_source = true; 1135
1111 1136 scheduler_settings_.use_external_begin_frame_source = true;
1112 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); 1137 SetUpScheduler(client, true);
1113 1138
1114 scheduler->SetImplLatencyTakesPriority(impl_latency_takes_priority); 1139 scheduler_->SetImplLatencyTakesPriority(impl_latency_takes_priority);
1115 1140
1116 // Impl thread hits deadline before commit finishes. 1141 // Impl thread hits deadline before commit finishes.
1117 scheduler->SetNeedsCommit(); 1142 scheduler_->SetNeedsCommit();
1118 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); 1143 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode());
1119 EXPECT_SCOPED(client.AdvanceFrame()); 1144 EXPECT_SCOPED(AdvanceFrame());
1120 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); 1145 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode());
1121 client.task_runner().RunPendingTasks(); // Run posted deadline. 1146 client->task_runner().RunPendingTasks(); // Run posted deadline.
1122 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); 1147 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode());
1123 scheduler->NotifyBeginMainFrameStarted(); 1148 scheduler_->NotifyBeginMainFrameStarted();
1124 scheduler->NotifyReadyToCommit(); 1149 scheduler_->NotifyReadyToCommit();
1125 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); 1150 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode());
1126 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame")); 1151 EXPECT_TRUE(client->HasAction("ScheduledActionSendBeginMainFrame"));
1127 1152
1128 client.Reset(); 1153 client->Reset();
1129 scheduler->SetNeedsCommit(); 1154 scheduler_->SetNeedsCommit();
1130 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); 1155 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode());
1131 EXPECT_SCOPED(client.AdvanceFrame()); 1156 EXPECT_SCOPED(AdvanceFrame());
1132 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); 1157 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode());
1133 client.task_runner().RunPendingTasks(); // Run posted deadline. 1158 client->task_runner().RunPendingTasks(); // Run posted deadline.
1134 EXPECT_EQ(scheduler->MainThreadIsInHighLatencyMode(), 1159 EXPECT_EQ(scheduler_->MainThreadIsInHighLatencyMode(),
1135 should_send_begin_main_frame); 1160 should_send_begin_main_frame);
1136 EXPECT_EQ(client.HasAction("ScheduledActionSendBeginMainFrame"), 1161 EXPECT_EQ(client->HasAction("ScheduledActionSendBeginMainFrame"),
1137 should_send_begin_main_frame); 1162 should_send_begin_main_frame);
1138 } 1163 }
1139 1164
1140 TEST(SchedulerTest, 1165 TEST_F(SchedulerTest,
1141 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { 1166 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) {
1142 // Set up client so that estimates indicate that we can commit and activate 1167 // Set up client so that estimates indicate that we can commit and activate
1143 // before the deadline (~8ms by default). 1168 // before the deadline (~8ms by default).
1144 MainFrameInHighLatencyMode(1, 1, false, false); 1169 MainFrameInHighLatencyMode(1, 1, false, false);
1145 } 1170 }
1146 1171
1147 TEST(SchedulerTest, NotSkipMainFrameIfHighLatencyAndCanCommitTooLong) { 1172 TEST_F(SchedulerTest, NotSkipMainFrameIfHighLatencyAndCanCommitTooLong) {
1148 // Set up client so that estimates indicate that the commit cannot finish 1173 // Set up client so that estimates indicate that the commit cannot finish
1149 // before the deadline (~8ms by default). 1174 // before the deadline (~8ms by default).
1150 MainFrameInHighLatencyMode(10, 1, false, true); 1175 MainFrameInHighLatencyMode(10, 1, false, true);
1151 } 1176 }
1152 1177
1153 TEST(SchedulerTest, NotSkipMainFrameIfHighLatencyAndCanActivateTooLong) { 1178 TEST_F(SchedulerTest, NotSkipMainFrameIfHighLatencyAndCanActivateTooLong) {
1154 // Set up client so that estimates indicate that the activate cannot finish 1179 // Set up client so that estimates indicate that the activate cannot finish
1155 // before the deadline (~8ms by default). 1180 // before the deadline (~8ms by default).
1156 MainFrameInHighLatencyMode(1, 10, false, true); 1181 MainFrameInHighLatencyMode(1, 10, false, true);
1157 } 1182 }
1158 1183
1159 TEST(SchedulerTest, NotSkipMainFrameInPreferImplLatencyMode) { 1184 TEST_F(SchedulerTest, NotSkipMainFrameInPreferImplLatencyMode) {
1160 // Set up client so that estimates indicate that we can commit and activate 1185 // Set up client so that estimates indicate that we can commit and activate
1161 // before the deadline (~8ms by default), but also enable impl latency takes 1186 // before the deadline (~8ms by default), but also enable impl latency takes
1162 // priority mode. 1187 // priority mode.
1163 MainFrameInHighLatencyMode(1, 1, true, true); 1188 MainFrameInHighLatencyMode(1, 1, true, true);
1164 } 1189 }
1165 1190
1166 TEST(SchedulerTest, PollForCommitCompletion) { 1191 TEST_F(SchedulerTest, PollForCommitCompletion) {
1167 // Since we are simulating a long commit, set up a client with draw duration 1192 // Since we are simulating a long commit, set up a client with draw duration
1168 // estimates that prevent skipping main frames to get to low latency mode. 1193 // estimates that prevent skipping main frames to get to low latency mode.
1169 SchedulerClientWithFixedEstimates client( 1194 SchedulerClientWithFixedEstimates* client =
1170 base::TimeDelta::FromMilliseconds(1), 1195 new SchedulerClientWithFixedEstimates(
1171 base::TimeDelta::FromMilliseconds(32), 1196 base::TimeDelta::FromMilliseconds(1),
1172 base::TimeDelta::FromMilliseconds(32)); 1197 base::TimeDelta::FromMilliseconds(32),
1173 SchedulerSettings scheduler_settings; 1198 base::TimeDelta::FromMilliseconds(32));
1174 scheduler_settings.use_external_begin_frame_source = true; 1199 scheduler_settings_.use_external_begin_frame_source = true;
1175 1200 SetUpScheduler(client, true);
1176 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); 1201
1177 1202 client->set_log_anticipated_draw_time_change(true);
1178 client.set_log_anticipated_draw_time_change(true);
1179 1203
1180 BeginFrameArgs frame_args = 1204 BeginFrameArgs frame_args =
1181 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client.now_src()); 1205 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client->now_src());
1182 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); 1206 frame_args.interval = base::TimeDelta::FromMilliseconds(1000);
1183 1207
1184 // At this point, we've drawn a frame. Start another commit, but hold off on 1208 // At this point, we've drawn a frame. Start another commit, but hold off on
1185 // the NotifyReadyToCommit for now. 1209 // the NotifyReadyToCommit for now.
1186 EXPECT_FALSE(scheduler->CommitPending()); 1210 EXPECT_FALSE(scheduler_->CommitPending());
1187 scheduler->SetNeedsCommit(); 1211 scheduler_->SetNeedsCommit();
1188 client.fake_external_begin_frame_source()->TestOnBeginFrame(frame_args); 1212 fake_external_begin_frame_source()->TestOnBeginFrame(frame_args);
1189 EXPECT_TRUE(scheduler->CommitPending()); 1213 EXPECT_TRUE(scheduler_->CommitPending());
1190 1214
1191 // Draw and swap the frame, but don't ack the swap to simulate the Browser 1215 // Draw and swap the frame, but don't ack the swap to simulate the Browser
1192 // blocking on the renderer. 1216 // blocking on the renderer.
1193 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1217 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1194 client.task_runner().RunPendingTasks(); // Run posted deadline. 1218 client->task_runner().RunPendingTasks(); // Run posted deadline.
1195 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1219 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
1196 scheduler->DidSwapBuffers(); 1220 scheduler_->DidSwapBuffers();
1197 1221
1198 // Spin the event loop a few times and make sure we get more 1222 // Spin the event loop a few times and make sure we get more
1199 // DidAnticipateDrawTimeChange calls every time. 1223 // DidAnticipateDrawTimeChange calls every time.
1200 int actions_so_far = client.num_actions_(); 1224 int actions_so_far = client->num_actions_();
1201 1225
1202 // Does three iterations to make sure that the timer is properly repeating. 1226 // Does three iterations to make sure that the timer is properly repeating.
1203 for (int i = 0; i < 3; ++i) { 1227 for (int i = 0; i < 3; ++i) {
1204 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), 1228 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(),
1205 client.task_runner().DelayToNextTaskTime().InMicroseconds()) 1229 client->task_runner().DelayToNextTaskTime().InMicroseconds())
1206 << scheduler->AsValue()->ToString(); 1230 << scheduler_->AsValue()->ToString();
1207 client.task_runner().RunPendingTasks(); 1231 client->task_runner().RunPendingTasks();
1208 EXPECT_GT(client.num_actions_(), actions_so_far); 1232 EXPECT_GT(client->num_actions_(), actions_so_far);
1209 EXPECT_STREQ(client.Action(client.num_actions_() - 1), 1233 EXPECT_STREQ(client->Action(client->num_actions_() - 1),
1210 "DidAnticipatedDrawTimeChange"); 1234 "DidAnticipatedDrawTimeChange");
1211 actions_so_far = client.num_actions_(); 1235 actions_so_far = client->num_actions_();
1212 } 1236 }
1213 1237
1214 // Do the same thing after BeginMainFrame starts but still before activation. 1238 // Do the same thing after BeginMainFrame starts but still before activation.
1215 scheduler->NotifyBeginMainFrameStarted(); 1239 scheduler_->NotifyBeginMainFrameStarted();
1216 for (int i = 0; i < 3; ++i) { 1240 for (int i = 0; i < 3; ++i) {
1217 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), 1241 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(),
1218 client.task_runner().DelayToNextTaskTime().InMicroseconds()) 1242 client->task_runner().DelayToNextTaskTime().InMicroseconds())
1219 << scheduler->AsValue()->ToString(); 1243 << scheduler_->AsValue()->ToString();
1220 client.task_runner().RunPendingTasks(); 1244 client->task_runner().RunPendingTasks();
1221 EXPECT_GT(client.num_actions_(), actions_so_far); 1245 EXPECT_GT(client->num_actions_(), actions_so_far);
1222 EXPECT_STREQ(client.Action(client.num_actions_() - 1), 1246 EXPECT_STREQ(client->Action(client->num_actions_() - 1),
1223 "DidAnticipatedDrawTimeChange"); 1247 "DidAnticipatedDrawTimeChange");
1224 actions_so_far = client.num_actions_(); 1248 actions_so_far = client->num_actions_();
1225 } 1249 }
1226 } 1250 }
1227 1251
1228 TEST(SchedulerTest, BeginRetroFrame) { 1252 TEST_F(SchedulerTest, BeginRetroFrame) {
1229 FakeSchedulerClient client; 1253 scheduler_settings_.use_external_begin_frame_source = true;
1230 SchedulerSettings scheduler_settings; 1254 SetUpScheduler(true);
1231 scheduler_settings.use_external_begin_frame_source = true;
1232
1233 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings);
1234 1255
1235 // SetNeedsCommit should begin the frame on the next BeginImplFrame. 1256 // SetNeedsCommit should begin the frame on the next BeginImplFrame.
1236 scheduler->SetNeedsCommit(); 1257 scheduler_->SetNeedsCommit();
1237 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); 1258 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
1238 client.Reset(); 1259 client_->Reset();
1239 1260
1240 // Create a BeginFrame with a long deadline to avoid race conditions. 1261 // Create a BeginFrame with a long deadline to avoid race conditions.
1241 // This is the first BeginFrame, which will be handled immediately. 1262 // This is the first BeginFrame, which will be handled immediately.
1242 BeginFrameArgs args = 1263 BeginFrameArgs args =
1243 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client.now_src()); 1264 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client_->now_src());
1244 args.deadline += base::TimeDelta::FromHours(1); 1265 args.deadline += base::TimeDelta::FromHours(1);
1245 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); 1266 fake_external_begin_frame_source()->TestOnBeginFrame(args);
1246 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1267 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1247 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 1268 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
1248 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1269 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1249 EXPECT_TRUE(client.needs_begin_frames()); 1270 EXPECT_TRUE(client_->needs_begin_frames());
1250 client.Reset(); 1271 client_->Reset();
1251 1272
1252 // Queue BeginFrames while we are still handling the previous BeginFrame. 1273 // Queue BeginFrames while we are still handling the previous BeginFrame.
1253 args.frame_time += base::TimeDelta::FromSeconds(1); 1274 args.frame_time += base::TimeDelta::FromSeconds(1);
1254 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); 1275 fake_external_begin_frame_source()->TestOnBeginFrame(args);
1255 args.frame_time += base::TimeDelta::FromSeconds(1); 1276 args.frame_time += base::TimeDelta::FromSeconds(1);
1256 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); 1277 fake_external_begin_frame_source()->TestOnBeginFrame(args);
1257 1278
1258 // If we don't swap on the deadline, we wait for the next BeginImplFrame. 1279 // If we don't swap on the deadline, we wait for the next BeginImplFrame.
1259 client.task_runner().RunPendingTasks(); // Run posted deadline. 1280 client_->task_runner().RunPendingTasks(); // Run posted deadline.
1260 EXPECT_NO_ACTION(client); 1281 EXPECT_NO_ACTION(client_);
1261 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1282 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
1262 EXPECT_TRUE(client.needs_begin_frames()); 1283 EXPECT_TRUE(client_->needs_begin_frames());
1263 client.Reset(); 1284 client_->Reset();
1264 1285
1265 // NotifyReadyToCommit should trigger the commit. 1286 // NotifyReadyToCommit should trigger the commit.
1266 scheduler->NotifyBeginMainFrameStarted(); 1287 scheduler_->NotifyBeginMainFrameStarted();
1267 scheduler->NotifyReadyToCommit(); 1288 scheduler_->NotifyReadyToCommit();
1268 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 1289 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_);
1269 EXPECT_TRUE(client.needs_begin_frames()); 1290 EXPECT_TRUE(client_->needs_begin_frames());
1270 client.Reset(); 1291 client_->Reset();
1271 1292
1272 // BeginImplFrame should prepare the draw. 1293 // BeginImplFrame should prepare the draw.
1273 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. 1294 client_->task_runner().RunPendingTasks(); // Run posted BeginRetroFrame.
1274 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1295 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1275 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 1296 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2);
1276 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1297 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1277 EXPECT_TRUE(client.needs_begin_frames()); 1298 EXPECT_TRUE(client_->needs_begin_frames());
1278 client.Reset(); 1299 client_->Reset();
1279 1300
1280 // BeginImplFrame deadline should draw. 1301 // BeginImplFrame deadline should draw.
1281 client.task_runner().RunPendingTasks(); // Run posted deadline. 1302 client_->task_runner().RunPendingTasks(); // Run posted deadline.
1282 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); 1303 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1);
1283 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1304 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
1284 EXPECT_TRUE(client.needs_begin_frames()); 1305 EXPECT_TRUE(client_->needs_begin_frames());
1285 client.Reset(); 1306 client_->Reset();
1286 1307
1287 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) 1308 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false)
1288 // to avoid excessive toggles. 1309 // to avoid excessive toggles.
1289 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. 1310 client_->task_runner().RunPendingTasks(); // Run posted BeginRetroFrame.
1290 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); 1311 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_);
1291 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1312 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1292 client.Reset(); 1313 client_->Reset();
1293 1314
1294 client.task_runner().RunPendingTasks(); // Run posted deadline. 1315 client_->task_runner().RunPendingTasks(); // Run posted deadline.
1295 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); 1316 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_);
1296 client.Reset(); 1317 client_->Reset();
1297 } 1318 }
1298 1319
1299 TEST(SchedulerTest, BeginRetroFrame_SwapThrottled) { 1320 TEST_F(SchedulerTest, BeginRetroFrame_SwapThrottled) {
1300 FakeSchedulerClient client; 1321 scheduler_settings_.use_external_begin_frame_source = true;
1301 SchedulerSettings scheduler_settings; 1322 SetUpScheduler(true);
1302 scheduler_settings.use_external_begin_frame_source = true; 1323
1303 1324 scheduler_->SetEstimatedParentDrawTime(base::TimeDelta::FromMicroseconds(1));
1304 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings);
1305 scheduler->SetEstimatedParentDrawTime(base::TimeDelta::FromMicroseconds(1));
1306 1325
1307 // To test swap ack throttling, this test disables automatic swap acks. 1326 // To test swap ack throttling, this test disables automatic swap acks.
1308 scheduler->SetMaxSwapsPending(1); 1327 scheduler_->SetMaxSwapsPending(1);
1309 client.SetAutomaticSwapAck(false); 1328 client_->SetAutomaticSwapAck(false);
1310 1329
1311 // SetNeedsCommit should begin the frame on the next BeginImplFrame. 1330 // SetNeedsCommit should begin the frame on the next BeginImplFrame.
1312 client.Reset(); 1331 client_->Reset();
1313 scheduler->SetNeedsCommit(); 1332 scheduler_->SetNeedsCommit();
1314 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); 1333 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
1315 client.Reset(); 1334 client_->Reset();
1316 1335
1317 EXPECT_SCOPED(client.AdvanceFrame()); 1336 EXPECT_SCOPED(AdvanceFrame());
1318 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1337 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1319 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 1338 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
1320 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1339 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1321 EXPECT_TRUE(client.needs_begin_frames()); 1340 EXPECT_TRUE(client_->needs_begin_frames());
1322 client.Reset(); 1341 client_->Reset();
1323 1342
1324 // Queue BeginFrame while we are still handling the previous BeginFrame. 1343 // Queue BeginFrame while we are still handling the previous BeginFrame.
1325 client.SendNextBeginFrame(); 1344 SendNextBeginFrame();
1326 EXPECT_NO_ACTION(client); 1345 EXPECT_NO_ACTION(client_);
1327 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1346 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1328 EXPECT_TRUE(client.needs_begin_frames()); 1347 EXPECT_TRUE(client_->needs_begin_frames());
1329 client.Reset(); 1348 client_->Reset();
1330 1349
1331 // NotifyReadyToCommit should trigger the pending commit and draw. 1350 // NotifyReadyToCommit should trigger the pending commit and draw.
1332 scheduler->NotifyBeginMainFrameStarted(); 1351 scheduler_->NotifyBeginMainFrameStarted();
1333 scheduler->NotifyReadyToCommit(); 1352 scheduler_->NotifyReadyToCommit();
1334 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 1353 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_);
1335 EXPECT_TRUE(client.needs_begin_frames()); 1354 EXPECT_TRUE(client_->needs_begin_frames());
1336 client.Reset(); 1355 client_->Reset();
1337 1356
1338 // Swapping will put us into a swap throttled state. 1357 // Swapping will put us into a swap throttled state.
1339 // Run posted deadline. 1358 // Run posted deadline.
1340 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); 1359 client_->task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true));
1341 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); 1360 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2);
1342 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); 1361 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2);
1343 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1362 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
1344 EXPECT_TRUE(client.needs_begin_frames()); 1363 EXPECT_TRUE(client_->needs_begin_frames());
1345 client.Reset(); 1364 client_->Reset();
1346 1365
1347 // While swap throttled, BeginRetroFrames should trigger BeginImplFrames 1366 // While swap throttled, BeginRetroFrames should trigger BeginImplFrames
1348 // but not a BeginMainFrame or draw. 1367 // but not a BeginMainFrame or draw.
1349 scheduler->SetNeedsCommit(); 1368 scheduler_->SetNeedsCommit();
1350 scheduler->SetNeedsRedraw(); 1369 scheduler_->SetNeedsRedraw();
1351 // Run posted BeginRetroFrame. 1370 // Run posted BeginRetroFrame.
1352 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(false)); 1371 client_->task_runner().RunTasksWhile(
1353 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1372 client_->ImplFrameDeadlinePending(false));
1354 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 1373 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1355 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1374 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2);
1356 EXPECT_TRUE(client.needs_begin_frames()); 1375 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1357 client.Reset(); 1376 EXPECT_TRUE(client_->needs_begin_frames());
1377 client_->Reset();
1358 1378
1359 // Let time pass sufficiently beyond the regular deadline but not beyond the 1379 // Let time pass sufficiently beyond the regular deadline but not beyond the
1360 // late deadline. 1380 // late deadline.
1361 client.now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() - 1381 client_->now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() -
1362 base::TimeDelta::FromMicroseconds(1)); 1382 base::TimeDelta::FromMicroseconds(1));
1363 client.task_runner().RunUntilTime(client.now_src()->Now()); 1383 client_->task_runner().RunUntilTime(client_->now_src()->Now());
1364 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1384 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1365 1385
1366 // Take us out of a swap throttled state. 1386 // Take us out of a swap throttled state.
1367 scheduler->DidSwapBuffersComplete(); 1387 scheduler_->DidSwapBuffersComplete();
1368 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); 1388 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_);
1369 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1389 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1370 EXPECT_TRUE(client.needs_begin_frames()); 1390 EXPECT_TRUE(client_->needs_begin_frames());
1371 client.Reset(); 1391 client_->Reset();
1372 1392
1373 // Verify that the deadline was rescheduled. 1393 // Verify that the deadline was rescheduled.
1374 client.task_runner().RunUntilTime(client.now_src()->Now()); 1394 client_->task_runner().RunUntilTime(client_->now_src()->Now());
1375 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client); 1395 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_);
1376 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1396 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
1377 EXPECT_TRUE(client.needs_begin_frames()); 1397 EXPECT_TRUE(client_->needs_begin_frames());
1378 client.Reset(); 1398 client_->Reset();
1379 } 1399 }
1380 1400
1381 TEST(SchedulerTest, RetroFrameDoesNotExpireTooEarly) { 1401 TEST_F(SchedulerTest, RetroFrameDoesNotExpireTooEarly) {
1382 FakeSchedulerClient client; 1402 scheduler_settings_.use_external_begin_frame_source = true;
1383 SchedulerSettings scheduler_settings; 1403 SetUpScheduler(true);
1384 scheduler_settings.use_external_begin_frame_source = true; 1404
1385 1405 scheduler_->SetNeedsCommit();
1386 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); 1406 EXPECT_TRUE(client_->needs_begin_frames());
1387 1407 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
1388 scheduler->SetNeedsCommit(); 1408
1389 EXPECT_TRUE(client.needs_begin_frames()); 1409 client_->Reset();
1390 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); 1410 EXPECT_SCOPED(AdvanceFrame());
1391 1411 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1392 client.Reset(); 1412 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
1393 EXPECT_SCOPED(client.AdvanceFrame()); 1413 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1394 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1414
1395 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 1415 client_->Reset();
1396 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1416 scheduler_->NotifyBeginMainFrameStarted();
1397 1417
1398 client.Reset(); 1418 client_->Reset();
1399 scheduler->NotifyBeginMainFrameStarted(); 1419 SendNextBeginFrame();
1400
1401 client.Reset();
1402 client.SendNextBeginFrame();
1403 // This BeginFrame is queued up as a retro frame. 1420 // This BeginFrame is queued up as a retro frame.
1404 EXPECT_NO_ACTION(client); 1421 EXPECT_NO_ACTION(client_);
1405 // The previous deadline is still pending. 1422 // The previous deadline is still pending.
1406 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1423 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1407 1424
1408 client.Reset(); 1425 client_->Reset();
1409 // This commit should schedule the (previous) deadline to trigger immediately. 1426 // This commit should schedule the (previous) deadline to trigger immediately.
1410 scheduler->NotifyReadyToCommit(); 1427 scheduler_->NotifyReadyToCommit();
1411 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 1428 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_);
1412 1429
1413 client.Reset(); 1430 client_->Reset();
1414 // The deadline task should trigger causing a draw. 1431 // The deadline task should trigger causing a draw.
1415 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1432 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1416 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); 1433 client_->task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true));
1417 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); 1434 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2);
1418 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); 1435 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2);
1419 1436
1420 // Keep animating. 1437 // Keep animating.
1421 client.Reset(); 1438 client_->Reset();
1422 scheduler->SetNeedsAnimate(); 1439 scheduler_->SetNeedsAnimate();
1423 scheduler->SetNeedsRedraw(); 1440 scheduler_->SetNeedsRedraw();
1424 EXPECT_NO_ACTION(client); 1441 EXPECT_NO_ACTION(client_);
1425 1442
1426 // Let's advance sufficiently past the next frame's deadline. 1443 // Let's advance sufficiently past the next frame's deadline.
1427 client.now_src()->AdvanceNow( 1444 client_->now_src()->AdvanceNow(
1428 BeginFrameArgs::DefaultInterval() - 1445 BeginFrameArgs::DefaultInterval() -
1429 BeginFrameArgs::DefaultEstimatedParentDrawTime() + 1446 BeginFrameArgs::DefaultEstimatedParentDrawTime() +
1430 base::TimeDelta::FromMicroseconds(1)); 1447 base::TimeDelta::FromMicroseconds(1));
1431 1448
1432 // The retro frame hasn't expired yet. 1449 // The retro frame hasn't expired yet.
1433 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(false)); 1450 client_->task_runner().RunTasksWhile(
1434 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1451 client_->ImplFrameDeadlinePending(false));
1435 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 1452 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1436 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1453 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2);
1454 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1437 1455
1438 // This is an immediate deadline case. 1456 // This is an immediate deadline case.
1439 client.Reset(); 1457 client_->Reset();
1440 client.task_runner().RunPendingTasks(); 1458 client_->task_runner().RunPendingTasks();
1441 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1459 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
1442 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client); 1460 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_);
1443 } 1461 }
1444 1462
1445 TEST(SchedulerTest, RetroFrameDoesNotExpireTooLate) { 1463 TEST_F(SchedulerTest, RetroFrameDoesNotExpireTooLate) {
1446 FakeSchedulerClient client; 1464 scheduler_settings_.use_external_begin_frame_source = true;
1447 SchedulerSettings scheduler_settings; 1465 SetUpScheduler(true);
1448 scheduler_settings.use_external_begin_frame_source = true; 1466
1449 1467 scheduler_->SetNeedsCommit();
1450 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); 1468 EXPECT_TRUE(client_->needs_begin_frames());
1451 1469 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
1452 scheduler->SetNeedsCommit(); 1470
1453 EXPECT_TRUE(client.needs_begin_frames()); 1471 client_->Reset();
1454 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); 1472 EXPECT_SCOPED(AdvanceFrame());
1455 1473 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1456 client.Reset(); 1474 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
1457 EXPECT_SCOPED(client.AdvanceFrame()); 1475 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1458 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1476
1459 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 1477 client_->Reset();
1460 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1478 scheduler_->NotifyBeginMainFrameStarted();
1461 1479
1462 client.Reset(); 1480 client_->Reset();
1463 scheduler->NotifyBeginMainFrameStarted(); 1481 SendNextBeginFrame();
1464
1465 client.Reset();
1466 client.SendNextBeginFrame();
1467 // This BeginFrame is queued up as a retro frame. 1482 // This BeginFrame is queued up as a retro frame.
1468 EXPECT_NO_ACTION(client); 1483 EXPECT_NO_ACTION(client_);
1469 // The previous deadline is still pending. 1484 // The previous deadline is still pending.
1470 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1485 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1471 1486
1472 client.Reset(); 1487 client_->Reset();
1473 // This commit should schedule the (previous) deadline to trigger immediately. 1488 // This commit should schedule the (previous) deadline to trigger immediately.
1474 scheduler->NotifyReadyToCommit(); 1489 scheduler_->NotifyReadyToCommit();
1475 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 1490 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_);
1476 1491
1477 client.Reset(); 1492 client_->Reset();
1478 // The deadline task should trigger causing a draw. 1493 // The deadline task should trigger causing a draw.
1479 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1494 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1480 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); 1495 client_->task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true));
1481 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); 1496 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2);
1482 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); 1497 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2);
1483 1498
1484 // Keep animating. 1499 // Keep animating.
1485 client.Reset(); 1500 client_->Reset();
1486 scheduler->SetNeedsAnimate(); 1501 scheduler_->SetNeedsAnimate();
1487 scheduler->SetNeedsRedraw(); 1502 scheduler_->SetNeedsRedraw();
1488 EXPECT_NO_ACTION(client); 1503 EXPECT_NO_ACTION(client_);
1489 1504
1490 // Let's advance sufficiently past the next frame's deadline. 1505 // Let's advance sufficiently past the next frame's deadline.
1491 client.now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() + 1506 client_->now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() +
1492 base::TimeDelta::FromMicroseconds(1)); 1507 base::TimeDelta::FromMicroseconds(1));
1493 1508
1494 // The retro frame should've expired. 1509 // The retro frame should've expired.
1495 EXPECT_NO_ACTION(client); 1510 EXPECT_NO_ACTION(client_);
1496 } 1511 }
1497 1512
1498 void BeginFramesNotFromClient(bool use_external_begin_frame_source, 1513 void SchedulerTest::BeginFramesNotFromClient(
1499 bool throttle_frame_production) { 1514 bool use_external_begin_frame_source,
1500 FakeSchedulerClient client; 1515 bool throttle_frame_production) {
1501 SchedulerSettings scheduler_settings; 1516 scheduler_settings_.use_external_begin_frame_source =
1502 scheduler_settings.use_external_begin_frame_source =
1503 use_external_begin_frame_source; 1517 use_external_begin_frame_source;
1504 scheduler_settings.throttle_frame_production = throttle_frame_production; 1518 scheduler_settings_.throttle_frame_production = throttle_frame_production;
1505 1519 SetUpScheduler(true);
1506 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings);
1507 1520
1508 // SetNeedsCommit should begin the frame on the next BeginImplFrame 1521 // SetNeedsCommit should begin the frame on the next BeginImplFrame
1509 // without calling SetNeedsBeginFrame. 1522 // without calling SetNeedsBeginFrame.
1510 scheduler->SetNeedsCommit(); 1523 scheduler_->SetNeedsCommit();
1511 EXPECT_NO_ACTION(client); 1524 EXPECT_NO_ACTION(client_);
1512 client.Reset(); 1525 client_->Reset();
1513 1526
1514 // When the client-driven BeginFrame are disabled, the scheduler posts it's 1527 // When the client-driven BeginFrame are disabled, the scheduler posts it's
1515 // own BeginFrame tasks. 1528 // own BeginFrame tasks.
1516 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. 1529 client_->task_runner().RunPendingTasks(); // Run posted BeginFrame.
1517 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1530 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1518 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 1531 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
1519 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1532 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1520 client.Reset(); 1533 client_->Reset();
1521 1534
1522 // If we don't swap on the deadline, we wait for the next BeginFrame. 1535 // If we don't swap on the deadline, we wait for the next BeginFrame.
1523 client.task_runner().RunPendingTasks(); // Run posted deadline. 1536 client_->task_runner().RunPendingTasks(); // Run posted deadline.
1524 EXPECT_NO_ACTION(client); 1537 EXPECT_NO_ACTION(client_);
1525 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1538 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
1526 client.Reset(); 1539 client_->Reset();
1527 1540
1528 // NotifyReadyToCommit should trigger the commit. 1541 // NotifyReadyToCommit should trigger the commit.
1529 scheduler->NotifyBeginMainFrameStarted(); 1542 scheduler_->NotifyBeginMainFrameStarted();
1530 scheduler->NotifyReadyToCommit(); 1543 scheduler_->NotifyReadyToCommit();
1531 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 1544 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_);
1532 client.Reset(); 1545 client_->Reset();
1533 1546
1534 // BeginImplFrame should prepare the draw. 1547 // BeginImplFrame should prepare the draw.
1535 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. 1548 client_->task_runner().RunPendingTasks(); // Run posted BeginFrame.
1536 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1549 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1537 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 1550 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2);
1538 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1551 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1539 client.Reset(); 1552 client_->Reset();
1540 1553
1541 // BeginImplFrame deadline should draw. 1554 // BeginImplFrame deadline should draw.
1542 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); 1555 client_->task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true));
1543 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); 1556 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1);
1544 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1557 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
1545 client.Reset(); 1558 client_->Reset();
1546 1559
1547 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) 1560 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false)
1548 // to avoid excessive toggles. 1561 // to avoid excessive toggles.
1549 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. 1562 client_->task_runner().RunPendingTasks(); // Run posted BeginFrame.
1550 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); 1563 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_);
1551 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1564 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1552 client.Reset(); 1565 client_->Reset();
1553 1566
1554 // Make sure SetNeedsBeginFrame isn't called on the client 1567 // Make sure SetNeedsBeginFrame isn't called on the client
1555 // when the BeginFrame is no longer needed. 1568 // when the BeginFrame is no longer needed.
1556 client.task_runner().RunPendingTasks(); // Run posted deadline. 1569 client_->task_runner().RunPendingTasks(); // Run posted deadline.
1557 EXPECT_NO_ACTION(client); 1570 EXPECT_NO_ACTION(client_);
1558 client.Reset(); 1571 client_->Reset();
1559 } 1572 }
1560 1573
1561 TEST(SchedulerTest, SyntheticBeginFrames) { 1574 TEST_F(SchedulerTest, SyntheticBeginFrames) {
1562 bool use_external_begin_frame_source = false; 1575 bool use_external_begin_frame_source = false;
1563 bool throttle_frame_production = true; 1576 bool throttle_frame_production = true;
1564 BeginFramesNotFromClient(use_external_begin_frame_source, 1577 BeginFramesNotFromClient(use_external_begin_frame_source,
1565 throttle_frame_production); 1578 throttle_frame_production);
1566 } 1579 }
1567 1580
1568 TEST(SchedulerTest, VSyncThrottlingDisabled) { 1581 TEST_F(SchedulerTest, VSyncThrottlingDisabled) {
1569 bool use_external_begin_frame_source = true; 1582 bool use_external_begin_frame_source = true;
1570 bool throttle_frame_production = false; 1583 bool throttle_frame_production = false;
1571 BeginFramesNotFromClient(use_external_begin_frame_source, 1584 BeginFramesNotFromClient(use_external_begin_frame_source,
1572 throttle_frame_production); 1585 throttle_frame_production);
1573 } 1586 }
1574 1587
1575 TEST(SchedulerTest, SyntheticBeginFrames_And_VSyncThrottlingDisabled) { 1588 TEST_F(SchedulerTest, SyntheticBeginFrames_And_VSyncThrottlingDisabled) {
1576 bool use_external_begin_frame_source = false; 1589 bool use_external_begin_frame_source = false;
1577 bool throttle_frame_production = false; 1590 bool throttle_frame_production = false;
1578 BeginFramesNotFromClient(use_external_begin_frame_source, 1591 BeginFramesNotFromClient(use_external_begin_frame_source,
1579 throttle_frame_production); 1592 throttle_frame_production);
1580 } 1593 }
1581 1594
1582 void BeginFramesNotFromClient_SwapThrottled( 1595 void SchedulerTest::BeginFramesNotFromClient_SwapThrottled(
1583 bool use_external_begin_frame_source, 1596 bool use_external_begin_frame_source,
1584 bool throttle_frame_production) { 1597 bool throttle_frame_production) {
1585 FakeSchedulerClient client; 1598 scheduler_settings_.use_external_begin_frame_source =
1586 SchedulerSettings scheduler_settings;
1587 scheduler_settings.use_external_begin_frame_source =
1588 use_external_begin_frame_source; 1599 use_external_begin_frame_source;
1589 scheduler_settings.throttle_frame_production = throttle_frame_production; 1600 scheduler_settings_.throttle_frame_production = throttle_frame_production;
1590 1601 SetUpScheduler(true);
1591 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); 1602
1592 scheduler->SetEstimatedParentDrawTime(base::TimeDelta::FromMicroseconds(1)); 1603 scheduler_->SetEstimatedParentDrawTime(base::TimeDelta::FromMicroseconds(1));
1593 1604
1594 // To test swap ack throttling, this test disables automatic swap acks. 1605 // To test swap ack throttling, this test disables automatic swap acks.
1595 scheduler->SetMaxSwapsPending(1); 1606 scheduler_->SetMaxSwapsPending(1);
1596 client.SetAutomaticSwapAck(false); 1607 client_->SetAutomaticSwapAck(false);
1597 1608
1598 // SetNeedsCommit should begin the frame on the next BeginImplFrame. 1609 // SetNeedsCommit should begin the frame on the next BeginImplFrame.
1599 client.Reset(); 1610 client_->Reset();
1600 scheduler->SetNeedsCommit(); 1611 scheduler_->SetNeedsCommit();
1601 EXPECT_NO_ACTION(client); 1612 EXPECT_NO_ACTION(client_);
1602 client.Reset(); 1613 client_->Reset();
1603 1614
1604 // Trigger the first BeginImplFrame and BeginMainFrame 1615 // Trigger the first BeginImplFrame and BeginMainFrame
1605 EXPECT_SCOPED(client.AdvanceFrame()); 1616 EXPECT_SCOPED(AdvanceFrame());
1606 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1617 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1607 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 1618 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
1608 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1619 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1609 client.Reset(); 1620 client_->Reset();
1610 1621
1611 // NotifyReadyToCommit should trigger the pending commit and draw. 1622 // NotifyReadyToCommit should trigger the pending commit and draw.
1612 scheduler->NotifyBeginMainFrameStarted(); 1623 scheduler_->NotifyBeginMainFrameStarted();
1613 scheduler->NotifyReadyToCommit(); 1624 scheduler_->NotifyReadyToCommit();
1614 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 1625 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_);
1615 client.Reset(); 1626 client_->Reset();
1616 1627
1617 // Swapping will put us into a swap throttled state. 1628 // Swapping will put us into a swap throttled state.
1618 // Run posted deadline. 1629 // Run posted deadline.
1619 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); 1630 client_->task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true));
1620 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); 1631 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2);
1621 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); 1632 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2);
1622 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1633 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
1623 client.Reset(); 1634 client_->Reset();
1624 1635
1625 // While swap throttled, BeginFrames should trigger BeginImplFrames, 1636 // While swap throttled, BeginFrames should trigger BeginImplFrames,
1626 // but not a BeginMainFrame or draw. 1637 // but not a BeginMainFrame or draw.
1627 scheduler->SetNeedsCommit(); 1638 scheduler_->SetNeedsCommit();
1628 scheduler->SetNeedsRedraw(); 1639 scheduler_->SetNeedsRedraw();
1629 EXPECT_SCOPED(client.AdvanceFrame()); // Run posted BeginFrame. 1640 EXPECT_SCOPED(AdvanceFrame()); // Run posted BeginFrame.
1630 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1641 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1631 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 1642 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2);
1632 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1643 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1633 client.Reset(); 1644 client_->Reset();
1634 1645
1635 // Let time pass sufficiently beyond the regular deadline but not beyond the 1646 // Let time pass sufficiently beyond the regular deadline but not beyond the
1636 // late deadline. 1647 // late deadline.
1637 client.now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() - 1648 client_->now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() -
1638 base::TimeDelta::FromMicroseconds(1)); 1649 base::TimeDelta::FromMicroseconds(1));
1639 client.task_runner().RunUntilTime(client.now_src()->Now()); 1650 client_->task_runner().RunUntilTime(client_->now_src()->Now());
1640 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1651 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1641 1652
1642 // Take us out of a swap throttled state. 1653 // Take us out of a swap throttled state.
1643 scheduler->DidSwapBuffersComplete(); 1654 scheduler_->DidSwapBuffersComplete();
1644 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); 1655 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_);
1645 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1656 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1646 client.Reset(); 1657 client_->Reset();
1647 1658
1648 // Verify that the deadline was rescheduled. 1659 // Verify that the deadline was rescheduled.
1649 // We can't use RunUntilTime(now) here because the next frame is also 1660 // We can't use RunUntilTime(now) here because the next frame is also
1650 // scheduled if throttle_frame_production = false. 1661 // scheduled if throttle_frame_production = false.
1651 base::TimeTicks before_deadline = client.now_src()->Now(); 1662 base::TimeTicks before_deadline = client_->now_src()->Now();
1652 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); 1663 client_->task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true));
1653 base::TimeTicks after_deadline = client.now_src()->Now(); 1664 base::TimeTicks after_deadline = client_->now_src()->Now();
1654 EXPECT_EQ(after_deadline, before_deadline); 1665 EXPECT_EQ(after_deadline, before_deadline);
1655 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1666 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
1656 client.Reset(); 1667 client_->Reset();
1657 } 1668 }
1658 1669
1659 TEST(SchedulerTest, SyntheticBeginFrames_SwapThrottled) { 1670 TEST_F(SchedulerTest, SyntheticBeginFrames_SwapThrottled) {
1660 bool use_external_begin_frame_source = false; 1671 bool use_external_begin_frame_source = false;
1661 bool throttle_frame_production = true; 1672 bool throttle_frame_production = true;
1662 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source, 1673 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source,
1663 throttle_frame_production); 1674 throttle_frame_production);
1664 } 1675 }
1665 1676
1666 TEST(SchedulerTest, VSyncThrottlingDisabled_SwapThrottled) { 1677 TEST_F(SchedulerTest, VSyncThrottlingDisabled_SwapThrottled) {
1667 bool use_external_begin_frame_source = true; 1678 bool use_external_begin_frame_source = true;
1668 bool throttle_frame_production = false; 1679 bool throttle_frame_production = false;
1669 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source, 1680 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source,
1670 throttle_frame_production); 1681 throttle_frame_production);
1671 } 1682 }
1672 1683
1673 TEST(SchedulerTest, 1684 TEST_F(SchedulerTest,
1674 SyntheticBeginFrames_And_VSyncThrottlingDisabled_SwapThrottled) { 1685 SyntheticBeginFrames_And_VSyncThrottlingDisabled_SwapThrottled) {
1675 bool use_external_begin_frame_source = false; 1686 bool use_external_begin_frame_source = false;
1676 bool throttle_frame_production = false; 1687 bool throttle_frame_production = false;
1677 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source, 1688 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source,
1678 throttle_frame_production); 1689 throttle_frame_production);
1679 } 1690 }
1680 1691
1681 TEST(SchedulerTest, DidLoseOutputSurfaceAfterOutputSurfaceIsInitialized) { 1692 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterOutputSurfaceIsInitialized) {
1682 FakeSchedulerClient client; 1693 scheduler_settings_.use_external_begin_frame_source = true;
1683 SchedulerSettings scheduler_settings; 1694 SetUpScheduler(false);
1684 scheduler_settings.use_external_begin_frame_source = true; 1695
1685 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); 1696 scheduler_->SetCanStart();
1686 scheduler->SetCanStart(); 1697 scheduler_->SetVisible(true);
1687 scheduler->SetVisible(true); 1698 scheduler_->SetCanDraw(true);
1688 scheduler->SetCanDraw(true); 1699
1689 1700 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_);
1690 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 1701 client_->Reset();
1691 client.Reset(); 1702 scheduler_->DidCreateAndInitializeOutputSurface();
1692 scheduler->DidCreateAndInitializeOutputSurface(); 1703 EXPECT_NO_ACTION(client_);
1693 EXPECT_NO_ACTION(client); 1704
1694 1705 scheduler_->DidLoseOutputSurface();
1695 scheduler->DidLoseOutputSurface(); 1706 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_);
1696 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 1707 }
1697 } 1708
1698 1709 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterBeginFrameStarted) {
1699 TEST(SchedulerTest, DidLoseOutputSurfaceAfterBeginFrameStarted) { 1710 scheduler_settings_.use_external_begin_frame_source = true;
1700 FakeSchedulerClient client; 1711 SetUpScheduler(true);
1701 SchedulerSettings scheduler_settings;
1702 scheduler_settings.use_external_begin_frame_source = true;
1703
1704 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings);
1705 1712
1706 // SetNeedsCommit should begin the frame. 1713 // SetNeedsCommit should begin the frame.
1707 scheduler->SetNeedsCommit(); 1714 scheduler_->SetNeedsCommit();
1708 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); 1715 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
1709 1716
1710 client.Reset(); 1717 client_->Reset();
1711 EXPECT_SCOPED(client.AdvanceFrame()); 1718 EXPECT_SCOPED(AdvanceFrame());
1712 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1719 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1713 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 1720 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
1714 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1721 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1715 1722
1716 client.Reset(); 1723 client_->Reset();
1717 scheduler->DidLoseOutputSurface(); 1724 scheduler_->DidLoseOutputSurface();
1718 // Do nothing when impl frame is in deadine pending state. 1725 // Do nothing when impl frame is in deadine pending state.
1719 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); 1726 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_);
1720 1727
1721 client.Reset(); 1728 client_->Reset();
1722 scheduler->NotifyBeginMainFrameStarted(); 1729 scheduler_->NotifyBeginMainFrameStarted();
1723 scheduler->NotifyReadyToCommit(); 1730 scheduler_->NotifyReadyToCommit();
1724 EXPECT_ACTION("ScheduledActionCommit", client, 0, 1); 1731 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 1);
1725 1732
1726 client.Reset(); 1733 client_->Reset();
1727 client.task_runner().RunPendingTasks(); // Run posted deadline. 1734 client_->task_runner().RunPendingTasks(); // Run posted deadline.
1728 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 1735 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_);
1729 } 1736 }
1730 1737
1731 void DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency( 1738 void SchedulerTest::DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency(
1732 bool impl_side_painting) { 1739 bool impl_side_painting) {
1733 FakeSchedulerClient client; 1740 scheduler_settings_.impl_side_painting = impl_side_painting;
1734 SchedulerSettings scheduler_settings; 1741 scheduler_settings_.use_external_begin_frame_source = true;
1735 scheduler_settings.impl_side_painting = impl_side_painting; 1742 SetUpScheduler(true);
1736 scheduler_settings.use_external_begin_frame_source = true;
1737
1738 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings);
1739 1743
1740 // SetNeedsCommit should begin the frame. 1744 // SetNeedsCommit should begin the frame.
1741 scheduler->SetNeedsCommit(); 1745 scheduler_->SetNeedsCommit();
1742 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); 1746 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
1743 1747
1744 client.Reset(); 1748 client_->Reset();
1745 EXPECT_SCOPED(client.AdvanceFrame()); 1749 EXPECT_SCOPED(AdvanceFrame());
1746 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1750 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1747 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 1751 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
1748 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1752 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1749 1753
1750 client.Reset(); 1754 client_->Reset();
1751 scheduler->DidLoseOutputSurface(); 1755 scheduler_->DidLoseOutputSurface();
1752 // Do nothing when impl frame is in deadine pending state. 1756 // Do nothing when impl frame is in deadine pending state.
1753 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); 1757 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_);
1754 1758
1755 client.Reset(); 1759 client_->Reset();
1756 // Run posted deadline. 1760 // Run posted deadline.
1757 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1761 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1758 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); 1762 client_->task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true));
1759 // OnBeginImplFrameDeadline didn't schedule any actions because main frame is 1763 // OnBeginImplFrameDeadline didn't schedule any actions because main frame is
1760 // not yet completed. 1764 // not yet completed.
1761 EXPECT_NO_ACTION(client); 1765 EXPECT_NO_ACTION(client_);
1762 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1766 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
1763 1767
1764 // BeginImplFrame is not started. 1768 // BeginImplFrame is not started.
1765 client.task_runner().RunUntilTime(client.now_src()->Now() + 1769 client_->task_runner().RunUntilTime(client_->now_src()->Now() +
1766 base::TimeDelta::FromMilliseconds(10)); 1770 base::TimeDelta::FromMilliseconds(10));
1767 EXPECT_NO_ACTION(client); 1771 EXPECT_NO_ACTION(client_);
1768 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1772 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
1769 1773
1770 client.Reset(); 1774 client_->Reset();
1771 scheduler->NotifyBeginMainFrameStarted(); 1775 scheduler_->NotifyBeginMainFrameStarted();
1772 scheduler->NotifyReadyToCommit(); 1776 scheduler_->NotifyReadyToCommit();
1773 if (impl_side_painting) { 1777 if (impl_side_painting) {
1774 EXPECT_ACTION("ScheduledActionCommit", client, 0, 3); 1778 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3);
1775 EXPECT_ACTION("ScheduledActionActivateSyncTree", client, 1, 3); 1779 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 3);
1776 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 2, 3); 1780 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 2, 3);
1777 } else { 1781 } else {
1778 EXPECT_ACTION("ScheduledActionCommit", client, 0, 2); 1782 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 2);
1779 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 1, 2); 1783 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 1, 2);
1780 } 1784 }
1781 } 1785 }
1782 1786
1783 TEST(SchedulerTest, DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency) { 1787 TEST_F(SchedulerTest,
1788 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency) {
1784 bool impl_side_painting = false; 1789 bool impl_side_painting = false;
1785 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency(impl_side_painting); 1790 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency(impl_side_painting);
1786 } 1791 }
1787 1792
1788 TEST(SchedulerTest, 1793 TEST_F(SchedulerTest,
1789 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatencyWithImplPaint) { 1794 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatencyWithImplPaint) {
1790 bool impl_side_painting = true; 1795 bool impl_side_painting = true;
1791 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency(impl_side_painting); 1796 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency(impl_side_painting);
1792 } 1797 }
1793 1798
1794 void DidLoseOutputSurfaceAfterReadyToCommit(bool impl_side_painting) { 1799 void SchedulerTest::DidLoseOutputSurfaceAfterReadyToCommit(
1795 FakeSchedulerClient client; 1800 bool impl_side_painting) {
1796 SchedulerSettings scheduler_settings; 1801 scheduler_settings_.impl_side_painting = impl_side_painting;
1797 scheduler_settings.impl_side_painting = impl_side_painting; 1802 scheduler_settings_.use_external_begin_frame_source = true;
1798 scheduler_settings.use_external_begin_frame_source = true; 1803 SetUpScheduler(true);
1799
1800 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings);
1801 1804
1802 // SetNeedsCommit should begin the frame. 1805 // SetNeedsCommit should begin the frame.
1803 scheduler->SetNeedsCommit(); 1806 scheduler_->SetNeedsCommit();
1804 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); 1807 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
1805 1808
1806 client.Reset(); 1809 client_->Reset();
1807 EXPECT_SCOPED(client.AdvanceFrame()); 1810 EXPECT_SCOPED(AdvanceFrame());
1808 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1811 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1809 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 1812 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
1810 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1813 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1811 1814
1812 client.Reset(); 1815 client_->Reset();
1813 scheduler->NotifyBeginMainFrameStarted(); 1816 scheduler_->NotifyBeginMainFrameStarted();
1814 scheduler->NotifyReadyToCommit(); 1817 scheduler_->NotifyReadyToCommit();
1815 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 1818 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_);
1816 1819
1817 client.Reset(); 1820 client_->Reset();
1818 scheduler->DidLoseOutputSurface(); 1821 scheduler_->DidLoseOutputSurface();
1819 if (impl_side_painting) { 1822 if (impl_side_painting) {
1820 // Sync tree should be forced to activate. 1823 // Sync tree should be forced to activate.
1821 EXPECT_ACTION("ScheduledActionActivateSyncTree", client, 0, 2); 1824 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 0, 2);
1822 EXPECT_ACTION("SetNeedsBeginFrames(false)", client, 1, 2); 1825 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 2);
1823 } else { 1826 } else {
1824 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); 1827 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_);
1825 } 1828 }
1826 1829
1827 client.Reset(); 1830 client_->Reset();
1828 client.task_runner().RunPendingTasks(); // Run posted deadline. 1831 client_->task_runner().RunPendingTasks(); // Run posted deadline.
1829 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 1832 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_);
1830 } 1833 }
1831 1834
1832 TEST(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommit) { 1835 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommit) {
1833 DidLoseOutputSurfaceAfterReadyToCommit(false); 1836 DidLoseOutputSurfaceAfterReadyToCommit(false);
1834 } 1837 }
1835 1838
1836 TEST(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommitWithImplPainting) { 1839 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommitWithImplPainting) {
1837 DidLoseOutputSurfaceAfterReadyToCommit(true); 1840 DidLoseOutputSurfaceAfterReadyToCommit(true);
1838 } 1841 }
1839 1842
1840 TEST(SchedulerTest, DidLoseOutputSurfaceAfterSetNeedsPrepareTiles) { 1843 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterSetNeedsPrepareTiles) {
1841 FakeSchedulerClient client; 1844 scheduler_settings_.use_external_begin_frame_source = true;
1842 SchedulerSettings scheduler_settings; 1845 SetUpScheduler(true);
1843 scheduler_settings.use_external_begin_frame_source = true; 1846
1844 1847 scheduler_->SetNeedsPrepareTiles();
1845 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); 1848 scheduler_->SetNeedsRedraw();
1846 1849 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
1847 scheduler->SetNeedsPrepareTiles(); 1850
1848 scheduler->SetNeedsRedraw(); 1851 client_->Reset();
1849 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); 1852 EXPECT_SCOPED(AdvanceFrame());
1850 1853 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1851 client.Reset(); 1854 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2);
1852 EXPECT_SCOPED(client.AdvanceFrame()); 1855 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1853 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1856
1854 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 1857 client_->Reset();
1855 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1858 scheduler_->DidLoseOutputSurface();
1856 1859 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_);
1857 client.Reset(); 1860
1858 scheduler->DidLoseOutputSurface(); 1861 client_->Reset();
1859 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); 1862 client_->task_runner().RunPendingTasks(); // Run posted deadline.
1860 1863 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 0, 2);
1861 client.Reset(); 1864 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 1, 2);
1862 client.task_runner().RunPendingTasks(); // Run posted deadline. 1865 }
1863 EXPECT_ACTION("ScheduledActionPrepareTiles", client, 0, 2); 1866
1864 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 1, 2); 1867 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterBeginRetroFramePosted) {
1865 } 1868 scheduler_settings_.use_external_begin_frame_source = true;
1866 1869 SetUpScheduler(true);
1867 TEST(SchedulerTest, DidLoseOutputSurfaceAfterBeginRetroFramePosted) {
1868 FakeSchedulerClient client;
1869 SchedulerSettings scheduler_settings;
1870 scheduler_settings.use_external_begin_frame_source = true;
1871
1872 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings);
1873 1870
1874 // SetNeedsCommit should begin the frame on the next BeginImplFrame. 1871 // SetNeedsCommit should begin the frame on the next BeginImplFrame.
1875 scheduler->SetNeedsCommit(); 1872 scheduler_->SetNeedsCommit();
1876 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); 1873 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
1877 1874
1878 // Create a BeginFrame with a long deadline to avoid race conditions. 1875 // Create a BeginFrame with a long deadline to avoid race conditions.
1879 // This is the first BeginFrame, which will be handled immediately. 1876 // This is the first BeginFrame, which will be handled immediately.
1880 client.Reset(); 1877 client_->Reset();
1881 BeginFrameArgs args = 1878 BeginFrameArgs args =
1882 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client.now_src()); 1879 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client_->now_src());
1883 args.deadline += base::TimeDelta::FromHours(1); 1880 args.deadline += base::TimeDelta::FromHours(1);
1884 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); 1881 fake_external_begin_frame_source()->TestOnBeginFrame(args);
1885 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1882 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1886 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 1883 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
1887 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1884 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1888 EXPECT_TRUE(client.needs_begin_frames()); 1885 EXPECT_TRUE(client_->needs_begin_frames());
1889 1886
1890 // Queue BeginFrames while we are still handling the previous BeginFrame. 1887 // Queue BeginFrames while we are still handling the previous BeginFrame.
1891 args.frame_time += base::TimeDelta::FromSeconds(1); 1888 args.frame_time += base::TimeDelta::FromSeconds(1);
1892 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); 1889 fake_external_begin_frame_source()->TestOnBeginFrame(args);
1893 args.frame_time += base::TimeDelta::FromSeconds(1); 1890 args.frame_time += base::TimeDelta::FromSeconds(1);
1894 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); 1891 fake_external_begin_frame_source()->TestOnBeginFrame(args);
1895 1892
1896 // If we don't swap on the deadline, we wait for the next BeginImplFrame. 1893 // If we don't swap on the deadline, we wait for the next BeginImplFrame.
1897 client.Reset(); 1894 client_->Reset();
1898 client.task_runner().RunPendingTasks(); // Run posted deadline. 1895 client_->task_runner().RunPendingTasks(); // Run posted deadline.
1899 EXPECT_NO_ACTION(client); 1896 EXPECT_NO_ACTION(client_);
1900 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1897 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
1901 EXPECT_TRUE(client.needs_begin_frames()); 1898 EXPECT_TRUE(client_->needs_begin_frames());
1902 1899
1903 // NotifyReadyToCommit should trigger the commit. 1900 // NotifyReadyToCommit should trigger the commit.
1904 client.Reset(); 1901 client_->Reset();
1905 scheduler->NotifyBeginMainFrameStarted(); 1902 scheduler_->NotifyBeginMainFrameStarted();
1906 scheduler->NotifyReadyToCommit(); 1903 scheduler_->NotifyReadyToCommit();
1907 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 1904 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_);
1908 EXPECT_TRUE(client.needs_begin_frames()); 1905 EXPECT_TRUE(client_->needs_begin_frames());
1909 1906
1910 client.Reset(); 1907 client_->Reset();
1911 EXPECT_FALSE(scheduler->IsBeginRetroFrameArgsEmpty()); 1908 EXPECT_FALSE(scheduler_->IsBeginRetroFrameArgsEmpty());
1912 scheduler->DidLoseOutputSurface(); 1909 scheduler_->DidLoseOutputSurface();
1913 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 0, 2); 1910 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 2);
1914 EXPECT_ACTION("SetNeedsBeginFrames(false)", client, 1, 2); 1911 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 2);
1915 EXPECT_TRUE(scheduler->IsBeginRetroFrameArgsEmpty()); 1912 EXPECT_TRUE(scheduler_->IsBeginRetroFrameArgsEmpty());
1916 1913
1917 // Posted BeginRetroFrame is aborted. 1914 // Posted BeginRetroFrame is aborted.
1918 client.Reset(); 1915 client_->Reset();
1919 client.task_runner().RunPendingTasks(); 1916 client_->task_runner().RunPendingTasks();
1920 EXPECT_NO_ACTION(client); 1917 EXPECT_NO_ACTION(client_);
1921 } 1918 }
1922 1919
1923 TEST(SchedulerTest, DidLoseOutputSurfaceDuringBeginRetroFrameRunning) { 1920 TEST_F(SchedulerTest, DidLoseOutputSurfaceDuringBeginRetroFrameRunning) {
1924 FakeSchedulerClient client; 1921 scheduler_settings_.use_external_begin_frame_source = true;
1925 SchedulerSettings scheduler_settings; 1922 SetUpScheduler(true);
1926 scheduler_settings.use_external_begin_frame_source = true;
1927
1928 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings);
1929 1923
1930 // SetNeedsCommit should begin the frame on the next BeginImplFrame. 1924 // SetNeedsCommit should begin the frame on the next BeginImplFrame.
1931 scheduler->SetNeedsCommit(); 1925 scheduler_->SetNeedsCommit();
1932 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); 1926 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
1933 1927
1934 // Create a BeginFrame with a long deadline to avoid race conditions. 1928 // Create a BeginFrame with a long deadline to avoid race conditions.
1935 // This is the first BeginFrame, which will be handled immediately. 1929 // This is the first BeginFrame, which will be handled immediately.
1936 client.Reset(); 1930 client_->Reset();
1937 BeginFrameArgs args = 1931 BeginFrameArgs args =
1938 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client.now_src()); 1932 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client_->now_src());
1939 args.deadline += base::TimeDelta::FromHours(1); 1933 args.deadline += base::TimeDelta::FromHours(1);
1940 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); 1934 fake_external_begin_frame_source()->TestOnBeginFrame(args);
1941 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1935 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1942 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 1936 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
1943 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1937 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1944 EXPECT_TRUE(client.needs_begin_frames()); 1938 EXPECT_TRUE(client_->needs_begin_frames());
1945 1939
1946 // Queue BeginFrames while we are still handling the previous BeginFrame. 1940 // Queue BeginFrames while we are still handling the previous BeginFrame.
1947 args.frame_time += base::TimeDelta::FromSeconds(1); 1941 args.frame_time += base::TimeDelta::FromSeconds(1);
1948 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); 1942 fake_external_begin_frame_source()->TestOnBeginFrame(args);
1949 args.frame_time += base::TimeDelta::FromSeconds(1); 1943 args.frame_time += base::TimeDelta::FromSeconds(1);
1950 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); 1944 fake_external_begin_frame_source()->TestOnBeginFrame(args);
1951 1945
1952 // If we don't swap on the deadline, we wait for the next BeginImplFrame. 1946 // If we don't swap on the deadline, we wait for the next BeginImplFrame.
1953 client.Reset(); 1947 client_->Reset();
1954 client.task_runner().RunPendingTasks(); // Run posted deadline. 1948 client_->task_runner().RunPendingTasks(); // Run posted deadline.
1955 EXPECT_NO_ACTION(client); 1949 EXPECT_NO_ACTION(client_);
1956 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1950 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
1957 EXPECT_TRUE(client.needs_begin_frames()); 1951 EXPECT_TRUE(client_->needs_begin_frames());
1958 1952
1959 // NotifyReadyToCommit should trigger the commit. 1953 // NotifyReadyToCommit should trigger the commit.
1960 client.Reset(); 1954 client_->Reset();
1961 scheduler->NotifyBeginMainFrameStarted(); 1955 scheduler_->NotifyBeginMainFrameStarted();
1962 scheduler->NotifyReadyToCommit(); 1956 scheduler_->NotifyReadyToCommit();
1963 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 1957 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_);
1964 EXPECT_TRUE(client.needs_begin_frames()); 1958 EXPECT_TRUE(client_->needs_begin_frames());
1965 1959
1966 // BeginImplFrame should prepare the draw. 1960 // BeginImplFrame should prepare the draw.
1967 client.Reset(); 1961 client_->Reset();
1968 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. 1962 client_->task_runner().RunPendingTasks(); // Run posted BeginRetroFrame.
1969 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1963 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
1970 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 1964 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2);
1971 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1965 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
1972 EXPECT_TRUE(client.needs_begin_frames()); 1966 EXPECT_TRUE(client_->needs_begin_frames());
1973 1967
1974 client.Reset(); 1968 client_->Reset();
1975 EXPECT_FALSE(scheduler->IsBeginRetroFrameArgsEmpty()); 1969 EXPECT_FALSE(scheduler_->IsBeginRetroFrameArgsEmpty());
1976 scheduler->DidLoseOutputSurface(); 1970 scheduler_->DidLoseOutputSurface();
1977 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); 1971 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_);
1978 EXPECT_TRUE(scheduler->IsBeginRetroFrameArgsEmpty()); 1972 EXPECT_TRUE(scheduler_->IsBeginRetroFrameArgsEmpty());
1979 1973
1980 // BeginImplFrame deadline should abort drawing. 1974 // BeginImplFrame deadline should abort drawing.
1981 client.Reset(); 1975 client_->Reset();
1982 client.task_runner().RunPendingTasks(); // Run posted deadline. 1976 client_->task_runner().RunPendingTasks(); // Run posted deadline.
1983 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 1977 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_);
1984 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1978 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
1985 EXPECT_FALSE(client.needs_begin_frames()); 1979 EXPECT_FALSE(client_->needs_begin_frames());
1986 1980
1987 // No more BeginRetroFrame because BeginRetroFrame queue is cleared. 1981 // No more BeginRetroFrame because BeginRetroFrame queue is cleared.
1988 client.Reset(); 1982 client_->Reset();
1989 client.task_runner().RunPendingTasks(); 1983 client_->task_runner().RunPendingTasks();
1990 EXPECT_NO_ACTION(client); 1984 EXPECT_NO_ACTION(client_);
1991 } 1985 }
1992 1986
1993 TEST(SchedulerTest, 1987 TEST_F(SchedulerTest,
1994 StopBeginFrameAfterDidLoseOutputSurfaceWithSyntheticBeginFrameSource) { 1988 StopBeginFrameAfterDidLoseOutputSurfaceWithSyntheticBeginFrameSource) {
1995 FakeSchedulerClient client; 1989 SetUpScheduler(true);
1996 SchedulerSettings scheduler_settings;
1997
1998 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings);
1999 1990
2000 // SetNeedsCommit should begin the frame on the next BeginImplFrame. 1991 // SetNeedsCommit should begin the frame on the next BeginImplFrame.
2001 EXPECT_FALSE(scheduler->frame_source().NeedsBeginFrames()); 1992 EXPECT_FALSE(scheduler_->frame_source().NeedsBeginFrames());
2002 scheduler->SetNeedsCommit(); 1993 scheduler_->SetNeedsCommit();
2003 EXPECT_TRUE(scheduler->frame_source().NeedsBeginFrames()); 1994 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames());
2004 1995
2005 client.Reset(); 1996 client_->Reset();
2006 client.task_runner().RunPendingTasks(); // Run posted Tick. 1997 client_->task_runner().RunPendingTasks(); // Run posted Tick.
2007 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1998 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
2008 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 1999 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
2009 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 2000 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
2010 EXPECT_TRUE(scheduler->frame_source().NeedsBeginFrames()); 2001 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames());
2011 2002
2012 // NotifyReadyToCommit should trigger the commit. 2003 // NotifyReadyToCommit should trigger the commit.
2013 client.Reset(); 2004 client_->Reset();
2014 scheduler->NotifyBeginMainFrameStarted(); 2005 scheduler_->NotifyBeginMainFrameStarted();
2015 scheduler->NotifyReadyToCommit(); 2006 scheduler_->NotifyReadyToCommit();
2016 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 2007 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_);
2017 EXPECT_TRUE(scheduler->frame_source().NeedsBeginFrames()); 2008 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames());
2018 2009
2019 client.Reset(); 2010 client_->Reset();
2020 scheduler->DidLoseOutputSurface(); 2011 scheduler_->DidLoseOutputSurface();
2021 EXPECT_NO_ACTION(client); 2012 EXPECT_NO_ACTION(client_);
2022 EXPECT_FALSE(scheduler->frame_source().NeedsBeginFrames()); 2013 EXPECT_FALSE(scheduler_->frame_source().NeedsBeginFrames());
2023 2014
2024 client.Reset(); 2015 client_->Reset();
2025 client.task_runner().RunPendingTasks(); // Run posted deadline. 2016 client_->task_runner().RunPendingTasks(); // Run posted deadline.
2026 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 2017 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_);
2027 EXPECT_FALSE(scheduler->frame_source().NeedsBeginFrames()); 2018 EXPECT_FALSE(scheduler_->frame_source().NeedsBeginFrames());
2028 } 2019 }
2029 2020
2030 TEST(SchedulerTest, ScheduledActionActivateAfterBecomingInvisible) { 2021 TEST_F(SchedulerTest, ScheduledActionActivateAfterBecomingInvisible) {
2031 FakeSchedulerClient client; 2022 scheduler_settings_.impl_side_painting = true;
2032 SchedulerSettings scheduler_settings; 2023 scheduler_settings_.use_external_begin_frame_source = true;
2033 scheduler_settings.impl_side_painting = true; 2024 SetUpScheduler(true);
2034 scheduler_settings.use_external_begin_frame_source = true;
2035
2036 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings);
2037 2025
2038 // SetNeedsCommit should begin the frame. 2026 // SetNeedsCommit should begin the frame.
2039 scheduler->SetNeedsCommit(); 2027 scheduler_->SetNeedsCommit();
2040 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); 2028 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
2041 2029
2042 client.Reset(); 2030 client_->Reset();
2043 EXPECT_SCOPED(client.AdvanceFrame()); 2031 EXPECT_SCOPED(AdvanceFrame());
2044 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 2032 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
2045 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 2033 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2);
2046 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 2034 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
2047 2035
2048 client.Reset(); 2036 client_->Reset();
2049 scheduler->NotifyBeginMainFrameStarted(); 2037 scheduler_->NotifyBeginMainFrameStarted();
2050 scheduler->NotifyReadyToCommit(); 2038 scheduler_->NotifyReadyToCommit();
2051 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 2039 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_);
2052 2040
2053 client.Reset(); 2041 client_->Reset();
2054 scheduler->SetVisible(false); 2042 scheduler_->SetVisible(false);
2055 // Sync tree should be forced to activate. 2043 // Sync tree should be forced to activate.
2056 EXPECT_ACTION("SetNeedsBeginFrames(false)", client, 0, 2); 2044 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2);
2057 EXPECT_ACTION("ScheduledActionActivateSyncTree", client, 1, 2); 2045 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 2);
2058 } 2046 }
2059 2047
2060 TEST(SchedulerTest, SchedulerPowerMonitoring) { 2048 TEST_F(SchedulerTest, SchedulerPowerMonitoring) {
2061 FakeSchedulerClient client; 2049 scheduler_settings_.disable_hi_res_timer_tasks_on_battery = true;
2062 SchedulerSettings settings; 2050 SetUpScheduler(true);
2063 settings.disable_hi_res_timer_tasks_on_battery = true;
2064
2065 CREATE_SCHEDULER_AND_INIT_SURFACE(settings);
2066 2051
2067 base::TimeTicks before_deadline, after_deadline; 2052 base::TimeTicks before_deadline, after_deadline;
2068 2053
2069 scheduler->SetNeedsCommit(); 2054 scheduler_->SetNeedsCommit();
2070 scheduler->SetNeedsRedraw(); 2055 scheduler_->SetNeedsRedraw();
2071 client.Reset(); 2056 client_->Reset();
2072 2057
2073 // On non-battery power 2058 // On non-battery power
2074 EXPECT_FALSE(client.PowerMonitor()->IsOnBatteryPower()); 2059 EXPECT_FALSE(PowerMonitor()->IsOnBatteryPower());
2075 2060
2076 EXPECT_SCOPED(client.AdvanceFrame()); 2061 EXPECT_SCOPED(AdvanceFrame());
2077 client.Reset(); 2062 client_->Reset();
2078 2063
2079 before_deadline = client.now_src()->Now(); 2064 before_deadline = client_->now_src()->Now();
2080 EXPECT_TRUE(client.task_runner().RunTasksWhile( 2065 EXPECT_TRUE(client_->task_runner().RunTasksWhile(
2081 client.ImplFrameDeadlinePending(true))); 2066 client_->ImplFrameDeadlinePending(true)));
2082 after_deadline = client.now_src()->Now(); 2067 after_deadline = client_->now_src()->Now();
2083 2068
2084 // We post a non-zero deadline task when not on battery 2069 // We post a non-zero deadline task when not on battery
2085 EXPECT_LT(before_deadline, after_deadline); 2070 EXPECT_LT(before_deadline, after_deadline);
2086 2071
2087 // Switch to battery power 2072 // Switch to battery power
2088 client.PowerMonitorSource()->GeneratePowerStateEvent(true); 2073 PowerMonitorSource()->GeneratePowerStateEvent(true);
2089 EXPECT_TRUE(client.PowerMonitor()->IsOnBatteryPower()); 2074 EXPECT_TRUE(PowerMonitor()->IsOnBatteryPower());
2090 2075
2091 EXPECT_SCOPED(client.AdvanceFrame()); 2076 EXPECT_SCOPED(AdvanceFrame());
2092 scheduler->SetNeedsCommit(); 2077 scheduler_->SetNeedsCommit();
2093 scheduler->SetNeedsRedraw(); 2078 scheduler_->SetNeedsRedraw();
2094 client.Reset(); 2079 client_->Reset();
2095 2080
2096 before_deadline = client.now_src()->Now(); 2081 before_deadline = client_->now_src()->Now();
2097 EXPECT_TRUE(client.task_runner().RunTasksWhile( 2082 EXPECT_TRUE(client_->task_runner().RunTasksWhile(
2098 client.ImplFrameDeadlinePending(true))); 2083 client_->ImplFrameDeadlinePending(true)));
2099 after_deadline = client.now_src()->Now(); 2084 after_deadline = client_->now_src()->Now();
2100 2085
2101 // We post a zero deadline task when on battery 2086 // We post a zero deadline task when on battery
2102 EXPECT_EQ(before_deadline, after_deadline); 2087 EXPECT_EQ(before_deadline, after_deadline);
2103 2088
2104 // Switch to non-battery power 2089 // Switch to non-battery power
2105 client.PowerMonitorSource()->GeneratePowerStateEvent(false); 2090 PowerMonitorSource()->GeneratePowerStateEvent(false);
2106 EXPECT_FALSE(client.PowerMonitor()->IsOnBatteryPower()); 2091 EXPECT_FALSE(PowerMonitor()->IsOnBatteryPower());
2107 2092
2108 EXPECT_SCOPED(client.AdvanceFrame()); 2093 EXPECT_SCOPED(AdvanceFrame());
2109 scheduler->SetNeedsCommit(); 2094 scheduler_->SetNeedsCommit();
2110 scheduler->SetNeedsRedraw(); 2095 scheduler_->SetNeedsRedraw();
2111 client.Reset(); 2096 client_->Reset();
2112 2097
2113 // Same as before 2098 // Same as before
2114 before_deadline = client.now_src()->Now(); 2099 before_deadline = client_->now_src()->Now();
2115 EXPECT_TRUE(client.task_runner().RunTasksWhile( 2100 EXPECT_TRUE(client_->task_runner().RunTasksWhile(
2116 client.ImplFrameDeadlinePending(true))); 2101 client_->ImplFrameDeadlinePending(true)));
2117 after_deadline = client.now_src()->Now(); 2102 after_deadline = client_->now_src()->Now();
2118 } 2103 }
2119 2104
2120 TEST(SchedulerTest, 2105 TEST_F(SchedulerTest,
2121 SimulateWindowsLowResolutionTimerOnBattery_PrioritizeImplLatencyOff) { 2106 SimulateWindowsLowResolutionTimerOnBattery_PrioritizeImplLatencyOff) {
2122 FakeSchedulerClient client; 2107 scheduler_settings_.use_external_begin_frame_source = true;
2123 SchedulerSettings settings; 2108 SetUpScheduler(true);
2124 settings.use_external_begin_frame_source = true;
2125
2126 CREATE_SCHEDULER_AND_INIT_SURFACE(settings);
2127 2109
2128 // Set needs commit so that the scheduler tries to wait for the main thread 2110 // Set needs commit so that the scheduler tries to wait for the main thread
2129 scheduler->SetNeedsCommit(); 2111 scheduler_->SetNeedsCommit();
2130 // Set needs redraw so that the scheduler doesn't wait too long 2112 // Set needs redraw so that the scheduler doesn't wait too long
2131 scheduler->SetNeedsRedraw(); 2113 scheduler_->SetNeedsRedraw();
2132 client.Reset(); 2114 client_->Reset();
2133 2115
2134 // Switch to battery power 2116 // Switch to battery power
2135 client.PowerMonitorSource()->GeneratePowerStateEvent(true); 2117 PowerMonitorSource()->GeneratePowerStateEvent(true);
2136 EXPECT_TRUE(client.PowerMonitor()->IsOnBatteryPower()); 2118 EXPECT_TRUE(PowerMonitor()->IsOnBatteryPower());
2137 2119
2138 EXPECT_SCOPED(client.AdvanceFrame()); 2120 EXPECT_SCOPED(AdvanceFrame());
2139 scheduler->SetNeedsCommit(); 2121 scheduler_->SetNeedsCommit();
2140 scheduler->SetNeedsRedraw(); 2122 scheduler_->SetNeedsRedraw();
2141 client.Reset(); 2123 client_->Reset();
2142 2124
2143 // Disable auto-advancing of now_src 2125 // Disable auto-advancing of now_src
2144 client.task_runner().SetAutoAdvanceNowToPendingTasks(false); 2126 client_->task_runner().SetAutoAdvanceNowToPendingTasks(false);
2145 2127
2146 // Deadline task is pending 2128 // Deadline task is pending
2147 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 2129 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
2148 client.task_runner().RunPendingTasks(); 2130 client_->task_runner().RunPendingTasks();
2149 // Deadline task is still pending 2131 // Deadline task is still pending
2150 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 2132 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
2151 2133
2152 // Advance now by 15 ms - same as windows low res timer 2134 // Advance now by 15 ms - same as windows low res timer
2153 client.now_src()->AdvanceNowMicroseconds(15000); 2135 client_->now_src()->AdvanceNowMicroseconds(15000);
2154 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 2136 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
2155 client.task_runner().RunPendingTasks(); 2137 client_->task_runner().RunPendingTasks();
2156 // Deadline task finally completes 2138 // Deadline task finally completes
2157 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 2139 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
2158 } 2140 }
2159 2141
2160 TEST(SchedulerTest, 2142 TEST_F(SchedulerTest,
2161 SimulateWindowsLowResolutionTimerOnBattery_PrioritizeImplLatencyOn) { 2143 SimulateWindowsLowResolutionTimerOnBattery_PrioritizeImplLatencyOn) {
2162 FakeSchedulerClient client; 2144 scheduler_settings_.disable_hi_res_timer_tasks_on_battery = true;
2163 SchedulerSettings settings; 2145 scheduler_settings_.use_external_begin_frame_source = true;
2164 settings.disable_hi_res_timer_tasks_on_battery = true; 2146 SetUpScheduler(true);
2165 settings.use_external_begin_frame_source = true;
2166
2167 CREATE_SCHEDULER_AND_INIT_SURFACE(settings);
2168 2147
2169 // Set needs commit so that the scheduler tries to wait for the main thread 2148 // Set needs commit so that the scheduler tries to wait for the main thread
2170 scheduler->SetNeedsCommit(); 2149 scheduler_->SetNeedsCommit();
2171 // Set needs redraw so that the scheduler doesn't wait too long 2150 // Set needs redraw so that the scheduler doesn't wait too long
2172 scheduler->SetNeedsRedraw(); 2151 scheduler_->SetNeedsRedraw();
2173 client.Reset(); 2152 client_->Reset();
2174 2153
2175 // Switch to battery power 2154 // Switch to battery power
2176 client.PowerMonitorSource()->GeneratePowerStateEvent(true); 2155 PowerMonitorSource()->GeneratePowerStateEvent(true);
2177 EXPECT_TRUE(client.PowerMonitor()->IsOnBatteryPower()); 2156 EXPECT_TRUE(PowerMonitor()->IsOnBatteryPower());
2178 2157
2179 EXPECT_SCOPED(client.AdvanceFrame()); 2158 EXPECT_SCOPED(AdvanceFrame());
2180 scheduler->SetNeedsCommit(); 2159 scheduler_->SetNeedsCommit();
2181 scheduler->SetNeedsRedraw(); 2160 scheduler_->SetNeedsRedraw();
2182 client.Reset(); 2161 client_->Reset();
2183 2162
2184 // Disable auto-advancing of now_src 2163 // Disable auto-advancing of now_src
2185 client.task_runner().SetAutoAdvanceNowToPendingTasks(false); 2164 client_->task_runner().SetAutoAdvanceNowToPendingTasks(false);
2186 2165
2187 // Deadline task is pending 2166 // Deadline task is pending
2188 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 2167 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
2189 client.task_runner().RunPendingTasks(); 2168 client_->task_runner().RunPendingTasks();
2190 // Deadline task runs immediately 2169 // Deadline task runs immediately
2191 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 2170 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
2192 } 2171 }
2193 2172
2194 // Tests to ensure frame sources can be successfully changed while drawing. 2173 // Tests to ensure frame sources can be successfully changed while drawing.
2195 TEST(SchedulerTest, SwitchFrameSourceToUnthrottled) { 2174 TEST_F(SchedulerTest, SwitchFrameSourceToUnthrottled) {
2196 FakeSchedulerClient client; 2175 scheduler_settings_.use_external_begin_frame_source = true;
2197 SchedulerSettings scheduler_settings; 2176 SetUpScheduler(true);
2198 scheduler_settings.use_external_begin_frame_source = true;
2199
2200 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings);
2201 2177
2202 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. 2178 // SetNeedsRedraw should begin the frame on the next BeginImplFrame.
2203 scheduler->SetNeedsRedraw(); 2179 scheduler_->SetNeedsRedraw();
2204 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); 2180 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
2205 client.Reset(); 2181 client_->Reset();
2206 2182
2207 EXPECT_SCOPED(client.AdvanceFrame()); 2183 EXPECT_SCOPED(AdvanceFrame());
2208 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 2184 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
2209 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 2185 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2);
2210 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 2186 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
2211 EXPECT_TRUE(client.needs_begin_frames()); 2187 EXPECT_TRUE(client_->needs_begin_frames());
2212 client.Reset(); 2188 client_->Reset();
2213 client.task_runner().RunPendingTasks(); // Run posted deadline. 2189 client_->task_runner().RunPendingTasks(); // Run posted deadline.
2214 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); 2190 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1);
2215 scheduler->SetNeedsRedraw(); 2191 scheduler_->SetNeedsRedraw();
2216 2192
2217 // Switch to an unthrottled frame source. 2193 // Switch to an unthrottled frame source.
2218 scheduler->SetThrottleFrameProduction(false); 2194 scheduler_->SetThrottleFrameProduction(false);
2219 client.Reset(); 2195 client_->Reset();
2220 2196
2221 // Unthrottled frame source will immediately begin a new frame. 2197 // Unthrottled frame source will immediately begin a new frame.
2222 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. 2198 client_->task_runner().RunPendingTasks(); // Run posted BeginFrame.
2223 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 2199 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
2224 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 2200 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2);
2225 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 2201 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
2226 client.Reset(); 2202 client_->Reset();
2227 2203
2228 // If we don't swap on the deadline, we wait for the next BeginFrame. 2204 // If we don't swap on the deadline, we wait for the next BeginFrame.
2229 client.task_runner().RunPendingTasks(); // Run posted deadline. 2205 client_->task_runner().RunPendingTasks(); // Run posted deadline.
2230 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); 2206 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1);
2231 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 2207 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
2232 client.Reset(); 2208 client_->Reset();
2233 } 2209 }
2234 2210
2235 // Tests to ensure frame sources can be successfully changed while a frame 2211 // Tests to ensure frame sources can be successfully changed while a frame
2236 // deadline is pending. 2212 // deadline is pending.
2237 TEST(SchedulerTest, SwitchFrameSourceToUnthrottledBeforeDeadline) { 2213 TEST_F(SchedulerTest, SwitchFrameSourceToUnthrottledBeforeDeadline) {
2238 FakeSchedulerClient client; 2214 scheduler_settings_.use_external_begin_frame_source = true;
2239 SchedulerSettings scheduler_settings; 2215 SetUpScheduler(true);
2240 scheduler_settings.use_external_begin_frame_source = true;
2241
2242 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings);
2243 2216
2244 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. 2217 // SetNeedsRedraw should begin the frame on the next BeginImplFrame.
2245 scheduler->SetNeedsRedraw(); 2218 scheduler_->SetNeedsRedraw();
2246 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); 2219 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_);
2247 client.Reset(); 2220 client_->Reset();
2248 2221
2249 EXPECT_SCOPED(client.AdvanceFrame()); 2222 EXPECT_SCOPED(AdvanceFrame());
2250 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 2223 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
2251 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 2224 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2);
2252 2225
2253 // Switch to an unthrottled frame source before the frame deadline is hit. 2226 // Switch to an unthrottled frame source before the frame deadline is hit.
2254 scheduler->SetThrottleFrameProduction(false); 2227 scheduler_->SetThrottleFrameProduction(false);
2255 client.Reset(); 2228 client_->Reset();
2256 2229
2257 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 2230 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
2258 EXPECT_TRUE(client.needs_begin_frames()); 2231 EXPECT_TRUE(client_->needs_begin_frames());
2259 client.Reset(); 2232 client_->Reset();
2260 2233
2261 client.task_runner() 2234 client_->task_runner()
2262 .RunPendingTasks(); // Run posted deadline and BeginFrame. 2235 .RunPendingTasks(); // Run posted deadline and BeginFrame.
2263 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); 2236 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 2);
2264 // Unthrottled frame source will immediately begin a new frame. 2237 // Unthrottled frame source will immediately begin a new frame.
2265 EXPECT_ACTION("WillBeginImplFrame", client, 1, 2); 2238 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 2);
2266 scheduler->SetNeedsRedraw(); 2239 scheduler_->SetNeedsRedraw();
2267 client.Reset(); 2240 client_->Reset();
2268 2241
2269 client.task_runner().RunPendingTasks(); // Run posted deadline. 2242 client_->task_runner().RunPendingTasks(); // Run posted deadline.
2270 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); 2243 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2);
2271 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); 2244 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2);
2272 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 2245 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
2273 client.Reset(); 2246 client_->Reset();
2274 } 2247 }
2275 2248
2276 // Tests to ensure that the active frame source can successfully be changed from 2249 // Tests to ensure that the active frame source can successfully be changed from
2277 // unthrottled to throttled. 2250 // unthrottled to throttled.
2278 TEST(SchedulerTest, SwitchFrameSourceToThrottled) { 2251 TEST_F(SchedulerTest, SwitchFrameSourceToThrottled) {
2279 FakeSchedulerClient client; 2252 scheduler_settings_.throttle_frame_production = false;
2280 SchedulerSettings scheduler_settings; 2253 scheduler_settings_.use_external_begin_frame_source = true;
2281 scheduler_settings.throttle_frame_production = false; 2254 SetUpScheduler(true);
2282 scheduler_settings.use_external_begin_frame_source = true; 2255
2283 2256 scheduler_->SetNeedsRedraw();
2284 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); 2257 EXPECT_NO_ACTION(client_);
2285 2258 client_->Reset();
2286 scheduler->SetNeedsRedraw(); 2259
2287 EXPECT_NO_ACTION(client); 2260 client_->task_runner().RunPendingTasks(); // Run posted BeginFrame.
2288 client.Reset(); 2261 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
2289 2262 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2);
2290 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. 2263 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
2291 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 2264 client_->Reset();
2292 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 2265
2293 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 2266 client_->task_runner().RunPendingTasks(); // Run posted deadline.
2294 client.Reset(); 2267 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1);
2295 2268 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending());
2296 client.task_runner().RunPendingTasks(); // Run posted deadline. 2269 client_->Reset();
2297 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1);
2298 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
2299 client.Reset();
2300 2270
2301 // Switch to a throttled frame source. 2271 // Switch to a throttled frame source.
2302 scheduler->SetThrottleFrameProduction(true); 2272 scheduler_->SetThrottleFrameProduction(true);
2303 client.Reset(); 2273 client_->Reset();
2304 2274
2305 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. 2275 // SetNeedsRedraw should begin the frame on the next BeginImplFrame.
2306 scheduler->SetNeedsRedraw(); 2276 scheduler_->SetNeedsRedraw();
2307 client.task_runner().RunPendingTasks(); 2277 client_->task_runner().RunPendingTasks();
2308 EXPECT_NO_ACTION(client); 2278 EXPECT_NO_ACTION(client_);
2309 client.Reset(); 2279 client_->Reset();
2310 2280
2311 EXPECT_SCOPED(client.AdvanceFrame()); 2281 EXPECT_SCOPED(AdvanceFrame());
2312 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 2282 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2);
2313 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 2283 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2);
2314 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 2284 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
2315 EXPECT_TRUE(client.needs_begin_frames()); 2285 EXPECT_TRUE(client_->needs_begin_frames());
2316 client.Reset(); 2286 client_->Reset();
2317 client.task_runner().RunPendingTasks(); // Run posted deadline. 2287 client_->task_runner().RunPendingTasks(); // Run posted deadline.
2318 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); 2288 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1);
2319 } 2289 }
2320 2290
2321 } // namespace 2291 } // namespace
2322 } // namespace cc 2292 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698