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/scoped_native_library.h" | 8 #include "base/scoped_native_library.h" |
9 #include "remoting/base/auto_thread.h" | 9 #include "remoting/base/auto_thread.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 class AutoThreadTest : public testing::Test { | 60 class AutoThreadTest : public testing::Test { |
61 public: | 61 public: |
62 AutoThreadTest() : message_loop_quit_correctly_(false) { | 62 AutoThreadTest() : message_loop_quit_correctly_(false) { |
63 } | 63 } |
64 | 64 |
65 void RunMessageLoop() { | 65 void RunMessageLoop() { |
66 // Release |main_task_runner_|, then run |message_loop_| until other | 66 // Release |main_task_runner_|, then run |message_loop_| until other |
67 // references created in tests are gone. We also post a delayed quit | 67 // 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. | 68 // task to |message_loop_| so the test will not hang on failure. |
69 main_task_runner_ = NULL; | 69 main_task_runner_ = NULL; |
70 message_loop_.PostDelayedTask( | 70 message_loop_.PostDelayedTask(FROM_HERE, |
71 FROM_HERE, MessageLoop::QuitClosure(), base::TimeDelta::FromSeconds(5)); | 71 base::MessageLoop::QuitClosure(), |
| 72 base::TimeDelta::FromSeconds(5)); |
72 message_loop_.Run(); | 73 message_loop_.Run(); |
73 } | 74 } |
74 | 75 |
75 virtual void SetUp() OVERRIDE { | 76 virtual void SetUp() OVERRIDE { |
76 main_task_runner_ = new AutoThreadTaskRunner( | 77 main_task_runner_ = new AutoThreadTaskRunner( |
77 message_loop_.message_loop_proxy(), | 78 message_loop_.message_loop_proxy(), |
78 base::Bind(&AutoThreadTest::QuitMainMessageLoop, | 79 base::Bind(&AutoThreadTest::QuitMainMessageLoop, |
79 base::Unretained(this))); | 80 base::Unretained(this))); |
80 } | 81 } |
81 | 82 |
82 virtual void TearDown() OVERRIDE { | 83 virtual void TearDown() OVERRIDE { |
83 // Verify that |message_loop_| was quit by the AutoThreadTaskRunner. | 84 // Verify that |message_loop_| was quit by the AutoThreadTaskRunner. |
84 EXPECT_TRUE(message_loop_quit_correctly_); | 85 EXPECT_TRUE(message_loop_quit_correctly_); |
85 } | 86 } |
86 | 87 |
87 protected: | 88 protected: |
88 void QuitMainMessageLoop() { | 89 void QuitMainMessageLoop() { |
89 message_loop_quit_correctly_ = true; | 90 message_loop_quit_correctly_ = true; |
90 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 91 message_loop_.PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); |
91 } | 92 } |
92 | 93 |
93 MessageLoop message_loop_; | 94 base::MessageLoop message_loop_; |
94 bool message_loop_quit_correctly_; | 95 bool message_loop_quit_correctly_; |
95 scoped_refptr<AutoThreadTaskRunner> main_task_runner_; | 96 scoped_refptr<AutoThreadTaskRunner> main_task_runner_; |
96 }; | 97 }; |
97 | 98 |
98 TEST_F(AutoThreadTest, StartAndStop) { | 99 TEST_F(AutoThreadTest, StartAndStop) { |
99 // Create an AutoThread joined by our MessageLoop. | 100 // Create an AutoThread joined by our MessageLoop. |
100 scoped_refptr<base::TaskRunner> task_runner = | 101 scoped_refptr<base::TaskRunner> task_runner = |
101 AutoThread::Create(kThreadName, main_task_runner_); | 102 AutoThread::Create(kThreadName, main_task_runner_); |
102 EXPECT_TRUE(task_runner.get()); | 103 EXPECT_TRUE(task_runner.get()); |
103 | 104 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 task_runner1 = NULL; | 139 task_runner1 = NULL; |
139 task_runner2 = NULL; | 140 task_runner2 = NULL; |
140 RunMessageLoop(); | 141 RunMessageLoop(); |
141 | 142 |
142 EXPECT_TRUE(success); | 143 EXPECT_TRUE(success); |
143 } | 144 } |
144 | 145 |
145 #if defined(OS_WIN) | 146 #if defined(OS_WIN) |
146 TEST_F(AutoThreadTest, ThreadWithComMta) { | 147 TEST_F(AutoThreadTest, ThreadWithComMta) { |
147 scoped_refptr<base::TaskRunner> task_runner = | 148 scoped_refptr<base::TaskRunner> task_runner = |
148 AutoThread::CreateWithLoopAndComInitTypes( | 149 AutoThread::CreateWithLoopAndComInitTypes(kThreadName, |
149 kThreadName, main_task_runner_, MessageLoop::TYPE_DEFAULT, | 150 main_task_runner_, |
150 AutoThread::COM_INIT_MTA); | 151 base::MessageLoop::TYPE_DEFAULT, |
| 152 AutoThread::COM_INIT_MTA); |
151 EXPECT_TRUE(task_runner.get()); | 153 EXPECT_TRUE(task_runner.get()); |
152 | 154 |
153 // Post a task to query the COM apartment type. | 155 // Post a task to query the COM apartment type. |
154 HRESULT hresult = E_FAIL; | 156 HRESULT hresult = E_FAIL; |
155 APTTYPE apt_type = APTTYPE_NA; | 157 APTTYPE apt_type = APTTYPE_NA; |
156 task_runner->PostTask(FROM_HERE, | 158 task_runner->PostTask(FROM_HERE, |
157 base::Bind(&CheckComAptTypeTask, &apt_type, &hresult)); | 159 base::Bind(&CheckComAptTypeTask, &apt_type, &hresult)); |
158 | 160 |
159 task_runner = NULL; | 161 task_runner = NULL; |
160 RunMessageLoop(); | 162 RunMessageLoop(); |
161 | 163 |
162 // CoGetApartmentType requires Windows 7 or above. | 164 // CoGetApartmentType requires Windows 7 or above. |
163 if (base::win::GetVersion() >= base::win::VERSION_WIN7) { | 165 if (base::win::GetVersion() >= base::win::VERSION_WIN7) { |
164 EXPECT_EQ(S_OK, hresult); | 166 EXPECT_EQ(S_OK, hresult); |
165 EXPECT_EQ(APTTYPE_MTA, apt_type); | 167 EXPECT_EQ(APTTYPE_MTA, apt_type); |
166 } else { | 168 } else { |
167 EXPECT_EQ(E_NOTIMPL, hresult); | 169 EXPECT_EQ(E_NOTIMPL, hresult); |
168 } | 170 } |
169 } | 171 } |
170 | 172 |
171 TEST_F(AutoThreadTest, ThreadWithComSta) { | 173 TEST_F(AutoThreadTest, ThreadWithComSta) { |
172 scoped_refptr<base::TaskRunner> task_runner = | 174 scoped_refptr<base::TaskRunner> task_runner = |
173 AutoThread::CreateWithLoopAndComInitTypes( | 175 AutoThread::CreateWithLoopAndComInitTypes(kThreadName, |
174 kThreadName, main_task_runner_, MessageLoop::TYPE_UI, | 176 main_task_runner_, |
175 AutoThread::COM_INIT_STA); | 177 base::MessageLoop::TYPE_UI, |
| 178 AutoThread::COM_INIT_STA); |
176 EXPECT_TRUE(task_runner.get()); | 179 EXPECT_TRUE(task_runner.get()); |
177 | 180 |
178 // Post a task to query the COM apartment type. | 181 // Post a task to query the COM apartment type. |
179 HRESULT hresult = E_FAIL; | 182 HRESULT hresult = E_FAIL; |
180 APTTYPE apt_type = APTTYPE_NA; | 183 APTTYPE apt_type = APTTYPE_NA; |
181 task_runner->PostTask(FROM_HERE, | 184 task_runner->PostTask(FROM_HERE, |
182 base::Bind(&CheckComAptTypeTask, &apt_type, &hresult)); | 185 base::Bind(&CheckComAptTypeTask, &apt_type, &hresult)); |
183 | 186 |
184 task_runner = NULL; | 187 task_runner = NULL; |
185 RunMessageLoop(); | 188 RunMessageLoop(); |
186 | 189 |
187 // CoGetApartmentType requires Windows 7 or above. | 190 // CoGetApartmentType requires Windows 7 or above. |
188 if (base::win::GetVersion() >= base::win::VERSION_WIN7) { | 191 if (base::win::GetVersion() >= base::win::VERSION_WIN7) { |
189 EXPECT_EQ(S_OK, hresult); | 192 EXPECT_EQ(S_OK, hresult); |
190 // Whether the thread is the "main" STA apartment depends upon previous | 193 // Whether the thread is the "main" STA apartment depends upon previous |
191 // COM activity in this test process, so allow both types here. | 194 // COM activity in this test process, so allow both types here. |
192 EXPECT_TRUE(apt_type == APTTYPE_MAINSTA || apt_type == APTTYPE_STA); | 195 EXPECT_TRUE(apt_type == APTTYPE_MAINSTA || apt_type == APTTYPE_STA); |
193 } else { | 196 } else { |
194 EXPECT_EQ(E_NOTIMPL, hresult); | 197 EXPECT_EQ(E_NOTIMPL, hresult); |
195 } | 198 } |
196 } | 199 } |
197 #endif // defined(OS_WIN) | 200 #endif // defined(OS_WIN) |
198 | 201 |
199 } // namespace remoting | 202 } // namespace remoting |
OLD | NEW |