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

Side by Side 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, 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/bind.h"
6 #include "base/memory/ref_counted.h"
7 #include "base/message_loop.h"
8 #include "base/threading/thread.h"
9 #include "remoting/base/auto_thread_task_runner.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace {
13
14 void PostQuitTask(MessageLoop* message_loop) {
15 message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure());
16 }
17
18 void ReleaseTaskRunner(
19 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.
20 // Do nothing. |task_runner| will be released once the function exits.
21 }
22
23 } // namespace
24
25 namespace remoting {
26
27 TEST(AutoThreadTaskRunnerTest, StartAndStopMain) {
28 // Create a task runner.
29 MessageLoop message_loop;
30 scoped_refptr<AutoThreadTaskRunner> task_runner =
31 new AutoThreadTaskRunner(
32 message_loop.message_loop_proxy(),
33 base::Bind(&PostQuitTask, &message_loop));
34
35 // Release the task runner to stop it.
36 message_loop.PostTask(
37 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.
38 task_runner = NULL;
39
40 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
41 }
42
43 TEST(AutoThreadTaskRunnerTest, StartAndStopWorker) {
44 // Create a task runner.
45 MessageLoop message_loop;
46 scoped_refptr<AutoThreadTaskRunner> task_runner =
47 new AutoThreadTaskRunner(
48 message_loop.message_loop_proxy(),
49 base::Bind(&PostQuitTask, &message_loop));
50
51 // Create a child task runner.
52 base::Thread thread("Child task runner");
53 thread.Start();
54 task_runner = new AutoThreadTaskRunner(thread.message_loop_proxy(),
55 task_runner);
56
57 // Release the child runner to stop both runners.
58 message_loop.PostTask(
59 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.
60 task_runner = NULL;
61
62 message_loop.Run();
63 thread.Stop();
64 }
65
66 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698