OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/run_loop.h" |
8 #include "base/scoped_native_library.h" | 9 #include "base/scoped_native_library.h" |
| 10 #include "base/single_thread_task_runner.h" |
9 #include "build/build_config.h" | 11 #include "build/build_config.h" |
10 #include "remoting/base/auto_thread.h" | 12 #include "remoting/base/auto_thread.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
12 | 14 |
13 #if defined(OS_WIN) | 15 #if defined(OS_WIN) |
14 #include <objbase.h> | 16 #include <objbase.h> |
15 #include "base/win/windows_version.h" | 17 #include "base/win/windows_version.h" |
16 #endif | 18 #endif |
17 | 19 |
18 namespace { | 20 namespace { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 class AutoThreadTest : public testing::Test { | 62 class AutoThreadTest : public testing::Test { |
61 public: | 63 public: |
62 AutoThreadTest() : message_loop_quit_correctly_(false) { | 64 AutoThreadTest() : message_loop_quit_correctly_(false) { |
63 } | 65 } |
64 | 66 |
65 void RunMessageLoop() { | 67 void RunMessageLoop() { |
66 // Release |main_task_runner_|, then run |message_loop_| until other | 68 // Release |main_task_runner_|, then run |message_loop_| until other |
67 // references created in tests are gone. We also post a delayed quit | 69 // references created in tests are gone. We also post a delayed quit |
68 // task to |message_loop_| so the test will not hang on failure. | 70 // task to |message_loop_| so the test will not hang on failure. |
69 main_task_runner_ = NULL; | 71 main_task_runner_ = NULL; |
70 message_loop_.PostDelayedTask(FROM_HERE, | 72 message_loop_.task_runner()->PostDelayedTask( |
71 base::MessageLoop::QuitWhenIdleClosure(), | 73 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), |
72 base::TimeDelta::FromSeconds(5)); | 74 base::TimeDelta::FromSeconds(5)); |
73 message_loop_.Run(); | 75 base::RunLoop().Run(); |
74 } | 76 } |
75 | 77 |
76 void SetUp() override { | 78 void SetUp() override { |
77 main_task_runner_ = new AutoThreadTaskRunner( | 79 main_task_runner_ = new AutoThreadTaskRunner( |
78 message_loop_.task_runner(), | 80 message_loop_.task_runner(), |
79 base::Bind(&AutoThreadTest::QuitMainMessageLoop, | 81 base::Bind(&AutoThreadTest::QuitMainMessageLoop, |
80 base::Unretained(this))); | 82 base::Unretained(this))); |
81 } | 83 } |
82 | 84 |
83 void TearDown() override { | 85 void TearDown() override { |
84 // Verify that |message_loop_| was quit by the AutoThreadTaskRunner. | 86 // Verify that |message_loop_| was quit by the AutoThreadTaskRunner. |
85 EXPECT_TRUE(message_loop_quit_correctly_); | 87 EXPECT_TRUE(message_loop_quit_correctly_); |
86 } | 88 } |
87 | 89 |
88 protected: | 90 protected: |
89 void QuitMainMessageLoop() { | 91 void QuitMainMessageLoop() { |
90 message_loop_quit_correctly_ = true; | 92 message_loop_quit_correctly_ = true; |
91 message_loop_.PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 93 message_loop_.task_runner()->PostTask( |
| 94 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
92 } | 95 } |
93 | 96 |
94 base::MessageLoop message_loop_; | 97 base::MessageLoop message_loop_; |
95 bool message_loop_quit_correctly_; | 98 bool message_loop_quit_correctly_; |
96 scoped_refptr<AutoThreadTaskRunner> main_task_runner_; | 99 scoped_refptr<AutoThreadTaskRunner> main_task_runner_; |
97 }; | 100 }; |
98 | 101 |
99 TEST_F(AutoThreadTest, StartAndStop) { | 102 TEST_F(AutoThreadTest, StartAndStop) { |
100 // Create an AutoThread joined by our MessageLoop. | 103 // Create an AutoThread joined by our MessageLoop. |
101 scoped_refptr<base::TaskRunner> task_runner = | 104 scoped_refptr<base::TaskRunner> task_runner = |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 // Whether the thread is the "main" STA apartment depends upon previous | 196 // Whether the thread is the "main" STA apartment depends upon previous |
194 // COM activity in this test process, so allow both types here. | 197 // COM activity in this test process, so allow both types here. |
195 EXPECT_TRUE(apt_type == APTTYPE_MAINSTA || apt_type == APTTYPE_STA); | 198 EXPECT_TRUE(apt_type == APTTYPE_MAINSTA || apt_type == APTTYPE_STA); |
196 } else { | 199 } else { |
197 EXPECT_EQ(E_NOTIMPL, hresult); | 200 EXPECT_EQ(E_NOTIMPL, hresult); |
198 } | 201 } |
199 } | 202 } |
200 #endif // defined(OS_WIN) | 203 #endif // defined(OS_WIN) |
201 | 204 |
202 } // namespace remoting | 205 } // namespace remoting |
OLD | NEW |