Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Side by Side Diff: base/test/test_mock_time_task_runner.cc

Issue 2494943005: [ash-md] Added a delay between system menu default/detailed view transitions. (Closed)
Patch Set: Addressed review comments. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/test/test_mock_time_task_runner.h" 5 #include "base/test/test_mock_time_task_runner.h"
6 6
7 #include <algorithm>
8
7 #include "base/logging.h" 9 #include "base/logging.h"
8 #include "base/macros.h" 10 #include "base/macros.h"
9 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
10 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/message_loop/message_loop.h"
14 #include "base/threading/thread_task_runner_handle.h"
gab 2016/11/15 22:02:06 rm includes added for impl which moved (as well as
bruthig 2016/11/15 22:17:58 Done.
11 #include "base/time/clock.h" 15 #include "base/time/clock.h"
12 #include "base/time/tick_clock.h" 16 #include "base/time/tick_clock.h"
13 17
14 namespace base { 18 namespace base {
15 19
16 namespace { 20 namespace {
17 21
18 // MockTickClock -------------------------------------------------------------- 22 // MockTickClock --------------------------------------------------------------
19 23
20 // TickClock that always returns the then-current mock time ticks of 24 // TickClock that always returns the then-current mock time ticks of
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 std::unique_ptr<Clock> TestMockTimeTaskRunner::GetMockClock() const { 170 std::unique_ptr<Clock> TestMockTimeTaskRunner::GetMockClock() const {
167 DCHECK(thread_checker_.CalledOnValidThread()); 171 DCHECK(thread_checker_.CalledOnValidThread());
168 return MakeUnique<MockClock>(this); 172 return MakeUnique<MockClock>(this);
169 } 173 }
170 174
171 std::unique_ptr<TickClock> TestMockTimeTaskRunner::GetMockTickClock() const { 175 std::unique_ptr<TickClock> TestMockTimeTaskRunner::GetMockTickClock() const {
172 DCHECK(thread_checker_.CalledOnValidThread()); 176 DCHECK(thread_checker_.CalledOnValidThread());
173 return MakeUnique<MockTickClock>(this); 177 return MakeUnique<MockTickClock>(this);
174 } 178 }
175 179
180 std::deque<TestPendingTask> TestMockTimeTaskRunner::TakePendingTasks() {
181 std::deque<TestPendingTask> tasks;
182 while (!tasks_.empty()) {
183 tasks.push_back(tasks_.top());
184 tasks_.pop();
185 }
gab 2016/11/15 22:02:06 Use std::move like TestSimpleTaskRunner does? http
bruthig 2016/11/15 22:17:58 Unless I'm missing something that won't work becau
186 return tasks;
187 }
188
176 bool TestMockTimeTaskRunner::HasPendingTask() const { 189 bool TestMockTimeTaskRunner::HasPendingTask() const {
177 DCHECK(thread_checker_.CalledOnValidThread()); 190 DCHECK(thread_checker_.CalledOnValidThread());
178 return !tasks_.empty(); 191 return !tasks_.empty();
179 } 192 }
180 193
181 size_t TestMockTimeTaskRunner::GetPendingTaskCount() const { 194 size_t TestMockTimeTaskRunner::GetPendingTaskCount() const {
182 DCHECK(thread_checker_.CalledOnValidThread()); 195 DCHECK(thread_checker_.CalledOnValidThread());
183 return tasks_.size(); 196 return tasks_.size();
184 } 197 }
185 198
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 AutoLock scoped_lock(tasks_lock_); 272 AutoLock scoped_lock(tasks_lock_);
260 if (!tasks_.empty() && 273 if (!tasks_.empty() &&
261 (tasks_.top().GetTimeToRun() - reference) <= max_delta) { 274 (tasks_.top().GetTimeToRun() - reference) <= max_delta) {
262 *next_task = tasks_.top(); 275 *next_task = tasks_.top();
263 tasks_.pop(); 276 tasks_.pop();
264 return true; 277 return true;
265 } 278 }
266 return false; 279 return false;
267 } 280 }
268 281
282 // ScopedTestMockTimeTaskRunner -----------------------------------------------
283
284 ScopedMockTaskRunnerWrapper::ScopedMockTaskRunnerWrapper() {
285 task_runner_ = new base::TestMockTimeTaskRunner;
286 previous_task_runner_ = base::ThreadTaskRunnerHandle::Get();
287 base::MessageLoop::current()->SetTaskRunner(task_runner_);
288 }
289
290 ScopedMockTaskRunnerWrapper::~ScopedMockTaskRunnerWrapper() {
291 DCHECK_EQ(task_runner_, base::ThreadTaskRunnerHandle::Get());
292 task_runner_->ClearPendingTasks();
293 base::MessageLoop::current()->SetTaskRunner(previous_task_runner_);
294 }
295
269 } // namespace base 296 } // namespace base
OLDNEW
« base/test/test_mock_time_task_runner.h ('K') | « base/test/test_mock_time_task_runner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698