Chromium Code Reviews| Index: base/test/scoped_mock_message_loop_task_runner_wrapper.cc |
| diff --git a/base/test/scoped_mock_message_loop_task_runner_wrapper.cc b/base/test/scoped_mock_message_loop_task_runner_wrapper.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1378f30f89e01d99126a33611ce1e837d50eeee4 |
| --- /dev/null |
| +++ b/base/test/scoped_mock_message_loop_task_runner_wrapper.cc |
| @@ -0,0 +1,42 @@ |
| +// Copyright 2015 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. |
| + |
| +#include "base/test/scoped_mock_message_loop_task_runner_wrapper.h" |
| + |
| +#include <deque> |
| +#include <utility> |
| + |
| +#include "base/logging.h" |
| +#include "base/macros.h" |
| +#include "base/memory/ptr_util.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/message_loop/message_loop.h" |
| +#include "base/test/test_mock_time_task_runner.h" |
| +#include "base/test/test_pending_task.h" |
| +#include "base/threading/thread_task_runner_handle.h" |
| +#include "base/time/clock.h" |
| +#include "base/time/tick_clock.h" |
|
gab
2016/11/15 22:02:05
rm unused includes
bruthig
2016/11/15 22:17:57
Done.
|
| + |
| +namespace base { |
| + |
| +// ScopedTestMockTimeTaskRunner ----------------------------------------------- |
|
gab
2016/11/15 22:02:05
not needed
bruthig
2016/11/15 22:17:57
Done.
|
| + |
| +ScopedMockMessageLoopTaskRunnerWrapper::ScopedMockMessageLoopTaskRunnerWrapper() |
| + : task_runner_(new TestMockTimeTaskRunner), |
| + previous_task_runner_(ThreadTaskRunnerHandle::Get()) { |
| + DCHECK(MessageLoop::current()); |
| + MessageLoop::current()->SetTaskRunner(task_runner_); |
| +} |
| + |
| +ScopedMockMessageLoopTaskRunnerWrapper:: |
| + ~ScopedMockMessageLoopTaskRunnerWrapper() { |
| + DCHECK(previous_task_runner_->RunsTasksOnCurrentThread()); |
| + DCHECK_EQ(task_runner_, ThreadTaskRunnerHandle::Get()); |
| + std::deque<TestPendingTask> tasks = task_runner_->TakePendingTasks(); |
| + for (auto it = tasks.begin(); it != tasks.end(); ++it) |
| + previous_task_runner_->PostDelayedTask(it->location, it->task, it->delay); |
| + MessageLoop::current()->SetTaskRunner(std::move(previous_task_runner_)); |
| +} |
| + |
| +} // namespace base |