Nits follow-up to https://chromium-review.googlesource.com/c/chromium/src/+/638550
R=robliao@chomium.org
Bug: 708584
Change-Id: I9c362e5cc3880644392cc6afcf4754d2fc834ea8
Reviewed-on: https://chromium-review.googlesource.com/783873
Commit-Queue: Gabriel Charette <gab@chromium.org>
Reviewed-by: Robert Liao <robliao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#518521}
diff --git a/base/test/scoped_task_environment.cc b/base/test/scoped_task_environment.cc
index f5d767a..6de729a 100644
--- a/base/test/scoped_task_environment.cc
+++ b/base/test/scoped_task_environment.cc
@@ -21,6 +21,26 @@
namespace base {
namespace test {
+namespace {
+
+std::unique_ptr<MessageLoop> CreateMessageLoopForMainThreadType(
+ ScopedTaskEnvironment::MainThreadType main_thread_type) {
+ switch (main_thread_type) {
+ case ScopedTaskEnvironment::MainThreadType::DEFAULT:
+ return std::make_unique<MessageLoop>(MessageLoop::TYPE_DEFAULT);
+ case ScopedTaskEnvironment::MainThreadType::MOCK_TIME:
+ return nullptr;
+ case ScopedTaskEnvironment::MainThreadType::UI:
+ return std::make_unique<MessageLoop>(MessageLoop::TYPE_UI);
+ case ScopedTaskEnvironment::MainThreadType::IO:
+ return std::make_unique<MessageLoop>(MessageLoop::TYPE_IO);
+ }
+ NOTREACHED();
+ return nullptr;
+}
+
+} // namespace
+
class ScopedTaskEnvironment::TestTaskTracker
: public internal::TaskSchedulerImpl::TaskTrackerImpl {
public:
@@ -59,14 +79,7 @@
MainThreadType main_thread_type,
ExecutionMode execution_control_mode)
: execution_control_mode_(execution_control_mode),
- message_loop_(main_thread_type == MainThreadType::MOCK_TIME
- ? nullptr
- : (std::make_unique<MessageLoop>(
- main_thread_type == MainThreadType::DEFAULT
- ? MessageLoop::TYPE_DEFAULT
- : (main_thread_type == MainThreadType::UI
- ? MessageLoop::TYPE_UI
- : MessageLoop::TYPE_IO)))),
+ message_loop_(CreateMessageLoopForMainThreadType(main_thread_type)),
mock_time_task_runner_(
main_thread_type == MainThreadType::MOCK_TIME
? MakeRefCounted<TestMockTimeTaskRunner>(
diff --git a/base/test/scoped_task_environment.h b/base/test/scoped_task_environment.h
index ed264ad..45b25316 100644
--- a/base/test/scoped_task_environment.h
+++ b/base/test/scoped_task_environment.h
@@ -96,15 +96,16 @@
// TaskScheduler's non-delayed queues are empty.
void RunUntilIdle();
- // Only valid for instances with a MOCK_TIME MainThreadType.
- // Fast-forwards virtual time by |delta|, causing all tasks on the main thread
- // with a remaining delay less than or equal to |delta| to be executed.
- // |delta| must be non-negative.
+ // Only valid for instances with a MOCK_TIME MainThreadType. Fast-forwards
+ // virtual time by |delta|, causing all tasks on the main thread with a
+ // remaining delay less than or equal to |delta| to be executed before this
+ // returns. |delta| must be non-negative.
+ // TODO(gab): Make this apply to TaskScheduler delayed tasks as well
+ // (currently only main thread time is mocked).
void FastForwardBy(TimeDelta delta);
// Only valid for instances with a MOCK_TIME MainThreadType.
- // Fast-forwards virtual time just until all tasks are executed on the main
- // thread.
+ // Short for FastForwardBy(TimeDelta::Max()).
void FastForwardUntilNoTasksRemain();
private: