[email protected] | ef948e6 | 2012-09-04 22:27:43 | [diff] [blame] | 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" | ||||
[email protected] | f368eeb | 2013-07-17 23:53:32 | [diff] [blame] | 7 | #include "base/message_loop/message_loop.h" |
fdoray | 2ad58be | 2016-06-22 20:36:16 | [diff] [blame] | 8 | #include "base/run_loop.h" |
9 | #include "base/single_thread_task_runner.h" | ||||
[email protected] | ef948e6 | 2012-09-04 22:27:43 | [diff] [blame] | 10 | #include "remoting/base/auto_thread_task_runner.h" |
11 | #include "testing/gtest/include/gtest/gtest.h" | ||||
12 | |||||
13 | namespace { | ||||
14 | |||||
[email protected] | 3d871d9 | 2012-12-07 07:36:45 | [diff] [blame] | 15 | void SetFlagTask(bool* success) { |
[email protected] | ef948e6 | 2012-09-04 22:27:43 | [diff] [blame] | 16 | *success = true; |
17 | } | ||||
18 | |||||
19 | } // namespace | ||||
20 | |||||
21 | namespace remoting { | ||||
22 | |||||
[email protected] | 3d871d9 | 2012-12-07 07:36:45 | [diff] [blame] | 23 | TEST(AutoThreadTaskRunnerTest, StartAndStop) { |
[email protected] | ef948e6 | 2012-09-04 22:27:43 | [diff] [blame] | 24 | // Create a task runner. |
[email protected] | faea9d2d | 2013-04-30 03:18:44 | [diff] [blame] | 25 | base::MessageLoop message_loop; |
26 | scoped_refptr<AutoThreadTaskRunner> task_runner = new AutoThreadTaskRunner( | ||||
ki.stfu | 659c758f | 2015-10-12 20:10:06 | [diff] [blame] | 27 | message_loop.task_runner(), base::MessageLoop::QuitWhenIdleClosure()); |
[email protected] | ef948e6 | 2012-09-04 22:27:43 | [diff] [blame] | 28 | |
29 | // Post a task to make sure it is executed. | ||||
30 | bool success = false; | ||||
fdoray | 2ad58be | 2016-06-22 20:36:16 | [diff] [blame] | 31 | message_loop.task_runner()->PostTask(FROM_HERE, |
32 | base::Bind(&SetFlagTask, &success)); | ||||
[email protected] | ef948e6 | 2012-09-04 22:27:43 | [diff] [blame] | 33 | |
34 | task_runner = NULL; | ||||
fdoray | 2ad58be | 2016-06-22 20:36:16 | [diff] [blame] | 35 | base::RunLoop().Run(); |
[email protected] | ef948e6 | 2012-09-04 22:27:43 | [diff] [blame] | 36 | EXPECT_TRUE(success); |
37 | } | ||||
38 | |||||
[email protected] | ef948e6 | 2012-09-04 22:27:43 | [diff] [blame] | 39 | } // namespace remoting |