Commit 01dd4ead authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Make BrowserWithTestWindowTests work with single process Mash

The InputDeviceClient needs to only be created once, so remove it
from AuraTestSuiteSetup. Otherwise, in BrowserWithTestWindowTest,
it gets created twice: during test suite setup, and as part of
OzonePlatform (due to AshTestHelper/ash::Shell).

Many tests still need one though, especially those that create a
WebContents, so add it to RenderViewHostTestEnabler, which should
take care of all RenderViewHostTestHarness tests or tests that create
the enabler manually.

Also update a few other tests to either create their own
RenderViewHostTestEnabler or InputDeviceClient as appropriate.

Also the InputDeviceManager can be a true singleton now (not thread-
singleton).

Bug: 905430
Change-Id: I2974968efe0415f0b56218e24b4fa546a1524fe1
Reviewed-on: https://chromium-review.googlesource.com/c/1341075Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611556}
parent 8715348f
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "content/public/browser/navigation_handle.h" #include "content/public/browser/navigation_handle.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/common/frame_navigate_params.h" #include "content/public/common/frame_navigate_params.h"
#include "content/public/test/test_web_contents_factory.h" #include "content/public/test/test_renderer_host.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -135,7 +135,9 @@ class DeclarativeChromeContentRulesRegistryTest : public testing::Test { ...@@ -135,7 +135,9 @@ class DeclarativeChromeContentRulesRegistryTest : public testing::Test {
private: private:
TestExtensionEnvironment env_; TestExtensionEnvironment env_;
content::TestWebContentsFactory factory_;
// Must come after |env_| so only one UI MessageLoop is created.
content::RenderViewHostTestEnabler rvh_enabler_;
DISALLOW_COPY_AND_ASSIGN(DeclarativeChromeContentRulesRegistryTest); DISALLOW_COPY_AND_ASSIGN(DeclarativeChromeContentRulesRegistryTest);
}; };
......
...@@ -131,6 +131,7 @@ class ParameterizedDeclarativeContentActionTest ...@@ -131,6 +131,7 @@ class ParameterizedDeclarativeContentActionTest
TEST_P(ParameterizedDeclarativeContentActionTest, ShowPageAction) { TEST_P(ParameterizedDeclarativeContentActionTest, ShowPageAction) {
TestExtensionEnvironment env; TestExtensionEnvironment env;
content::RenderViewHostTestEnabler rvh_enabler;
scoped_refptr<const Extension> extension = scoped_refptr<const Extension> extension =
ExtensionBuilder("extension") ExtensionBuilder("extension")
...@@ -198,6 +199,7 @@ INSTANTIATE_TEST_CASE_P( ...@@ -198,6 +199,7 @@ INSTANTIATE_TEST_CASE_P(
TEST(DeclarativeContentActionTest, SetIcon) { TEST(DeclarativeContentActionTest, SetIcon) {
TestExtensionEnvironment env; TestExtensionEnvironment env;
content::RenderViewHostTestEnabler rvh_enabler;
// Simulate the process of passing ImageData to SetIcon::Create. // Simulate the process of passing ImageData to SetIcon::Create.
SkBitmap bitmap; SkBitmap bitmap;
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#if defined(USE_OZONE) || defined(USE_X11) #if defined(USE_OZONE) || defined(USE_X11)
#include "services/ws/public/cpp/input_devices/input_device_client_test_api.h" #include "services/ws/public/cpp/input_devices/input_device_client_test_api.h"
#include "ui/aura/test/aura_test_utils.h"
#include "ui/events/devices/input_device_manager.h"
#endif #endif
namespace { namespace {
...@@ -33,6 +35,7 @@ class ChromeBrowserMainExtraPartsMetricsTest : public testing::Test { ...@@ -33,6 +35,7 @@ class ChromeBrowserMainExtraPartsMetricsTest : public testing::Test {
protected: protected:
#if defined(USE_OZONE) || defined(USE_X11) #if defined(USE_OZONE) || defined(USE_X11)
std::unique_ptr<ui::InputDeviceManager> input_manager_;
ws::InputDeviceClientTestApi input_device_client_test_api_; ws::InputDeviceClientTestApi input_device_client_test_api_;
#endif #endif
...@@ -50,6 +53,9 @@ class ChromeBrowserMainExtraPartsMetricsTest : public testing::Test { ...@@ -50,6 +53,9 @@ class ChromeBrowserMainExtraPartsMetricsTest : public testing::Test {
ChromeBrowserMainExtraPartsMetricsTest:: ChromeBrowserMainExtraPartsMetricsTest::
ChromeBrowserMainExtraPartsMetricsTest() { ChromeBrowserMainExtraPartsMetricsTest() {
display::Screen::SetScreenInstance(&test_screen_); display::Screen::SetScreenInstance(&test_screen_);
#if defined(USE_OZONE) || defined(USE_X11)
input_manager_ = aura::test::CreateTestInputDeviceManager();
#endif
} }
ChromeBrowserMainExtraPartsMetricsTest:: ChromeBrowserMainExtraPartsMetricsTest::
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "components/ukm/test_ukm_recorder.h" #include "components/ukm/test_ukm_recorder.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/test_renderer_host.h"
#include "content/public/test/web_contents_tester.h" #include "content/public/test/web_contents_tester.h"
#include "services/metrics/public/cpp/ukm_recorder.h" #include "services/metrics/public/cpp/ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_source.h" #include "services/metrics/public/cpp/ukm_source.h"
...@@ -193,6 +194,7 @@ class ManagePasswordsBubbleModelTest : public ::testing::Test { ...@@ -193,6 +194,7 @@ class ManagePasswordsBubbleModelTest : public ::testing::Test {
private: private:
content::TestBrowserThreadBundle thread_bundle_; content::TestBrowserThreadBundle thread_bundle_;
content::RenderViewHostTestEnabler rvh_enabler_;
TestingProfile profile_; TestingProfile profile_;
std::unique_ptr<content::WebContents> test_web_contents_; std::unique_ptr<content::WebContents> test_web_contents_;
std::unique_ptr<ManagePasswordsBubbleModel> model_; std::unique_ptr<ManagePasswordsBubbleModel> model_;
......
...@@ -14,7 +14,9 @@ ...@@ -14,7 +14,9 @@
#include "content/public/test/test_web_ui.h" #include "content/public/test/test_web_ui.h"
#include "services/ws/public/cpp/input_devices/input_device_client_test_api.h" #include "services/ws/public/cpp/input_devices/input_device_client_test_api.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/test/aura_test_utils.h"
#include "ui/events/devices/input_device.h" #include "ui/events/devices/input_device.h"
#include "ui/events/devices/input_device_manager.h"
namespace chromeos { namespace chromeos {
namespace settings { namespace settings {
...@@ -32,6 +34,8 @@ class TestKeyboardHandler : public KeyboardHandler { ...@@ -32,6 +34,8 @@ class TestKeyboardHandler : public KeyboardHandler {
class KeyboardHandlerTest : public testing::Test { class KeyboardHandlerTest : public testing::Test {
public: public:
KeyboardHandlerTest() : handler_test_api_(&handler_) { KeyboardHandlerTest() : handler_test_api_(&handler_) {
input_device_manager_ = aura::test::CreateTestInputDeviceManager();
handler_.set_web_ui(&web_ui_); handler_.set_web_ui(&web_ui_);
handler_.RegisterMessages(); handler_.RegisterMessages();
handler_.AllowJavascriptForTesting(); handler_.AllowJavascriptForTesting();
...@@ -157,6 +161,7 @@ class KeyboardHandlerTest : public testing::Test { ...@@ -157,6 +161,7 @@ class KeyboardHandlerTest : public testing::Test {
return has_internal_search_key; return has_internal_search_key;
} }
std::unique_ptr<ui::InputDeviceManager> input_device_manager_;
ws::InputDeviceClientTestApi input_device_client_test_api_; ws::InputDeviceClientTestApi input_device_client_test_api_;
content::TestWebUI web_ui_; content::TestWebUI web_ui_;
TestKeyboardHandler handler_; TestKeyboardHandler handler_;
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "ash/test/ash_test_views_delegate.h" #include "ash/test/ash_test_views_delegate.h"
#include "chrome/test/base/ash_test_environment_chrome.h"
#else #else
#include "ui/views/test/test_views_delegate.h" #include "ui/views/test/test_views_delegate.h"
#endif #endif
...@@ -66,13 +65,11 @@ BrowserWithTestWindowTest::BrowserWithTestWindowTest( ...@@ -66,13 +65,11 @@ BrowserWithTestWindowTest::BrowserWithTestWindowTest(
bool hosted_app, bool hosted_app,
content::TestBrowserThreadBundle::Options thread_bundle_options) content::TestBrowserThreadBundle::Options thread_bundle_options)
: thread_bundle_(thread_bundle_options), : thread_bundle_(thread_bundle_options),
browser_type_(browser_type),
hosted_app_(hosted_app) {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
ash_test_environment_ = std::make_unique<AshTestEnvironmentChrome>(); ash_test_helper_(&ash_test_environment_),
ash_test_helper_ =
std::make_unique<ash::AshTestHelper>(ash_test_environment_.get());
#endif #endif
browser_type_(browser_type),
hosted_app_(hosted_app) {
} }
BrowserWithTestWindowTest::~BrowserWithTestWindowTest() {} BrowserWithTestWindowTest::~BrowserWithTestWindowTest() {}
...@@ -80,11 +77,16 @@ BrowserWithTestWindowTest::~BrowserWithTestWindowTest() {} ...@@ -80,11 +77,16 @@ BrowserWithTestWindowTest::~BrowserWithTestWindowTest() {}
void BrowserWithTestWindowTest::SetUp() { void BrowserWithTestWindowTest::SetUp() {
testing::Test::SetUp(); testing::Test::SetUp();
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
ash_test_helper_->SetUp(true); ash_test_helper_.SetUp(true);
ash_test_helper_->SetRunningOutsideAsh(); ash_test_helper_.SetRunningOutsideAsh();
#elif defined(TOOLKIT_VIEWS) #elif defined(TOOLKIT_VIEWS)
views_test_helper_.reset(new views::ScopedViewsTestHelper()); views_test_helper_.reset(new views::ScopedViewsTestHelper());
#endif #endif
// This must be created after ash_test_helper_ is set up so that it doesn't
// create an InputDeviceManager.
rvh_test_enabler_ = std::make_unique<content::RenderViewHostTestEnabler>();
#if defined(TOOLKIT_VIEWS) #if defined(TOOLKIT_VIEWS)
SetConstrainedWindowViewsClient(CreateChromeConstrainedWindowViewsClient()); SetConstrainedWindowViewsClient(CreateChromeConstrainedWindowViewsClient());
...@@ -131,7 +133,7 @@ void BrowserWithTestWindowTest::TearDown() { ...@@ -131,7 +133,7 @@ void BrowserWithTestWindowTest::TearDown() {
profile_manager_.reset(); profile_manager_.reset();
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
ash_test_helper_->TearDown(); ash_test_helper_.TearDown();
#elif defined(TOOLKIT_VIEWS) #elif defined(TOOLKIT_VIEWS)
views_test_helper_.reset(); views_test_helper_.reset();
#endif #endif
...@@ -146,7 +148,7 @@ void BrowserWithTestWindowTest::TearDown() { ...@@ -146,7 +148,7 @@ void BrowserWithTestWindowTest::TearDown() {
gfx::NativeWindow BrowserWithTestWindowTest::GetContext() { gfx::NativeWindow BrowserWithTestWindowTest::GetContext() {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
return ash_test_helper_->CurrentContext(); return ash_test_helper_.CurrentContext();
#elif defined(TOOLKIT_VIEWS) #elif defined(TOOLKIT_VIEWS)
return views_test_helper_->GetContext(); return views_test_helper_->GetContext();
#else #else
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "ash/test/ash_test_views_delegate.h" #include "ash/test/ash_test_views_delegate.h"
#include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h"
#include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h"
#include "chrome/test/base/ash_test_environment_chrome.h"
#else #else
#include "ui/views/test/scoped_views_test_helper.h" #include "ui/views/test/scoped_views_test_helper.h"
#endif #endif
...@@ -35,13 +36,6 @@ class GURL; ...@@ -35,13 +36,6 @@ class GURL;
namespace views { namespace views {
class TestViewsDelegate; class TestViewsDelegate;
} }
#if defined(OS_CHROMEOS)
namespace ash {
namespace test {
class AshTestEnvironment;
}
}
#endif
#endif #endif
namespace content { namespace content {
...@@ -124,7 +118,7 @@ class BrowserWithTestWindowTest : public testing::Test { ...@@ -124,7 +118,7 @@ class BrowserWithTestWindowTest : public testing::Test {
} }
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
ash::AshTestHelper* ash_test_helper() { return ash_test_helper_.get(); } ash::AshTestHelper* ash_test_helper() { return &ash_test_helper_; }
#endif #endif
// The context to help determine desktop type when creating new Widgets. // The context to help determine desktop type when creating new Widgets.
...@@ -175,7 +169,7 @@ class BrowserWithTestWindowTest : public testing::Test { ...@@ -175,7 +169,7 @@ class BrowserWithTestWindowTest : public testing::Test {
#if defined(TOOLKIT_VIEWS) #if defined(TOOLKIT_VIEWS)
views::TestViewsDelegate* test_views_delegate() { views::TestViewsDelegate* test_views_delegate() {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
return ash_test_helper_->test_views_delegate(); return ash_test_helper_.test_views_delegate();
#else #else
return views_test_helper_->test_views_delegate(); return views_test_helper_->test_views_delegate();
#endif #endif
...@@ -197,17 +191,16 @@ class BrowserWithTestWindowTest : public testing::Test { ...@@ -197,17 +191,16 @@ class BrowserWithTestWindowTest : public testing::Test {
std::unique_ptr<BrowserWindow> window_; // Usually a TestBrowserWindow. std::unique_ptr<BrowserWindow> window_; // Usually a TestBrowserWindow.
std::unique_ptr<Browser> browser_; std::unique_ptr<Browser> browser_;
// The existence of this object enables tests via
// RenderViewHostTester.
content::RenderViewHostTestEnabler rvh_test_enabler_;
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
std::unique_ptr<ash::AshTestEnvironment> ash_test_environment_; AshTestEnvironmentChrome ash_test_environment_;
std::unique_ptr<ash::AshTestHelper> ash_test_helper_; ash::AshTestHelper ash_test_helper_;
#elif defined(TOOLKIT_VIEWS) #elif defined(TOOLKIT_VIEWS)
std::unique_ptr<views::ScopedViewsTestHelper> views_test_helper_; std::unique_ptr<views::ScopedViewsTestHelper> views_test_helper_;
#endif #endif
// The existence of this object enables tests via RenderViewHostTester.
std::unique_ptr<content::RenderViewHostTestEnabler> rvh_test_enabler_;
#if defined(OS_WIN) #if defined(OS_WIN)
ui::ScopedOleInitializer ole_initializer_; ui::ScopedOleInitializer ole_initializer_;
#endif #endif
......
...@@ -14,12 +14,10 @@ ...@@ -14,12 +14,10 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "base/test/scoped_command_line.h" #include "base/test/scoped_command_line.h"
#include "base/test/test_message_loop.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "content/browser/media/session/media_session_impl.h" #include "content/browser/media/session/media_session_impl.h"
#include "content/public/test/test_browser_context.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/test_renderer_host.h"
#include "content/public/test/test_service_manager_context.h" #include "content/public/test/test_service_manager_context.h"
#include "content/test/test_web_contents.h" #include "content/test/test_web_contents.h"
#include "media/base/audio_parameters.h" #include "media/base/audio_parameters.h"
...@@ -29,8 +27,6 @@ ...@@ -29,8 +27,6 @@
#include "services/media_session/public/cpp/switches.h" #include "services/media_session/public/cpp/switches.h"
#include "services/media_session/public/mojom/audio_focus.mojom.h" #include "services/media_session/public/mojom/audio_focus.mojom.h"
#include "services/media_session/public/mojom/constants.mojom.h" #include "services/media_session/public/mojom/constants.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
namespace { namespace {
...@@ -44,16 +40,18 @@ using media_session::mojom::AudioFocusRequestStatePtr; ...@@ -44,16 +40,18 @@ using media_session::mojom::AudioFocusRequestStatePtr;
// integer/string values. // integer/string values.
class MediaInternalsTestBase { class MediaInternalsTestBase {
public: public:
MediaInternalsTestBase() : media_internals_(nullptr) { MediaInternalsTestBase() = default;
virtual ~MediaInternalsTestBase() = default;
void SetUpServiceManager() {
scoped_command_line_.GetProcessCommandLine()->AppendSwitch( scoped_command_line_.GetProcessCommandLine()->AppendSwitch(
media_session::switches::kEnableAudioFocus); media_session::switches::kEnableAudioFocus);
service_manager_context_ = service_manager_context_ =
std::make_unique<content::TestServiceManagerContext>(); std::make_unique<content::TestServiceManagerContext>();
media_internals_ = content::MediaInternals::GetInstance();
} }
virtual ~MediaInternalsTestBase() {} void TearDownServiceManager() { service_manager_context_.reset(); }
protected: protected:
// Extracts and deserializes the JSON update data; merges into |update_data_|. // Extracts and deserializes the JSON update data; merges into |update_data_|.
...@@ -107,14 +105,13 @@ class MediaInternalsTestBase { ...@@ -107,14 +105,13 @@ class MediaInternalsTestBase {
} }
} }
const content::TestBrowserThreadBundle thread_bundle_;
base::DictionaryValue update_data_; base::DictionaryValue update_data_;
content::MediaInternals* media_internals() const { return media_internals_; } content::MediaInternals* media_internals() const {
return content::MediaInternals::GetInstance();
}
private: private:
content::MediaInternals* media_internals_;
base::test::ScopedCommandLine scoped_command_line_; base::test::ScopedCommandLine scoped_command_line_;
std::unique_ptr<content::TestServiceManagerContext> service_manager_context_; std::unique_ptr<content::TestServiceManagerContext> service_manager_context_;
}; };
...@@ -132,14 +129,17 @@ class MediaInternalsVideoCaptureDeviceTest : public testing::Test, ...@@ -132,14 +129,17 @@ class MediaInternalsVideoCaptureDeviceTest : public testing::Test,
: update_cb_(base::Bind( : update_cb_(base::Bind(
&MediaInternalsVideoCaptureDeviceTest::UpdateCallbackImpl, &MediaInternalsVideoCaptureDeviceTest::UpdateCallbackImpl,
base::Unretained(this))) { base::Unretained(this))) {
SetUpServiceManager();
media_internals()->AddUpdateCallback(update_cb_); media_internals()->AddUpdateCallback(update_cb_);
} }
~MediaInternalsVideoCaptureDeviceTest() override { ~MediaInternalsVideoCaptureDeviceTest() override {
media_internals()->RemoveUpdateCallback(update_cb_); media_internals()->RemoveUpdateCallback(update_cb_);
TearDownServiceManager();
} }
protected: protected:
const content::TestBrowserThreadBundle thread_bundle_;
MediaInternals::UpdateCallback update_cb_; MediaInternals::UpdateCallback update_cb_;
}; };
...@@ -228,11 +228,13 @@ class MediaInternalsAudioLogTest ...@@ -228,11 +228,13 @@ class MediaInternalsAudioLogTest
test_component_(GetParam()), test_component_(GetParam()),
audio_log_(media_internals()->CreateAudioLog(test_component_, audio_log_(media_internals()->CreateAudioLog(test_component_,
kTestComponentID)) { kTestComponentID)) {
SetUpServiceManager();
media_internals()->AddUpdateCallback(update_cb_); media_internals()->AddUpdateCallback(update_cb_);
} }
virtual ~MediaInternalsAudioLogTest() { virtual ~MediaInternalsAudioLogTest() {
media_internals()->RemoveUpdateCallback(update_cb_); media_internals()->RemoveUpdateCallback(update_cb_);
TearDownServiceManager();
} }
protected: protected:
...@@ -249,6 +251,8 @@ class MediaInternalsAudioLogTest ...@@ -249,6 +251,8 @@ class MediaInternalsAudioLogTest
media::AudioParameters::DUCKING); media::AudioParameters::DUCKING);
return params; return params;
} }
const content::TestBrowserThreadBundle thread_bundle_;
}; };
TEST_P(MediaInternalsAudioLogTest, AudioLogCreateStartStopErrorClose) { TEST_P(MediaInternalsAudioLogTest, AudioLogCreateStartStopErrorClose) {
...@@ -319,15 +323,19 @@ const char kTestTitle2[] = "Test Title 2"; ...@@ -319,15 +323,19 @@ const char kTestTitle2[] = "Test Title 2";
} // namespace } // namespace
class MediaInternalsAudioFocusTest : public testing::Test, class MediaInternalsAudioFocusTest : public RenderViewHostTestHarness,
public MediaInternalsTestBase { public MediaInternalsTestBase {
public: public:
MediaInternalsAudioFocusTest() = default;
~MediaInternalsAudioFocusTest() override = default;
void SetUp() override { void SetUp() override {
RenderViewHostTestHarness::SetUp();
SetUpServiceManager();
update_cb_ = update_cb_ =
base::BindRepeating(&MediaInternalsAudioFocusTest::UpdateCallbackImpl, base::BindRepeating(&MediaInternalsAudioFocusTest::UpdateCallbackImpl,
base::Unretained(this)); base::Unretained(this));
browser_context_.reset(new TestBrowserContext());
run_loop_ = std::make_unique<base::RunLoop>(); run_loop_ = std::make_unique<base::RunLoop>();
content::ServiceManagerConnection::GetForProcess() content::ServiceManagerConnection::GetForProcess()
...@@ -339,7 +347,8 @@ class MediaInternalsAudioFocusTest : public testing::Test, ...@@ -339,7 +347,8 @@ class MediaInternalsAudioFocusTest : public testing::Test,
void TearDown() override { void TearDown() override {
content::MediaInternals::GetInstance()->RemoveUpdateCallback(update_cb_); content::MediaInternals::GetInstance()->RemoveUpdateCallback(update_cb_);
browser_context_.reset(); TearDownServiceManager();
RenderViewHostTestHarness::TearDown();
} }
protected: protected:
...@@ -374,11 +383,6 @@ class MediaInternalsAudioFocusTest : public testing::Test, ...@@ -374,11 +383,6 @@ class MediaInternalsAudioFocusTest : public testing::Test,
call_count_ = 0; call_count_ = 0;
} }
std::unique_ptr<TestWebContents> CreateWebContents() {
return TestWebContents::Create(
browser_context_.get(), SiteInstance::Create(browser_context_.get()));
}
void RemoveAllPlayersForTest(MediaSessionImpl* session) { void RemoveAllPlayersForTest(MediaSessionImpl* session) {
session->RemoveAllPlayersForTest(); session->RemoveAllPlayersForTest();
} }
...@@ -417,15 +421,15 @@ class MediaInternalsAudioFocusTest : public testing::Test, ...@@ -417,15 +421,15 @@ class MediaInternalsAudioFocusTest : public testing::Test,
base::Lock lock_; base::Lock lock_;
std::unique_ptr<base::RunLoop> run_loop_; std::unique_ptr<base::RunLoop> run_loop_;
std::unique_ptr<TestBrowserContext> browser_context_;
media_session::mojom::AudioFocusManagerPtr audio_focus_ptr_; media_session::mojom::AudioFocusManagerPtr audio_focus_ptr_;
}; };
TEST_F(MediaInternalsAudioFocusTest, AudioFocusStateIsUpdated) { TEST_F(MediaInternalsAudioFocusTest, AudioFocusStateIsUpdated) {
// Create a test media session and request audio focus. // Create a test media session and request audio focus.
std::unique_ptr<TestWebContents> web_contents1 = CreateWebContents(); std::unique_ptr<WebContents> web_contents1 = CreateTestWebContents();
web_contents1->SetTitle(base::UTF8ToUTF16(kTestTitle1)); static_cast<TestWebContents*>(web_contents1.get())
->SetTitle(base::UTF8ToUTF16(kTestTitle1));
MediaSessionImpl* media_session1 = MediaSessionImpl::Get(web_contents1.get()); MediaSessionImpl* media_session1 = MediaSessionImpl::Get(web_contents1.get());
media_session1->RequestSystemAudioFocus(AudioFocusType::kGain); media_session1->RequestSystemAudioFocus(AudioFocusType::kGain);
WaitForCallbackCount(1); WaitForCallbackCount(1);
...@@ -446,8 +450,9 @@ TEST_F(MediaInternalsAudioFocusTest, AudioFocusStateIsUpdated) { ...@@ -446,8 +450,9 @@ TEST_F(MediaInternalsAudioFocusTest, AudioFocusStateIsUpdated) {
} }
// Create another media session. // Create another media session.
std::unique_ptr<TestWebContents> web_contents2 = CreateWebContents(); std::unique_ptr<WebContents> web_contents2 = CreateTestWebContents();
web_contents2->SetTitle(base::UTF8ToUTF16(kTestTitle2)); static_cast<TestWebContents*>(web_contents2.get())
->SetTitle(base::UTF8ToUTF16(kTestTitle2));
MediaSessionImpl* media_session2 = MediaSessionImpl::Get(web_contents2.get()); MediaSessionImpl* media_session2 = MediaSessionImpl::Get(web_contents2.get());
media_session2->RequestSystemAudioFocus( media_session2->RequestSystemAudioFocus(
AudioFocusType::kGainTransientMayDuck); AudioFocusType::kGainTransientMayDuck);
......
...@@ -10,11 +10,9 @@ ...@@ -10,11 +10,9 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "content/browser/media/session/media_session_player_observer.h" #include "content/browser/media/session/media_session_player_observer.h"
#include "content/browser/media/session/mock_media_session_player_observer.h" #include "content/browser/media/session/mock_media_session_player_observer.h"
#include "content/public/test/mock_render_process_host.h" #include "content/public/common/service_manager_connection.h"
#include "content/public/test/test_browser_context.h" #include "content/public/test/test_renderer_host.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/test_service_manager_context.h" #include "content/public/test/test_service_manager_context.h"
#include "content/test/test_web_contents.h"
#include "media/base/media_content_type.h" #include "media/base/media_content_type.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/interface_request.h" #include "mojo/public/cpp/bindings/interface_request.h"
...@@ -74,7 +72,7 @@ class MockAudioFocusDelegate : public AudioFocusDelegate { ...@@ -74,7 +72,7 @@ class MockAudioFocusDelegate : public AudioFocusDelegate {
} // anonymous namespace } // anonymous namespace
class MediaSessionImplTest : public testing::Test { class MediaSessionImplTest : public RenderViewHostTestHarness {
public: public:
MediaSessionImplTest() = default; MediaSessionImplTest() = default;
...@@ -82,10 +80,8 @@ class MediaSessionImplTest : public testing::Test { ...@@ -82,10 +80,8 @@ class MediaSessionImplTest : public testing::Test {
base::CommandLine::ForCurrentProcess()->AppendSwitch( base::CommandLine::ForCurrentProcess()->AppendSwitch(
media_session::switches::kEnableAudioFocus); media_session::switches::kEnableAudioFocus);
rph_factory_.reset(new MockRenderProcessHostFactory()); RenderViewHostTestHarness::SetUp();
RenderProcessHostImpl::set_render_process_host_factory_for_testing(
rph_factory_.get());
browser_context_.reset(new TestBrowserContext());
player_observer_.reset(new MockMediaSessionPlayerObserver()); player_observer_.reset(new MockMediaSessionPlayerObserver());
// Connect to the Media Session service and bind |audio_focus_ptr_| to it. // Connect to the Media Session service and bind |audio_focus_ptr_| to it.
...@@ -98,9 +94,8 @@ class MediaSessionImplTest : public testing::Test { ...@@ -98,9 +94,8 @@ class MediaSessionImplTest : public testing::Test {
void TearDown() override { void TearDown() override {
service_manager_context_.reset(); service_manager_context_.reset();
browser_context_.reset();
RenderProcessHostImpl::set_render_process_host_factory_for_testing(nullptr); RenderViewHostTestHarness::TearDown();
rph_factory_.reset();
} }
void RequestAudioFocus(MediaSessionImpl* session, void RequestAudioFocus(MediaSessionImpl* session,
...@@ -128,11 +123,6 @@ class MediaSessionImplTest : public testing::Test { ...@@ -128,11 +123,6 @@ class MediaSessionImplTest : public testing::Test {
session->FlushForTesting(); session->FlushForTesting();
} }
std::unique_ptr<WebContents> CreateWebContents() {
return TestWebContents::Create(
browser_context_.get(), SiteInstance::Create(browser_context_.get()));
}
std::unique_ptr<TestAudioFocusObserver> CreateAudioFocusObserver() { std::unique_ptr<TestAudioFocusObserver> CreateAudioFocusObserver() {
std::unique_ptr<TestAudioFocusObserver> observer = std::unique_ptr<TestAudioFocusObserver> observer =
std::make_unique<TestAudioFocusObserver>(); std::make_unique<TestAudioFocusObserver>();
...@@ -153,17 +143,15 @@ class MediaSessionImplTest : public testing::Test { ...@@ -153,17 +143,15 @@ class MediaSessionImplTest : public testing::Test {
} }
private: private:
TestBrowserThreadBundle test_browser_thread_bundle_;
media_session::mojom::AudioFocusManagerPtr audio_focus_ptr_; media_session::mojom::AudioFocusManagerPtr audio_focus_ptr_;
std::unique_ptr<TestServiceManagerContext> service_manager_context_; std::unique_ptr<TestServiceManagerContext> service_manager_context_;
std::unique_ptr<MockRenderProcessHostFactory> rph_factory_;
std::unique_ptr<TestBrowserContext> browser_context_; DISALLOW_COPY_AND_ASSIGN(MediaSessionImplTest);
}; };
TEST_F(MediaSessionImplTest, SessionInfoState) { TEST_F(MediaSessionImplTest, SessionInfoState) {
std::unique_ptr<WebContents> web_contents(CreateWebContents()); std::unique_ptr<WebContents> web_contents(CreateTestWebContents());
MediaSessionImpl* media_session = MediaSessionImpl::Get(web_contents.get()); MediaSessionImpl* media_session = MediaSessionImpl::Get(web_contents.get());
EXPECT_EQ(MediaSessionInfo::SessionState::kInactive, GetState(media_session)); EXPECT_EQ(MediaSessionInfo::SessionState::kInactive, GetState(media_session));
...@@ -229,7 +217,7 @@ TEST_F(MediaSessionImplTest, SessionInfoState) { ...@@ -229,7 +217,7 @@ TEST_F(MediaSessionImplTest, SessionInfoState) {
} }
TEST_F(MediaSessionImplTest, NotifyDelegateOnStateChange) { TEST_F(MediaSessionImplTest, NotifyDelegateOnStateChange) {
std::unique_ptr<WebContents> web_contents(CreateWebContents()); std::unique_ptr<WebContents> web_contents(CreateTestWebContents());
MediaSessionImpl* media_session = MediaSessionImpl::Get(web_contents.get()); MediaSessionImpl* media_session = MediaSessionImpl::Get(web_contents.get());
MockAudioFocusDelegate* delegate = new MockAudioFocusDelegate(); MockAudioFocusDelegate* delegate = new MockAudioFocusDelegate();
SetDelegateForTests(media_session, delegate); SetDelegateForTests(media_session, delegate);
...@@ -260,7 +248,7 @@ TEST_F(MediaSessionImplTest, NotifyDelegateOnStateChange) { ...@@ -260,7 +248,7 @@ TEST_F(MediaSessionImplTest, NotifyDelegateOnStateChange) {
} }
TEST_F(MediaSessionImplTest, PepperForcesDuckAndRequestsFocus) { TEST_F(MediaSessionImplTest, PepperForcesDuckAndRequestsFocus) {
std::unique_ptr<WebContents> web_contents(CreateWebContents()); std::unique_ptr<WebContents> web_contents(CreateTestWebContents());
MediaSessionImpl* media_session = MediaSessionImpl::Get(web_contents.get()); MediaSessionImpl* media_session = MediaSessionImpl::Get(web_contents.get());
int player_id = player_observer_->StartNewPlayer(); int player_id = player_observer_->StartNewPlayer();
...@@ -284,7 +272,7 @@ TEST_F(MediaSessionImplTest, PepperForcesDuckAndRequestsFocus) { ...@@ -284,7 +272,7 @@ TEST_F(MediaSessionImplTest, PepperForcesDuckAndRequestsFocus) {
} }
TEST_F(MediaSessionImplTest, RegisterMojoObserver) { TEST_F(MediaSessionImplTest, RegisterMojoObserver) {
std::unique_ptr<WebContents> web_contents(CreateWebContents()); std::unique_ptr<WebContents> web_contents(CreateTestWebContents());
MediaSessionImpl* media_session = MediaSessionImpl::Get(web_contents.get()); MediaSessionImpl* media_session = MediaSessionImpl::Get(web_contents.get());
EXPECT_FALSE(HasMojoObservers(media_session)); EXPECT_FALSE(HasMojoObservers(media_session));
...@@ -296,7 +284,7 @@ TEST_F(MediaSessionImplTest, RegisterMojoObserver) { ...@@ -296,7 +284,7 @@ TEST_F(MediaSessionImplTest, RegisterMojoObserver) {
} }
TEST_F(MediaSessionImplTest, SessionInfo_PlaybackState) { TEST_F(MediaSessionImplTest, SessionInfo_PlaybackState) {
std::unique_ptr<WebContents> web_contents(CreateWebContents()); std::unique_ptr<WebContents> web_contents(CreateTestWebContents());
MediaSessionImpl* media_session = MediaSessionImpl::Get(web_contents.get()); MediaSessionImpl* media_session = MediaSessionImpl::Get(web_contents.get());
EXPECT_EQ(MediaPlaybackState::kPaused, EXPECT_EQ(MediaPlaybackState::kPaused,
...@@ -322,7 +310,7 @@ TEST_F(MediaSessionImplTest, SessionInfo_PlaybackState) { ...@@ -322,7 +310,7 @@ TEST_F(MediaSessionImplTest, SessionInfo_PlaybackState) {
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
TEST_F(MediaSessionImplTest, WebContentsDestroyed_ReleasesFocus) { TEST_F(MediaSessionImplTest, WebContentsDestroyed_ReleasesFocus) {
std::unique_ptr<WebContents> web_contents(CreateWebContents()); std::unique_ptr<WebContents> web_contents(CreateTestWebContents());
MediaSessionImpl* media_session = MediaSessionImpl::Get(web_contents.get()); MediaSessionImpl* media_session = MediaSessionImpl::Get(web_contents.get());
{ {
...@@ -346,7 +334,7 @@ TEST_F(MediaSessionImplTest, WebContentsDestroyed_ReleasesFocus) { ...@@ -346,7 +334,7 @@ TEST_F(MediaSessionImplTest, WebContentsDestroyed_ReleasesFocus) {
} }
TEST_F(MediaSessionImplTest, WebContentsDestroyed_ReleasesTransients) { TEST_F(MediaSessionImplTest, WebContentsDestroyed_ReleasesTransients) {
std::unique_ptr<WebContents> web_contents(CreateWebContents()); std::unique_ptr<WebContents> web_contents(CreateTestWebContents());
MediaSessionImpl* media_session = MediaSessionImpl::Get(web_contents.get()); MediaSessionImpl* media_session = MediaSessionImpl::Get(web_contents.get());
{ {
...@@ -370,11 +358,11 @@ TEST_F(MediaSessionImplTest, WebContentsDestroyed_ReleasesTransients) { ...@@ -370,11 +358,11 @@ TEST_F(MediaSessionImplTest, WebContentsDestroyed_ReleasesTransients) {
} }
TEST_F(MediaSessionImplTest, WebContentsDestroyed_StopsDucking) { TEST_F(MediaSessionImplTest, WebContentsDestroyed_StopsDucking) {
std::unique_ptr<WebContents> web_contents_1(CreateWebContents()); std::unique_ptr<WebContents> web_contents_1(CreateTestWebContents());
MediaSessionImpl* media_session_1 = MediaSessionImpl* media_session_1 =
MediaSessionImpl::Get(web_contents_1.get()); MediaSessionImpl::Get(web_contents_1.get());
std::unique_ptr<WebContents> web_contents_2(CreateWebContents()); std::unique_ptr<WebContents> web_contents_2(CreateTestWebContents());
MediaSessionImpl* media_session_2 = MediaSessionImpl* media_session_2 =
MediaSessionImpl::Get(web_contents_2.get()); MediaSessionImpl::Get(web_contents_2.get());
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "content/test/test_web_contents.h" #include "content/test/test_web_contents.h"
#include "net/base/network_change_notifier.h" #include "net/base/network_change_notifier.h"
#include "ui/base/material_design/material_design_controller.h" #include "ui/base/material_design/material_design_controller.h"
#include "ui/events/devices/input_device_manager.h"
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
#include "ui/android/dummy_screen_android.h" #include "ui/android/dummy_screen_android.h"
...@@ -47,6 +48,7 @@ ...@@ -47,6 +48,7 @@
#if defined(USE_AURA) #if defined(USE_AURA)
#include "ui/aura/test/aura_test_helper.h" #include "ui/aura/test/aura_test_helper.h"
#include "ui/aura/test/aura_test_utils.h"
#include "ui/compositor/test/context_factories_for_test.h" #include "ui/compositor/test/context_factories_for_test.h"
#include "ui/wm/core/default_activation_client.h" #include "ui/wm/core/default_activation_client.h"
#endif #endif
...@@ -160,6 +162,9 @@ RenderViewHostTestEnabler::RenderViewHostTestEnabler() ...@@ -160,6 +162,9 @@ RenderViewHostTestEnabler::RenderViewHostTestEnabler()
if (base::ThreadTaskRunnerHandle::IsSet()) if (base::ThreadTaskRunnerHandle::IsSet())
ui::WindowResizeHelperMac::Get()->Init(base::ThreadTaskRunnerHandle::Get()); ui::WindowResizeHelperMac::Get()->Init(base::ThreadTaskRunnerHandle::Get());
#endif // OS_MACOSX #endif // OS_MACOSX
#if defined(USE_AURA)
input_device_client_ = aura::test::CreateTestInputDeviceManager();
#endif
} }
RenderViewHostTestEnabler::~RenderViewHostTestEnabler() { RenderViewHostTestEnabler::~RenderViewHostTestEnabler() {
......
...@@ -39,6 +39,7 @@ class NetworkChangeNotifier; ...@@ -39,6 +39,7 @@ class NetworkChangeNotifier;
} }
namespace ui { namespace ui {
class InputDeviceManager;
class ScopedOleInitializer; class ScopedOleInitializer;
} }
...@@ -179,6 +180,9 @@ class RenderViewHostTestEnabler { ...@@ -179,6 +180,9 @@ class RenderViewHostTestEnabler {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
std::unique_ptr<display::Screen> screen_; std::unique_ptr<display::Screen> screen_;
#endif
#if defined(USE_AURA)
std::unique_ptr<ui::InputDeviceManager> input_device_client_;
#endif #endif
std::unique_ptr<base::test::ScopedTaskEnvironment> task_environment_; std::unique_ptr<base::test::ScopedTaskEnvironment> task_environment_;
std::unique_ptr<MockRenderProcessHostFactory> rph_factory_; std::unique_ptr<MockRenderProcessHostFactory> rph_factory_;
......
...@@ -10,32 +10,12 @@ ...@@ -10,32 +10,12 @@
#include "ui/aura/test/aura_test_context_factory.h" #include "ui/aura/test/aura_test_context_factory.h"
#include "ui/base/ui_base_features.h" #include "ui/base/ui_base_features.h"
#if defined(USE_OZONE)
#include "services/ws/public/cpp/input_devices/input_device_client.h"
#endif
#if BUILDFLAG(ENABLE_MUS) #if BUILDFLAG(ENABLE_MUS)
#include "ui/aura/test/mus/test_window_tree_client_delegate.h" #include "ui/aura/test/mus/test_window_tree_client_delegate.h"
#include "ui/aura/test/mus/test_window_tree_client_setup.h" #include "ui/aura/test/mus/test_window_tree_client_setup.h"
#endif #endif
namespace aura { namespace aura {
namespace {
#if defined(USE_OZONE)
class TestInputDeviceClient : public ws::InputDeviceClient {
public:
TestInputDeviceClient() = default;
~TestInputDeviceClient() override = default;
using InputDeviceClient::GetIntefacePtr;
private:
DISALLOW_COPY_AND_ASSIGN(TestInputDeviceClient);
};
#endif
} // namespace
AuraTestSuiteSetup::AuraTestSuiteSetup() { AuraTestSuiteSetup::AuraTestSuiteSetup() {
DCHECK(!Env::HasInstance()); DCHECK(!Env::HasInstance());
...@@ -63,12 +43,11 @@ void AuraTestSuiteSetup::ConfigureMus() { ...@@ -63,12 +43,11 @@ void AuraTestSuiteSetup::ConfigureMus() {
test_window_tree_client_delegate_.get()); test_window_tree_client_delegate_.get());
env_->SetWindowTreeClient(window_tree_client_setup_->window_tree_client()); env_->SetWindowTreeClient(window_tree_client_setup_->window_tree_client());
#if defined(USE_OZONE) #if !defined(USE_OZONE)
input_device_client_ = std::make_unique<TestInputDeviceClient>();
#endif
context_factory_ = std::make_unique<test::AuraTestContextFactory>(); context_factory_ = std::make_unique<test::AuraTestContextFactory>();
env_->set_context_factory(context_factory_.get()); env_->set_context_factory(context_factory_.get());
env_->set_context_factory_private(nullptr); env_->set_context_factory_private(nullptr);
#endif
} }
#endif #endif
......
...@@ -14,10 +14,6 @@ namespace ui { ...@@ -14,10 +14,6 @@ namespace ui {
class ContextFactory; class ContextFactory;
} // namespace ui } // namespace ui
namespace ws {
class InputDeviceClient;
}
namespace aura { namespace aura {
class Env; class Env;
...@@ -48,10 +44,6 @@ class AuraTestSuiteSetup { ...@@ -48,10 +44,6 @@ class AuraTestSuiteSetup {
std::unique_ptr<TestWindowTreeClientSetup> window_tree_client_setup_; std::unique_ptr<TestWindowTreeClientSetup> window_tree_client_setup_;
#endif #endif
#if defined(USE_OZONE)
std::unique_ptr<ws::InputDeviceClient> input_device_client_;
#endif
DISALLOW_COPY_AND_ASSIGN(AuraTestSuiteSetup); DISALLOW_COPY_AND_ASSIGN(AuraTestSuiteSetup);
}; };
......
...@@ -10,6 +10,14 @@ ...@@ -10,6 +10,14 @@
#include "ui/aura/window_event_dispatcher.h" #include "ui/aura/window_event_dispatcher.h"
#include "ui/aura/window_tree_host.h" #include "ui/aura/window_tree_host.h"
#if defined(USE_OZONE)
#include "services/ws/public/cpp/input_devices/input_device_client.h"
#include "ui/aura/env.h"
#include "ui/base/ui_base_features.h"
#else
#include "ui/events/devices/input_device_manager.h"
#endif
namespace aura { namespace aura {
namespace test { namespace test {
...@@ -48,5 +56,17 @@ void DisableIME(WindowTreeHost* host) { ...@@ -48,5 +56,17 @@ void DisableIME(WindowTreeHost* host) {
WindowTreeHostTestApi(host).disable_ime(); WindowTreeHostTestApi(host).disable_ime();
} }
std::unique_ptr<ui::InputDeviceManager> CreateTestInputDeviceManager() {
#if defined(USE_OZONE)
// Some tests may have already created an InputDeviceManager, e.g. through
// AshTestHelper. Some tests will not have created their Env yet, which may
// create an InputDeviceManager. So only create one if an Env has been created
// but it didn't create an InputDeviceManager.
if (aura::Env::HasInstance() && !ui::InputDeviceManager::HasInstance())
return std::make_unique<ws::InputDeviceClient>();
#endif
return nullptr;
}
} // namespace test } // namespace test
} // namespace aura } // namespace aura
...@@ -13,6 +13,10 @@ namespace gfx { ...@@ -13,6 +13,10 @@ namespace gfx {
class Point; class Point;
} }
namespace ui {
class InputDeviceManager;
}
namespace aura { namespace aura {
class WindowEventDispatcher; class WindowEventDispatcher;
class WindowTreeHost; class WindowTreeHost;
...@@ -24,6 +28,8 @@ void SetHostDispatcher(WindowTreeHost* host, ...@@ -24,6 +28,8 @@ void SetHostDispatcher(WindowTreeHost* host,
std::unique_ptr<WindowEventDispatcher> dispatcher); std::unique_ptr<WindowEventDispatcher> dispatcher);
void DisableIME(WindowTreeHost* host); void DisableIME(WindowTreeHost* host);
std::unique_ptr<ui::InputDeviceManager> CreateTestInputDeviceManager();
} // namespace test } // namespace test
} // namespace aura } // namespace aura
......
...@@ -3,41 +3,35 @@ ...@@ -3,41 +3,35 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "ui/events/devices/input_device_manager.h" #include "ui/events/devices/input_device_manager.h"
#include "base/lazy_instance.h"
#include "base/threading/thread_local.h"
namespace ui { namespace ui {
namespace { namespace {
// InputDeviceManager singleton is thread-local so that different instances can InputDeviceManager* g_instance = nullptr;
// be used on different threads (eg. UI Service thread vs. browser UI thread).
base::LazyInstance<base::ThreadLocalPointer<InputDeviceManager>>::Leaky
lazy_tls_ptr = LAZY_INSTANCE_INITIALIZER;
} // namespace } // namespace
// static // static
InputDeviceManager* InputDeviceManager::GetInstance() { InputDeviceManager* InputDeviceManager::GetInstance() {
InputDeviceManager* instance = lazy_tls_ptr.Pointer()->Get(); DCHECK(g_instance) << "InputDeviceManager::SetInstance must be called before "
DCHECK(instance) << "InputDeviceManager::SetInstance must be called before " "getting the instance of InputDeviceManager.";
"getting the instance of InputDeviceManager."; return g_instance;
return instance;
} }
// static // static
bool InputDeviceManager::HasInstance() { bool InputDeviceManager::HasInstance() {
return lazy_tls_ptr.Pointer()->Get() != nullptr; return g_instance;
} }
// static // static
void InputDeviceManager::SetInstance(InputDeviceManager* instance) { void InputDeviceManager::SetInstance(InputDeviceManager* instance) {
DCHECK(!lazy_tls_ptr.Pointer()->Get()); DCHECK(!g_instance);
lazy_tls_ptr.Pointer()->Set(instance); g_instance = instance;
} }
// static // static
void InputDeviceManager::ClearInstance() { void InputDeviceManager::ClearInstance() {
lazy_tls_ptr.Pointer()->Set(nullptr); g_instance = nullptr;
} }
} // namespace ui } // namespace ui
...@@ -15,13 +15,13 @@ ...@@ -15,13 +15,13 @@
namespace ui { namespace ui {
// Interface to query available input devices. Holds a thread-local pointer to // Interface to query available input devices. The implementation, which is a
// an implementation that provides this service. The implementation could be // singleton, could be DeviceDataManager or something that mirrors the necessary
// DeviceDataManager or something that mirrors the necessary state if // state if DeviceDataManager is in a different process.
// DeviceDataManager is in a different process.
class EVENTS_DEVICES_EXPORT InputDeviceManager { class EVENTS_DEVICES_EXPORT InputDeviceManager {
public: public:
InputDeviceManager() {} InputDeviceManager() = default;
virtual ~InputDeviceManager() = default;
static InputDeviceManager* GetInstance(); static InputDeviceManager* GetInstance();
static bool HasInstance(); static bool HasInstance();
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "content/public/test/mock_render_process_host.h" #include "content/public/test/mock_render_process_host.h"
#include "content/public/test/test_browser_context.h" #include "content/public/test/test_browser_context.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/test_renderer_host.h"
#include "content/public/test/web_contents_tester.h" #include "content/public/test/web_contents_tester.h"
#include "content/test/test_content_browser_client.h" #include "content/test/test_content_browser_client.h"
#include "ui/events/event.h" #include "ui/events/event.h"
...@@ -187,6 +188,7 @@ class WebViewUnitTest : public views::test::WidgetTest { ...@@ -187,6 +188,7 @@ class WebViewUnitTest : public views::test::WidgetTest {
private: private:
content::TestBrowserThreadBundle test_browser_thread_bundle_; content::TestBrowserThreadBundle test_browser_thread_bundle_;
content::RenderViewHostTestEnabler rvh_enabler_;
std::unique_ptr<content::TestBrowserContext> browser_context_; std::unique_ptr<content::TestBrowserContext> browser_context_;
content::TestContentBrowserClient test_browser_client_; content::TestContentBrowserClient test_browser_client_;
std::unique_ptr<views::WebView::ScopedWebContentsCreatorForTesting> std::unique_ptr<views::WebView::ScopedWebContentsCreatorForTesting>
......
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