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

Unified Diff: remoting/base/auto_thread_unittest.cc

Issue 11348087: Add AutoThread types for Windows that initialize COM. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: remoting/base/auto_thread_unittest.cc
diff --git a/remoting/base/auto_thread_unittest.cc b/remoting/base/auto_thread_unittest.cc
index 65f4aa5882ddffc6349caaee95c1e45d1c574275..92c31e73a1b095a00d68ccd66569ac404b7ae3a7 100644
--- a/remoting/base/auto_thread_unittest.cc
+++ b/remoting/base/auto_thread_unittest.cc
@@ -7,6 +7,11 @@
#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 +27,13 @@ void PostSetFlagTask(
task_runner->PostTask(FROM_HERE, base::Bind(&SetFlagTask, success));
}
+#if defined(OS_WIN)
+void CheckComAptTypeTask(APTTYPE* apt_type_out, HRESULT* hresult) {
+ APTTYPEQUALIFIER apt_type_qualifier;
+ *hresult = CoGetApartmentType(apt_type_out, &apt_type_qualifier);
+}
+#endif
+
} // namespace
namespace remoting {
@@ -59,7 +71,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 +123,54 @@ TEST_F(AutoThreadTest, ThreadDependency) {
EXPECT_TRUE(success);
}
+#if defined(OS_WIN)
+TEST_F(AutoThreadTest, ThreadWithComMta) {
+ // CoGetApartmentType requires Windows 7 or above.
+ if (base::win::GetVersion() < base::win::VERSION_WIN7)
+ return;
+
+ scoped_refptr<base::TaskRunner> task_runner =
+ AutoThread::CreateWithType(kThreadName, main_task_runner_,
+ AutoThread::TYPE_UI_COM_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();
+
+ EXPECT_EQ(S_OK, hresult);
+ EXPECT_EQ(APTTYPE_MTA, apt_type);
+}
+
+TEST_F(AutoThreadTest, ThreadWithComSta) {
+ // CoGetApartmentType requires Windows 7 or above.
+ if (base::win::GetVersion() < base::win::VERSION_WIN7)
+ return;
+
+ scoped_refptr<base::TaskRunner> task_runner =
+ AutoThread::CreateWithType(kThreadName, main_task_runner_,
+ AutoThread::TYPE_UI_COM_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();
+
+ 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);
+}
+#endif
+
} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698