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 "config.h" | 5 #include "config.h" |
6 #include "platform/scheduler/Scheduler.h" | 6 #include "platform/scheduler/Scheduler.h" |
7 | 7 |
8 #include "platform/TestingPlatformSupport.h" | 8 #include "platform/TestingPlatformSupport.h" |
9 #include "platform/TraceLocation.h" | 9 #include "platform/TraceLocation.h" |
10 #include "public/platform/Platform.h" | 10 #include "public/platform/Platform.h" |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 ~SchedulerTest() | 169 ~SchedulerTest() |
170 { | 170 { |
171 Scheduler::shutdown(); | 171 Scheduler::shutdown(); |
172 } | 172 } |
173 | 173 |
174 virtual void SetUp() OVERRIDE | 174 virtual void SetUp() OVERRIDE |
175 { | 175 { |
176 m_scheduler->enterSchedulerPolicy(SchedulerForTest::Normal); | 176 m_scheduler->enterSchedulerPolicy(SchedulerForTest::Normal); |
177 } | 177 } |
178 | 178 |
| 179 virtual void TearDown() OVERRIDE |
| 180 { |
| 181 // If the Scheduler hasn't been shut down then explicitly flush the task
s. |
| 182 if (Scheduler::shared()) |
| 183 runPendingTasks(); |
| 184 } |
| 185 |
179 void runPendingTasks() | 186 void runPendingTasks() |
180 { | 187 { |
181 m_platformSupport.runPendingTasks(); | 188 m_platformSupport.runPendingTasks(); |
182 } | 189 } |
183 | 190 |
184 void appendToVector(std::string value) | 191 void appendToVector(std::string value) |
185 { | 192 { |
186 m_order.push_back(value); | 193 m_order.push_back(value); |
187 } | 194 } |
188 | 195 |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 m_scheduler->setSharedTimerFiredFunction(nullptr); | 467 m_scheduler->setSharedTimerFiredFunction(nullptr); |
461 } | 468 } |
462 | 469 |
463 TEST_F(SchedulerTest, TestInputEventDoesNotTriggerShouldYield_InNormalMode) | 470 TEST_F(SchedulerTest, TestInputEventDoesNotTriggerShouldYield_InNormalMode) |
464 { | 471 { |
465 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&dummyTask)); | 472 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&dummyTask)); |
466 | 473 |
467 EXPECT_FALSE(m_scheduler->shouldYieldForHighPriorityWork()); | 474 EXPECT_FALSE(m_scheduler->shouldYieldForHighPriorityWork()); |
468 } | 475 } |
469 | 476 |
| 477 TEST_F(SchedulerTest, TestDidReceiveInputEventDoesNotTriggerShouldYield) |
| 478 { |
| 479 m_scheduler->didReceiveInputEvent(); |
| 480 |
| 481 EXPECT_FALSE(m_scheduler->shouldYieldForHighPriorityWork()); |
| 482 } |
| 483 |
470 TEST_F(SchedulerTest, TestCompositorEventDoesNotTriggerShouldYield_InNormalMode) | 484 TEST_F(SchedulerTest, TestCompositorEventDoesNotTriggerShouldYield_InNormalMode) |
471 { | 485 { |
472 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&dummyTask)); | 486 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&dummyTask)); |
473 | 487 |
474 EXPECT_FALSE(m_scheduler->shouldYieldForHighPriorityWork()); | 488 EXPECT_FALSE(m_scheduler->shouldYieldForHighPriorityWork()); |
475 } | 489 } |
476 | 490 |
477 TEST_F(SchedulerTest, TestInputEventDoesTriggerShouldYield_InLowSchedulerPolicy) | 491 TEST_F(SchedulerTest, TestCompositorEventDoesTriggerShouldYieldAfterDidReceiveIn
putEvent) |
| 492 { |
| 493 m_scheduler->didReceiveInputEvent(); |
| 494 |
| 495 ASSERT_FALSE(m_scheduler->shouldYieldForHighPriorityWork()); |
| 496 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&dummyTask)); |
| 497 |
| 498 EXPECT_TRUE(m_scheduler->shouldYieldForHighPriorityWork()); |
| 499 } |
| 500 |
| 501 TEST_F(SchedulerTest, TestInputEventDoesTriggerShouldYield_InCompositorPriorityM
ode) |
478 { | 502 { |
479 m_scheduler->enterSchedulerPolicy(SchedulerForTest::CompositorPriority); | 503 m_scheduler->enterSchedulerPolicy(SchedulerForTest::CompositorPriority); |
480 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&dummyTask)); | 504 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&dummyTask)); |
481 | 505 |
482 EXPECT_TRUE(m_scheduler->shouldYieldForHighPriorityWork()); | 506 EXPECT_TRUE(m_scheduler->shouldYieldForHighPriorityWork()); |
483 } | 507 } |
484 | 508 |
485 TEST_F(SchedulerTest, TestCompositorEventDoesTriggerShouldYield_InLowSchedulerPo
licy) | 509 TEST_F(SchedulerTest, TestCompositorEventDoesTriggerShouldYield_InCompositorPrio
rityMode) |
486 { | 510 { |
487 m_scheduler->enterSchedulerPolicy(SchedulerForTest::CompositorPriority); | 511 m_scheduler->enterSchedulerPolicy(SchedulerForTest::CompositorPriority); |
488 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&dummyTask)); | 512 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&dummyTask)); |
489 | 513 |
490 EXPECT_TRUE(m_scheduler->shouldYieldForHighPriorityWork()); | 514 EXPECT_TRUE(m_scheduler->shouldYieldForHighPriorityWork()); |
491 } | 515 } |
492 | 516 |
493 TEST_F(SchedulerTest, TestCompositorEvent_LowSchedulerPolicyDoesntLastLong) | 517 TEST_F(SchedulerTest, TestCompositorEvent_LowSchedulerPolicyDoesntLastLong) |
494 { | 518 { |
495 m_platformSupport.setMonotonicTimeForTest(1000.0); | 519 m_platformSupport.setMonotonicTimeForTest(1000.0); |
496 | 520 |
497 m_scheduler->enterSchedulerPolicy(SchedulerForTest::CompositorPriority); | 521 m_scheduler->enterSchedulerPolicy(SchedulerForTest::CompositorPriority); |
498 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&dummyTask)); | 522 m_scheduler->postInputTask(FROM_HERE, WTF::bind(&dummyTask)); |
499 m_platformSupport.setMonotonicTimeForTest(1000.5); | 523 m_platformSupport.setMonotonicTimeForTest(1000.5); |
500 runPendingTasks(); | 524 runPendingTasks(); |
501 | 525 |
502 ASSERT_FALSE(m_scheduler->shouldYieldForHighPriorityWork()); | 526 ASSERT_FALSE(m_scheduler->shouldYieldForHighPriorityWork()); |
503 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&dummyTask)); | 527 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&dummyTask)); |
504 | 528 |
505 EXPECT_FALSE(m_scheduler->shouldYieldForHighPriorityWork()); | 529 EXPECT_FALSE(m_scheduler->shouldYieldForHighPriorityWork()); |
506 } | 530 } |
507 | 531 |
| 532 TEST_F(SchedulerTest, testDidReceiveInputEvent_DoesntTriggerLowLatencyModeForLon
g) |
| 533 { |
| 534 m_platformSupport.setMonotonicTimeForTest(1000.0); |
| 535 |
| 536 // Note the latency mode gets reset by executeHighPriorityTasks, so we need
a dummy task here |
| 537 // to make sure runPendingTasks triggers executeHighPriorityTasks. |
| 538 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&dummyTask)); |
| 539 m_scheduler->didReceiveInputEvent(); |
| 540 m_platformSupport.setMonotonicTimeForTest(1000.5); |
| 541 runPendingTasks(); |
| 542 |
| 543 ASSERT_FALSE(m_scheduler->shouldYieldForHighPriorityWork()); |
| 544 m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&dummyTask)); |
| 545 |
| 546 EXPECT_FALSE(m_scheduler->shouldYieldForHighPriorityWork()); |
| 547 } |
| 548 |
508 } // namespace | 549 } // namespace |
OLD | NEW |