Chromium Code Reviews| 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 |