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 #include <utility> | |
9 | |
10 #include "base/logging.h" | |
11 #include "base/macros.h" | |
12 #include "base/memory/ptr_util.h" | |
13 #include "base/memory/ref_counted.h" | |
14 #include "base/message_loop/message_loop.h" | |
15 #include "base/test/test_mock_time_task_runner.h" | |
16 #include "base/test/test_pending_task.h" | |
17 #include "base/threading/thread_task_runner_handle.h" | |
18 #include "base/time/clock.h" | |
19 #include "base/time/tick_clock.h" | |
gab
2016/11/15 22:02:05
rm unused includes
bruthig
2016/11/15 22:17:57
Done.
| |
20 | |
21 namespace base { | |
22 | |
23 // ScopedTestMockTimeTaskRunner ----------------------------------------------- | |
gab
2016/11/15 22:02:05
not needed
bruthig
2016/11/15 22:17:57
Done.
| |
24 | |
25 ScopedMockMessageLoopTaskRunnerWrapper::ScopedMockMessageLoopTaskRunnerWrapper() | |
26 : task_runner_(new TestMockTimeTaskRunner), | |
27 previous_task_runner_(ThreadTaskRunnerHandle::Get()) { | |
28 DCHECK(MessageLoop::current()); | |
29 MessageLoop::current()->SetTaskRunner(task_runner_); | |
30 } | |
31 | |
32 ScopedMockMessageLoopTaskRunnerWrapper:: | |
33 ~ScopedMockMessageLoopTaskRunnerWrapper() { | |
34 DCHECK(previous_task_runner_->RunsTasksOnCurrentThread()); | |
35 DCHECK_EQ(task_runner_, ThreadTaskRunnerHandle::Get()); | |
36 std::deque<TestPendingTask> tasks = task_runner_->TakePendingTasks(); | |
37 for (auto it = tasks.begin(); it != tasks.end(); ++it) | |
38 previous_task_runner_->PostDelayedTask(it->location, it->task, it->delay); | |
39 MessageLoop::current()->SetTaskRunner(std::move(previous_task_runner_)); | |
40 } | |
41 | |
42 } // namespace base | |
OLD | NEW |