Chromium Code Reviews| 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" |
| 11 #include "public/platform/WebThread.h" | 11 #include "public/platform/WebThread.h" |
| 12 #include "wtf/text/WTFString.h" | |
| 12 | 13 |
| 14 #include <gmock/gmock.h> | |
| 13 #include <gtest/gtest.h> | 15 #include <gtest/gtest.h> |
| 16 #include <vector> | |
| 14 | 17 |
| 15 using blink::Scheduler; | 18 using blink::Scheduler; |
| 16 | 19 |
| 17 namespace { | 20 namespace { |
| 18 | 21 |
| 19 class TestMainThread : public blink::WebThread { | 22 class TestMainThread : public blink::WebThread { |
| 20 public: | 23 public: |
| 21 // blink::WebThread implementation. | 24 // blink::WebThread implementation. |
| 22 virtual void postTask(Task* task) OVERRIDE | 25 virtual void postTask(Task* task) OVERRIDE |
| 23 { | 26 { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 ~SchedulerTest() | 127 ~SchedulerTest() |
| 125 { | 128 { |
| 126 Scheduler::shutdown(); | 129 Scheduler::shutdown(); |
| 127 } | 130 } |
| 128 | 131 |
| 129 void runPendingTasks() | 132 void runPendingTasks() |
| 130 { | 133 { |
| 131 m_platformSupport.runPendingTasks(); | 134 m_platformSupport.runPendingTasks(); |
| 132 } | 135 } |
| 133 | 136 |
| 137 void appendToVector(String value) | |
|
Sami
2014/08/07 14:24:45
nit: looks like this could be a normal std::string
alexclarke
2014/08/07 15:15:29
Done.
| |
| 138 { | |
| 139 m_order.push_back(value); | |
| 140 } | |
| 141 | |
| 142 void appendToVectorReentrant(int count) | |
| 143 { | |
| 144 m_intOrder.push_back(count); | |
| 145 | |
| 146 if (count < 4) | |
| 147 m_scheduler->postTask(FROM_HERE, bind(&SchedulerTest::appendToVector Reentrant, this, count + 1)); | |
| 148 } | |
| 149 | |
| 134 protected: | 150 protected: |
| 135 SchedulerTestingPlatformSupport m_platformSupport; | 151 SchedulerTestingPlatformSupport m_platformSupport; |
| 136 Scheduler* m_scheduler; | 152 Scheduler* m_scheduler; |
| 153 std::vector<String> m_order; | |
| 154 std::vector<int> m_intOrder; | |
|
Sami
2014/08/07 14:24:45
bikeshed: m_reentrantOrder?
alexclarke
2014/08/07 15:15:29
Done.
| |
| 137 }; | 155 }; |
| 138 | 156 |
| 139 void orderedTestTask(int value, int* result) | 157 void orderedTestTask(int value, int* result) |
| 140 { | 158 { |
| 141 *result = (*result << 4) | value; | 159 *result = (*result << 4) | value; |
| 142 } | 160 } |
| 143 | 161 |
| 144 void unorderedTestTask(int value, int* result) | 162 void unorderedTestTask(int value, int* result) |
| 145 { | 163 { |
| 146 *result += value; | 164 *result += value; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 // TODO: Check task allottedTime when implemented in the scheduler. | 220 // TODO: Check task allottedTime when implemented in the scheduler. |
| 203 int result = 0; | 221 int result = 0; |
| 204 m_scheduler->postIdleTask(bind<double>(&idleTestTask, 1, &result)); | 222 m_scheduler->postIdleTask(bind<double>(&idleTestTask, 1, &result)); |
| 205 m_scheduler->postIdleTask(bind<double>(&idleTestTask, 1, &result)); | 223 m_scheduler->postIdleTask(bind<double>(&idleTestTask, 1, &result)); |
| 206 m_scheduler->postIdleTask(bind<double>(&idleTestTask, 1, &result)); | 224 m_scheduler->postIdleTask(bind<double>(&idleTestTask, 1, &result)); |
| 207 m_scheduler->postIdleTask(bind<double>(&idleTestTask, 1, &result)); | 225 m_scheduler->postIdleTask(bind<double>(&idleTestTask, 1, &result)); |
| 208 runPendingTasks(); | 226 runPendingTasks(); |
| 209 EXPECT_EQ(4, result); | 227 EXPECT_EQ(4, result); |
| 210 } | 228 } |
| 211 | 229 |
| 230 TEST_F(SchedulerTest, TestTaskPrioritization) | |
| 231 { | |
| 232 m_scheduler->postTask(FROM_HERE, bind(&SchedulerTest::appendToVector, this, String("L1"))); | |
| 233 m_scheduler->postTask(FROM_HERE, bind(&SchedulerTest::appendToVector, this, String("L2"))); | |
| 234 m_scheduler->postInputTask(FROM_HERE, bind(&SchedulerTest::appendToVector, t his, String("I1"))); | |
| 235 m_scheduler->postInputTask(FROM_HERE, bind(&SchedulerTest::appendToVector, t his, String("I2"))); | |
| 236 m_scheduler->postCompositorTask(FROM_HERE, bind(&SchedulerTest::appendToVect or, this, String("C1"))); | |
| 237 m_scheduler->postCompositorTask(FROM_HERE, bind(&SchedulerTest::appendToVect or, this, String("C2"))); | |
| 238 | |
| 239 runPendingTasks(); | |
| 240 EXPECT_THAT(m_order, testing::ElementsAre( | |
| 241 String("I1"), String("I2"), String("C1"), String("C2"), String("L1"), St ring("L2"))); | |
| 242 } | |
| 243 | |
| 244 TEST_F(SchedulerTest, TestRentrantTask) | |
| 245 { | |
| 246 m_scheduler->postTask(FROM_HERE, bind(&SchedulerTest::appendToVectorReentran t, this, 0)); | |
| 247 runPendingTasks(); | |
| 248 | |
| 249 EXPECT_THAT(m_intOrder, testing::ElementsAre(0, 1, 2, 3, 4)); | |
| 250 } | |
| 251 | |
| 252 | |
|
Sami
2014/08/07 14:24:45
Would you mind adding a test that checks all pendi
alexclarke
2014/08/07 15:15:29
Done.
| |
| 212 } // namespace | 253 } // namespace |
| OLD | NEW |