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 class defines tests that implementations of TaskRunner should | 5 // This class defines tests that implementations of TaskRunner should |
6 // pass in order to be conformant. Here's how you use it to test your | 6 // pass in order to be conformant. Here's how you use it to test your |
7 // implementation. | 7 // 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 | 46 |
47 #ifndef BASE_TEST_TASK_RUNNER_TEST_TEMPLATE_H_ | 47 #ifndef BASE_TEST_TASK_RUNNER_TEST_TEMPLATE_H_ |
48 #define BASE_TEST_TASK_RUNNER_TEST_TEMPLATE_H_ | 48 #define BASE_TEST_TASK_RUNNER_TEST_TEMPLATE_H_ |
49 | 49 |
50 #include <cstddef> | 50 #include <cstddef> |
51 #include <map> | 51 #include <map> |
52 | 52 |
53 #include "base/basictypes.h" | 53 #include "base/basictypes.h" |
54 #include "base/bind.h" | 54 #include "base/bind.h" |
55 #include "base/callback.h" | 55 #include "base/callback.h" |
| 56 #include "base/location.h" |
56 #include "base/memory/ref_counted.h" | 57 #include "base/memory/ref_counted.h" |
| 58 #include "base/single_thread_task_runner.h" |
57 #include "base/synchronization/condition_variable.h" | 59 #include "base/synchronization/condition_variable.h" |
58 #include "base/synchronization/lock.h" | 60 #include "base/synchronization/lock.h" |
59 #include "base/task_runner.h" | 61 #include "base/task_runner.h" |
60 #include "base/threading/thread.h" | 62 #include "base/threading/thread.h" |
61 #include "base/tracked_objects.h" | 63 #include "base/tracked_objects.h" |
62 #include "testing/gtest/include/gtest/gtest.h" | 64 #include "testing/gtest/include/gtest/gtest.h" |
63 | 65 |
64 namespace base { | 66 namespace base { |
65 | 67 |
66 namespace internal { | 68 namespace internal { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 Bind(&internal::ExpectRunsTasksOnCurrentThread, | 190 Bind(&internal::ExpectRunsTasksOnCurrentThread, |
189 true, task_runner), | 191 true, task_runner), |
190 i); | 192 i); |
191 const Closure& ith_non_task_runner_task = | 193 const Closure& ith_non_task_runner_task = |
192 this->task_tracker_->WrapTask( | 194 this->task_tracker_->WrapTask( |
193 Bind(&internal::ExpectRunsTasksOnCurrentThread, | 195 Bind(&internal::ExpectRunsTasksOnCurrentThread, |
194 false, task_runner), | 196 false, task_runner), |
195 i); | 197 i); |
196 for (int j = 0; j < i + 1; ++j) { | 198 for (int j = 0; j < i + 1; ++j) { |
197 task_runner->PostTask(FROM_HERE, ith_task_runner_task); | 199 task_runner->PostTask(FROM_HERE, ith_task_runner_task); |
198 thread.message_loop()->PostTask(FROM_HERE, ith_non_task_runner_task); | 200 thread.task_runner()->PostTask(FROM_HERE, ith_non_task_runner_task); |
199 expected_task_run_counts[i] += 2; | 201 expected_task_run_counts[i] += 2; |
200 } | 202 } |
201 } | 203 } |
202 | 204 |
203 this->delegate_.StopTaskRunner(); | 205 this->delegate_.StopTaskRunner(); |
204 thread.Stop(); | 206 thread.Stop(); |
205 | 207 |
206 EXPECT_EQ(expected_task_run_counts, | 208 EXPECT_EQ(expected_task_run_counts, |
207 this->task_tracker_->GetTaskRunCounts()); | 209 this->task_tracker_->GetTaskRunCounts()); |
208 } | 210 } |
209 | 211 |
210 REGISTER_TYPED_TEST_CASE_P( | 212 REGISTER_TYPED_TEST_CASE_P( |
211 TaskRunnerTest, Basic, Delayed, RunsTasksOnCurrentThread); | 213 TaskRunnerTest, Basic, Delayed, RunsTasksOnCurrentThread); |
212 | 214 |
213 } // namespace base | 215 } // namespace base |
214 | 216 |
215 #endif // BASE_TEST_TASK_RUNNER_TEST_TEMPLATE_H_ | 217 #endif // BASE_TEST_TASK_RUNNER_TEST_TEMPLATE_H_ |
OLD | NEW |