OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/scheduler/renderer_scheduler_impl.h" | 5 #include "content/renderer/scheduler/renderer_scheduler_impl.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "cc/output/begin_frame_args.h" | 8 #include "cc/output/begin_frame_args.h" |
9 #include "cc/test/ordered_simple_task_runner.h" | 9 #include "cc/test/ordered_simple_task_runner.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 | 130 |
131 void PostingYieldingTestTask( | 131 void PostingYieldingTestTask( |
132 RendererSchedulerImpl* scheduler, | 132 RendererSchedulerImpl* scheduler, |
133 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 133 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
134 bool simulate_input, | 134 bool simulate_input, |
135 bool* should_yield_before, | 135 bool* should_yield_before, |
136 bool* should_yield_after) { | 136 bool* should_yield_after) { |
137 *should_yield_before = scheduler->ShouldYieldForHighPriorityWork(); | 137 *should_yield_before = scheduler->ShouldYieldForHighPriorityWork(); |
138 task_runner->PostTask(FROM_HERE, base::Bind(NullTask)); | 138 task_runner->PostTask(FROM_HERE, base::Bind(NullTask)); |
139 if (simulate_input) { | 139 if (simulate_input) { |
140 scheduler->DidReceiveInputEventOnCompositorThread(); | 140 scheduler->DidReceiveInputEventOnCompositorThread( |
| 141 blink::WebInputEvent::GestureFlingStart); |
141 } | 142 } |
142 *should_yield_after = scheduler->ShouldYieldForHighPriorityWork(); | 143 *should_yield_after = scheduler->ShouldYieldForHighPriorityWork(); |
143 } | 144 } |
144 | 145 |
145 TEST_F(RendererSchedulerImplTest, TestPostDefaultTask) { | 146 TEST_F(RendererSchedulerImplTest, TestPostDefaultTask) { |
146 int result = 0; | 147 int result = 0; |
147 default_task_runner_->PostTask(FROM_HERE, | 148 default_task_runner_->PostTask(FROM_HERE, |
148 base::Bind(OrderedTestTask, 1, &result)); | 149 base::Bind(OrderedTestTask, 1, &result)); |
149 default_task_runner_->PostTask(FROM_HERE, | 150 default_task_runner_->PostTask(FROM_HERE, |
150 base::Bind(OrderedTestTask, 2, &result)); | 151 base::Bind(OrderedTestTask, 2, &result)); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 compositor_task_runner_->PostTask( | 292 compositor_task_runner_->PostTask( |
292 FROM_HERE, | 293 FROM_HERE, |
293 base::Bind(&AppendToVectorTestTask, &order, std::string("C1"))); | 294 base::Bind(&AppendToVectorTestTask, &order, std::string("C1"))); |
294 default_task_runner_->PostTask( | 295 default_task_runner_->PostTask( |
295 FROM_HERE, | 296 FROM_HERE, |
296 base::Bind(&AppendToVectorTestTask, &order, std::string("D2"))); | 297 base::Bind(&AppendToVectorTestTask, &order, std::string("D2"))); |
297 compositor_task_runner_->PostTask( | 298 compositor_task_runner_->PostTask( |
298 FROM_HERE, | 299 FROM_HERE, |
299 base::Bind(&AppendToVectorTestTask, &order, std::string("C2"))); | 300 base::Bind(&AppendToVectorTestTask, &order, std::string("C2"))); |
300 | 301 |
301 scheduler_->DidReceiveInputEventOnCompositorThread(); | 302 scheduler_->DidReceiveInputEventOnCompositorThread( |
| 303 blink::WebInputEvent::GestureFlingStart); |
302 EnableIdleTasks(); | 304 EnableIdleTasks(); |
303 RunUntilIdle(); | 305 RunUntilIdle(); |
304 EXPECT_THAT(order, testing::ElementsAre(std::string("C1"), std::string("C2"), | 306 EXPECT_THAT(order, testing::ElementsAre(std::string("C1"), std::string("C2"), |
305 std::string("D1"), std::string("D2"), | 307 std::string("D1"), std::string("D2"), |
306 std::string("I1"))); | 308 std::string("I1"))); |
307 } | 309 } |
308 | 310 |
| 311 TEST_F(RendererSchedulerImplTest, TestCompositorPolicy_DidAnimateForInput) { |
| 312 std::vector<std::string> order; |
| 313 |
| 314 idle_task_runner_->PostIdleTask( |
| 315 FROM_HERE, |
| 316 base::Bind(&AppendToVectorIdleTestTask, &order, std::string("I1"))); |
| 317 default_task_runner_->PostTask( |
| 318 FROM_HERE, |
| 319 base::Bind(&AppendToVectorTestTask, &order, std::string("D1"))); |
| 320 compositor_task_runner_->PostTask( |
| 321 FROM_HERE, |
| 322 base::Bind(&AppendToVectorTestTask, &order, std::string("C1"))); |
| 323 default_task_runner_->PostTask( |
| 324 FROM_HERE, |
| 325 base::Bind(&AppendToVectorTestTask, &order, std::string("D2"))); |
| 326 compositor_task_runner_->PostTask( |
| 327 FROM_HERE, |
| 328 base::Bind(&AppendToVectorTestTask, &order, std::string("C2"))); |
| 329 |
| 330 scheduler_->DidAnimateForInputOnCompositorThread(); |
| 331 EnableIdleTasks(); |
| 332 RunUntilIdle(); |
| 333 EXPECT_THAT(order, testing::ElementsAre(std::string("C1"), std::string("C2"), |
| 334 std::string("D1"), std::string("D2"), |
| 335 std::string("I1"))); |
| 336 } |
| 337 |
| 338 TEST_F(RendererSchedulerImplTest, |
| 339 DidReceiveInputEventOnCompositorThread_IgnoresMouseEvents) { |
| 340 std::vector<std::string> order; |
| 341 |
| 342 idle_task_runner_->PostIdleTask( |
| 343 FROM_HERE, |
| 344 base::Bind(&AppendToVectorIdleTestTask, &order, std::string("I1"))); |
| 345 default_task_runner_->PostTask( |
| 346 FROM_HERE, |
| 347 base::Bind(&AppendToVectorTestTask, &order, std::string("D1"))); |
| 348 compositor_task_runner_->PostTask( |
| 349 FROM_HERE, |
| 350 base::Bind(&AppendToVectorTestTask, &order, std::string("C1"))); |
| 351 default_task_runner_->PostTask( |
| 352 FROM_HERE, |
| 353 base::Bind(&AppendToVectorTestTask, &order, std::string("D2"))); |
| 354 compositor_task_runner_->PostTask( |
| 355 FROM_HERE, |
| 356 base::Bind(&AppendToVectorTestTask, &order, std::string("C2"))); |
| 357 |
| 358 scheduler_->DidReceiveInputEventOnCompositorThread( |
| 359 blink::WebInputEvent::MouseMove); |
| 360 EnableIdleTasks(); |
| 361 RunUntilIdle(); |
| 362 // Note compositor tasks are not prioritized. |
| 363 EXPECT_THAT(order, testing::ElementsAre(std::string("D1"), std::string("C1"), |
| 364 std::string("D2"), std::string("C2"), |
| 365 std::string("I1"))); |
| 366 } |
| 367 |
| 368 TEST_F(RendererSchedulerImplTest, |
| 369 DidReceiveInputEventOnCompositorThread_IgnoresKeyboardEvents) { |
| 370 std::vector<std::string> order; |
| 371 |
| 372 idle_task_runner_->PostIdleTask( |
| 373 FROM_HERE, |
| 374 base::Bind(&AppendToVectorIdleTestTask, &order, std::string("I1"))); |
| 375 default_task_runner_->PostTask( |
| 376 FROM_HERE, |
| 377 base::Bind(&AppendToVectorTestTask, &order, std::string("D1"))); |
| 378 compositor_task_runner_->PostTask( |
| 379 FROM_HERE, |
| 380 base::Bind(&AppendToVectorTestTask, &order, std::string("C1"))); |
| 381 default_task_runner_->PostTask( |
| 382 FROM_HERE, |
| 383 base::Bind(&AppendToVectorTestTask, &order, std::string("D2"))); |
| 384 compositor_task_runner_->PostTask( |
| 385 FROM_HERE, |
| 386 base::Bind(&AppendToVectorTestTask, &order, std::string("C2"))); |
| 387 |
| 388 scheduler_->DidReceiveInputEventOnCompositorThread( |
| 389 blink::WebInputEvent::KeyDown); |
| 390 EnableIdleTasks(); |
| 391 RunUntilIdle(); |
| 392 // Note compositor tasks are not prioritized. |
| 393 EXPECT_THAT(order, testing::ElementsAre(std::string("D1"), std::string("C1"), |
| 394 std::string("D2"), std::string("C2"), |
| 395 std::string("I1"))); |
| 396 } |
| 397 |
309 TEST_F(RendererSchedulerImplTest, | 398 TEST_F(RendererSchedulerImplTest, |
310 TestCompositorPolicyDoesNotStarveDefaultTasks) { | 399 TestCompositorPolicyDoesNotStarveDefaultTasks) { |
311 std::vector<std::string> order; | 400 std::vector<std::string> order; |
312 | 401 |
313 default_task_runner_->PostTask( | 402 default_task_runner_->PostTask( |
314 FROM_HERE, | 403 FROM_HERE, |
315 base::Bind(&AppendToVectorTestTask, &order, std::string("D1"))); | 404 base::Bind(&AppendToVectorTestTask, &order, std::string("D1"))); |
316 compositor_task_runner_->PostTask( | 405 compositor_task_runner_->PostTask( |
317 FROM_HERE, | 406 FROM_HERE, |
318 base::Bind(&AppendToVectorTestTask, &order, std::string("C1"))); | 407 base::Bind(&AppendToVectorTestTask, &order, std::string("C1"))); |
319 for (int i = 0; i < 20; i++) { | 408 for (int i = 0; i < 20; i++) { |
320 compositor_task_runner_->PostTask(FROM_HERE, base::Bind(&NullTask)); | 409 compositor_task_runner_->PostTask(FROM_HERE, base::Bind(&NullTask)); |
321 } | 410 } |
322 compositor_task_runner_->PostTask( | 411 compositor_task_runner_->PostTask( |
323 FROM_HERE, | 412 FROM_HERE, |
324 base::Bind(&AppendToVectorTestTask, &order, std::string("C2"))); | 413 base::Bind(&AppendToVectorTestTask, &order, std::string("C2"))); |
325 | 414 |
326 scheduler_->DidReceiveInputEventOnCompositorThread(); | 415 scheduler_->DidReceiveInputEventOnCompositorThread( |
| 416 blink::WebInputEvent::GestureFlingStart); |
327 RunUntilIdle(); | 417 RunUntilIdle(); |
328 // Ensure that the default D1 task gets to run at some point before the final | 418 // Ensure that the default D1 task gets to run at some point before the final |
329 // C2 compositor task. | 419 // C2 compositor task. |
330 EXPECT_THAT(order, testing::ElementsAre(std::string("C1"), std::string("D1"), | 420 EXPECT_THAT(order, testing::ElementsAre(std::string("C1"), std::string("D1"), |
331 std::string("C2"))); | 421 std::string("C2"))); |
332 } | 422 } |
333 | 423 |
334 TEST_F(RendererSchedulerImplTest, TestCompositorPolicyEnds) { | 424 TEST_F(RendererSchedulerImplTest, TestCompositorPolicyEnds) { |
335 std::vector<std::string> order; | 425 std::vector<std::string> order; |
336 | 426 |
337 default_task_runner_->PostTask( | 427 default_task_runner_->PostTask( |
338 FROM_HERE, | 428 FROM_HERE, |
339 base::Bind(&AppendToVectorTestTask, &order, std::string("D1"))); | 429 base::Bind(&AppendToVectorTestTask, &order, std::string("D1"))); |
340 compositor_task_runner_->PostTask( | 430 compositor_task_runner_->PostTask( |
341 FROM_HERE, | 431 FROM_HERE, |
342 base::Bind(&AppendToVectorTestTask, &order, std::string("C1"))); | 432 base::Bind(&AppendToVectorTestTask, &order, std::string("C1"))); |
343 default_task_runner_->PostTask( | 433 default_task_runner_->PostTask( |
344 FROM_HERE, | 434 FROM_HERE, |
345 base::Bind(&AppendToVectorTestTask, &order, std::string("D2"))); | 435 base::Bind(&AppendToVectorTestTask, &order, std::string("D2"))); |
346 compositor_task_runner_->PostTask( | 436 compositor_task_runner_->PostTask( |
347 FROM_HERE, | 437 FROM_HERE, |
348 base::Bind(&AppendToVectorTestTask, &order, std::string("C2"))); | 438 base::Bind(&AppendToVectorTestTask, &order, std::string("C2"))); |
349 | 439 |
350 scheduler_->DidReceiveInputEventOnCompositorThread(); | 440 scheduler_->DidReceiveInputEventOnCompositorThread( |
| 441 blink::WebInputEvent::GestureFlingStart); |
351 RunUntilIdle(); | 442 RunUntilIdle(); |
352 EXPECT_THAT(order, | 443 EXPECT_THAT(order, |
353 testing::ElementsAre(std::string("C1"), std::string("C2"), | 444 testing::ElementsAre(std::string("C1"), std::string("C2"), |
354 std::string("D1"), std::string("D2"))); | 445 std::string("D1"), std::string("D2"))); |
355 | 446 |
356 order.clear(); | 447 order.clear(); |
357 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1000)); | 448 clock_->AdvanceNow(base::TimeDelta::FromMilliseconds(1000)); |
358 | 449 |
359 default_task_runner_->PostTask( | 450 default_task_runner_->PostTask( |
360 FROM_HERE, | 451 FROM_HERE, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), | 493 FROM_HERE, base::Bind(&PostingYieldingTestTask, scheduler_.get(), |
403 compositor_task_runner_, true, &should_yield_before, | 494 compositor_task_runner_, true, &should_yield_before, |
404 &should_yield_after)); | 495 &should_yield_after)); |
405 RunUntilIdle(); | 496 RunUntilIdle(); |
406 // We should be able to switch to compositor priority mid-task. | 497 // We should be able to switch to compositor priority mid-task. |
407 EXPECT_FALSE(should_yield_before); | 498 EXPECT_FALSE(should_yield_before); |
408 EXPECT_TRUE(should_yield_after); | 499 EXPECT_TRUE(should_yield_after); |
409 } | 500 } |
410 | 501 |
411 } // namespace content | 502 } // namespace content |
OLD | NEW |