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

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

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

Powered by Google App Engine
This is Rietveld 408576698