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

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

Issue 387493002: Fixing and enhancing OrderedSimpleTaskRunner to allow 100% deterministic tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sprintf is hard. Created 6 years, 5 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 | Annotate | Revision Log
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 #include "cc/scheduler/scheduler.h" 4 #include "cc/scheduler/scheduler.h"
5 5
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
(...skipping 24 matching lines...) Expand all
35 EXPECT_ACTION(action, client, 0, 1) 35 EXPECT_ACTION(action, client, 0, 1)
36 36
37 namespace cc { 37 namespace cc {
38 namespace { 38 namespace {
39 39
40 class FakeSchedulerClient; 40 class FakeSchedulerClient;
41 41
42 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, 42 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler,
43 FakeSchedulerClient* client); 43 FakeSchedulerClient* client);
44 44
45 class TestScheduler : public Scheduler {
46 public:
47 static scoped_ptr<TestScheduler> Create(
48 SchedulerClient* client,
49 const SchedulerSettings& scheduler_settings,
50 int layer_tree_host_id,
51 const scoped_refptr<base::SingleThreadTaskRunner>& impl_task_runner) {
52 return make_scoped_ptr(new TestScheduler(
53 client, scheduler_settings, layer_tree_host_id, impl_task_runner));
54 }
55
56 virtual ~TestScheduler() {}
57
58 bool IsBeginRetroFrameArgsEmpty() const {
59 return begin_retro_frame_args_.empty();
60 }
61
62 bool IsSyntheticBeginFrameSourceActive() const {
63 return synthetic_begin_frame_source_->IsActive();
64 }
65
66 private:
67 TestScheduler(
68 SchedulerClient* client,
69 const SchedulerSettings& scheduler_settings,
70 int layer_tree_host_id,
71 const scoped_refptr<base::SingleThreadTaskRunner> & impl_task_runner)
72 : Scheduler(client,
73 scheduler_settings,
74 layer_tree_host_id,
75 impl_task_runner) {
76 }
77 };
78
79 class FakeSchedulerClient : public SchedulerClient { 45 class FakeSchedulerClient : public SchedulerClient {
80 public: 46 public:
81 FakeSchedulerClient() 47 FakeSchedulerClient()
82 : needs_begin_frame_(false), 48 : needs_begin_frame_(false),
83 automatic_swap_ack_(true), 49 automatic_swap_ack_(true),
84 swap_contains_incomplete_tile_(false), 50 swap_contains_incomplete_tile_(false),
85 redraw_will_happen_if_update_visible_tiles_happens_(false) { 51 redraw_will_happen_if_update_visible_tiles_happens_(false) {
86 Reset(); 52 Reset();
87 } 53 }
88 54
89 void Reset() { 55 void Reset() {
90 actions_.clear(); 56 actions_.clear();
91 states_.clear(); 57 states_.clear();
92 draw_will_happen_ = true; 58 draw_will_happen_ = true;
93 swap_will_happen_if_draw_happens_ = true; 59 swap_will_happen_if_draw_happens_ = true;
94 num_draws_ = 0; 60 num_draws_ = 0;
95 log_anticipated_draw_time_change_ = false; 61 log_anticipated_draw_time_change_ = false;
96 } 62 }
97 63
98 TestScheduler* CreateScheduler(const SchedulerSettings& settings) { 64 TestScheduler* CreateScheduler(const SchedulerSettings& settings) {
99 task_runner_ = new OrderedSimpleTaskRunner; 65 scheduler_ = TestScheduler::Create(this, settings, 0);
100 scheduler_ = TestScheduler::Create(this, settings, 0, task_runner_);
101 return scheduler_.get(); 66 return scheduler_.get();
102 } 67 }
103 68
104 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it 69 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it
105 // for tests that do. 70 // for tests that do.
106 void set_log_anticipated_draw_time_change(bool log) { 71 void set_log_anticipated_draw_time_change(bool log) {
107 log_anticipated_draw_time_change_ = log; 72 log_anticipated_draw_time_change_ = log;
108 } 73 }
109 bool needs_begin_frame() { return needs_begin_frame_; } 74 bool needs_begin_frame() { return needs_begin_frame_; }
110 int num_draws() const { return num_draws_; } 75 int num_draws() const { return num_draws_; }
111 int num_actions_() const { return static_cast<int>(actions_.size()); } 76 int num_actions_() const { return static_cast<int>(actions_.size()); }
112 const char* Action(int i) const { return actions_[i]; } 77 const char* Action(int i) const { return actions_[i]; }
113 base::Value& StateForAction(int i) const { return *states_[i]; } 78 base::Value& StateForAction(int i) const { return *states_[i]; }
114 base::TimeTicks posted_begin_impl_frame_deadline() const { 79 base::TimeTicks posted_begin_impl_frame_deadline() const {
115 return posted_begin_impl_frame_deadline_; 80 return posted_begin_impl_frame_deadline_;
116 } 81 }
117 82
118 OrderedSimpleTaskRunner& task_runner() { return *task_runner_; }
119
120 int ActionIndex(const char* action) const { 83 int ActionIndex(const char* action) const {
121 for (size_t i = 0; i < actions_.size(); i++) 84 for (size_t i = 0; i < actions_.size(); i++)
122 if (!strcmp(actions_[i], action)) 85 if (!strcmp(actions_[i], action))
123 return i; 86 return i;
124 return -1; 87 return -1;
125 } 88 }
126 89
127 void SetSwapContainsIncompleteTile(bool contain) { 90 void SetSwapContainsIncompleteTile(bool contain) {
128 swap_contains_incomplete_tile_ = contain; 91 swap_contains_incomplete_tile_ = contain;
129 } 92 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 } 183 }
221 virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() OVERRIDE { 184 virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() OVERRIDE {
222 return base::TimeDelta(); 185 return base::TimeDelta();
223 } 186 }
224 virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE { 187 virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE {
225 return base::TimeDelta(); 188 return base::TimeDelta();
226 } 189 }
227 190
228 virtual void DidBeginImplFrameDeadline() OVERRIDE {} 191 virtual void DidBeginImplFrameDeadline() OVERRIDE {}
229 192
193 virtual void RunPendingTasks(bool advance_now) {
194 scheduler_->RunPendingTasks(advance_now);
195 }
196
197 virtual base::TimeDelta NextPendingTaskDelay() {
198 return scheduler_->NextPendingTaskDelay();
199 }
200
230 protected: 201 protected:
231 bool needs_begin_frame_; 202 bool needs_begin_frame_;
232 bool draw_will_happen_; 203 bool draw_will_happen_;
233 bool swap_will_happen_if_draw_happens_; 204 bool swap_will_happen_if_draw_happens_;
234 bool automatic_swap_ack_; 205 bool automatic_swap_ack_;
235 int num_draws_; 206 int num_draws_;
236 bool log_anticipated_draw_time_change_; 207 bool log_anticipated_draw_time_change_;
237 bool swap_contains_incomplete_tile_; 208 bool swap_contains_incomplete_tile_;
238 bool redraw_will_happen_if_update_visible_tiles_happens_; 209 bool redraw_will_happen_if_update_visible_tiles_happens_;
239 base::TimeTicks posted_begin_impl_frame_deadline_; 210 base::TimeTicks posted_begin_impl_frame_deadline_;
240 std::vector<const char*> actions_; 211 std::vector<const char*> actions_;
241 ScopedVector<base::Value> states_; 212 ScopedVector<base::Value> states_;
242 scoped_ptr<TestScheduler> scheduler_; 213 scoped_ptr<TestScheduler> scheduler_;
243 scoped_refptr<OrderedSimpleTaskRunner> task_runner_;
244 }; 214 };
245 215
246 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, 216 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler,
247 FakeSchedulerClient* client) { 217 FakeSchedulerClient* client) {
248 bool client_initiates_begin_frame = 218 bool client_initiates_begin_frame =
249 scheduler->settings().begin_frame_scheduling_enabled && 219 scheduler->settings().begin_frame_scheduling_enabled &&
250 scheduler->settings().throttle_frame_production; 220 scheduler->settings().throttle_frame_production;
251 221
252 scheduler->DidCreateAndInitializeOutputSurface(); 222 scheduler->DidCreateAndInitializeOutputSurface();
253 scheduler->SetNeedsCommit(); 223 scheduler->SetNeedsCommit();
254 scheduler->NotifyBeginMainFrameStarted(); 224 scheduler->NotifyBeginMainFrameStarted();
255 scheduler->NotifyReadyToCommit(); 225 scheduler->NotifyReadyToCommit();
256 if (scheduler->settings().impl_side_painting) 226 if (scheduler->settings().impl_side_painting)
257 scheduler->NotifyReadyToActivate(); 227 scheduler->NotifyReadyToActivate();
258 // Go through the motions to draw the commit. 228 // Go through the motions to draw the commit.
259 if (client_initiates_begin_frame) 229 if (client_initiates_begin_frame)
260 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 230 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
261 else 231 else
262 client->task_runner().RunPendingTasks(); // Run posted BeginFrame. 232 client->RunPendingTasks(true); // Run posted BeginFrame.
263 233
264 // Run the posted deadline task. 234 // Run the posted deadline task.
265 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 235 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
266 client->task_runner().RunPendingTasks(); 236 client->RunPendingTasks(true);
267 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 237 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
268 238
269 // We need another BeginImplFrame so Scheduler calls 239 // We need another BeginImplFrame so Scheduler calls
270 // SetNeedsBeginFrame(false). 240 // SetNeedsBeginFrame(false).
271 if (client_initiates_begin_frame) 241 if (client_initiates_begin_frame)
272 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 242 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
273 else 243 else
274 client->task_runner().RunPendingTasks(); // Run posted BeginFrame. 244 client->RunPendingTasks(true); // Run posted BeginFrame.
275 245
276 // Run the posted deadline task. 246 // Run the posted deadline task.
277 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 247 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
278 client->task_runner().RunPendingTasks(); 248 client->RunPendingTasks(true);
279 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 249 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
280 } 250 }
281 251
282 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { 252 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) {
283 FakeSchedulerClient client; 253 FakeSchedulerClient client;
284 SchedulerSettings default_scheduler_settings; 254 SchedulerSettings default_scheduler_settings;
285 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 255 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
286 scheduler->SetCanStart(); 256 scheduler->SetCanStart();
287 scheduler->SetVisible(true); 257 scheduler->SetVisible(true);
288 scheduler->SetCanDraw(true); 258 scheduler->SetCanDraw(true);
(...skipping 23 matching lines...) Expand all
312 client.Reset(); 282 client.Reset();
313 283
314 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 284 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
315 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 285 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
316 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 286 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
317 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 287 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
318 EXPECT_TRUE(client.needs_begin_frame()); 288 EXPECT_TRUE(client.needs_begin_frame());
319 client.Reset(); 289 client.Reset();
320 290
321 // If we don't swap on the deadline, we wait for the next BeginFrame. 291 // If we don't swap on the deadline, we wait for the next BeginFrame.
322 client.task_runner().RunPendingTasks(); // Run posted deadline. 292 client.RunPendingTasks(true); // Run posted deadline.
323 EXPECT_NO_ACTION(client); 293 EXPECT_NO_ACTION(client);
324 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 294 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
325 EXPECT_TRUE(client.needs_begin_frame()); 295 EXPECT_TRUE(client.needs_begin_frame());
326 client.Reset(); 296 client.Reset();
327 297
328 // NotifyReadyToCommit should trigger the commit. 298 // NotifyReadyToCommit should trigger the commit.
329 scheduler->NotifyBeginMainFrameStarted(); 299 scheduler->NotifyBeginMainFrameStarted();
330 scheduler->NotifyReadyToCommit(); 300 scheduler->NotifyReadyToCommit();
331 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 301 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
332 EXPECT_TRUE(client.needs_begin_frame()); 302 EXPECT_TRUE(client.needs_begin_frame());
333 client.Reset(); 303 client.Reset();
334 304
335 // BeginImplFrame should prepare the draw. 305 // BeginImplFrame should prepare the draw.
336 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 306 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
337 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 307 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
338 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 308 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2);
339 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 309 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
340 EXPECT_TRUE(client.needs_begin_frame()); 310 EXPECT_TRUE(client.needs_begin_frame());
341 client.Reset(); 311 client.Reset();
342 312
343 // BeginImplFrame deadline should draw. 313 // BeginImplFrame deadline should draw.
344 client.task_runner().RunPendingTasks(); // Run posted deadline. 314 client.RunPendingTasks(true); // Run posted deadline.
345 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); 315 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1);
346 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 316 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
347 EXPECT_TRUE(client.needs_begin_frame()); 317 EXPECT_TRUE(client.needs_begin_frame());
348 client.Reset(); 318 client.Reset();
349 319
350 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) 320 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false)
351 // to avoid excessive toggles. 321 // to avoid excessive toggles.
352 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 322 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
353 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); 323 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
354 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 324 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
355 client.Reset(); 325 client.Reset();
356 326
357 client.task_runner().RunPendingTasks(); // Run posted deadline. 327 client.RunPendingTasks(true); // Run posted deadline.
358 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); 328 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
359 EXPECT_FALSE(client.needs_begin_frame()); 329 EXPECT_FALSE(client.needs_begin_frame());
360 client.Reset(); 330 client.Reset();
361 } 331 }
362 332
363 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { 333 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) {
364 FakeSchedulerClient client; 334 FakeSchedulerClient client;
365 SchedulerSettings scheduler_settings; 335 SchedulerSettings scheduler_settings;
366 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); 336 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings);
367 scheduler->SetCanStart(); 337 scheduler->SetCanStart();
(...skipping 21 matching lines...) Expand all
389 scheduler->SetNeedsCommit(); 359 scheduler->SetNeedsCommit();
390 EXPECT_EQ(client.num_actions_(), 0); 360 EXPECT_EQ(client.num_actions_(), 0);
391 client.Reset(); 361 client.Reset();
392 362
393 // Finish the first commit. 363 // Finish the first commit.
394 scheduler->NotifyBeginMainFrameStarted(); 364 scheduler->NotifyBeginMainFrameStarted();
395 scheduler->NotifyReadyToCommit(); 365 scheduler->NotifyReadyToCommit();
396 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 366 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
397 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 367 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
398 client.Reset(); 368 client.Reset();
399 client.task_runner().RunPendingTasks(); // Run posted deadline. 369 client.RunPendingTasks(true); // Run posted deadline.
400 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); 370 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2);
401 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); 371 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2);
402 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 372 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
403 373
404 // Because we just swapped, the Scheduler should also request the next 374 // Because we just swapped, the Scheduler should also request the next
405 // BeginImplFrame from the OutputSurface. 375 // BeginImplFrame from the OutputSurface.
406 EXPECT_TRUE(client.needs_begin_frame()); 376 EXPECT_TRUE(client.needs_begin_frame());
407 client.Reset(); 377 client.Reset();
408 // Since another commit is needed, the next BeginImplFrame should initiate 378 // Since another commit is needed, the next BeginImplFrame should initiate
409 // the second commit. 379 // the second commit.
410 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 380 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
411 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 381 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
412 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 382 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
413 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 383 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
414 client.Reset(); 384 client.Reset();
415 385
416 // Finishing the commit before the deadline should post a new deadline task 386 // Finishing the commit before the deadline should post a new deadline task
417 // to trigger the deadline early. 387 // to trigger the deadline early.
418 scheduler->NotifyBeginMainFrameStarted(); 388 scheduler->NotifyBeginMainFrameStarted();
419 scheduler->NotifyReadyToCommit(); 389 scheduler->NotifyReadyToCommit();
420 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 390 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
421 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 391 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
422 client.Reset(); 392 client.Reset();
423 client.task_runner().RunPendingTasks(); // Run posted deadline. 393 client.RunPendingTasks(true); // Run posted deadline.
424 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); 394 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2);
425 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); 395 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2);
426 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 396 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
427 EXPECT_TRUE(client.needs_begin_frame()); 397 EXPECT_TRUE(client.needs_begin_frame());
428 client.Reset(); 398 client.Reset();
429 399
430 // On the next BeginImplFrame, verify we go back to a quiescent state and 400 // On the next BeginImplFrame, verify we go back to a quiescent state and
431 // no longer request BeginImplFrames. 401 // no longer request BeginImplFrames.
432 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 402 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
433 client.task_runner().RunPendingTasks(); // Run posted deadline. 403 client.RunPendingTasks(true); // Run posted deadline.
434 EXPECT_FALSE(client.needs_begin_frame()); 404 EXPECT_FALSE(client.needs_begin_frame());
435 client.Reset(); 405 client.Reset();
436 } 406 }
437 407
438 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { 408 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient {
439 public: 409 public:
440 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} 410 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {}
441 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() 411 virtual DrawResult ScheduledActionDrawAndSwapIfPossible()
442 OVERRIDE { 412 OVERRIDE {
443 // Only SetNeedsRedraw the first time this is called 413 // Only SetNeedsRedraw the first time this is called
(...skipping 25 matching lines...) Expand all
469 scheduler->SetCanDraw(true); 439 scheduler->SetCanDraw(true);
470 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 440 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
471 client.Reset(); 441 client.Reset();
472 442
473 scheduler->SetNeedsRedraw(); 443 scheduler->SetNeedsRedraw();
474 EXPECT_TRUE(scheduler->RedrawPending()); 444 EXPECT_TRUE(scheduler->RedrawPending());
475 EXPECT_TRUE(client.needs_begin_frame()); 445 EXPECT_TRUE(client.needs_begin_frame());
476 EXPECT_EQ(0, client.num_draws()); 446 EXPECT_EQ(0, client.num_draws());
477 447
478 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 448 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
479 client.task_runner().RunPendingTasks(); // Run posted deadline. 449 client.RunPendingTasks(true); // Run posted deadline.
480 EXPECT_EQ(1, client.num_draws()); 450 EXPECT_EQ(1, client.num_draws());
481 EXPECT_TRUE(scheduler->RedrawPending()); 451 EXPECT_TRUE(scheduler->RedrawPending());
482 EXPECT_TRUE(client.needs_begin_frame()); 452 EXPECT_TRUE(client.needs_begin_frame());
483 453
484 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 454 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
485 client.task_runner().RunPendingTasks(); // Run posted deadline. 455 client.RunPendingTasks(true); // Run posted deadline.
486 EXPECT_EQ(2, client.num_draws()); 456 EXPECT_EQ(2, client.num_draws());
487 EXPECT_FALSE(scheduler->RedrawPending()); 457 EXPECT_FALSE(scheduler->RedrawPending());
488 EXPECT_TRUE(client.needs_begin_frame()); 458 EXPECT_TRUE(client.needs_begin_frame());
489 459
490 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't 460 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't
491 // swap. 461 // swap.
492 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 462 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
493 client.task_runner().RunPendingTasks(); // Run posted deadline. 463 client.RunPendingTasks(true); // Run posted deadline.
494 EXPECT_EQ(2, client.num_draws()); 464 EXPECT_EQ(2, client.num_draws());
495 EXPECT_FALSE(scheduler->RedrawPending()); 465 EXPECT_FALSE(scheduler->RedrawPending());
496 EXPECT_FALSE(client.needs_begin_frame()); 466 EXPECT_FALSE(client.needs_begin_frame());
497 } 467 }
498 468
499 // Test that requesting redraw inside a failed draw doesn't lose the request. 469 // Test that requesting redraw inside a failed draw doesn't lose the request.
500 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { 470 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) {
501 SchedulerClientThatsetNeedsDrawInsideDraw client; 471 SchedulerClientThatsetNeedsDrawInsideDraw client;
502 SchedulerSettings default_scheduler_settings; 472 SchedulerSettings default_scheduler_settings;
503 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 473 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
504 scheduler->SetCanStart(); 474 scheduler->SetCanStart();
505 scheduler->SetVisible(true); 475 scheduler->SetVisible(true);
506 scheduler->SetCanDraw(true); 476 scheduler->SetCanDraw(true);
507 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 477 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
508 client.Reset(); 478 client.Reset();
509 479
510 client.SetDrawWillHappen(false); 480 client.SetDrawWillHappen(false);
511 481
512 scheduler->SetNeedsRedraw(); 482 scheduler->SetNeedsRedraw();
513 EXPECT_TRUE(scheduler->RedrawPending()); 483 EXPECT_TRUE(scheduler->RedrawPending());
514 EXPECT_TRUE(client.needs_begin_frame()); 484 EXPECT_TRUE(client.needs_begin_frame());
515 EXPECT_EQ(0, client.num_draws()); 485 EXPECT_EQ(0, client.num_draws());
516 486
517 // Fail the draw. 487 // Fail the draw.
518 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 488 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
519 client.task_runner().RunPendingTasks(); // Run posted deadline. 489 client.RunPendingTasks(true); // Run posted deadline.
520 EXPECT_EQ(1, client.num_draws()); 490 EXPECT_EQ(1, client.num_draws());
521 491
522 // We have a commit pending and the draw failed, and we didn't lose the redraw 492 // We have a commit pending and the draw failed, and we didn't lose the redraw
523 // request. 493 // request.
524 EXPECT_TRUE(scheduler->CommitPending()); 494 EXPECT_TRUE(scheduler->CommitPending());
525 EXPECT_TRUE(scheduler->RedrawPending()); 495 EXPECT_TRUE(scheduler->RedrawPending());
526 EXPECT_TRUE(client.needs_begin_frame()); 496 EXPECT_TRUE(client.needs_begin_frame());
527 497
528 // Fail the draw again. 498 // Fail the draw again.
529 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 499 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
530 client.task_runner().RunPendingTasks(); // Run posted deadline. 500 client.RunPendingTasks(true); // Run posted deadline.
531 EXPECT_EQ(2, client.num_draws()); 501 EXPECT_EQ(2, client.num_draws());
532 EXPECT_TRUE(scheduler->CommitPending()); 502 EXPECT_TRUE(scheduler->CommitPending());
533 EXPECT_TRUE(scheduler->RedrawPending()); 503 EXPECT_TRUE(scheduler->RedrawPending());
534 EXPECT_TRUE(client.needs_begin_frame()); 504 EXPECT_TRUE(client.needs_begin_frame());
535 505
536 // Draw successfully. 506 // Draw successfully.
537 client.SetDrawWillHappen(true); 507 client.SetDrawWillHappen(true);
538 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 508 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
539 client.task_runner().RunPendingTasks(); // Run posted deadline. 509 client.RunPendingTasks(true); // Run posted deadline.
540 EXPECT_EQ(3, client.num_draws()); 510 EXPECT_EQ(3, client.num_draws());
541 EXPECT_TRUE(scheduler->CommitPending()); 511 EXPECT_TRUE(scheduler->CommitPending());
542 EXPECT_FALSE(scheduler->RedrawPending()); 512 EXPECT_FALSE(scheduler->RedrawPending());
543 EXPECT_TRUE(client.needs_begin_frame()); 513 EXPECT_TRUE(client.needs_begin_frame());
544 } 514 }
545 515
546 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { 516 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient {
547 public: 517 public:
548 SchedulerClientThatSetNeedsCommitInsideDraw() 518 SchedulerClientThatSetNeedsCommitInsideDraw()
549 : set_needs_commit_on_next_draw_(false) {} 519 : set_needs_commit_on_next_draw_(false) {}
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 558
589 EXPECT_FALSE(client.needs_begin_frame()); 559 EXPECT_FALSE(client.needs_begin_frame());
590 scheduler->SetNeedsRedraw(); 560 scheduler->SetNeedsRedraw();
591 EXPECT_TRUE(scheduler->RedrawPending()); 561 EXPECT_TRUE(scheduler->RedrawPending());
592 EXPECT_EQ(0, client.num_draws()); 562 EXPECT_EQ(0, client.num_draws());
593 EXPECT_TRUE(client.needs_begin_frame()); 563 EXPECT_TRUE(client.needs_begin_frame());
594 564
595 client.SetNeedsCommitOnNextDraw(); 565 client.SetNeedsCommitOnNextDraw();
596 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 566 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
597 client.SetNeedsCommitOnNextDraw(); 567 client.SetNeedsCommitOnNextDraw();
598 client.task_runner().RunPendingTasks(); // Run posted deadline. 568 client.RunPendingTasks(true); // Run posted deadline.
599 EXPECT_EQ(1, client.num_draws()); 569 EXPECT_EQ(1, client.num_draws());
600 EXPECT_TRUE(scheduler->CommitPending()); 570 EXPECT_TRUE(scheduler->CommitPending());
601 EXPECT_TRUE(client.needs_begin_frame()); 571 EXPECT_TRUE(client.needs_begin_frame());
602 scheduler->NotifyBeginMainFrameStarted(); 572 scheduler->NotifyBeginMainFrameStarted();
603 scheduler->NotifyReadyToCommit(); 573 scheduler->NotifyReadyToCommit();
604 574
605 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 575 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
606 client.task_runner().RunPendingTasks(); // Run posted deadline. 576 client.RunPendingTasks(true); // Run posted deadline.
607 EXPECT_EQ(2, client.num_draws()); 577 EXPECT_EQ(2, client.num_draws());
608 578
609 EXPECT_FALSE(scheduler->RedrawPending()); 579 EXPECT_FALSE(scheduler->RedrawPending());
610 EXPECT_FALSE(scheduler->CommitPending()); 580 EXPECT_FALSE(scheduler->CommitPending());
611 EXPECT_TRUE(client.needs_begin_frame()); 581 EXPECT_TRUE(client.needs_begin_frame());
612 582
613 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't 583 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't
614 // swap. 584 // swap.
615 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 585 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
616 client.task_runner().RunPendingTasks(); // Run posted deadline. 586 client.RunPendingTasks(true); // Run posted deadline.
617 EXPECT_EQ(2, client.num_draws()); 587 EXPECT_EQ(2, client.num_draws());
618 EXPECT_FALSE(scheduler->RedrawPending()); 588 EXPECT_FALSE(scheduler->RedrawPending());
619 EXPECT_FALSE(scheduler->CommitPending()); 589 EXPECT_FALSE(scheduler->CommitPending());
620 EXPECT_FALSE(client.needs_begin_frame()); 590 EXPECT_FALSE(client.needs_begin_frame());
621 } 591 }
622 592
623 // Tests that when a draw fails then the pending commit should not be dropped. 593 // Tests that when a draw fails then the pending commit should not be dropped.
624 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { 594 TEST(SchedulerTest, RequestCommitInsideFailedDraw) {
625 SchedulerClientThatsetNeedsDrawInsideDraw client; 595 SchedulerClientThatsetNeedsDrawInsideDraw client;
626 SchedulerSettings default_scheduler_settings; 596 SchedulerSettings default_scheduler_settings;
627 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 597 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
628 scheduler->SetCanStart(); 598 scheduler->SetCanStart();
629 scheduler->SetVisible(true); 599 scheduler->SetVisible(true);
630 scheduler->SetCanDraw(true); 600 scheduler->SetCanDraw(true);
631 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 601 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
632 client.Reset(); 602 client.Reset();
633 603
634 client.SetDrawWillHappen(false); 604 client.SetDrawWillHappen(false);
635 605
636 scheduler->SetNeedsRedraw(); 606 scheduler->SetNeedsRedraw();
637 EXPECT_TRUE(scheduler->RedrawPending()); 607 EXPECT_TRUE(scheduler->RedrawPending());
638 EXPECT_TRUE(client.needs_begin_frame()); 608 EXPECT_TRUE(client.needs_begin_frame());
639 EXPECT_EQ(0, client.num_draws()); 609 EXPECT_EQ(0, client.num_draws());
640 610
641 // Fail the draw. 611 // Fail the draw.
642 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 612 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
643 client.task_runner().RunPendingTasks(); // Run posted deadline. 613 client.RunPendingTasks(true); // Run posted deadline.
644 EXPECT_EQ(1, client.num_draws()); 614 EXPECT_EQ(1, client.num_draws());
645 615
646 // We have a commit pending and the draw failed, and we didn't lose the commit 616 // We have a commit pending and the draw failed, and we didn't lose the commit
647 // request. 617 // request.
648 EXPECT_TRUE(scheduler->CommitPending()); 618 EXPECT_TRUE(scheduler->CommitPending());
649 EXPECT_TRUE(scheduler->RedrawPending()); 619 EXPECT_TRUE(scheduler->RedrawPending());
650 EXPECT_TRUE(client.needs_begin_frame()); 620 EXPECT_TRUE(client.needs_begin_frame());
651 621
652 // Fail the draw again. 622 // Fail the draw again.
653 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 623 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
654 624
655 client.task_runner().RunPendingTasks(); // Run posted deadline. 625 client.RunPendingTasks(true); // Run posted deadline.
656 EXPECT_EQ(2, client.num_draws()); 626 EXPECT_EQ(2, client.num_draws());
657 EXPECT_TRUE(scheduler->CommitPending()); 627 EXPECT_TRUE(scheduler->CommitPending());
658 EXPECT_TRUE(scheduler->RedrawPending()); 628 EXPECT_TRUE(scheduler->RedrawPending());
659 EXPECT_TRUE(client.needs_begin_frame()); 629 EXPECT_TRUE(client.needs_begin_frame());
660 630
661 // Draw successfully. 631 // Draw successfully.
662 client.SetDrawWillHappen(true); 632 client.SetDrawWillHappen(true);
663 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 633 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
664 client.task_runner().RunPendingTasks(); // Run posted deadline. 634 client.RunPendingTasks(true); // Run posted deadline.
665 EXPECT_EQ(3, client.num_draws()); 635 EXPECT_EQ(3, client.num_draws());
666 EXPECT_TRUE(scheduler->CommitPending()); 636 EXPECT_TRUE(scheduler->CommitPending());
667 EXPECT_FALSE(scheduler->RedrawPending()); 637 EXPECT_FALSE(scheduler->RedrawPending());
668 EXPECT_TRUE(client.needs_begin_frame()); 638 EXPECT_TRUE(client.needs_begin_frame());
669 } 639 }
670 640
671 TEST(SchedulerTest, NoSwapWhenDrawFails) { 641 TEST(SchedulerTest, NoSwapWhenDrawFails) {
672 SchedulerClientThatSetNeedsCommitInsideDraw client; 642 SchedulerClientThatSetNeedsCommitInsideDraw client;
673 SchedulerSettings default_scheduler_settings; 643 SchedulerSettings default_scheduler_settings;
674 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 644 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
675 scheduler->SetCanStart(); 645 scheduler->SetCanStart();
676 scheduler->SetVisible(true); 646 scheduler->SetVisible(true);
677 scheduler->SetCanDraw(true); 647 scheduler->SetCanDraw(true);
678 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 648 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
679 client.Reset(); 649 client.Reset();
680 650
681 scheduler->SetNeedsRedraw(); 651 scheduler->SetNeedsRedraw();
682 EXPECT_TRUE(scheduler->RedrawPending()); 652 EXPECT_TRUE(scheduler->RedrawPending());
683 EXPECT_TRUE(client.needs_begin_frame()); 653 EXPECT_TRUE(client.needs_begin_frame());
684 EXPECT_EQ(0, client.num_draws()); 654 EXPECT_EQ(0, client.num_draws());
685 655
686 // Draw successfully, this starts a new frame. 656 // Draw successfully, this starts a new frame.
687 client.SetNeedsCommitOnNextDraw(); 657 client.SetNeedsCommitOnNextDraw();
688 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 658 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
689 client.task_runner().RunPendingTasks(); // Run posted deadline. 659 client.RunPendingTasks(true); // Run posted deadline.
690 EXPECT_EQ(1, client.num_draws()); 660 EXPECT_EQ(1, client.num_draws());
691 661
692 scheduler->SetNeedsRedraw(); 662 scheduler->SetNeedsRedraw();
693 EXPECT_TRUE(scheduler->RedrawPending()); 663 EXPECT_TRUE(scheduler->RedrawPending());
694 EXPECT_TRUE(client.needs_begin_frame()); 664 EXPECT_TRUE(client.needs_begin_frame());
695 665
696 // Fail to draw, this should not start a frame. 666 // Fail to draw, this should not start a frame.
697 client.SetDrawWillHappen(false); 667 client.SetDrawWillHappen(false);
698 client.SetNeedsCommitOnNextDraw(); 668 client.SetNeedsCommitOnNextDraw();
699 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 669 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
700 client.task_runner().RunPendingTasks(); // Run posted deadline. 670 client.RunPendingTasks(true); // Run posted deadline.
701 EXPECT_EQ(2, client.num_draws()); 671 EXPECT_EQ(2, client.num_draws());
702 } 672 }
703 673
704 class SchedulerClientNeedsManageTilesInDraw : public FakeSchedulerClient { 674 class SchedulerClientNeedsManageTilesInDraw : public FakeSchedulerClient {
705 public: 675 public:
706 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() 676 virtual DrawResult ScheduledActionDrawAndSwapIfPossible()
707 OVERRIDE { 677 OVERRIDE {
708 scheduler_->SetNeedsManageTiles(); 678 scheduler_->SetNeedsManageTiles();
709 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); 679 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible();
710 } 680 }
(...skipping 24 matching lines...) Expand all
735 // We have no immediate actions to perform, so the BeginImplFrame should post 705 // We have no immediate actions to perform, so the BeginImplFrame should post
736 // the deadline task. 706 // the deadline task.
737 client.Reset(); 707 client.Reset();
738 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 708 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
739 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 709 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
740 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 710 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2);
741 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 711 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
742 712
743 // On the deadline, he actions should have occured in the right order. 713 // On the deadline, he actions should have occured in the right order.
744 client.Reset(); 714 client.Reset();
745 client.task_runner().RunPendingTasks(); // Run posted deadline. 715 client.RunPendingTasks(true); // Run posted deadline.
746 EXPECT_EQ(1, client.num_draws()); 716 EXPECT_EQ(1, client.num_draws());
747 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 717 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
748 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); 718 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles"));
749 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), 719 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"),
750 client.ActionIndex("ScheduledActionManageTiles")); 720 client.ActionIndex("ScheduledActionManageTiles"));
751 EXPECT_FALSE(scheduler->RedrawPending()); 721 EXPECT_FALSE(scheduler->RedrawPending());
752 EXPECT_FALSE(scheduler->ManageTilesPending()); 722 EXPECT_FALSE(scheduler->ManageTilesPending());
753 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 723 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
754 724
755 // Request a draw. We don't need a ManageTiles yet. 725 // Request a draw. We don't need a ManageTiles yet.
756 client.Reset(); 726 client.Reset();
757 scheduler->SetNeedsRedraw(); 727 scheduler->SetNeedsRedraw();
758 EXPECT_TRUE(scheduler->RedrawPending()); 728 EXPECT_TRUE(scheduler->RedrawPending());
759 EXPECT_FALSE(scheduler->ManageTilesPending()); 729 EXPECT_FALSE(scheduler->ManageTilesPending());
760 EXPECT_TRUE(client.needs_begin_frame()); 730 EXPECT_TRUE(client.needs_begin_frame());
761 EXPECT_EQ(0, client.num_draws()); 731 EXPECT_EQ(0, client.num_draws());
762 732
763 // We have no immediate actions to perform, so the BeginImplFrame should post 733 // We have no immediate actions to perform, so the BeginImplFrame should post
764 // the deadline task. 734 // the deadline task.
765 client.Reset(); 735 client.Reset();
766 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 736 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
767 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 737 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
768 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 738 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2);
769 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 739 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
770 740
771 // Draw. The draw will trigger SetNeedsManageTiles, and 741 // Draw. The draw will trigger SetNeedsManageTiles, and
772 // then the ManageTiles action will be triggered after the Draw. 742 // then the ManageTiles action will be triggered after the Draw.
773 // Afterwards, neither a draw nor ManageTiles are pending. 743 // Afterwards, neither a draw nor ManageTiles are pending.
774 client.Reset(); 744 client.Reset();
775 client.task_runner().RunPendingTasks(); // Run posted deadline. 745 client.RunPendingTasks(true); // Run posted deadline.
776 EXPECT_EQ(1, client.num_draws()); 746 EXPECT_EQ(1, client.num_draws());
777 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 747 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
778 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); 748 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles"));
779 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), 749 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"),
780 client.ActionIndex("ScheduledActionManageTiles")); 750 client.ActionIndex("ScheduledActionManageTiles"));
781 EXPECT_FALSE(scheduler->RedrawPending()); 751 EXPECT_FALSE(scheduler->RedrawPending());
782 EXPECT_FALSE(scheduler->ManageTilesPending()); 752 EXPECT_FALSE(scheduler->ManageTilesPending());
783 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 753 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
784 754
785 // We need a BeginImplFrame where we don't swap to go idle. 755 // We need a BeginImplFrame where we don't swap to go idle.
786 client.Reset(); 756 client.Reset();
787 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 757 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
788 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); 758 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
789 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 759 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
790 client.Reset(); 760 client.Reset();
791 client.task_runner().RunPendingTasks(); // Run posted deadline. 761 client.RunPendingTasks(true); // Run posted deadline.
792 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); 762 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
793 EXPECT_FALSE(client.needs_begin_frame()); 763 EXPECT_FALSE(client.needs_begin_frame());
794 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 764 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
795 EXPECT_EQ(0, client.num_draws()); 765 EXPECT_EQ(0, client.num_draws());
796 766
797 // Now trigger a ManageTiles outside of a draw. We will then need 767 // Now trigger a ManageTiles outside of a draw. We will then need
798 // a begin-frame for the ManageTiles, but we don't need a draw. 768 // a begin-frame for the ManageTiles, but we don't need a draw.
799 client.Reset(); 769 client.Reset();
800 EXPECT_FALSE(client.needs_begin_frame()); 770 EXPECT_FALSE(client.needs_begin_frame());
801 scheduler->SetNeedsManageTiles(); 771 scheduler->SetNeedsManageTiles();
802 EXPECT_TRUE(client.needs_begin_frame()); 772 EXPECT_TRUE(client.needs_begin_frame());
803 EXPECT_TRUE(scheduler->ManageTilesPending()); 773 EXPECT_TRUE(scheduler->ManageTilesPending());
804 EXPECT_FALSE(scheduler->RedrawPending()); 774 EXPECT_FALSE(scheduler->RedrawPending());
805 775
806 // BeginImplFrame. There will be no draw, only ManageTiles. 776 // BeginImplFrame. There will be no draw, only ManageTiles.
807 client.Reset(); 777 client.Reset();
808 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 778 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
809 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); 779 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
810 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 780 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
811 client.Reset(); 781 client.Reset();
812 client.task_runner().RunPendingTasks(); // Run posted deadline. 782 client.RunPendingTasks(true); // Run posted deadline.
813 EXPECT_EQ(0, client.num_draws()); 783 EXPECT_EQ(0, client.num_draws());
814 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 784 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
815 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); 785 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles"));
816 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 786 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
817 } 787 }
818 788
819 // Test that ManageTiles only happens once per frame. If an external caller 789 // Test that ManageTiles only happens once per frame. If an external caller
820 // initiates it, then the state machine should not ManageTiles on that frame. 790 // initiates it, then the state machine should not ManageTiles on that frame.
821 TEST(SchedulerTest, ManageTilesOncePerFrame) { 791 TEST(SchedulerTest, ManageTilesOncePerFrame) {
822 FakeSchedulerClient client; 792 FakeSchedulerClient client;
(...skipping 11 matching lines...) Expand all
834 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 804 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
835 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 805 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
836 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 806 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2);
837 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 807 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
838 808
839 EXPECT_TRUE(scheduler->ManageTilesPending()); 809 EXPECT_TRUE(scheduler->ManageTilesPending());
840 scheduler->DidManageTiles(); // An explicit ManageTiles. 810 scheduler->DidManageTiles(); // An explicit ManageTiles.
841 EXPECT_FALSE(scheduler->ManageTilesPending()); 811 EXPECT_FALSE(scheduler->ManageTilesPending());
842 812
843 client.Reset(); 813 client.Reset();
844 client.task_runner().RunPendingTasks(); // Run posted deadline. 814 client.RunPendingTasks(true); // Run posted deadline.
845 EXPECT_EQ(1, client.num_draws()); 815 EXPECT_EQ(1, client.num_draws());
846 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 816 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
847 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); 817 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles"));
848 EXPECT_FALSE(scheduler->RedrawPending()); 818 EXPECT_FALSE(scheduler->RedrawPending());
849 EXPECT_FALSE(scheduler->ManageTilesPending()); 819 EXPECT_FALSE(scheduler->ManageTilesPending());
850 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 820 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
851 821
852 // Next frame without DidManageTiles should ManageTiles with draw. 822 // Next frame without DidManageTiles should ManageTiles with draw.
853 scheduler->SetNeedsManageTiles(); 823 scheduler->SetNeedsManageTiles();
854 scheduler->SetNeedsRedraw(); 824 scheduler->SetNeedsRedraw();
855 client.Reset(); 825 client.Reset();
856 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 826 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
857 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 827 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
858 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 828 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2);
859 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 829 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
860 830
861 client.Reset(); 831 client.Reset();
862 client.task_runner().RunPendingTasks(); // Run posted deadline. 832 client.RunPendingTasks(true); // Run posted deadline.
863 EXPECT_EQ(1, client.num_draws()); 833 EXPECT_EQ(1, client.num_draws());
864 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 834 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
865 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); 835 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles"));
866 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), 836 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"),
867 client.ActionIndex("ScheduledActionManageTiles")); 837 client.ActionIndex("ScheduledActionManageTiles"));
868 EXPECT_FALSE(scheduler->RedrawPending()); 838 EXPECT_FALSE(scheduler->RedrawPending());
869 EXPECT_FALSE(scheduler->ManageTilesPending()); 839 EXPECT_FALSE(scheduler->ManageTilesPending());
870 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 840 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
871 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles 841 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles
872 842
873 // If we get another DidManageTiles within the same frame, we should 843 // If we get another DidManageTiles within the same frame, we should
874 // not ManageTiles on the next frame. 844 // not ManageTiles on the next frame.
875 scheduler->DidManageTiles(); // An explicit ManageTiles. 845 scheduler->DidManageTiles(); // An explicit ManageTiles.
876 scheduler->SetNeedsManageTiles(); 846 scheduler->SetNeedsManageTiles();
877 scheduler->SetNeedsRedraw(); 847 scheduler->SetNeedsRedraw();
878 client.Reset(); 848 client.Reset();
879 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 849 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
880 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 850 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
881 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 851 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2);
882 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 852 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
883 853
884 EXPECT_TRUE(scheduler->ManageTilesPending()); 854 EXPECT_TRUE(scheduler->ManageTilesPending());
885 855
886 client.Reset(); 856 client.Reset();
887 client.task_runner().RunPendingTasks(); // Run posted deadline. 857 client.RunPendingTasks(true); // Run posted deadline.
888 EXPECT_EQ(1, client.num_draws()); 858 EXPECT_EQ(1, client.num_draws());
889 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 859 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
890 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); 860 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles"));
891 EXPECT_FALSE(scheduler->RedrawPending()); 861 EXPECT_FALSE(scheduler->RedrawPending());
892 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 862 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
893 863
894 // If we get another DidManageTiles, we should not ManageTiles on the next 864 // If we get another DidManageTiles, we should not ManageTiles on the next
895 // frame. This verifies we don't alternate calling ManageTiles once and twice. 865 // frame. This verifies we don't alternate calling ManageTiles once and twice.
896 EXPECT_TRUE(scheduler->ManageTilesPending()); 866 EXPECT_TRUE(scheduler->ManageTilesPending());
897 scheduler->DidManageTiles(); // An explicit ManageTiles. 867 scheduler->DidManageTiles(); // An explicit ManageTiles.
898 EXPECT_FALSE(scheduler->ManageTilesPending()); 868 EXPECT_FALSE(scheduler->ManageTilesPending());
899 scheduler->SetNeedsManageTiles(); 869 scheduler->SetNeedsManageTiles();
900 scheduler->SetNeedsRedraw(); 870 scheduler->SetNeedsRedraw();
901 client.Reset(); 871 client.Reset();
902 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 872 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
903 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 873 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
904 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 874 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2);
905 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 875 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
906 876
907 EXPECT_TRUE(scheduler->ManageTilesPending()); 877 EXPECT_TRUE(scheduler->ManageTilesPending());
908 878
909 client.Reset(); 879 client.Reset();
910 client.task_runner().RunPendingTasks(); // Run posted deadline. 880 client.RunPendingTasks(true); // Run posted deadline.
911 EXPECT_EQ(1, client.num_draws()); 881 EXPECT_EQ(1, client.num_draws());
912 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 882 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
913 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); 883 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles"));
914 EXPECT_FALSE(scheduler->RedrawPending()); 884 EXPECT_FALSE(scheduler->RedrawPending());
915 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 885 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
916 886
917 // Next frame without DidManageTiles should ManageTiles with draw. 887 // Next frame without DidManageTiles should ManageTiles with draw.
918 scheduler->SetNeedsManageTiles(); 888 scheduler->SetNeedsManageTiles();
919 scheduler->SetNeedsRedraw(); 889 scheduler->SetNeedsRedraw();
920 client.Reset(); 890 client.Reset();
921 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 891 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
922 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 892 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
923 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 893 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2);
924 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 894 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
925 895
926 client.Reset(); 896 client.Reset();
927 client.task_runner().RunPendingTasks(); // Run posted deadline. 897 client.RunPendingTasks(true); // Run posted deadline.
928 EXPECT_EQ(1, client.num_draws()); 898 EXPECT_EQ(1, client.num_draws());
929 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 899 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
930 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); 900 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles"));
931 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), 901 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"),
932 client.ActionIndex("ScheduledActionManageTiles")); 902 client.ActionIndex("ScheduledActionManageTiles"));
933 EXPECT_FALSE(scheduler->RedrawPending()); 903 EXPECT_FALSE(scheduler->RedrawPending());
934 EXPECT_FALSE(scheduler->ManageTilesPending()); 904 EXPECT_FALSE(scheduler->ManageTilesPending());
935 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 905 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
936 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles 906 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles
937 } 907 }
(...skipping 25 matching lines...) Expand all
963 scheduler->NotifyBeginMainFrameStarted(); 933 scheduler->NotifyBeginMainFrameStarted();
964 scheduler->NotifyReadyToCommit(); 934 scheduler->NotifyReadyToCommit();
965 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 935 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
966 936
967 client.Reset(); 937 client.Reset();
968 scheduler->NotifyReadyToActivate(); 938 scheduler->NotifyReadyToActivate();
969 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client); 939 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client);
970 940
971 client.Reset(); 941 client.Reset();
972 client.SetSwapContainsIncompleteTile(true); 942 client.SetSwapContainsIncompleteTile(true);
973 client.task_runner().RunPendingTasks(); // Run posted deadline. 943 client.RunPendingTasks(true); // Run posted deadline.
974 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); 944 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2);
975 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); 945 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2);
976 EXPECT_FALSE(scheduler->RedrawPending()); 946 EXPECT_FALSE(scheduler->RedrawPending());
977 947
978 client.Reset(); 948 client.Reset();
979 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 949 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
980 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); 950 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
981 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 951 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
982 952
983 client.Reset(); 953 client.Reset();
984 client.task_runner().RunPendingTasks(); // Run posted deadline. 954 client.RunPendingTasks(true); // Run posted deadline.
985 EXPECT_ACTION("ScheduledActionUpdateVisibleTiles", client, 0, 3); 955 EXPECT_ACTION("ScheduledActionUpdateVisibleTiles", client, 0, 3);
986 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 3); 956 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 3);
987 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 2, 3); 957 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 2, 3);
988 958
989 client.Reset(); 959 client.Reset();
990 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 960 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
991 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); 961 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
992 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 962 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
993 963
994 // No more UpdateVisibleTiles(). 964 // No more UpdateVisibleTiles().
995 client.Reset(); 965 client.Reset();
996 client.task_runner().RunPendingTasks(); // Run posted deadline. 966 client.RunPendingTasks(true); // Run posted deadline.
997 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); 967 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
998 EXPECT_FALSE(client.needs_begin_frame()); 968 EXPECT_FALSE(client.needs_begin_frame());
999 } 969 }
1000 970
1001 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { 971 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) {
1002 SchedulerClientNeedsManageTilesInDraw client; 972 SchedulerClientNeedsManageTilesInDraw client;
1003 SchedulerSettings default_scheduler_settings; 973 SchedulerSettings default_scheduler_settings;
1004 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 974 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
1005 scheduler->SetCanStart(); 975 scheduler->SetCanStart();
1006 scheduler->SetVisible(true); 976 scheduler->SetVisible(true);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 scheduler->SetCanDraw(true); 1030 scheduler->SetCanDraw(true);
1061 scheduler->SetSmoothnessTakesPriority(smoothness_takes_priority); 1031 scheduler->SetSmoothnessTakesPriority(smoothness_takes_priority);
1062 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 1032 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
1063 1033
1064 // Impl thread hits deadline before commit finishes. 1034 // Impl thread hits deadline before commit finishes.
1065 client.Reset(); 1035 client.Reset();
1066 scheduler->SetNeedsCommit(); 1036 scheduler->SetNeedsCommit();
1067 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); 1037 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode());
1068 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 1038 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
1069 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); 1039 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode());
1070 client.task_runner().RunPendingTasks(); // Run posted deadline. 1040 client.RunPendingTasks(true); // Run posted deadline.
1071 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); 1041 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode());
1072 scheduler->NotifyBeginMainFrameStarted(); 1042 scheduler->NotifyBeginMainFrameStarted();
1073 scheduler->NotifyReadyToCommit(); 1043 scheduler->NotifyReadyToCommit();
1074 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); 1044 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode());
1075 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame")); 1045 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame"));
1076 1046
1077 client.Reset(); 1047 client.Reset();
1078 scheduler->SetNeedsCommit(); 1048 scheduler->SetNeedsCommit();
1079 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); 1049 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode());
1080 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 1050 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
1081 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); 1051 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode());
1082 client.task_runner().RunPendingTasks(); // Run posted deadline. 1052 client.RunPendingTasks(true); // Run posted deadline.
1083 EXPECT_EQ(scheduler->MainThreadIsInHighLatencyMode(), 1053 EXPECT_EQ(scheduler->MainThreadIsInHighLatencyMode(),
1084 should_send_begin_main_frame); 1054 should_send_begin_main_frame);
1085 EXPECT_EQ(client.HasAction("ScheduledActionSendBeginMainFrame"), 1055 EXPECT_EQ(client.HasAction("ScheduledActionSendBeginMainFrame"),
1086 should_send_begin_main_frame); 1056 should_send_begin_main_frame);
1087 } 1057 }
1088 1058
1089 TEST(SchedulerTest, 1059 TEST(SchedulerTest,
1090 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { 1060 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) {
1091 // Set up client so that estimates indicate that we can commit and activate 1061 // Set up client so that estimates indicate that we can commit and activate
1092 // before the deadline (~8ms by default). 1062 // before the deadline (~8ms by default).
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 EXPECT_TRUE(scheduler->CommitPending()); 1102 EXPECT_TRUE(scheduler->CommitPending());
1133 scheduler->NotifyBeginMainFrameStarted(); 1103 scheduler->NotifyBeginMainFrameStarted();
1134 scheduler->NotifyReadyToCommit(); 1104 scheduler->NotifyReadyToCommit();
1135 scheduler->SetNeedsRedraw(); 1105 scheduler->SetNeedsRedraw();
1136 1106
1137 BeginFrameArgs frame_args = CreateBeginFrameArgsForTesting(); 1107 BeginFrameArgs frame_args = CreateBeginFrameArgsForTesting();
1138 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); 1108 frame_args.interval = base::TimeDelta::FromMilliseconds(1000);
1139 scheduler->BeginFrame(frame_args); 1109 scheduler->BeginFrame(frame_args);
1140 1110
1141 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1111 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1142 client.task_runner().RunPendingTasks(); // Run posted deadline. 1112 client.RunPendingTasks(true); // Run posted deadline.
1143 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1113 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1144 1114
1145 scheduler->DidSwapBuffers(); 1115 scheduler->DidSwapBuffers();
1146 scheduler->DidSwapBuffersComplete(); 1116 scheduler->DidSwapBuffersComplete();
1147 1117
1148 // At this point, we've drawn a frame. Start another commit, but hold off on 1118 // At this point, we've drawn a frame. Start another commit, but hold off on
1149 // the NotifyReadyToCommit for now. 1119 // the NotifyReadyToCommit for now.
1150 EXPECT_FALSE(scheduler->CommitPending()); 1120 EXPECT_FALSE(scheduler->CommitPending());
1151 scheduler->SetNeedsCommit(); 1121 scheduler->SetNeedsCommit();
1152 scheduler->BeginFrame(frame_args); 1122 scheduler->BeginFrame(frame_args);
1153 EXPECT_TRUE(scheduler->CommitPending()); 1123 EXPECT_TRUE(scheduler->CommitPending());
1154 1124
1155 // Draw and swap the frame, but don't ack the swap to simulate the Browser 1125 // Draw and swap the frame, but don't ack the swap to simulate the Browser
1156 // blocking on the renderer. 1126 // blocking on the renderer.
1157 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1127 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1158 client.task_runner().RunPendingTasks(); // Run posted deadline. 1128 client.RunPendingTasks(true); // Run posted deadline.
1159 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1129 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1160 scheduler->DidSwapBuffers(); 1130 scheduler->DidSwapBuffers();
1161 1131
1162 // Spin the event loop a few times and make sure we get more 1132 // Spin the event loop a few times and make sure we get more
1163 // DidAnticipateDrawTimeChange calls every time. 1133 // DidAnticipateDrawTimeChange calls every time.
1164 int actions_so_far = client.num_actions_(); 1134 int actions_so_far = client.num_actions_();
1165 1135
1166 // Does three iterations to make sure that the timer is properly repeating. 1136 // Does three iterations to make sure that the timer is properly repeating.
1167 for (int i = 0; i < 3; ++i) { 1137 for (int i = 0; i < 3; ++i) {
1168 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), 1138 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(),
1169 client.task_runner().NextPendingTaskDelay().InMicroseconds()) 1139 client.NextPendingTaskDelay().InMicroseconds())
1170 << *scheduler->AsValue(); 1140 << *scheduler->AsValue();
1171 client.task_runner().RunPendingTasks(); 1141 client.RunPendingTasks(true);
1172 EXPECT_GT(client.num_actions_(), actions_so_far); 1142 EXPECT_GT(client.num_actions_(), actions_so_far);
1173 EXPECT_STREQ(client.Action(client.num_actions_() - 1), 1143 EXPECT_STREQ(client.Action(client.num_actions_() - 1),
1174 "DidAnticipatedDrawTimeChange"); 1144 "DidAnticipatedDrawTimeChange");
1175 actions_so_far = client.num_actions_(); 1145 actions_so_far = client.num_actions_();
1176 } 1146 }
1177 1147
1178 // Do the same thing after BeginMainFrame starts but still before activation. 1148 // Do the same thing after BeginMainFrame starts but still before activation.
1179 scheduler->NotifyBeginMainFrameStarted(); 1149 scheduler->NotifyBeginMainFrameStarted();
1180 for (int i = 0; i < 3; ++i) { 1150 for (int i = 0; i < 3; ++i) {
1181 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), 1151 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(),
1182 client.task_runner().NextPendingTaskDelay().InMicroseconds()) 1152 client.NextPendingTaskDelay().InMicroseconds())
1183 << *scheduler->AsValue(); 1153 << *scheduler->AsValue();
1184 client.task_runner().RunPendingTasks(); 1154 client.RunPendingTasks(true);
1185 EXPECT_GT(client.num_actions_(), actions_so_far); 1155 EXPECT_GT(client.num_actions_(), actions_so_far);
1186 EXPECT_STREQ(client.Action(client.num_actions_() - 1), 1156 EXPECT_STREQ(client.Action(client.num_actions_() - 1),
1187 "DidAnticipatedDrawTimeChange"); 1157 "DidAnticipatedDrawTimeChange");
1188 actions_so_far = client.num_actions_(); 1158 actions_so_far = client.num_actions_();
1189 } 1159 }
1190 } 1160 }
1191 1161
1192 TEST(SchedulerTest, BeginRetroFrame) { 1162 TEST(SchedulerTest, BeginRetroFrame) {
1193 FakeSchedulerClient client; 1163 FakeSchedulerClient client;
1194 SchedulerSettings scheduler_settings; 1164 SchedulerSettings scheduler_settings;
(...skipping 21 matching lines...) Expand all
1216 EXPECT_TRUE(client.needs_begin_frame()); 1186 EXPECT_TRUE(client.needs_begin_frame());
1217 client.Reset(); 1187 client.Reset();
1218 1188
1219 // Queue BeginFrames while we are still handling the previous BeginFrame. 1189 // Queue BeginFrames while we are still handling the previous BeginFrame.
1220 args.frame_time += base::TimeDelta::FromSeconds(1); 1190 args.frame_time += base::TimeDelta::FromSeconds(1);
1221 scheduler->BeginFrame(args); 1191 scheduler->BeginFrame(args);
1222 args.frame_time += base::TimeDelta::FromSeconds(1); 1192 args.frame_time += base::TimeDelta::FromSeconds(1);
1223 scheduler->BeginFrame(args); 1193 scheduler->BeginFrame(args);
1224 1194
1225 // If we don't swap on the deadline, we wait for the next BeginImplFrame. 1195 // If we don't swap on the deadline, we wait for the next BeginImplFrame.
1226 client.task_runner().RunPendingTasks(); // Run posted deadline. 1196 client.RunPendingTasks(true); // Run posted deadline.
1227 EXPECT_NO_ACTION(client); 1197 EXPECT_NO_ACTION(client);
1228 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1198 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1229 EXPECT_TRUE(client.needs_begin_frame()); 1199 EXPECT_TRUE(client.needs_begin_frame());
1230 client.Reset(); 1200 client.Reset();
1231 1201
1232 // NotifyReadyToCommit should trigger the commit. 1202 // NotifyReadyToCommit should trigger the commit.
1233 scheduler->NotifyBeginMainFrameStarted(); 1203 scheduler->NotifyBeginMainFrameStarted();
1234 scheduler->NotifyReadyToCommit(); 1204 scheduler->NotifyReadyToCommit();
1235 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 1205 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
1236 EXPECT_TRUE(client.needs_begin_frame()); 1206 EXPECT_TRUE(client.needs_begin_frame());
1237 client.Reset(); 1207 client.Reset();
1238 1208
1239 // BeginImplFrame should prepare the draw. 1209 // BeginImplFrame should prepare the draw.
1240 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. 1210 client.RunPendingTasks(true); // Run posted BeginRetroFrame.
1241 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1211 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1242 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 1212 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2);
1243 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1213 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1244 EXPECT_TRUE(client.needs_begin_frame()); 1214 EXPECT_TRUE(client.needs_begin_frame());
1245 client.Reset(); 1215 client.Reset();
1246 1216
1247 // BeginImplFrame deadline should draw. 1217 // BeginImplFrame deadline should draw.
1248 client.task_runner().RunPendingTasks(); // Run posted deadline. 1218 client.RunPendingTasks(true); // Run posted deadline.
1249 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); 1219 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1);
1250 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1220 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1251 EXPECT_TRUE(client.needs_begin_frame()); 1221 EXPECT_TRUE(client.needs_begin_frame());
1252 client.Reset(); 1222 client.Reset();
1253 1223
1254 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) 1224 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false)
1255 // to avoid excessive toggles. 1225 // to avoid excessive toggles.
1256 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. 1226 client.RunPendingTasks(true); // Run posted BeginRetroFrame.
1257 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); 1227 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
1258 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1228 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1259 client.Reset(); 1229 client.Reset();
1260 1230
1261 client.task_runner().RunPendingTasks(); // Run posted deadline. 1231 client.RunPendingTasks(true); // Run posted deadline.
1262 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); 1232 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client);
1263 EXPECT_FALSE(client.needs_begin_frame()); 1233 EXPECT_FALSE(client.needs_begin_frame());
1264 client.Reset(); 1234 client.Reset();
1265 } 1235 }
1266 1236
1267 TEST(SchedulerTest, BeginRetroFrame_SwapThrottled) { 1237 TEST(SchedulerTest, BeginRetroFrame_SwapThrottled) {
1268 FakeSchedulerClient client; 1238 FakeSchedulerClient client;
1269 SchedulerSettings scheduler_settings; 1239 SchedulerSettings scheduler_settings;
1270 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); 1240 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings);
1271 scheduler->SetCanStart(); 1241 scheduler->SetCanStart();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 client.Reset(); 1274 client.Reset();
1305 1275
1306 // NotifyReadyToCommit should trigger the pending commit and draw. 1276 // NotifyReadyToCommit should trigger the pending commit and draw.
1307 scheduler->NotifyBeginMainFrameStarted(); 1277 scheduler->NotifyBeginMainFrameStarted();
1308 scheduler->NotifyReadyToCommit(); 1278 scheduler->NotifyReadyToCommit();
1309 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 1279 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
1310 EXPECT_TRUE(client.needs_begin_frame()); 1280 EXPECT_TRUE(client.needs_begin_frame());
1311 client.Reset(); 1281 client.Reset();
1312 1282
1313 // Swapping will put us into a swap throttled state. 1283 // Swapping will put us into a swap throttled state.
1314 client.task_runner().RunPendingTasks(); // Run posted deadline. 1284 client.RunPendingTasks(true); // Run posted deadline.
1315 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); 1285 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2);
1316 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); 1286 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2);
1317 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1287 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1318 EXPECT_TRUE(client.needs_begin_frame()); 1288 EXPECT_TRUE(client.needs_begin_frame());
1319 client.Reset(); 1289 client.Reset();
1320 1290
1321 // While swap throttled, BeginRetroFrames should trigger BeginImplFrames 1291 // While swap throttled, BeginRetroFrames should trigger BeginImplFrames
1322 // but not a BeginMainFrame or draw. 1292 // but not a BeginMainFrame or draw.
1323 scheduler->SetNeedsCommit(); 1293 scheduler->SetNeedsCommit();
1324 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. 1294 client.RunPendingTasks(true); // Run posted BeginRetroFrame.
1325 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); 1295 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1);
1326 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1296 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1327 EXPECT_TRUE(client.needs_begin_frame()); 1297 EXPECT_TRUE(client.needs_begin_frame());
1328 client.Reset(); 1298 client.Reset();
1329 1299
1330 // Queue BeginFrame while we are still handling the previous BeginFrame. 1300 // Queue BeginFrame while we are still handling the previous BeginFrame.
1331 args.frame_time += base::TimeDelta::FromSeconds(1); 1301 args.frame_time += base::TimeDelta::FromSeconds(1);
1332 scheduler->BeginFrame(args); 1302 scheduler->BeginFrame(args);
1333 EXPECT_NO_ACTION(client); 1303 EXPECT_NO_ACTION(client);
1334 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1304 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1335 EXPECT_TRUE(client.needs_begin_frame()); 1305 EXPECT_TRUE(client.needs_begin_frame());
1336 client.Reset(); 1306 client.Reset();
1337 1307
1338 // Take us out of a swap throttled state. 1308 // Take us out of a swap throttled state.
1339 scheduler->DidSwapBuffersComplete(); 1309 scheduler->DidSwapBuffersComplete();
1340 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); 1310 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1);
1341 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1311 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1342 EXPECT_TRUE(client.needs_begin_frame()); 1312 EXPECT_TRUE(client.needs_begin_frame());
1343 client.Reset(); 1313 client.Reset();
1344 1314
1345 // BeginImplFrame deadline should draw. 1315 // BeginImplFrame deadline should draw.
1346 scheduler->SetNeedsRedraw(); 1316 scheduler->SetNeedsRedraw();
1347 client.task_runner().RunPendingTasks(); // Run posted deadline. 1317 client.RunPendingTasks(true); // Run posted deadline.
1348 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); 1318 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2);
1349 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); 1319 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2);
1350 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1320 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1351 EXPECT_TRUE(client.needs_begin_frame()); 1321 EXPECT_TRUE(client.needs_begin_frame());
1352 client.Reset(); 1322 client.Reset();
1353 } 1323 }
1354 1324
1355 void BeginFramesNotFromClient(bool begin_frame_scheduling_enabled, 1325 void BeginFramesNotFromClient(bool begin_frame_scheduling_enabled,
1356 bool throttle_frame_production) { 1326 bool throttle_frame_production) {
1357 FakeSchedulerClient client; 1327 FakeSchedulerClient client;
(...skipping 10 matching lines...) Expand all
1368 // SetNeedsCommit should begin the frame on the next BeginImplFrame 1338 // SetNeedsCommit should begin the frame on the next BeginImplFrame
1369 // without calling SetNeedsBeginFrame. 1339 // without calling SetNeedsBeginFrame.
1370 client.Reset(); 1340 client.Reset();
1371 scheduler->SetNeedsCommit(); 1341 scheduler->SetNeedsCommit();
1372 EXPECT_FALSE(client.needs_begin_frame()); 1342 EXPECT_FALSE(client.needs_begin_frame());
1373 EXPECT_NO_ACTION(client); 1343 EXPECT_NO_ACTION(client);
1374 client.Reset(); 1344 client.Reset();
1375 1345
1376 // When the client-driven BeginFrame are disabled, the scheduler posts it's 1346 // When the client-driven BeginFrame are disabled, the scheduler posts it's
1377 // own BeginFrame tasks. 1347 // own BeginFrame tasks.
1378 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. 1348 client.RunPendingTasks(true); // Run posted BeginFrame.
1379 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1349 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1380 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 1350 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
1381 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1351 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1382 EXPECT_FALSE(client.needs_begin_frame()); 1352 EXPECT_FALSE(client.needs_begin_frame());
1383 client.Reset(); 1353 client.Reset();
1384 1354
1385 // If we don't swap on the deadline, we wait for the next BeginFrame. 1355 // If we don't swap on the deadline, we wait for the next BeginFrame.
1386 client.task_runner().RunPendingTasks(); // Run posted deadline. 1356 client.RunPendingTasks(true); // Run posted deadline.
1387 EXPECT_NO_ACTION(client); 1357 EXPECT_NO_ACTION(client);
1388 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1358 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1389 EXPECT_FALSE(client.needs_begin_frame()); 1359 EXPECT_FALSE(client.needs_begin_frame());
1390 client.Reset(); 1360 client.Reset();
1391 1361
1392 // NotifyReadyToCommit should trigger the commit. 1362 // NotifyReadyToCommit should trigger the commit.
1393 scheduler->NotifyBeginMainFrameStarted(); 1363 scheduler->NotifyBeginMainFrameStarted();
1394 scheduler->NotifyReadyToCommit(); 1364 scheduler->NotifyReadyToCommit();
1395 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 1365 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
1396 EXPECT_FALSE(client.needs_begin_frame()); 1366 EXPECT_FALSE(client.needs_begin_frame());
1397 client.Reset(); 1367 client.Reset();
1398 1368
1399 // BeginImplFrame should prepare the draw. 1369 // BeginImplFrame should prepare the draw.
1400 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. 1370 client.RunPendingTasks(true); // Run posted BeginFrame.
1401 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1371 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1402 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 1372 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2);
1403 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1373 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1404 EXPECT_FALSE(client.needs_begin_frame()); 1374 EXPECT_FALSE(client.needs_begin_frame());
1405 client.Reset(); 1375 client.Reset();
1406 1376
1407 // BeginImplFrame deadline should draw. 1377 // BeginImplFrame deadline should draw.
1408 client.task_runner().RunPendingTasks(); // Run posted deadline. 1378 client.RunPendingTasks(true); // Run posted deadline.
1409 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); 1379 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1);
1410 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1380 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1411 EXPECT_FALSE(client.needs_begin_frame()); 1381 EXPECT_FALSE(client.needs_begin_frame());
1412 client.Reset(); 1382 client.Reset();
1413 1383
1414 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) 1384 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false)
1415 // to avoid excessive toggles. 1385 // to avoid excessive toggles.
1416 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. 1386 client.RunPendingTasks(true); // Run posted BeginFrame.
1417 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); 1387 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client);
1418 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1388 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1419 client.Reset(); 1389 client.Reset();
1420 1390
1421 // Make sure SetNeedsBeginFrame isn't called on the client 1391 // Make sure SetNeedsBeginFrame isn't called on the client
1422 // when the BeginFrame is no longer needed. 1392 // when the BeginFrame is no longer needed.
1423 client.task_runner().RunPendingTasks(); // Run posted deadline. 1393 client.RunPendingTasks(true); // Run posted deadline.
1424 EXPECT_NO_ACTION(client); 1394 EXPECT_NO_ACTION(client);
1425 EXPECT_FALSE(client.needs_begin_frame()); 1395 EXPECT_FALSE(client.needs_begin_frame());
1426 client.Reset(); 1396 client.Reset();
1427 } 1397 }
1428 1398
1429 // See: http://crbug.com/388901 1399 // See: http://crbug.com/388901
1430 TEST(SchedulerTest, DISABLED_SyntheticBeginFrames) { 1400 TEST(SchedulerTest, DISABLED_SyntheticBeginFrames) {
1431 bool begin_frame_scheduling_enabled = false; 1401 bool begin_frame_scheduling_enabled = false;
1432 bool throttle_frame_production = true; 1402 bool throttle_frame_production = true;
1433 BeginFramesNotFromClient(begin_frame_scheduling_enabled, 1403 BeginFramesNotFromClient(begin_frame_scheduling_enabled,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1466 client.SetAutomaticSwapAck(false); 1436 client.SetAutomaticSwapAck(false);
1467 1437
1468 // SetNeedsCommit should begin the frame on the next BeginImplFrame. 1438 // SetNeedsCommit should begin the frame on the next BeginImplFrame.
1469 client.Reset(); 1439 client.Reset();
1470 scheduler->SetNeedsCommit(); 1440 scheduler->SetNeedsCommit();
1471 EXPECT_FALSE(client.needs_begin_frame()); 1441 EXPECT_FALSE(client.needs_begin_frame());
1472 EXPECT_NO_ACTION(client); 1442 EXPECT_NO_ACTION(client);
1473 client.Reset(); 1443 client.Reset();
1474 1444
1475 // Trigger the first BeginImplFrame and BeginMainFrame 1445 // Trigger the first BeginImplFrame and BeginMainFrame
1476 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. 1446 client.RunPendingTasks(true); // Run posted BeginFrame.
1477 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1447 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1478 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 1448 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
1479 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1449 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1480 EXPECT_FALSE(client.needs_begin_frame()); 1450 EXPECT_FALSE(client.needs_begin_frame());
1481 client.Reset(); 1451 client.Reset();
1482 1452
1483 // NotifyReadyToCommit should trigger the pending commit and draw. 1453 // NotifyReadyToCommit should trigger the pending commit and draw.
1484 scheduler->NotifyBeginMainFrameStarted(); 1454 scheduler->NotifyBeginMainFrameStarted();
1485 scheduler->NotifyReadyToCommit(); 1455 scheduler->NotifyReadyToCommit();
1486 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 1456 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
1487 EXPECT_FALSE(client.needs_begin_frame()); 1457 EXPECT_FALSE(client.needs_begin_frame());
1488 client.Reset(); 1458 client.Reset();
1489 1459
1490 // Swapping will put us into a swap throttled state. 1460 // Swapping will put us into a swap throttled state.
1491 client.task_runner().RunPendingTasks(); // Run posted deadline. 1461 client.RunPendingTasks(true); // Run posted deadline.
1492 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); 1462 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2);
1493 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); 1463 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2);
1494 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1464 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1495 EXPECT_FALSE(client.needs_begin_frame()); 1465 EXPECT_FALSE(client.needs_begin_frame());
1496 client.Reset(); 1466 client.Reset();
1497 1467
1498 // While swap throttled, BeginFrames should trigger BeginImplFrames, 1468 // While swap throttled, BeginFrames should trigger BeginImplFrames,
1499 // but not a BeginMainFrame or draw. 1469 // but not a BeginMainFrame or draw.
1500 scheduler->SetNeedsCommit(); 1470 scheduler->SetNeedsCommit();
1501 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. 1471 client.RunPendingTasks(true); // Run posted BeginFrame.
1502 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); 1472 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1);
1503 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1473 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1504 EXPECT_FALSE(client.needs_begin_frame()); 1474 EXPECT_FALSE(client.needs_begin_frame());
1505 client.Reset(); 1475 client.Reset();
1506 1476
1507 // Take us out of a swap throttled state. 1477 // Take us out of a swap throttled state.
1508 scheduler->DidSwapBuffersComplete(); 1478 scheduler->DidSwapBuffersComplete();
1509 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); 1479 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1);
1510 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1480 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1511 EXPECT_FALSE(client.needs_begin_frame()); 1481 EXPECT_FALSE(client.needs_begin_frame());
1512 client.Reset(); 1482 client.Reset();
1513 1483
1514 // BeginImplFrame deadline should draw. 1484 // BeginImplFrame deadline should draw.
1515 scheduler->SetNeedsRedraw(); 1485 scheduler->SetNeedsRedraw();
1516 client.task_runner().RunPendingTasks(); // Run posted deadline. 1486 client.RunPendingTasks(true); // Run posted deadline.
1517 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); 1487 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2);
1518 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); 1488 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2);
1519 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1489 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1520 EXPECT_FALSE(client.needs_begin_frame()); 1490 EXPECT_FALSE(client.needs_begin_frame());
1521 client.Reset(); 1491 client.Reset();
1522 } 1492 }
1523 1493
1524 TEST(SchedulerTest, SyntheticBeginFrames_SwapThrottled) { 1494 TEST(SchedulerTest, SyntheticBeginFrames_SwapThrottled) {
1525 bool begin_frame_scheduling_enabled = false; 1495 bool begin_frame_scheduling_enabled = false;
1526 bool throttle_frame_production = true; 1496 bool throttle_frame_production = true;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1585 scheduler->DidLoseOutputSurface(); 1555 scheduler->DidLoseOutputSurface();
1586 // Do nothing when impl frame is in deadine pending state. 1556 // Do nothing when impl frame is in deadine pending state.
1587 EXPECT_NO_ACTION(client); 1557 EXPECT_NO_ACTION(client);
1588 1558
1589 client.Reset(); 1559 client.Reset();
1590 scheduler->NotifyBeginMainFrameStarted(); 1560 scheduler->NotifyBeginMainFrameStarted();
1591 scheduler->NotifyReadyToCommit(); 1561 scheduler->NotifyReadyToCommit();
1592 EXPECT_ACTION("ScheduledActionCommit", client, 0, 1); 1562 EXPECT_ACTION("ScheduledActionCommit", client, 0, 1);
1593 1563
1594 client.Reset(); 1564 client.Reset();
1595 client.task_runner().RunPendingTasks(); // Run posted deadline. 1565 client.RunPendingTasks(true); // Run posted deadline.
1596 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 1566 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
1597 } 1567 }
1598 1568
1599 void DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency( 1569 void DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency(
1600 bool impl_side_painting) { 1570 bool impl_side_painting) {
1601 FakeSchedulerClient client; 1571 FakeSchedulerClient client;
1602 SchedulerSettings scheduler_settings; 1572 SchedulerSettings scheduler_settings;
1603 scheduler_settings.impl_side_painting = impl_side_painting; 1573 scheduler_settings.impl_side_painting = impl_side_painting;
1604 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); 1574 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings);
1605 scheduler->SetCanStart(); 1575 scheduler->SetCanStart();
(...skipping 13 matching lines...) Expand all
1619 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1589 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1620 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 1590 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
1621 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1591 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1622 1592
1623 client.Reset(); 1593 client.Reset();
1624 scheduler->DidLoseOutputSurface(); 1594 scheduler->DidLoseOutputSurface();
1625 // Do nothing when impl frame is in deadine pending state. 1595 // Do nothing when impl frame is in deadine pending state.
1626 EXPECT_NO_ACTION(client); 1596 EXPECT_NO_ACTION(client);
1627 1597
1628 client.Reset(); 1598 client.Reset();
1629 client.task_runner().RunPendingTasks(); // Run posted deadline. 1599 client.RunPendingTasks(true); // Run posted deadline.
1630 // OnBeginImplFrameDeadline didn't schedule any actions because main frame is 1600 // OnBeginImplFrameDeadline didn't schedule any actions because main frame is
1631 // not yet completed. 1601 // not yet completed.
1632 EXPECT_NO_ACTION(client); 1602 EXPECT_NO_ACTION(client);
1633 1603
1634 // BeginImplFrame is not started. 1604 // BeginImplFrame is not started.
1635 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 1605 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
1636 EXPECT_NO_ACTION(client); 1606 EXPECT_NO_ACTION(client);
1637 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1607 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1638 1608
1639 client.Reset(); 1609 client.Reset();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1692 scheduler->DidLoseOutputSurface(); 1662 scheduler->DidLoseOutputSurface();
1693 if (impl_side_painting) { 1663 if (impl_side_painting) {
1694 // Sync tree should be forced to activate. 1664 // Sync tree should be forced to activate.
1695 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client); 1665 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client);
1696 } else { 1666 } else {
1697 // Do nothing when impl frame is in deadine pending state. 1667 // Do nothing when impl frame is in deadine pending state.
1698 EXPECT_NO_ACTION(client); 1668 EXPECT_NO_ACTION(client);
1699 } 1669 }
1700 1670
1701 client.Reset(); 1671 client.Reset();
1702 client.task_runner().RunPendingTasks(); // Run posted deadline. 1672 client.RunPendingTasks(true); // Run posted deadline.
1703 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 1673 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
1704 } 1674 }
1705 1675
1706 TEST(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommit) { 1676 TEST(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommit) {
1707 DidLoseOutputSurfaceAfterReadyToCommit(false); 1677 DidLoseOutputSurfaceAfterReadyToCommit(false);
1708 } 1678 }
1709 1679
1710 TEST(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommitWithImplPainting) { 1680 TEST(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommitWithImplPainting) {
1711 DidLoseOutputSurfaceAfterReadyToCommit(true); 1681 DidLoseOutputSurfaceAfterReadyToCommit(true);
1712 } 1682 }
(...skipping 17 matching lines...) Expand all
1730 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); 1700 scheduler->BeginFrame(CreateBeginFrameArgsForTesting());
1731 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1701 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1732 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 1702 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2);
1733 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1703 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1734 1704
1735 client.Reset(); 1705 client.Reset();
1736 scheduler->DidLoseOutputSurface(); 1706 scheduler->DidLoseOutputSurface();
1737 EXPECT_NO_ACTION(client); 1707 EXPECT_NO_ACTION(client);
1738 1708
1739 client.Reset(); 1709 client.Reset();
1740 client.task_runner().RunPendingTasks(); // Run posted deadline. 1710 client.RunPendingTasks(true); // Run posted deadline.
1741 EXPECT_ACTION("ScheduledActionManageTiles", client, 0, 2); 1711 EXPECT_ACTION("ScheduledActionManageTiles", client, 0, 2);
1742 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 1, 2); 1712 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 1, 2);
1743 } 1713 }
1744 1714
1745 TEST(SchedulerTest, DidLoseOutputSurfaceAfterBeginRetroFramePosted) { 1715 TEST(SchedulerTest, DidLoseOutputSurfaceAfterBeginRetroFramePosted) {
1746 FakeSchedulerClient client; 1716 FakeSchedulerClient client;
1747 SchedulerSettings scheduler_settings; 1717 SchedulerSettings scheduler_settings;
1748 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); 1718 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings);
1749 scheduler->SetCanStart(); 1719 scheduler->SetCanStart();
1750 scheduler->SetVisible(true); 1720 scheduler->SetVisible(true);
(...skipping 18 matching lines...) Expand all
1769 EXPECT_TRUE(client.needs_begin_frame()); 1739 EXPECT_TRUE(client.needs_begin_frame());
1770 1740
1771 // Queue BeginFrames while we are still handling the previous BeginFrame. 1741 // Queue BeginFrames while we are still handling the previous BeginFrame.
1772 args.frame_time += base::TimeDelta::FromSeconds(1); 1742 args.frame_time += base::TimeDelta::FromSeconds(1);
1773 scheduler->BeginFrame(args); 1743 scheduler->BeginFrame(args);
1774 args.frame_time += base::TimeDelta::FromSeconds(1); 1744 args.frame_time += base::TimeDelta::FromSeconds(1);
1775 scheduler->BeginFrame(args); 1745 scheduler->BeginFrame(args);
1776 1746
1777 // If we don't swap on the deadline, we wait for the next BeginImplFrame. 1747 // If we don't swap on the deadline, we wait for the next BeginImplFrame.
1778 client.Reset(); 1748 client.Reset();
1779 client.task_runner().RunPendingTasks(); // Run posted deadline. 1749 client.RunPendingTasks(true); // Run posted deadline.
1780 EXPECT_NO_ACTION(client); 1750 EXPECT_NO_ACTION(client);
1781 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1751 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1782 EXPECT_TRUE(client.needs_begin_frame()); 1752 EXPECT_TRUE(client.needs_begin_frame());
1783 1753
1784 // NotifyReadyToCommit should trigger the commit. 1754 // NotifyReadyToCommit should trigger the commit.
1785 client.Reset(); 1755 client.Reset();
1786 scheduler->NotifyBeginMainFrameStarted(); 1756 scheduler->NotifyBeginMainFrameStarted();
1787 scheduler->NotifyReadyToCommit(); 1757 scheduler->NotifyReadyToCommit();
1788 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 1758 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
1789 EXPECT_TRUE(client.needs_begin_frame()); 1759 EXPECT_TRUE(client.needs_begin_frame());
1790 1760
1791 client.Reset(); 1761 client.Reset();
1792 EXPECT_FALSE(scheduler->IsBeginRetroFrameArgsEmpty()); 1762 EXPECT_FALSE(scheduler->IsBeginRetroFrameArgsEmpty());
1793 scheduler->DidLoseOutputSurface(); 1763 scheduler->DidLoseOutputSurface();
1794 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 1764 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
1795 EXPECT_TRUE(client.needs_begin_frame()); 1765 EXPECT_TRUE(client.needs_begin_frame());
1796 EXPECT_TRUE(scheduler->IsBeginRetroFrameArgsEmpty()); 1766 EXPECT_TRUE(scheduler->IsBeginRetroFrameArgsEmpty());
1797 1767
1798 // Posted BeginRetroFrame is aborted. 1768 // Posted BeginRetroFrame is aborted.
1799 client.Reset(); 1769 client.Reset();
1800 client.task_runner().RunPendingTasks(); 1770 client.RunPendingTasks(true);
1801 EXPECT_NO_ACTION(client); 1771 EXPECT_NO_ACTION(client);
1802 } 1772 }
1803 1773
1804 TEST(SchedulerTest, DidLoseOutputSurfaceDuringBeginRetroFrameRunning) { 1774 TEST(SchedulerTest, DidLoseOutputSurfaceDuringBeginRetroFrameRunning) {
1805 FakeSchedulerClient client; 1775 FakeSchedulerClient client;
1806 SchedulerSettings scheduler_settings; 1776 SchedulerSettings scheduler_settings;
1807 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); 1777 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings);
1808 scheduler->SetCanStart(); 1778 scheduler->SetCanStart();
1809 scheduler->SetVisible(true); 1779 scheduler->SetVisible(true);
1810 scheduler->SetCanDraw(true); 1780 scheduler->SetCanDraw(true);
(...skipping 17 matching lines...) Expand all
1828 EXPECT_TRUE(client.needs_begin_frame()); 1798 EXPECT_TRUE(client.needs_begin_frame());
1829 1799
1830 // Queue BeginFrames while we are still handling the previous BeginFrame. 1800 // Queue BeginFrames while we are still handling the previous BeginFrame.
1831 args.frame_time += base::TimeDelta::FromSeconds(1); 1801 args.frame_time += base::TimeDelta::FromSeconds(1);
1832 scheduler->BeginFrame(args); 1802 scheduler->BeginFrame(args);
1833 args.frame_time += base::TimeDelta::FromSeconds(1); 1803 args.frame_time += base::TimeDelta::FromSeconds(1);
1834 scheduler->BeginFrame(args); 1804 scheduler->BeginFrame(args);
1835 1805
1836 // If we don't swap on the deadline, we wait for the next BeginImplFrame. 1806 // If we don't swap on the deadline, we wait for the next BeginImplFrame.
1837 client.Reset(); 1807 client.Reset();
1838 client.task_runner().RunPendingTasks(); // Run posted deadline. 1808 client.RunPendingTasks(true); // Run posted deadline.
1839 EXPECT_NO_ACTION(client); 1809 EXPECT_NO_ACTION(client);
1840 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1810 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1841 EXPECT_TRUE(client.needs_begin_frame()); 1811 EXPECT_TRUE(client.needs_begin_frame());
1842 1812
1843 // NotifyReadyToCommit should trigger the commit. 1813 // NotifyReadyToCommit should trigger the commit.
1844 client.Reset(); 1814 client.Reset();
1845 scheduler->NotifyBeginMainFrameStarted(); 1815 scheduler->NotifyBeginMainFrameStarted();
1846 scheduler->NotifyReadyToCommit(); 1816 scheduler->NotifyReadyToCommit();
1847 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 1817 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
1848 EXPECT_TRUE(client.needs_begin_frame()); 1818 EXPECT_TRUE(client.needs_begin_frame());
1849 1819
1850 // BeginImplFrame should prepare the draw. 1820 // BeginImplFrame should prepare the draw.
1851 client.Reset(); 1821 client.Reset();
1852 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. 1822 client.RunPendingTasks(true); // Run posted BeginRetroFrame.
1853 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1823 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1854 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); 1824 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2);
1855 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1825 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1856 EXPECT_TRUE(client.needs_begin_frame()); 1826 EXPECT_TRUE(client.needs_begin_frame());
1857 1827
1858 client.Reset(); 1828 client.Reset();
1859 EXPECT_FALSE(scheduler->IsBeginRetroFrameArgsEmpty()); 1829 EXPECT_FALSE(scheduler->IsBeginRetroFrameArgsEmpty());
1860 scheduler->DidLoseOutputSurface(); 1830 scheduler->DidLoseOutputSurface();
1861 EXPECT_NO_ACTION(client); 1831 EXPECT_NO_ACTION(client);
1862 EXPECT_TRUE(scheduler->IsBeginRetroFrameArgsEmpty()); 1832 EXPECT_TRUE(scheduler->IsBeginRetroFrameArgsEmpty());
1863 1833
1864 // BeginImplFrame deadline should abort drawing. 1834 // BeginImplFrame deadline should abort drawing.
1865 client.Reset(); 1835 client.Reset();
1866 client.task_runner().RunPendingTasks(); // Run posted deadline. 1836 client.RunPendingTasks(true); // Run posted deadline.
1867 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 1837 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
1868 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); 1838 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1869 EXPECT_TRUE(client.needs_begin_frame()); 1839 EXPECT_TRUE(client.needs_begin_frame());
1870 1840
1871 // No more BeginRetroFrame because BeginRetroFrame queue is cleared. 1841 // No more BeginRetroFrame because BeginRetroFrame queue is cleared.
1872 client.Reset(); 1842 client.Reset();
1873 client.task_runner().RunPendingTasks(); 1843 client.RunPendingTasks(true);
1874 EXPECT_NO_ACTION(client); 1844 EXPECT_NO_ACTION(client);
1875 } 1845 }
1876 1846
1877 TEST(SchedulerTest, 1847 TEST(SchedulerTest,
1878 StopBeginFrameAfterDidLoseOutputSurfaceWithSyntheticBeginFrameSource) { 1848 StopBeginFrameAfterDidLoseOutputSurfaceWithSyntheticBeginFrameSource) {
1879 FakeSchedulerClient client; 1849 FakeSchedulerClient client;
1880 SchedulerSettings scheduler_settings; 1850 SchedulerSettings scheduler_settings;
1881 scheduler_settings.begin_frame_scheduling_enabled = false; 1851 scheduler_settings.begin_frame_scheduling_enabled = false;
1882 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); 1852 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings);
1883 scheduler->SetCanStart(); 1853 scheduler->SetCanStart();
1884 scheduler->SetVisible(true); 1854 scheduler->SetVisible(true);
1885 scheduler->SetCanDraw(true); 1855 scheduler->SetCanDraw(true);
1886 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); 1856 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
1887 1857
1888 // SetNeedsCommit should begin the frame on the next BeginImplFrame. 1858 // SetNeedsCommit should begin the frame on the next BeginImplFrame.
1889 client.Reset(); 1859 client.Reset();
1890 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); 1860 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive());
1891 scheduler->SetNeedsCommit(); 1861 scheduler->SetNeedsCommit();
1892 EXPECT_TRUE(scheduler->IsSyntheticBeginFrameSourceActive()); 1862 EXPECT_TRUE(scheduler->IsSyntheticBeginFrameSourceActive());
1893 1863
1894 client.Reset(); 1864 client.Reset();
1895 client.task_runner().RunPendingTasks(); // Run posted Tick. 1865 client.RunPendingTasks(true); // Run posted Tick.
1896 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); 1866 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
1897 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); 1867 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2);
1898 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1868 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1899 EXPECT_TRUE(scheduler->IsSyntheticBeginFrameSourceActive()); 1869 EXPECT_TRUE(scheduler->IsSyntheticBeginFrameSourceActive());
1900 1870
1901 // NotifyReadyToCommit should trigger the commit. 1871 // NotifyReadyToCommit should trigger the commit.
1902 client.Reset(); 1872 client.Reset();
1903 scheduler->NotifyBeginMainFrameStarted(); 1873 scheduler->NotifyBeginMainFrameStarted();
1904 scheduler->NotifyReadyToCommit(); 1874 scheduler->NotifyReadyToCommit();
1905 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 1875 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
1906 EXPECT_TRUE(scheduler->IsSyntheticBeginFrameSourceActive()); 1876 EXPECT_TRUE(scheduler->IsSyntheticBeginFrameSourceActive());
1907 1877
1908 client.Reset(); 1878 client.Reset();
1909 scheduler->DidLoseOutputSurface(); 1879 scheduler->DidLoseOutputSurface();
1910 EXPECT_EQ(0, client.num_actions_()); 1880 EXPECT_EQ(0, client.num_actions_());
1911 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); 1881 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive());
1912 1882
1913 client.Reset(); 1883 client.Reset();
1914 client.task_runner().RunPendingTasks(); // Run posted deadline. 1884 client.RunPendingTasks(true); // Run posted deadline.
1915 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 1885 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
1916 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); 1886 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive());
1917 } 1887 }
1918 1888
1919 } // namespace 1889 } // namespace
1920 } // namespace cc 1890 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698