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 "components/scheduler/child/task_queue_manager.h" | 5 #include "components/scheduler/child/task_queue_manager.h" |
6 | 6 |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "base/test/simple_test_tick_clock.h" | 9 #include "base/test/simple_test_tick_clock.h" |
10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 enum class SelectorType { | 115 enum class SelectorType { |
116 Automatic, | 116 Automatic, |
117 Explicit, | 117 Explicit, |
118 }; | 118 }; |
119 | 119 |
120 void Initialize(size_t num_queues, SelectorType type) { | 120 void Initialize(size_t num_queues, SelectorType type) { |
121 now_src_.reset(new base::SimpleTestTickClock()); | 121 now_src_.reset(new base::SimpleTestTickClock()); |
122 now_src_->Advance(base::TimeDelta::FromMicroseconds(1000)); | 122 now_src_->Advance(base::TimeDelta::FromMicroseconds(1000)); |
123 test_task_runner_ = make_scoped_refptr( | 123 test_task_runner_ = make_scoped_refptr( |
124 new cc::OrderedSimpleTaskRunner(now_src_.get(), false)); | 124 new cc::OrderedSimpleTaskRunner(now_src_.get(), false)); |
125 main_task_runner_ = | |
126 NestableTaskRunnerForTest::Create(test_task_runner_.get()); | |
125 selector_ = make_scoped_ptr(createSelectorForTest(type)); | 127 selector_ = make_scoped_ptr(createSelectorForTest(type)); |
126 manager_ = make_scoped_ptr(new TaskQueueManager( | 128 manager_ = make_scoped_ptr( |
127 num_queues, NestableTaskRunnerForTest::Create(test_task_runner_.get()), | 129 new TaskQueueManager(num_queues, main_task_runner_, selector_.get(), |
128 selector_.get(), "test.scheduler", "test.scheduler.debug")); | 130 "test.scheduler", "test.scheduler.debug")); |
129 manager_->SetTimeSourceForTesting( | 131 manager_->SetTimeSourceForTesting( |
130 make_scoped_ptr(new TestTimeSource(now_src_.get()))); | 132 make_scoped_ptr(new TestTimeSource(now_src_.get()))); |
131 | 133 |
132 EXPECT_EQ(num_queues, selector_->work_queues().size()); | 134 EXPECT_EQ(num_queues, selector_->work_queues().size()); |
133 } | 135 } |
134 | 136 |
135 void InitializeWithRealMessageLoop(size_t num_queues, SelectorType type) { | 137 void InitializeWithRealMessageLoop(size_t num_queues, SelectorType type) { |
136 message_loop_.reset(new base::MessageLoop()); | 138 message_loop_.reset(new base::MessageLoop()); |
137 selector_ = make_scoped_ptr(createSelectorForTest(type)); | 139 selector_ = make_scoped_ptr(createSelectorForTest(type)); |
138 manager_ = make_scoped_ptr(new TaskQueueManager( | 140 manager_ = make_scoped_ptr(new TaskQueueManager( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 &TaskQueueManager::PumpPolicyToString); | 172 &TaskQueueManager::PumpPolicyToString); |
171 } | 173 } |
172 | 174 |
173 static void CheckAllWakeupPolicyToString() { | 175 static void CheckAllWakeupPolicyToString() { |
174 CallForEachEnumValue<TaskQueueManager::WakeupPolicy>( | 176 CallForEachEnumValue<TaskQueueManager::WakeupPolicy>( |
175 TaskQueueManager::WakeupPolicy::FIRST_WAKEUP_POLICY, | 177 TaskQueueManager::WakeupPolicy::FIRST_WAKEUP_POLICY, |
176 TaskQueueManager::WakeupPolicy::WAKEUP_POLICY_COUNT, | 178 TaskQueueManager::WakeupPolicy::WAKEUP_POLICY_COUNT, |
177 &TaskQueueManager::WakeupPolicyToString); | 179 &TaskQueueManager::WakeupPolicyToString); |
178 } | 180 } |
179 | 181 |
182 scoped_ptr<base::MessageLoop> message_loop_; | |
180 scoped_ptr<base::SimpleTestTickClock> now_src_; | 183 scoped_ptr<base::SimpleTestTickClock> now_src_; |
184 scoped_refptr<NestableTaskRunnerForTest> main_task_runner_; | |
181 scoped_refptr<cc::OrderedSimpleTaskRunner> test_task_runner_; | 185 scoped_refptr<cc::OrderedSimpleTaskRunner> test_task_runner_; |
182 scoped_ptr<SelectorForTest> selector_; | 186 scoped_ptr<SelectorForTest> selector_; |
183 scoped_ptr<TaskQueueManager> manager_; | 187 scoped_ptr<TaskQueueManager> manager_; |
184 scoped_ptr<base::MessageLoop> message_loop_; | |
185 }; | 188 }; |
186 | 189 |
187 void PostFromNestedRunloop(base::MessageLoop* message_loop, | 190 void PostFromNestedRunloop(base::MessageLoop* message_loop, |
188 base::SingleThreadTaskRunner* runner, | 191 base::SingleThreadTaskRunner* runner, |
189 std::vector<std::pair<base::Closure, bool>>* tasks) { | 192 std::vector<std::pair<base::Closure, bool>>* tasks) { |
190 base::MessageLoop::ScopedNestableTaskAllower allow(message_loop); | 193 base::MessageLoop::ScopedNestableTaskAllower allow(message_loop); |
191 for (std::pair<base::Closure, bool>& pair : *tasks) { | 194 for (std::pair<base::Closure, bool>& pair : *tasks) { |
192 if (pair.second) { | 195 if (pair.second) { |
193 runner->PostTask(FROM_HERE, pair.first); | 196 runner->PostTask(FROM_HERE, pair.first); |
194 } else { | 197 } else { |
(...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1235 EXPECT_EQ(TaskQueueManager::QueueState::HAS_WORK, | 1238 EXPECT_EQ(TaskQueueManager::QueueState::HAS_WORK, |
1236 manager_->GetQueueState(1)); | 1239 manager_->GetQueueState(1)); |
1237 | 1240 |
1238 test_task_runner_->RunUntilIdle(); | 1241 test_task_runner_->RunUntilIdle(); |
1239 EXPECT_EQ(TaskQueueManager::QueueState::EMPTY, | 1242 EXPECT_EQ(TaskQueueManager::QueueState::EMPTY, |
1240 manager_->GetQueueState(0)); | 1243 manager_->GetQueueState(0)); |
1241 EXPECT_EQ(TaskQueueManager::QueueState::EMPTY, | 1244 EXPECT_EQ(TaskQueueManager::QueueState::EMPTY, |
1242 manager_->GetQueueState(1)); | 1245 manager_->GetQueueState(1)); |
1243 } | 1246 } |
1244 | 1247 |
1248 TEST_F(TaskQueueManagerTest, DefaultTaskRunnerRegistration) { | |
1249 Initialize(1u, SelectorType::Automatic); | |
1250 EXPECT_EQ(main_task_runner_->default_task_runner(), | |
1251 manager_->TaskRunnerForQueue(0)); | |
1252 } | |
1253 | |
alex clarke (OOO till 29th)
2015/07/08 13:30:53
Can we have a test to ensure the original task run
Sami
2015/07/08 18:45:07
Done.
alex clarke (OOO till 29th)
2015/07/10 15:21:11
Not seeing the test, does it still make sense to h
Sami
2015/07/10 15:35:12
That one's now in components/scheduler/child/sched
| |
1245 } // namespace scheduler | 1254 } // namespace scheduler |
OLD | NEW |