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..9e2d54846c3ecd775eb71c1bc7f41924bc7ba16b 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 { |
| @@ -131,9 +135,24 @@ public: |
| m_platformSupport.runPendingTasks(); |
| } |
| + void appendToVector(string value) |
| + { |
| + m_order.push_back(value); |
| + } |
| + |
| + void appendToVectorReentrant(int count) |
| + { |
| + m_reentrantOrder.push_back(count); |
| + |
| + if (count < 4) |
| + m_scheduler->postTask(FROM_HERE, bind(&SchedulerTest::appendToVectorReentrant, this, count + 1)); |
| + } |
| + |
| protected: |
| SchedulerTestingPlatformSupport m_platformSupport; |
| Scheduler* m_scheduler; |
| + std::vector<string> m_order; |
| + std::vector<int> m_reentrantOrder; |
| }; |
| void orderedTestTask(int value, int* result) |
| @@ -173,6 +192,17 @@ TEST_F(SchedulerTest, TestPostMixedTaskTypes) |
| EXPECT_EQ(15, result); |
| } |
| +TEST_F(SchedulerTest, TestTasksExecutedOnShutdown) |
| +{ |
| + 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)); |
| + Scheduler::shutdown(); |
|
Sami
2014/08/07 15:51:27
Thanks for adding this test. Can you add a re-entr
alexclarke
2014/08/07 16:01:30
Done.
|
| + EXPECT_EQ(15, result); |
| +} |
| + |
| int s_sharedTimerTickCount; |
| void sharedTimerFunction() |
| { |
| @@ -209,4 +239,27 @@ TEST_F(SchedulerTest, TestIdleTask) |
| EXPECT_EQ(4, result); |
| } |
| +TEST_F(SchedulerTest, TestTaskPrioritization) |
| +{ |
| + m_scheduler->postTask(FROM_HERE, bind(&SchedulerTest::appendToVector, this, string("L1"))); |
| + m_scheduler->postTask(FROM_HERE, bind(&SchedulerTest::appendToVector, this, string("L2"))); |
| + m_scheduler->postInputTask(FROM_HERE, bind(&SchedulerTest::appendToVector, this, string("I1"))); |
| + m_scheduler->postInputTask(FROM_HERE, bind(&SchedulerTest::appendToVector, this, string("I2"))); |
| + m_scheduler->postCompositorTask(FROM_HERE, bind(&SchedulerTest::appendToVector, this, string("C1"))); |
| + m_scheduler->postCompositorTask(FROM_HERE, 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, bind(&SchedulerTest::appendToVectorReentrant, this, 0)); |
| + runPendingTasks(); |
| + |
| + EXPECT_THAT(m_reentrantOrder, testing::ElementsAre(0, 1, 2, 3, 4)); |
| +} |
| + |
| + |
| } // namespace |