Chromium Code Reviews| Index: base/test/scoped_task_environment.h |
| diff --git a/base/test/scoped_task_environment.h b/base/test/scoped_task_environment.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..17655bd9b7bb78bd7c22bc5041107c5a9ee937d9 |
| --- /dev/null |
| +++ b/base/test/scoped_task_environment.h |
| @@ -0,0 +1,52 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef BASE_TEST_SCOPED_TASK_ENVIRONMENT_H_ |
| +#define BASE_TEST_SCOPED_TASK_ENVIRONMENT_H_ |
| + |
| +#include "base/macros.h" |
| +#include "base/message_loop/message_loop.h" |
| + |
| +namespace base { |
| + |
| +class TaskScheduler; |
| + |
| +namespace test { |
| + |
| +// ScopedTaskEnvironment allows usage of these APIs within its scope: |
| +// - ThreadTaskRunnerHandle, on the thread where it lives |
|
gab
2017/04/05 20:44:24
(Thread|Sequenced)TaskRunnerHandle
fdoray
2017/04/06 14:00:23
Done.
|
| +// - base/task_scheduler/post_task.h, on any thread |
| +// |
| +// Tests that need either of these APIs should instantiate a |
| +// ScopedTaskEnvironment. |
| +// |
| +// Tasks posted to the ThreadTaskRunnerHandle run synchronously when |
| +// RunLoop::Run(UntilIdle) is called on the thread where the |
| +// ScopedTaskEnvironment lives. |
| +// |
| +// Tasks posted through base/task_scheduler/post_task.h run on dedicated threads |
| +// as they are posted. |
| +// |
| +// Future improvements documented in: |
|
gab
2017/04/05 20:44:24
// Design and future improvements documented in
fdoray
2017/04/06 14:00:22
Done.
|
| +// https://docs.google.com/document/d/1QabRo8c7D9LsYY3cEcaPQbOCLo8Tu-6VLykYXyl3Pkk/edit |
| +class ScopedTaskEnvironment { |
| + public: |
| + ScopedTaskEnvironment(); |
| + |
| + // Runs pending ThreadTaskRunnerHandle tasks and pending BLOCK_SHUTDOWN |
| + // TaskScheduler tasks. Then, unregisters the TaskScheduler and the |
| + // ThreadTaskRunnerHandle. |
| + ~ScopedTaskEnvironment(); |
| + |
| + private: |
| + MessageLoop message_loop_; |
|
gab
2017/04/05 20:44:24
// Note: |message_loop_| is an implementation deta
fdoray
2017/04/06 14:00:23
Done.
|
| + const TaskScheduler* task_scheduler_ = nullptr; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ScopedTaskEnvironment); |
| +}; |
| + |
| +} // namespace test |
| +} // namespace base |
| + |
| +#endif // BASE_TEST_SCOPED_ASYNC_TASK_SCHEDULER_H_ |