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

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: CR feedback and a unit test for AutoThreadTaskRunner. Created 8 years, 4 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
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..ed0b707448365442f7caf651a5131b928d7ca24a
--- /dev/null
+++ b/remoting/base/auto_thread_task_runner_unittest.cc
@@ -0,0 +1,66 @@
+// 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 ReleaseTaskRunner(
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
Wez 2012/09/04 18:09:38 This method is actually used to keep the TaskRunne
alexeypa (please no reviews) 2012/09/04 18:42:53 Done.
+ // Do nothing. |task_runner| will be released once the function exits.
+}
+
+} // 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));
+
+ // Release the task runner to stop it.
+ message_loop.PostTask(
+ FROM_HERE, base::Bind(&ReleaseTaskRunner, task_runner));
Wez 2012/09/04 18:09:38 Do you actually need this? When you NULL |task_run
alexeypa (please no reviews) 2012/09/04 18:42:53 Done.
+ task_runner = NULL;
+
+ message_loop.Run();
Wez 2012/09/04 18:09:38 If your test is successful it'll exit almost immed
alexeypa (please no reviews) 2012/09/04 18:42:53 I added a test to make sure that the posted task h
+}
+
+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);
+
+ // Release the child runner to stop both runners.
+ message_loop.PostTask(
+ FROM_HERE, base::Bind(&ReleaseTaskRunner, task_runner));
Wez 2012/09/04 18:09:38 See above.
alexeypa (please no reviews) 2012/09/04 18:42:53 Done.
+ task_runner = NULL;
+
+ message_loop.Run();
+ thread.Stop();
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698