Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: base/test/scoped_task_environment.h

Issue 2868093002: Add base::test::ScopedTaskEnvironment::RunUntilIdle(). (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 namespace base { 11 namespace base {
12 12
13 class TaskScheduler; 13 class TaskScheduler;
14 14
15 namespace test { 15 namespace test {
16 16
17 // ScopedTaskEnvironment allows usage of these APIs within its scope: 17 // ScopedTaskEnvironment allows usage of these APIs within its scope:
18 // - (Thread|Sequenced)TaskRunnerHandle, on the thread where it lives 18 // - (Thread|Sequenced)TaskRunnerHandle, on the thread where it lives
19 // - base/task_scheduler/post_task.h, on any thread 19 // - base/task_scheduler/post_task.h, on any thread
20 // 20 //
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) or ScopedTaskEnvironment::RunUntilIdle is called on
robliao 2017/05/09 21:52:52 Nit: RunUntilIdle()
26 // ScopedTaskEnvironment lives. 26 // the thread where the 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 // All methods of ScopedTaskEnvironment must be called from the same thread.
32 //
31 // Usage: 33 // Usage:
32 // 34 //
33 // class MyTestFixture : public testing::Test { 35 // class MyTestFixture : public testing::Test {
34 // public: 36 // public:
35 // (...) 37 // (...)
36 // 38 //
37 // protected: 39 // protected:
38 // // Must be the first member (or at least before any member that cares 40 // // Must be the first member (or at least before any member that cares
39 // // about tasks) to be initialized first and destroyed last. protected 41 // // about tasks) to be initialized first and destroyed last. protected
40 // // instead of private visibility will allow controlling the task 42 // // instead of private visibility will allow controlling the task
(...skipping 18 matching lines...) Expand all
59 }; 61 };
60 62
61 ScopedTaskEnvironment( 63 ScopedTaskEnvironment(
62 MainThreadType main_thread_type = MainThreadType::DEFAULT); 64 MainThreadType main_thread_type = MainThreadType::DEFAULT);
63 65
64 // Runs pending (Thread|Sequenced)TaskRunnerHandle tasks and pending 66 // Runs pending (Thread|Sequenced)TaskRunnerHandle tasks and pending
65 // BLOCK_SHUTDOWN TaskScheduler tasks. Then, unregisters the TaskScheduler and 67 // BLOCK_SHUTDOWN TaskScheduler tasks. Then, unregisters the TaskScheduler and
66 // the (Thread|Sequenced)TaskRunnerHandle. 68 // the (Thread|Sequenced)TaskRunnerHandle.
67 ~ScopedTaskEnvironment(); 69 ~ScopedTaskEnvironment();
68 70
71 // Synchronously runs (Thread|Sequenced)TaskRunnerHandle tasks until no
72 // undelayed (Thread|Sequenced)TaskRunnerHandle or TaskScheduler tasks remain.
73 void RunUntilIdle();
74
69 private: 75 private:
70 // Note: |message_loop_| is an implementation detail and will be replaced in 76 // Note: |message_loop_| is an implementation detail and will be replaced in
71 // the future, do NOT rely on the presence of a MessageLoop beyond 77 // the future, do NOT rely on the presence of a MessageLoop beyond
72 // (Thread|Sequenced)TaskRunnerHandle and RunLoop. 78 // (Thread|Sequenced)TaskRunnerHandle and RunLoop.
73 MessageLoop message_loop_; 79 MessageLoop message_loop_;
74 80
75 const TaskScheduler* task_scheduler_ = nullptr; 81 const TaskScheduler* task_scheduler_ = nullptr;
76 82
77 DISALLOW_COPY_AND_ASSIGN(ScopedTaskEnvironment); 83 DISALLOW_COPY_AND_ASSIGN(ScopedTaskEnvironment);
78 }; 84 };
79 85
80 } // namespace test 86 } // namespace test
81 } // namespace base 87 } // namespace base
82 88
83 #endif // BASE_TEST_SCOPED_ASYNC_TASK_SCHEDULER_H_ 89 #endif // BASE_TEST_SCOPED_ASYNC_TASK_SCHEDULER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698