summaryrefslogtreecommitdiffstats
path: root/remoting/base/auto_thread_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'remoting/base/auto_thread_unittest.cc')
-rw-r--r--remoting/base/auto_thread_unittest.cc86
1 files changed, 85 insertions, 1 deletions
diff --git a/remoting/base/auto_thread_unittest.cc b/remoting/base/auto_thread_unittest.cc
index 65f4aa5..25bdd03 100644
--- a/remoting/base/auto_thread_unittest.cc
+++ b/remoting/base/auto_thread_unittest.cc
@@ -3,10 +3,17 @@
// found in the LICENSE file.
#include "base/bind.h"
+#include "base/file_path.h"
#include "base/memory/ref_counted.h"
+#include "base/scoped_native_library.h"
#include "remoting/base/auto_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
+#if defined(OS_WIN)
+#include <objbase.h>
+#include "base/win/windows_version.h"
+#endif
+
namespace {
const char kThreadName[] = "Test thread";
@@ -22,6 +29,30 @@ void PostSetFlagTask(
task_runner->PostTask(FROM_HERE, base::Bind(&SetFlagTask, success));
}
+#if defined(OS_WIN)
+void CheckComAptTypeTask(APTTYPE* apt_type_out, HRESULT* hresult) {
+ typedef HRESULT (WINAPI * CoGetApartmentTypeFunc)
+ (APTTYPE*, APTTYPEQUALIFIER*);
+
+ // CoGetApartmentType requires Windows 7 or above.
+ if (base::win::GetVersion() < base::win::VERSION_WIN7) {
+ *hresult = E_NOTIMPL;
+ return;
+ }
+
+ // Dynamic link to the API so the same test binary can run on older systems.
+ base::ScopedNativeLibrary com_library(FilePath(L"ole32.dll"));
+ ASSERT_TRUE(com_library.is_valid());
+ CoGetApartmentTypeFunc co_get_apartment_type =
+ static_cast<CoGetApartmentTypeFunc>(
+ com_library.GetFunctionPointer("CoGetApartmentType"));
+ ASSERT_TRUE(co_get_apartment_type != NULL);
+
+ APTTYPEQUALIFIER apt_type_qualifier;
+ *hresult = (*co_get_apartment_type)(apt_type_out, &apt_type_qualifier);
+}
+#endif
+
} // namespace
namespace remoting {
@@ -59,7 +90,6 @@ class AutoThreadTest : public testing::Test {
message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure());
}
-
MessageLoop message_loop_;
bool message_loop_quit_correctly_;
scoped_refptr<AutoThreadTaskRunner> main_task_runner_;
@@ -112,4 +142,58 @@ TEST_F(AutoThreadTest, ThreadDependency) {
EXPECT_TRUE(success);
}
+#if defined(OS_WIN)
+TEST_F(AutoThreadTest, ThreadWithComMta) {
+ scoped_refptr<base::TaskRunner> task_runner =
+ AutoThread::CreateWithLoopAndComInitTypes(
+ kThreadName, main_task_runner_, MessageLoop::TYPE_DEFAULT,
+ AutoThread::COM_INIT_MTA);
+ EXPECT_TRUE(task_runner.get());
+
+ // Post a task to query the COM apartment type.
+ HRESULT hresult = E_FAIL;
+ APTTYPE apt_type = APTTYPE_NA;
+ task_runner->PostTask(FROM_HERE,
+ base::Bind(&CheckComAptTypeTask, &apt_type, &hresult));
+
+ task_runner = NULL;
+ RunMessageLoop();
+
+ // CoGetApartmentType requires Windows 7 or above.
+ if (base::win::GetVersion() >= base::win::VERSION_WIN7) {
+ EXPECT_EQ(S_OK, hresult);
+ EXPECT_EQ(APTTYPE_MTA, apt_type);
+ } else {
+ EXPECT_EQ(E_NOTIMPL, hresult);
+ }
+}
+
+TEST_F(AutoThreadTest, ThreadWithComSta) {
+ scoped_refptr<base::TaskRunner> task_runner =
+ AutoThread::CreateWithLoopAndComInitTypes(
+ kThreadName, main_task_runner_, MessageLoop::TYPE_UI,
+ AutoThread::COM_INIT_STA);
+ EXPECT_TRUE(task_runner.get());
+
+ // Post a task to query the COM apartment type.
+ HRESULT hresult = E_FAIL;
+ APTTYPE apt_type = APTTYPE_NA;
+ task_runner->PostTask(FROM_HERE,
+ base::Bind(&CheckComAptTypeTask, &apt_type, &hresult));
+
+ task_runner = NULL;
+ RunMessageLoop();
+
+ // CoGetApartmentType requires Windows 7 or above.
+ if (base::win::GetVersion() >= base::win::VERSION_WIN7) {
+ EXPECT_EQ(S_OK, hresult);
+ // Whether the thread is the "main" STA apartment depends upon previous
+ // COM activity in this test process, so allow both types here.
+ EXPECT_TRUE(apt_type == APTTYPE_MAINSTA || apt_type == APTTYPE_STA);
+ } else {
+ EXPECT_EQ(E_NOTIMPL, hresult);
+ }
+}
+#endif // defined(OS_WIN)
+
} // namespace remoting