Chromium Code Reviews| Index: Source/platform/scheduler/SchedulerTest.cpp |
| diff --git a/Source/platform/scheduler/SchedulerTest.cpp b/Source/platform/scheduler/SchedulerTest.cpp |
| index 0b35485e9232fb0518f3c5ef9e964dca34c5de72..b1d3d75d21569284d63b3922c169120a026d98d9 100644 |
| --- a/Source/platform/scheduler/SchedulerTest.cpp |
| +++ b/Source/platform/scheduler/SchedulerTest.cpp |
| @@ -10,9 +10,13 @@ |
| #include "public/platform/Platform.h" |
| #include "public/platform/WebThread.h" |
| +#include <gmock/gmock.h> |
| #include <gtest/gtest.h> |
| +#include <string> |
| +#include <vector> |
| using blink::Scheduler; |
| +using namespace std; |
| namespace { |
| @@ -116,6 +120,7 @@ private: |
| class SchedulerTest : public testing::Test { |
| public: |
| SchedulerTest() |
| + : m_reentrantCount(0) |
| { |
| Scheduler::initializeOnMainThread(); |
| m_scheduler = Scheduler::shared(); |
| @@ -131,9 +136,47 @@ public: |
| m_platformSupport.runPendingTasks(); |
| } |
| + void appendToVector(string value) |
| + { |
| + m_order.push_back(value); |
| + } |
| + |
| + void appendToVectorReentrantTask() |
| + { |
| + m_reentrantOrder.push_back(m_reentrantCount++); |
| + |
| + // Note TestRentrantTaskAfterShutdown exposes the case where a low priority task |
| + // is executed after the Scheduler has shut down. It's necessary to check here |
| + // that the Scheduler still exists before making the re-entrant call. |
| + if (m_reentrantCount <= 4 && Scheduler::shared()) { |
|
eseidel
2014/08/12 16:16:01
Why this magic value of 4? I would at least put t
alexclarke
2014/08/13 10:08:59
Done.
|
| + Scheduler::shared()->postTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVectorReentrantTask, this)); |
| + } |
| + } |
| + |
| + void appendToVectorReentrantInputTask() |
| + { |
| + m_reentrantOrder.push_back(m_reentrantCount++); |
| + |
| + if (m_reentrantCount > 4) |
| + return; |
| + m_scheduler->postInputTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVectorReentrantInputTask, this)); |
| + } |
| + |
| + void appendToVectorReentrantCompositorTask() |
| + { |
| + m_reentrantOrder.push_back(m_reentrantCount++); |
| + |
| + if (m_reentrantCount > 4) |
| + return; |
| + m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVectorReentrantCompositorTask, this)); |
| + } |
| + |
| protected: |
| SchedulerTestingPlatformSupport m_platformSupport; |
| Scheduler* m_scheduler; |
| + std::vector<string> m_order; |
| + std::vector<int> m_reentrantOrder; |
| + int m_reentrantCount; |
| }; |
| void orderedTestTask(int value, int* result) |
| @@ -154,10 +197,10 @@ void idleTestTask(int value, int* result, double allottedTime) |
| TEST_F(SchedulerTest, TestPostTask) |
| { |
| int result = 0; |
| - m_scheduler->postTask(FROM_HERE, bind(&orderedTestTask, 1, &result)); |
| - m_scheduler->postTask(FROM_HERE, bind(&orderedTestTask, 2, &result)); |
| - m_scheduler->postTask(FROM_HERE, bind(&orderedTestTask, 3, &result)); |
| - m_scheduler->postTask(FROM_HERE, bind(&orderedTestTask, 4, &result)); |
| + m_scheduler->postTask(FROM_HERE, WTF::bind(&orderedTestTask, 1, &result)); |
| + m_scheduler->postTask(FROM_HERE, WTF::bind(&orderedTestTask, 2, &result)); |
| + m_scheduler->postTask(FROM_HERE, WTF::bind(&orderedTestTask, 3, &result)); |
| + m_scheduler->postTask(FROM_HERE, WTF::bind(&orderedTestTask, 4, &result)); |
| runPendingTasks(); |
| EXPECT_EQ(0x1234, result); |
| } |
| @@ -165,10 +208,10 @@ TEST_F(SchedulerTest, TestPostTask) |
| TEST_F(SchedulerTest, TestPostMixedTaskTypes) |
| { |
| int result = 0; |
| - m_scheduler->postTask(FROM_HERE, bind(&unorderedTestTask, 1, &result)); |
| - m_scheduler->postInputTask(FROM_HERE, bind(&unorderedTestTask, 2, &result)); |
| - m_scheduler->postCompositorTask(FROM_HERE, bind(&unorderedTestTask, 4, &result)); |
| - m_scheduler->postTask(FROM_HERE, bind(&unorderedTestTask, 8, &result)); |
| + m_scheduler->postTask(FROM_HERE, WTF::bind(&unorderedTestTask, 1, &result)); |
| + m_scheduler->postInputTask(FROM_HERE, WTF::bind(&unorderedTestTask, 2, &result)); |
| + m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&unorderedTestTask, 4, &result)); |
| + m_scheduler->postTask(FROM_HERE, WTF::bind(&unorderedTestTask, 8, &result)); |
| runPendingTasks(); |
| EXPECT_EQ(15, result); |
| } |
| @@ -201,12 +244,51 @@ TEST_F(SchedulerTest, TestIdleTask) |
| { |
| // TODO: Check task allottedTime when implemented in the scheduler. |
| int result = 0; |
| - m_scheduler->postIdleTask(bind<double>(&idleTestTask, 1, &result)); |
| - m_scheduler->postIdleTask(bind<double>(&idleTestTask, 1, &result)); |
| - m_scheduler->postIdleTask(bind<double>(&idleTestTask, 1, &result)); |
| - m_scheduler->postIdleTask(bind<double>(&idleTestTask, 1, &result)); |
| + m_scheduler->postIdleTask(FROM_HERE, WTF::bind<double>(&idleTestTask, 1, &result)); |
| + m_scheduler->postIdleTask(FROM_HERE, WTF::bind<double>(&idleTestTask, 1, &result)); |
| + m_scheduler->postIdleTask(FROM_HERE, WTF::bind<double>(&idleTestTask, 1, &result)); |
| + m_scheduler->postIdleTask(FROM_HERE, WTF::bind<double>(&idleTestTask, 1, &result)); |
| runPendingTasks(); |
| EXPECT_EQ(4, result); |
| } |
| +TEST_F(SchedulerTest, TestTaskPrioritization) |
| +{ |
| + m_scheduler->postTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, this, string("L1"))); |
| + m_scheduler->postTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, this, string("L2"))); |
| + m_scheduler->postInputTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, this, string("I1"))); |
| + m_scheduler->postInputTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, this, string("I2"))); |
| + m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, this, string("C1"))); |
| + m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVector, this, string("C2"))); |
| + |
| + runPendingTasks(); |
| + EXPECT_THAT(m_order, testing::ElementsAre( |
| + string("I1"), string("I2"), string("C1"), string("C2"), string("L1"), string("L2"))); |
| +} |
| + |
| +TEST_F(SchedulerTest, TestRentrantTask) |
| +{ |
| + m_scheduler->postTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVectorReentrantTask, this)); |
| + runPendingTasks(); |
| + |
| + EXPECT_THAT(m_reentrantOrder, testing::ElementsAre(0, 1, 2, 3, 4)); |
| +} |
| + |
| + |
| +TEST_F(SchedulerTest, TestRentrantInputTaskDuringShutdown) |
| +{ |
| + m_scheduler->postInputTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVectorReentrantInputTask, this)); |
| + Scheduler::shutdown(); |
| + |
| + EXPECT_THAT(m_reentrantOrder, testing::ElementsAre(0, 1, 2, 3, 4)); |
| +} |
| + |
| +TEST_F(SchedulerTest, TestRentrantCompositorTaskDuringShutdown) |
| +{ |
| + m_scheduler->postCompositorTask(FROM_HERE, WTF::bind(&SchedulerTest::appendToVectorReentrantCompositorTask, this)); |
| + Scheduler::shutdown(); |
| + |
| + EXPECT_THAT(m_reentrantOrder, testing::ElementsAre(0, 1, 2, 3, 4)); |
| +} |
| + |
| } // namespace |