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

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

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

Powered by Google App Engine
This is Rietveld 408576698