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

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: 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 SetFlagTask(
19 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
20 bool* success) {
21 *success = true;
22 }
23
24 } // namespace
25
26 namespace remoting {
27
28 TEST(AutoThreadTaskRunnerTest, StartAndStopMain) {
29 // Create a task runner.
30 MessageLoop message_loop;
31 scoped_refptr<AutoThreadTaskRunner> task_runner =
32 new AutoThreadTaskRunner(
33 message_loop.message_loop_proxy(),
34 base::Bind(&PostQuitTask, &message_loop));
35
36 // Post a task to make sure it is executed.
37 bool success = false;
38 message_loop.PostTask(FROM_HERE, base::Bind(&SetFlagTask, task_runner,
39 &success));
40
41 task_runner = NULL;
42 message_loop.Run();
43 EXPECT_TRUE(success);
44 }
45
46 TEST(AutoThreadTaskRunnerTest, StartAndStopWorker) {
47 // Create a task runner.
48 MessageLoop message_loop;
49 scoped_refptr<AutoThreadTaskRunner> task_runner =
50 new AutoThreadTaskRunner(
51 message_loop.message_loop_proxy(),
52 base::Bind(&PostQuitTask, &message_loop));
53
54 // Create a child task runner.
55 base::Thread thread("Child task runner");
56 thread.Start();
57 task_runner = new AutoThreadTaskRunner(thread.message_loop_proxy(),
58 task_runner);
59
60 // Post a task to make sure it is executed.
61 bool success = false;
62 message_loop.PostTask(FROM_HERE, base::Bind(&SetFlagTask, task_runner,
63 &success));
64
65 task_runner = NULL;
66 message_loop.Run();
67 EXPECT_TRUE(success);
68
69 thread.Stop();
70 }
71
72 } // namespace remoting
OLDNEW
« 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