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

Side by Side Diff: remoting/base/auto_thread_unittest.cc

Issue 2909943003: Removing useless Win7 checks + standardize its use (Closed)
Patch Set: Various nits Created 3 years, 6 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
« no previous file with comments | « media/gpu/gpu_video_decode_accelerator_factory.cc ('k') | rlz/test/rlz_test_helpers.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "remoting/base/auto_thread.h" 5 #include "remoting/base/auto_thread.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/scoped_native_library.h" 11 #include "base/scoped_native_library.h"
12 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 #if defined(OS_WIN) 16 #if defined(OS_WIN)
17 #include <objbase.h> 17 #include <objbase.h>
18 #include "base/win/windows_version.h"
19 #endif 18 #endif
20 19
21 namespace { 20 namespace {
22 21
23 const char kThreadName[] = "Test thread"; 22 const char kThreadName[] = "Test thread";
24 23
25 void SetFlagTask(bool* success) { 24 void SetFlagTask(bool* success) {
26 *success = true; 25 *success = true;
27 } 26 }
28 27
29 void PostSetFlagTask( 28 void PostSetFlagTask(
30 scoped_refptr<base::TaskRunner> task_runner, 29 scoped_refptr<base::TaskRunner> task_runner,
31 bool* success) { 30 bool* success) {
32 task_runner->PostTask(FROM_HERE, base::Bind(&SetFlagTask, success)); 31 task_runner->PostTask(FROM_HERE, base::Bind(&SetFlagTask, success));
33 } 32 }
34 33
35 #if defined(OS_WIN) 34 #if defined(OS_WIN)
36 void CheckComAptTypeTask(APTTYPE* apt_type_out, HRESULT* hresult) { 35 void CheckComAptTypeTask(APTTYPE* apt_type_out, HRESULT* hresult) {
37 typedef HRESULT (WINAPI * CoGetApartmentTypeFunc) 36 typedef HRESULT (WINAPI * CoGetApartmentTypeFunc)
38 (APTTYPE*, APTTYPEQUALIFIER*); 37 (APTTYPE*, APTTYPEQUALIFIER*);
39 38
40 // CoGetApartmentType requires Windows 7 or above.
41 if (base::win::GetVersion() < base::win::VERSION_WIN7) {
42 *hresult = E_NOTIMPL;
43 return;
44 }
45
46 // Dynamic link to the API so the same test binary can run on older systems. 39 // Dynamic link to the API so the same test binary can run on older systems.
47 base::ScopedNativeLibrary com_library(base::FilePath(L"ole32.dll")); 40 base::ScopedNativeLibrary com_library(base::FilePath(L"ole32.dll"));
48 ASSERT_TRUE(com_library.is_valid()); 41 ASSERT_TRUE(com_library.is_valid());
49 CoGetApartmentTypeFunc co_get_apartment_type = 42 CoGetApartmentTypeFunc co_get_apartment_type =
50 reinterpret_cast<CoGetApartmentTypeFunc>( 43 reinterpret_cast<CoGetApartmentTypeFunc>(
51 com_library.GetFunctionPointer("CoGetApartmentType")); 44 com_library.GetFunctionPointer("CoGetApartmentType"));
52 ASSERT_TRUE(co_get_apartment_type != NULL); 45 ASSERT_TRUE(co_get_apartment_type != NULL);
53 46
54 APTTYPEQUALIFIER apt_type_qualifier; 47 APTTYPEQUALIFIER apt_type_qualifier;
55 *hresult = (*co_get_apartment_type)(apt_type_out, &apt_type_qualifier); 48 *hresult = (*co_get_apartment_type)(apt_type_out, &apt_type_qualifier);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 151
159 // Post a task to query the COM apartment type. 152 // Post a task to query the COM apartment type.
160 HRESULT hresult = E_FAIL; 153 HRESULT hresult = E_FAIL;
161 APTTYPE apt_type = APTTYPE_NA; 154 APTTYPE apt_type = APTTYPE_NA;
162 task_runner->PostTask(FROM_HERE, 155 task_runner->PostTask(FROM_HERE,
163 base::Bind(&CheckComAptTypeTask, &apt_type, &hresult)); 156 base::Bind(&CheckComAptTypeTask, &apt_type, &hresult));
164 157
165 task_runner = NULL; 158 task_runner = NULL;
166 RunMessageLoop(); 159 RunMessageLoop();
167 160
168 // CoGetApartmentType requires Windows 7 or above. 161 EXPECT_EQ(S_OK, hresult);
169 if (base::win::GetVersion() >= base::win::VERSION_WIN7) { 162 EXPECT_EQ(APTTYPE_MTA, apt_type);
170 EXPECT_EQ(S_OK, hresult);
171 EXPECT_EQ(APTTYPE_MTA, apt_type);
172 } else {
173 EXPECT_EQ(E_NOTIMPL, hresult);
174 }
175 } 163 }
176 164
177 TEST_F(AutoThreadTest, ThreadWithComSta) { 165 TEST_F(AutoThreadTest, ThreadWithComSta) {
178 scoped_refptr<base::TaskRunner> task_runner = 166 scoped_refptr<base::TaskRunner> task_runner =
179 AutoThread::CreateWithLoopAndComInitTypes(kThreadName, 167 AutoThread::CreateWithLoopAndComInitTypes(kThreadName,
180 main_task_runner_, 168 main_task_runner_,
181 base::MessageLoop::TYPE_UI, 169 base::MessageLoop::TYPE_UI,
182 AutoThread::COM_INIT_STA); 170 AutoThread::COM_INIT_STA);
183 EXPECT_TRUE(task_runner.get()); 171 EXPECT_TRUE(task_runner.get());
184 172
185 // Post a task to query the COM apartment type. 173 // Post a task to query the COM apartment type.
186 HRESULT hresult = E_FAIL; 174 HRESULT hresult = E_FAIL;
187 APTTYPE apt_type = APTTYPE_NA; 175 APTTYPE apt_type = APTTYPE_NA;
188 task_runner->PostTask(FROM_HERE, 176 task_runner->PostTask(FROM_HERE,
189 base::Bind(&CheckComAptTypeTask, &apt_type, &hresult)); 177 base::Bind(&CheckComAptTypeTask, &apt_type, &hresult));
190 178
191 task_runner = NULL; 179 task_runner = NULL;
192 RunMessageLoop(); 180 RunMessageLoop();
193 181
194 // CoGetApartmentType requires Windows 7 or above. 182 EXPECT_EQ(S_OK, hresult);
195 if (base::win::GetVersion() >= base::win::VERSION_WIN7) { 183 // Whether the thread is the "main" STA apartment depends upon previous
196 EXPECT_EQ(S_OK, hresult); 184 // COM activity in this test process, so allow both types here.
197 // Whether the thread is the "main" STA apartment depends upon previous 185 EXPECT_TRUE(apt_type == APTTYPE_MAINSTA || apt_type == APTTYPE_STA);
198 // COM activity in this test process, so allow both types here.
199 EXPECT_TRUE(apt_type == APTTYPE_MAINSTA || apt_type == APTTYPE_STA);
200 } else {
201 EXPECT_EQ(E_NOTIMPL, hresult);
202 }
203 } 186 }
204 #endif // defined(OS_WIN) 187 #endif // defined(OS_WIN)
205 188
206 } // namespace remoting 189 } // namespace remoting
OLDNEW
« no previous file with comments | « media/gpu/gpu_video_decode_accelerator_factory.cc ('k') | rlz/test/rlz_test_helpers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698