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

Unified Diff: base/test/scoped_mock_time_message_loop_task_runner_unittest.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
« no previous file with comments | « base/test/scoped_mock_time_message_loop_task_runner.cc ('k') | base/test/test_mock_time_task_runner.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/test/scoped_mock_time_message_loop_task_runner_unittest.cc
diff --git a/base/test/scoped_mock_time_message_loop_task_runner_unittest.cc b/base/test/scoped_mock_time_message_loop_task_runner_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4d782e2cc26c0b6ea9bff7b5dea0209b065a2969
--- /dev/null
+++ b/base/test/scoped_mock_time_message_loop_task_runner_unittest.cc
@@ -0,0 +1,108 @@
+// 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 <memory>
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/callback_forward.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/time/time.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace base {
+namespace {
+
+TaskRunner* GetCurrentTaskRunner() {
+ return MessageLoop::current()->task_runner().get();
+}
+
+// Pops a task from the front of |pending_tasks| and returns it.
+TestPendingTask PopFront(std::deque<TestPendingTask>* pending_tasks) {
+ TestPendingTask task = pending_tasks->front();
+ pending_tasks->pop_front();
+ return task;
+}
+
+class ScopedMockTimeMessageLoopTaskRunnerTest : public testing::Test {
+ public:
+ ScopedMockTimeMessageLoopTaskRunnerTest()
+ : original_task_runner_(new TestMockTimeTaskRunner()) {
+ MessageLoop::current()->SetTaskRunner(original_task_runner_);
+ }
+
+ protected:
+ TestMockTimeTaskRunner* original_task_runner() {
+ return original_task_runner_.get();
+ }
+
+ private:
+ scoped_refptr<TestMockTimeTaskRunner> original_task_runner_;
+
+ MessageLoop message_loop_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedMockTimeMessageLoopTaskRunnerTest);
+};
+
+// Verifies a new TaskRunner is installed while a
+// ScopedMockTimeMessageLoopTaskRunner exists and the previous one is installed
+// after destruction.
+TEST_F(ScopedMockTimeMessageLoopTaskRunnerTest, CurrentTaskRunners) {
+ auto scoped_task_runner_ =
+ base::MakeUnique<ScopedMockTimeMessageLoopTaskRunner>();
+ EXPECT_EQ(scoped_task_runner_->task_runner(), GetCurrentTaskRunner());
+ scoped_task_runner_.reset();
+ EXPECT_EQ(original_task_runner(), GetCurrentTaskRunner());
+}
+
+TEST_F(ScopedMockTimeMessageLoopTaskRunnerTest,
+ IncompleteTasksAreCopiedToPreviousTaskRunnerAfterDestruction) {
+ auto scoped_task_runner_ =
+ base::MakeUnique<ScopedMockTimeMessageLoopTaskRunner>();
+
+ Closure task_1 = Bind(&DoNothing);
+ Closure task_2 = Bind(&DoNothing);
+ Closure task_10 = Bind(&DoNothing);
+ Closure task_11 = Bind(&DoNothing);
+
+ constexpr TimeDelta task_1_delay = TimeDelta::FromSeconds(1);
+ constexpr TimeDelta task_2_delay = TimeDelta::FromSeconds(2);
+ constexpr TimeDelta task_10_delay = TimeDelta::FromSeconds(10);
+ constexpr TimeDelta task_11_delay = TimeDelta::FromSeconds(11);
+
+ constexpr TimeDelta step_time_by = TimeDelta::FromSeconds(5);
+
+ GetCurrentTaskRunner()->PostDelayedTask(FROM_HERE, task_1, task_1_delay);
+ GetCurrentTaskRunner()->PostDelayedTask(FROM_HERE, task_2, task_2_delay);
+ GetCurrentTaskRunner()->PostDelayedTask(FROM_HERE, task_10, task_10_delay);
+ GetCurrentTaskRunner()->PostDelayedTask(FROM_HERE, task_11, task_11_delay);
+
+ scoped_task_runner_->task_runner()->FastForwardBy(step_time_by);
+
+ scoped_task_runner_.reset();
+
+ std::deque<TestPendingTask> pending_tasks =
+ original_task_runner()->TakePendingTasks();
+
+ EXPECT_EQ(2U, pending_tasks.size());
+
+ TestPendingTask pending_task = PopFront(&pending_tasks);
+ EXPECT_TRUE(task_10.Equals(pending_task.task));
+ EXPECT_EQ(task_10_delay - step_time_by, pending_task.delay);
+
+ pending_task = PopFront(&pending_tasks);
+ EXPECT_TRUE(task_11.Equals(pending_task.task));
+ EXPECT_EQ(task_11_delay - step_time_by, pending_task.delay);
+}
+
+} // namespace
+} // namespace base
« no previous file with comments | « base/test/scoped_mock_time_message_loop_task_runner.cc ('k') | base/test/test_mock_time_task_runner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698