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

Unified Diff: base/test/scoped_mock_time_message_loop_task_runner.cc

Issue 2494943005: [ash-md] Added a delay between system menu default/detailed view transitions. (Closed)
Patch Set: Addressed danakj@ 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 side-by-side diff with in-line comments
Download patch
Index: base/test/scoped_mock_time_message_loop_task_runner.cc
diff --git a/base/test/scoped_mock_time_message_loop_task_runner.cc b/base/test/scoped_mock_time_message_loop_task_runner.cc
new file mode 100644
index 0000000000000000000000000000000000000000..03c9c42c2292cfcd36e136d72182c15ba1102060
--- /dev/null
+++ b/base/test/scoped_mock_time_message_loop_task_runner.cc
@@ -0,0 +1,39 @@
+// 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_time_message_loop_task_runner.h"
+
+#include <deque>
+
+#include "base/logging.h"
+#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
+#include "base/test/test_pending_task.h"
+#include "base/threading/thread_task_runner_handle.h"
+#include "base/time/time.h"
+
+namespace base {
+
+ScopedMockTimeMessageLoopTaskRunner::ScopedMockTimeMessageLoopTaskRunner()
+ : task_runner_(new TestMockTimeTaskRunner),
+ previous_task_runner_(ThreadTaskRunnerHandle::Get()) {
+ DCHECK(MessageLoop::current());
+ // To ensure that we process any initialization tasks posted to the
+ // MessageLoop by a test fixture before replacing its TaskRunner.
+ RunLoop().RunUntilIdle();
+ MessageLoop::current()->SetTaskRunner(task_runner_);
+}
+
+ScopedMockTimeMessageLoopTaskRunner::~ScopedMockTimeMessageLoopTaskRunner() {
+ DCHECK(previous_task_runner_->RunsTasksOnCurrentThread());
+ DCHECK_EQ(task_runner_, ThreadTaskRunnerHandle::Get());
+ for (const auto& pending_task : task_runner_->TakePendingTasks()) {
+ previous_task_runner_->PostDelayedTask(
+ pending_task.location, pending_task.task,
+ pending_task.GetTimeToRun() - task_runner_->NowTicks());
+ }
+ MessageLoop::current()->SetTaskRunner(std::move(previous_task_runner_));
+}
+
+} // namespace base
« no previous file with comments | « base/test/scoped_mock_time_message_loop_task_runner.h ('k') | base/test/scoped_mock_time_message_loop_task_runner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698