Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/test/scoped_mock_message_loop_task_runner_wrapper.h" | |
| 6 | |
| 7 #include <deque> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/message_loop/message_loop.h" | |
| 11 #include "base/test/test_mock_time_task_runner.h" | |
| 12 #include "base/test/test_pending_task.h" | |
| 13 #include "base/threading/thread_task_runner_handle.h" | |
| 14 | |
| 15 namespace base { | |
| 16 | |
| 17 ScopedMockMessageLoopTaskRunnerWrapper::ScopedMockMessageLoopTaskRunnerWrapper() | |
| 18 : task_runner_(new TestMockTimeTaskRunner), | |
| 19 previous_task_runner_(ThreadTaskRunnerHandle::Get()) { | |
| 20 DCHECK(MessageLoop::current()); | |
| 21 MessageLoop::current()->SetTaskRunner(task_runner_); | |
|
gab
2016/11/17 19:35:54
One more thing, add this above this line:
RunLoop
bruthig
2016/11/17 23:57:08
Done.
| |
| 22 } | |
| 23 | |
| 24 ScopedMockMessageLoopTaskRunnerWrapper:: | |
| 25 ~ScopedMockMessageLoopTaskRunnerWrapper() { | |
| 26 DCHECK(previous_task_runner_->RunsTasksOnCurrentThread()); | |
| 27 DCHECK_EQ(task_runner_, ThreadTaskRunnerHandle::Get()); | |
| 28 std::deque<TestPendingTask> tasks = task_runner_->TakePendingTasks(); | |
| 29 for (auto it = tasks.begin(); it != tasks.end(); ++it) | |
| 30 previous_task_runner_->PostDelayedTask(it->location, it->task, it->delay); | |
| 31 MessageLoop::current()->SetTaskRunner(std::move(previous_task_runner_)); | |
| 32 } | |
| 33 | |
| 34 } // namespace base | |
| OLD | NEW |