Index: Source/platform/scheduler/SchedulerTest.cpp |
diff --git a/Source/platform/scheduler/SchedulerTest.cpp b/Source/platform/scheduler/SchedulerTest.cpp |
index 40b8a7cc62a6bcea7114b4b316256d28975aca61..2ce6714f43c3b72bb6ec309b485d500ea2d8407e 100644 |
--- a/Source/platform/scheduler/SchedulerTest.cpp |
+++ b/Source/platform/scheduler/SchedulerTest.cpp |
@@ -76,6 +76,12 @@ public: |
, m_sharedTimerRunning(false) |
, m_sharedTimerFireInterval(0) |
{ |
+ WTF::setMonotonicallyIncreasingTimeFunction(getDebugTime); |
+ } |
+ |
+ virtual ~SchedulerTestingPlatformSupport() |
+ { |
+ WTF::setMonotonicallyIncreasingTimeFunction(0); |
} |
// blink::Platform implementation. |
@@ -89,6 +95,11 @@ public: |
m_sharedTimerFunction = timerFunction; |
} |
+ virtual double monotonicallyIncreasingTime() OVERRIDE |
+ { |
+ return s_debugTime; |
+ } |
+ |
virtual void setSharedTimerFireInterval(double) |
{ |
m_sharedTimerFireInterval = 0; |
@@ -125,13 +136,27 @@ public: |
return m_mainThread.numPendingMainThreadTasks(); |
} |
+ static void setDebugTime(double time) |
+ { |
+ s_debugTime = time; |
+ } |
+ |
private: |
+ static double getDebugTime(void) |
eseidel
2014/09/10 16:09:01
Atypical to have "get" as a method prefix in blink
|
+ { |
+ return s_debugTime; |
+ } |
+ |
TestMainThread m_mainThread; |
SharedTimerFunction m_sharedTimerFunction; |
bool m_sharedTimerRunning; |
double m_sharedTimerFireInterval; |
+ |
+ static double s_debugTime; |
}; |
+double SchedulerTestingPlatformSupport::s_debugTime = 0; |
+ |
class SchedulerTest : public testing::Test { |
public: |
SchedulerTest() |
@@ -399,4 +424,47 @@ TEST_F(SchedulerTest, HighPriorityTasksOnlyRunOncePerSharedTimerFiring) |
m_scheduler->setSharedTimerFiredFunction(nullptr); |
} |
+TEST_F(SchedulerTest, TestInputEventTriggersShouldYield) |
+{ |
+ ASSERT_FALSE(m_scheduler->shouldYieldForHighPriorityWork()); |
+ m_scheduler->postInputTask(FROM_HERE, WTF::bind(&dummyTask)); |
+ |
+ EXPECT_TRUE(m_scheduler->shouldYieldForHighPriorityWork()); |
+} |
+ |
+TEST_F(SchedulerTest, TestCompositorEventDoesNotTriggerShouldYield_InNormalMode) |
+{ |
+ ASSERT_FALSE(m_scheduler->shouldYieldForHighPriorityWork()); |
+ m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&dummyTask)); |
+ |
+ EXPECT_FALSE(m_scheduler->shouldYieldForHighPriorityWork()); |
+} |
+ |
+TEST_F(SchedulerTest, TestInputEventTriggersLowLatencyMode) |
+{ |
+ // Fire off an input task to put us in low latency mode. |
+ m_scheduler->postInputTask(FROM_HERE, WTF::bind(&dummyTask)); |
+ runPendingTasks(); |
+ |
+ ASSERT_FALSE(m_scheduler->shouldYieldForHighPriorityWork()); |
+ m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&dummyTask)); |
+ |
+ EXPECT_TRUE(m_scheduler->shouldYieldForHighPriorityWork()); |
+} |
+ |
+TEST_F(SchedulerTest, TestCompositorEvent_LowLatencyModeDoesntLastLongWithoutInputEvents) |
+{ |
+ SchedulerTestingPlatformSupport::setDebugTime(1000.0); |
+ |
+ // Fire off an input task to put us in low latency mode. |
+ m_scheduler->postInputTask(FROM_HERE, WTF::bind(&dummyTask)); |
+ SchedulerTestingPlatformSupport::setDebugTime(1000.5); |
+ runPendingTasks(); |
+ |
+ ASSERT_FALSE(m_scheduler->shouldYieldForHighPriorityWork()); |
+ m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&dummyTask)); |
+ |
+ EXPECT_FALSE(m_scheduler->shouldYieldForHighPriorityWork()); |
+} |
+ |
} // namespace |