| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This file defines tests that implementations of TaskRunner should | 5 // This file defines tests that implementations of TaskRunner should |
| 6 // pass in order to be conformant, as well as test cases for optional behavior. | 6 // pass in order to be conformant, as well as test cases for optional behavior. |
| 7 // Here's how you use it to test your implementation. | 7 // Here's how you use it to test your implementation. |
| 8 // | 8 // |
| 9 // Say your class is called MyTaskRunner. Then you need to define a | 9 // Say your class is called MyTaskRunner. Then you need to define a |
| 10 // class called MyTaskRunnerTestDelegate in my_task_runner_unittest.cc | 10 // class called MyTaskRunnerTestDelegate in my_task_runner_unittest.cc |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 | 194 |
| 195 Thread thread("Non-task-runner thread"); | 195 Thread thread("Non-task-runner thread"); |
| 196 ASSERT_TRUE(thread.Start()); | 196 ASSERT_TRUE(thread.Start()); |
| 197 this->delegate_.StartTaskRunner(); | 197 this->delegate_.StartTaskRunner(); |
| 198 | 198 |
| 199 scoped_refptr<TaskRunner> task_runner = this->delegate_.GetTaskRunner(); | 199 scoped_refptr<TaskRunner> task_runner = this->delegate_.GetTaskRunner(); |
| 200 // Post each ith task i+1 times on the task runner and i+1 times on | 200 // Post each ith task i+1 times on the task runner and i+1 times on |
| 201 // the non-task-runner thread. | 201 // the non-task-runner thread. |
| 202 for (int i = 0; i < 20; ++i) { | 202 for (int i = 0; i < 20; ++i) { |
| 203 const Closure& ith_task_runner_task = this->task_tracker_->WrapTask( | 203 const Closure& ith_task_runner_task = this->task_tracker_->WrapTask( |
| 204 Bind(&test::ExpectRunsTasksOnCurrentThread, true, task_runner), i); | 204 Bind(&test::ExpectRunsTasksOnCurrentThread, true, |
| 205 base::RetainedRef(task_runner)), |
| 206 i); |
| 205 const Closure& ith_non_task_runner_task = this->task_tracker_->WrapTask( | 207 const Closure& ith_non_task_runner_task = this->task_tracker_->WrapTask( |
| 206 Bind(&test::ExpectRunsTasksOnCurrentThread, false, task_runner), i); | 208 Bind(&test::ExpectRunsTasksOnCurrentThread, false, |
| 209 base::RetainedRef(task_runner)), |
| 210 i); |
| 207 for (int j = 0; j < i + 1; ++j) { | 211 for (int j = 0; j < i + 1; ++j) { |
| 208 task_runner->PostTask(FROM_HERE, ith_task_runner_task); | 212 task_runner->PostTask(FROM_HERE, ith_task_runner_task); |
| 209 thread.task_runner()->PostTask(FROM_HERE, ith_non_task_runner_task); | 213 thread.task_runner()->PostTask(FROM_HERE, ith_non_task_runner_task); |
| 210 expected_task_run_counts[i] += 2; | 214 expected_task_run_counts[i] += 2; |
| 211 } | 215 } |
| 212 } | 216 } |
| 213 | 217 |
| 214 this->delegate_.StopTaskRunner(); | 218 this->delegate_.StopTaskRunner(); |
| 215 thread.Stop(); | 219 thread.Stop(); |
| 216 | 220 |
| 217 EXPECT_EQ(expected_task_run_counts, | 221 EXPECT_EQ(expected_task_run_counts, |
| 218 this->task_tracker_->GetTaskRunCounts()); | 222 this->task_tracker_->GetTaskRunCounts()); |
| 219 } | 223 } |
| 220 | 224 |
| 221 // TaskRunnerAffinityTest tests that the TaskRunner implementation | 225 // TaskRunnerAffinityTest tests that the TaskRunner implementation |
| 222 // can determine if tasks will never be run on a specific thread. | 226 // can determine if tasks will never be run on a specific thread. |
| 223 REGISTER_TYPED_TEST_CASE_P(TaskRunnerAffinityTest, RunsTasksOnCurrentThread); | 227 REGISTER_TYPED_TEST_CASE_P(TaskRunnerAffinityTest, RunsTasksOnCurrentThread); |
| 224 | 228 |
| 225 } // namespace base | 229 } // namespace base |
| 226 | 230 |
| 227 #endif // BASE_TEST_TASK_RUNNER_TEST_TEMPLATE_H_ | 231 #endif // BASE_TEST_TASK_RUNNER_TEST_TEMPLATE_H_ |
| OLD | NEW |