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

Unified Diff: remoting/base/auto_thread_task_runner_unittest.cc

Issue 10829467: [Chromoting] Introducing refcount-based life time management of the message loops in the service (d… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 8 years, 3 months 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 | « remoting/base/auto_thread_task_runner.cc ('k') | remoting/host/chromoting_host_context.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/base/auto_thread_task_runner_unittest.cc
diff --git a/remoting/base/auto_thread_task_runner_unittest.cc b/remoting/base/auto_thread_task_runner_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..07ea8bb434f25c889cbeef41dfe10b85a33c1926
--- /dev/null
+++ b/remoting/base/auto_thread_task_runner_unittest.cc
@@ -0,0 +1,72 @@
+// Copyright (c) 2012 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/bind.h"
+#include "base/memory/ref_counted.h"
+#include "base/message_loop.h"
+#include "base/threading/thread.h"
+#include "remoting/base/auto_thread_task_runner.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+void PostQuitTask(MessageLoop* message_loop) {
+ message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure());
+}
+
+void SetFlagTask(
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner,
+ bool* success) {
+ *success = true;
+}
+
+} // namespace
+
+namespace remoting {
+
+TEST(AutoThreadTaskRunnerTest, StartAndStopMain) {
+ // Create a task runner.
+ MessageLoop message_loop;
+ scoped_refptr<AutoThreadTaskRunner> task_runner =
+ new AutoThreadTaskRunner(
+ message_loop.message_loop_proxy(),
+ base::Bind(&PostQuitTask, &message_loop));
+
+ // Post a task to make sure it is executed.
+ bool success = false;
+ message_loop.PostTask(FROM_HERE, base::Bind(&SetFlagTask, task_runner,
+ &success));
+
+ task_runner = NULL;
+ message_loop.Run();
+ EXPECT_TRUE(success);
+}
+
+TEST(AutoThreadTaskRunnerTest, StartAndStopWorker) {
+ // Create a task runner.
+ MessageLoop message_loop;
+ scoped_refptr<AutoThreadTaskRunner> task_runner =
+ new AutoThreadTaskRunner(
+ message_loop.message_loop_proxy(),
+ base::Bind(&PostQuitTask, &message_loop));
+
+ // Create a child task runner.
+ base::Thread thread("Child task runner");
+ thread.Start();
+ task_runner = new AutoThreadTaskRunner(thread.message_loop_proxy(),
+ task_runner);
+
+ // Post a task to make sure it is executed.
+ bool success = false;
+ message_loop.PostTask(FROM_HERE, base::Bind(&SetFlagTask, task_runner,
+ &success));
+
+ task_runner = NULL;
+ message_loop.Run();
+ EXPECT_TRUE(success);
+
+ thread.Stop();
+}
+
+} // namespace remoting
« no previous file with comments | « remoting/base/auto_thread_task_runner.cc ('k') | remoting/host/chromoting_host_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698