Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #ifndef BASE_TEST_SCOPED_TASK_ENVIRONMENT_H_ | 5 #ifndef BASE_TEST_SCOPED_TASK_ENVIRONMENT_H_ |
| 6 #define BASE_TEST_SCOPED_TASK_ENVIRONMENT_H_ | 6 #define BASE_TEST_SCOPED_TASK_ENVIRONMENT_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 // Tests that need either of these APIs should instantiate a | 21 // Tests that need either of these APIs should instantiate a |
| 22 // ScopedTaskEnvironment. | 22 // ScopedTaskEnvironment. |
| 23 // | 23 // |
| 24 // Tasks posted to the (Thread|Sequenced)TaskRunnerHandle run synchronously when | 24 // Tasks posted to the (Thread|Sequenced)TaskRunnerHandle run synchronously when |
| 25 // RunLoop::Run(UntilIdle) is called on the thread where the | 25 // RunLoop::Run(UntilIdle) is called on the thread where the |
| 26 // ScopedTaskEnvironment lives. | 26 // ScopedTaskEnvironment lives. |
| 27 // | 27 // |
| 28 // Tasks posted through base/task_scheduler/post_task.h run on dedicated threads | 28 // Tasks posted through base/task_scheduler/post_task.h run on dedicated threads |
| 29 // as they are posted. | 29 // as they are posted. |
| 30 // | 30 // |
| 31 // Usage: | |
| 32 // | |
| 33 // class MyTestFixture : public testing::Test { | |
| 34 // public: | |
| 35 // (...) | |
| 36 // | |
| 37 // protected: | |
| 38 // // Must be first member (or at least before any member that cares about | |
|
robliao
2017/05/04 21:54:28
Nit: s/be first/be the first/
Here and in TestBrow
gab
2017/05/04 22:27:41
Done.
| |
| 39 // // tasks) to be initialized first and destroyed last. protected instead | |
| 40 // // of private visibility will allow controlling the task environment | |
| 41 // // (e.g. clock) once such features are added (see design doc below for | |
| 42 // // details), until then it at least doesn't hurt :). | |
| 43 // base::test::ScopedTaskEnvironment scoped_task_environment_; | |
| 44 // | |
| 45 // // Other members go here (or further below in private section.) | |
| 46 // }; | |
| 47 // | |
| 31 // Design and future improvements documented in | 48 // Design and future improvements documented in |
| 32 // https://docs.google.com/document/d/1QabRo8c7D9LsYY3cEcaPQbOCLo8Tu-6VLykYXyl3P kk/edit | 49 // https://docs.google.com/document/d/1QabRo8c7D9LsYY3cEcaPQbOCLo8Tu-6VLykYXyl3P kk/edit |
| 33 class ScopedTaskEnvironment { | 50 class ScopedTaskEnvironment { |
| 34 public: | 51 public: |
| 35 ScopedTaskEnvironment(); | 52 ScopedTaskEnvironment(); |
| 36 | 53 |
| 37 // Runs pending (Thread|Sequenced)TaskRunnerHandle tasks and pending | 54 // Runs pending (Thread|Sequenced)TaskRunnerHandle tasks and pending |
| 38 // BLOCK_SHUTDOWN TaskScheduler tasks. Then, unregisters the TaskScheduler and | 55 // BLOCK_SHUTDOWN TaskScheduler tasks. Then, unregisters the TaskScheduler and |
| 39 // the (Thread|Sequenced)TaskRunnerHandle. | 56 // the (Thread|Sequenced)TaskRunnerHandle. |
| 40 ~ScopedTaskEnvironment(); | 57 ~ScopedTaskEnvironment(); |
| 41 | 58 |
| 42 private: | 59 private: |
| 43 // Note: |message_loop_| is an implementation detail and will be replaced in | 60 // Note: |message_loop_| is an implementation detail and will be replaced in |
| 44 // the future, do NOT rely on the presence of a MessageLoop beyond | 61 // the future, do NOT rely on the presence of a MessageLoop beyond |
| 45 // (Thread|Sequenced)TaskRunnerHandle and RunLoop. | 62 // (Thread|Sequenced)TaskRunnerHandle and RunLoop. |
| 46 MessageLoop message_loop_; | 63 MessageLoop message_loop_; |
| 47 | 64 |
| 48 const TaskScheduler* task_scheduler_ = nullptr; | 65 const TaskScheduler* task_scheduler_ = nullptr; |
| 49 | 66 |
| 50 DISALLOW_COPY_AND_ASSIGN(ScopedTaskEnvironment); | 67 DISALLOW_COPY_AND_ASSIGN(ScopedTaskEnvironment); |
| 51 }; | 68 }; |
| 52 | 69 |
| 53 } // namespace test | 70 } // namespace test |
| 54 } // namespace base | 71 } // namespace base |
| 55 | 72 |
| 56 #endif // BASE_TEST_SCOPED_ASYNC_TASK_SCHEDULER_H_ | 73 #endif // BASE_TEST_SCOPED_ASYNC_TASK_SCHEDULER_H_ |
| OLD | NEW |