Commit 0bde45e4 authored by Robert Liao's avatar Robert Liao Committed by Commit Bot

Add COM Initialization to TestBrowserThread and TestBrowserThreadBundle

BrowserProcessSubThread initializes COM, so TestBrowserThread and
TestBrowserThreadBundle should too.

BUG=734135

Change-Id: I8cd0f1422bd4e680372c542f79dc9763879433ec
Reviewed-on: https://chromium-review.googlesource.com/540100Reviewed-by: default avatarAnthony Vallee-Dubois <anthonyvd@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Commit-Queue: Robert Liao <robliao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#481908}
parent 69ad872e
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "base/test/scoped_path_override.h" #include "base/test/scoped_path_override.h"
#include "base/test/test_shortcut_win.h" #include "base/test/test_shortcut_win.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/win/scoped_com_initializer.h"
#include "base/win/shortcut.h" #include "base/win/shortcut.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_attributes_entry.h" #include "chrome/browser/profiles/profile_attributes_entry.h"
...@@ -44,10 +43,6 @@ class ProfileShortcutManagerTest : public testing::Test { ...@@ -44,10 +43,6 @@ class ProfileShortcutManagerTest : public testing::Test {
} }
void SetUp() override { void SetUp() override {
scoped_com_ = base::MakeUnique<base::win::ScopedCOMInitializer>(
base::win::ScopedCOMInitializer::kMTA);
ASSERT_TRUE(scoped_com_->succeeded());
TestingBrowserProcess* browser_process = TestingBrowserProcess* browser_process =
TestingBrowserProcess::GetGlobal(); TestingBrowserProcess::GetGlobal();
profile_manager_.reset(new TestingProfileManager(browser_process)); profile_manager_.reset(new TestingProfileManager(browser_process));
...@@ -83,7 +78,6 @@ class ProfileShortcutManagerTest : public testing::Test { ...@@ -83,7 +78,6 @@ class ProfileShortcutManagerTest : public testing::Test {
profiles::internal::GetProfileIconPath(profile_path); profiles::internal::GetProfileIconPath(profile_path);
ASSERT_TRUE(base::PathExists(icon_path)); ASSERT_TRUE(base::PathExists(icon_path));
} }
scoped_com_.reset();
} }
base::FilePath CreateProfileDirectory(const base::string16& profile_name) { base::FilePath CreateProfileDirectory(const base::string16& profile_name) {
...@@ -273,7 +267,6 @@ class ProfileShortcutManagerTest : public testing::Test { ...@@ -273,7 +267,6 @@ class ProfileShortcutManagerTest : public testing::Test {
} }
content::TestBrowserThreadBundle thread_bundle_; content::TestBrowserThreadBundle thread_bundle_;
std::unique_ptr<base::win::ScopedCOMInitializer> scoped_com_;
std::unique_ptr<TestingProfileManager> profile_manager_; std::unique_ptr<TestingProfileManager> profile_manager_;
std::unique_ptr<ProfileShortcutManager> profile_shortcut_manager_; std::unique_ptr<ProfileShortcutManager> profile_shortcut_manager_;
ProfileAttributesStorage* profile_attributes_storage_; ProfileAttributesStorage* profile_attributes_storage_;
......
...@@ -5,11 +5,17 @@ ...@@ -5,11 +5,17 @@
#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_browser_thread.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "build/build_config.h"
#include "content/browser/browser_thread_impl.h" #include "content/browser/browser_thread_impl.h"
#include "content/browser/notification_service_impl.h" #include "content/browser/notification_service_impl.h"
#if defined(OS_WIN)
#include "base/win/scoped_com_initializer.h"
#endif
namespace content { namespace content {
class TestBrowserThreadImpl : public BrowserThreadImpl { class TestBrowserThreadImpl : public BrowserThreadImpl {
...@@ -24,16 +30,27 @@ class TestBrowserThreadImpl : public BrowserThreadImpl { ...@@ -24,16 +30,27 @@ class TestBrowserThreadImpl : public BrowserThreadImpl {
~TestBrowserThreadImpl() override { Stop(); } ~TestBrowserThreadImpl() override { Stop(); }
void Init() override { void Init() override {
notification_service_.reset(new NotificationServiceImpl); #if defined(OS_WIN)
com_initializer_ = base::MakeUnique<base::win::ScopedCOMInitializer>();
#endif
notification_service_ = base::MakeUnique<NotificationServiceImpl>();
BrowserThreadImpl::Init(); BrowserThreadImpl::Init();
} }
void CleanUp() override { void CleanUp() override {
notification_service_.reset();
BrowserThreadImpl::CleanUp(); BrowserThreadImpl::CleanUp();
notification_service_.reset();
#if defined(OS_WIN)
com_initializer_.reset();
#endif
} }
private: private:
#if defined(OS_WIN)
std::unique_ptr<base::win::ScopedCOMInitializer> com_initializer_;
#endif
std::unique_ptr<NotificationService> notification_service_; std::unique_ptr<NotificationService> notification_service_;
DISALLOW_COPY_AND_ASSIGN(TestBrowserThreadImpl); DISALLOW_COPY_AND_ASSIGN(TestBrowserThreadImpl);
......
...@@ -15,6 +15,10 @@ ...@@ -15,6 +15,10 @@
#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_browser_thread.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
#if defined(OS_WIN)
#include "base/win/scoped_com_initializer.h"
#endif
namespace content { namespace content {
TestBrowserThreadBundle::TestBrowserThreadBundle() TestBrowserThreadBundle::TestBrowserThreadBundle()
...@@ -78,6 +82,10 @@ TestBrowserThreadBundle::~TestBrowserThreadBundle() { ...@@ -78,6 +82,10 @@ TestBrowserThreadBundle::~TestBrowserThreadBundle() {
// for DestructionObservers hooked to |message_loop_| to be able to invoke // for DestructionObservers hooked to |message_loop_| to be able to invoke
// BrowserThread::CurrentlyOn() -- ref. ~TestBrowserThread(). // BrowserThread::CurrentlyOn() -- ref. ~TestBrowserThread().
message_loop_.reset(); message_loop_.reset();
#if defined(OS_WIN)
com_initializer_.reset();
#endif
} }
void TestBrowserThreadBundle::Init() { void TestBrowserThreadBundle::Init() {
...@@ -90,6 +98,14 @@ void TestBrowserThreadBundle::Init() { ...@@ -90,6 +98,14 @@ void TestBrowserThreadBundle::Init() {
// There must be a thread to start to use DONT_CREATE_THREADS // There must be a thread to start to use DONT_CREATE_THREADS
CHECK((options_ & ~IO_MAINLOOP) != DONT_CREATE_THREADS); CHECK((options_ & ~IO_MAINLOOP) != DONT_CREATE_THREADS);
#if defined(OS_WIN)
// Similar to Chrome's UI thread, we need to initialize COM separately for
// this thread as we don't call Start() for the UI TestBrowserThread; it's
// already started!
com_initializer_ = base::MakeUnique<base::win::ScopedCOMInitializer>();
CHECK(com_initializer_->succeeded());
#endif
// Create the main MessageLoop, if it doesn't already exist, and set the // Create the main MessageLoop, if it doesn't already exist, and set the
// current thread as the UI thread. In production, this work is done in // current thread as the UI thread. In production, this work is done in
// BrowserMainLoop::MainMessageLoopStart(). The main MessageLoop may already // BrowserMainLoop::MainMessageLoopStart(). The main MessageLoop may already
......
...@@ -87,12 +87,18 @@ ...@@ -87,12 +87,18 @@
#include <memory> #include <memory>
#include "base/macros.h" #include "base/macros.h"
#include "build/build_config.h"
namespace base { namespace base {
class MessageLoop; class MessageLoop;
namespace test { namespace test {
class ScopedAsyncTaskScheduler; class ScopedAsyncTaskScheduler;
} // namespace test } // namespace test
#if defined(OS_WIN)
namespace win {
class ScopedCOMInitializer;
} // namespace win
#endif
} // namespace base } // namespace base
namespace content { namespace content {
...@@ -139,6 +145,10 @@ class TestBrowserThreadBundle { ...@@ -139,6 +145,10 @@ class TestBrowserThreadBundle {
int options_; int options_;
bool threads_created_; bool threads_created_;
#if defined(OS_WIN)
std::unique_ptr<base::win::ScopedCOMInitializer> com_initializer_;
#endif
DISALLOW_COPY_AND_ASSIGN(TestBrowserThreadBundle); DISALLOW_COPY_AND_ASSIGN(TestBrowserThreadBundle);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment