Commit a060c4e9 authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

Revert "Make BrowserWithTestWindowTests work with single process Mash"

This reverts commit 01dd4ead.

Reason for revert: Seems to have broken fushcia cast: https://ci.chromium.org/p/chromium/builders/luci.chromium.ci/fuchsia-arm64-cast/2910

Original change's description:
> 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/1341075
> Reviewed-by: Scott Violet <sky@chromium.org>
> Commit-Queue: Evan Stade <estade@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#611556}

TBR=sky@chromium.org,estade@chromium.org

Change-Id: Iadad5f76d31d82e8dc4cd427db184f536fdbef38
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 905430
Reviewed-on: https://chromium-review.googlesource.com/c/1352125Reviewed-by: default avatarDarren Shen <shend@chromium.org>
Commit-Queue: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611559}
parent 7499de42
...@@ -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_renderer_host.h" #include "content/public/test/test_web_contents_factory.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,9 +135,7 @@ class DeclarativeChromeContentRulesRegistryTest : public testing::Test { ...@@ -135,9 +135,7 @@ 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,7 +131,6 @@ class ParameterizedDeclarativeContentActionTest ...@@ -131,7 +131,6 @@ 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")
...@@ -199,7 +198,6 @@ INSTANTIATE_TEST_CASE_P( ...@@ -199,7 +198,6 @@ 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,8 +17,6 @@ ...@@ -17,8 +17,6 @@
#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 {
...@@ -35,7 +33,6 @@ class ChromeBrowserMainExtraPartsMetricsTest : public testing::Test { ...@@ -35,7 +33,6 @@ 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
...@@ -53,9 +50,6 @@ class ChromeBrowserMainExtraPartsMetricsTest : public testing::Test { ...@@ -53,9 +50,6 @@ 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,7 +34,6 @@ ...@@ -34,7 +34,6 @@
#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"
...@@ -194,7 +193,6 @@ class ManagePasswordsBubbleModelTest : public ::testing::Test { ...@@ -194,7 +193,6 @@ 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,9 +14,7 @@ ...@@ -14,9 +14,7 @@
#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 {
...@@ -34,8 +32,6 @@ class TestKeyboardHandler : public KeyboardHandler { ...@@ -34,8 +32,6 @@ 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();
...@@ -161,7 +157,6 @@ class KeyboardHandlerTest : public testing::Test { ...@@ -161,7 +157,6 @@ 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,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#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
...@@ -65,11 +66,13 @@ BrowserWithTestWindowTest::BrowserWithTestWindowTest( ...@@ -65,11 +66,13 @@ 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),
#if defined(OS_CHROMEOS)
ash_test_helper_(&ash_test_environment_),
#endif
browser_type_(browser_type), browser_type_(browser_type),
hosted_app_(hosted_app) { hosted_app_(hosted_app) {
#if defined(OS_CHROMEOS)
ash_test_environment_ = std::make_unique<AshTestEnvironmentChrome>();
ash_test_helper_ =
std::make_unique<ash::AshTestHelper>(ash_test_environment_.get());
#endif
} }
BrowserWithTestWindowTest::~BrowserWithTestWindowTest() {} BrowserWithTestWindowTest::~BrowserWithTestWindowTest() {}
...@@ -77,16 +80,11 @@ BrowserWithTestWindowTest::~BrowserWithTestWindowTest() {} ...@@ -77,16 +80,11 @@ 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());
...@@ -133,7 +131,7 @@ void BrowserWithTestWindowTest::TearDown() { ...@@ -133,7 +131,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
...@@ -148,7 +146,7 @@ void BrowserWithTestWindowTest::TearDown() { ...@@ -148,7 +146,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,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#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
...@@ -36,6 +35,13 @@ class GURL; ...@@ -36,6 +35,13 @@ 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 {
...@@ -118,7 +124,7 @@ class BrowserWithTestWindowTest : public testing::Test { ...@@ -118,7 +124,7 @@ class BrowserWithTestWindowTest : public testing::Test {
} }
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
ash::AshTestHelper* ash_test_helper() { return &ash_test_helper_; } ash::AshTestHelper* ash_test_helper() { return ash_test_helper_.get(); }
#endif #endif
// The context to help determine desktop type when creating new Widgets. // The context to help determine desktop type when creating new Widgets.
...@@ -169,7 +175,7 @@ class BrowserWithTestWindowTest : public testing::Test { ...@@ -169,7 +175,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
...@@ -191,16 +197,17 @@ class BrowserWithTestWindowTest : public testing::Test { ...@@ -191,16 +197,17 @@ 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)
AshTestEnvironmentChrome ash_test_environment_; std::unique_ptr<ash::AshTestEnvironment> ash_test_environment_;
ash::AshTestHelper ash_test_helper_; std::unique_ptr<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,10 +14,12 @@ ...@@ -14,10 +14,12 @@
#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"
...@@ -27,6 +29,8 @@ ...@@ -27,6 +29,8 @@
#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 {
...@@ -40,18 +44,16 @@ using media_session::mojom::AudioFocusRequestStatePtr; ...@@ -40,18 +44,16 @@ using media_session::mojom::AudioFocusRequestStatePtr;
// integer/string values. // integer/string values.
class MediaInternalsTestBase { class MediaInternalsTestBase {
public: public:
MediaInternalsTestBase() = default; MediaInternalsTestBase() : media_internals_(nullptr) {
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();
} }
void TearDownServiceManager() { service_manager_context_.reset(); } virtual ~MediaInternalsTestBase() {}
protected: protected:
// Extracts and deserializes the JSON update data; merges into |update_data_|. // Extracts and deserializes the JSON update data; merges into |update_data_|.
...@@ -105,13 +107,14 @@ class MediaInternalsTestBase { ...@@ -105,13 +107,14 @@ class MediaInternalsTestBase {
} }
} }
const content::TestBrowserThreadBundle thread_bundle_;
base::DictionaryValue update_data_; base::DictionaryValue update_data_;
content::MediaInternals* media_internals() const { content::MediaInternals* media_internals() const { return media_internals_; }
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_;
}; };
...@@ -129,17 +132,14 @@ class MediaInternalsVideoCaptureDeviceTest : public testing::Test, ...@@ -129,17 +132,14 @@ 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,13 +228,11 @@ class MediaInternalsAudioLogTest ...@@ -228,13 +228,11 @@ 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:
...@@ -251,8 +249,6 @@ class MediaInternalsAudioLogTest ...@@ -251,8 +249,6 @@ 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) {
...@@ -323,19 +319,15 @@ const char kTestTitle2[] = "Test Title 2"; ...@@ -323,19 +319,15 @@ const char kTestTitle2[] = "Test Title 2";
} // namespace } // namespace
class MediaInternalsAudioFocusTest : public RenderViewHostTestHarness, class MediaInternalsAudioFocusTest : public testing::Test,
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()
...@@ -347,8 +339,7 @@ class MediaInternalsAudioFocusTest : public RenderViewHostTestHarness, ...@@ -347,8 +339,7 @@ class MediaInternalsAudioFocusTest : public RenderViewHostTestHarness,
void TearDown() override { void TearDown() override {
content::MediaInternals::GetInstance()->RemoveUpdateCallback(update_cb_); content::MediaInternals::GetInstance()->RemoveUpdateCallback(update_cb_);
TearDownServiceManager(); browser_context_.reset();
RenderViewHostTestHarness::TearDown();
} }
protected: protected:
...@@ -383,6 +374,11 @@ class MediaInternalsAudioFocusTest : public RenderViewHostTestHarness, ...@@ -383,6 +374,11 @@ class MediaInternalsAudioFocusTest : public RenderViewHostTestHarness,
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();
} }
...@@ -421,15 +417,15 @@ class MediaInternalsAudioFocusTest : public RenderViewHostTestHarness, ...@@ -421,15 +417,15 @@ class MediaInternalsAudioFocusTest : public RenderViewHostTestHarness,
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<WebContents> web_contents1 = CreateTestWebContents(); std::unique_ptr<TestWebContents> web_contents1 = CreateWebContents();
static_cast<TestWebContents*>(web_contents1.get()) web_contents1->SetTitle(base::UTF8ToUTF16(kTestTitle1));
->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);
...@@ -450,9 +446,8 @@ TEST_F(MediaInternalsAudioFocusTest, AudioFocusStateIsUpdated) { ...@@ -450,9 +446,8 @@ TEST_F(MediaInternalsAudioFocusTest, AudioFocusStateIsUpdated) {
} }
// Create another media session. // Create another media session.
std::unique_ptr<WebContents> web_contents2 = CreateTestWebContents(); std::unique_ptr<TestWebContents> web_contents2 = CreateWebContents();
static_cast<TestWebContents*>(web_contents2.get()) web_contents2->SetTitle(base::UTF8ToUTF16(kTestTitle2));
->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,9 +10,11 @@ ...@@ -10,9 +10,11 @@
#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/common/service_manager_connection.h" #include "content/public/test/mock_render_process_host.h"
#include "content/public/test/test_renderer_host.h" #include "content/public/test/test_browser_context.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"
...@@ -72,7 +74,7 @@ class MockAudioFocusDelegate : public AudioFocusDelegate { ...@@ -72,7 +74,7 @@ class MockAudioFocusDelegate : public AudioFocusDelegate {
} // anonymous namespace } // anonymous namespace
class MediaSessionImplTest : public RenderViewHostTestHarness { class MediaSessionImplTest : public testing::Test {
public: public:
MediaSessionImplTest() = default; MediaSessionImplTest() = default;
...@@ -80,8 +82,10 @@ class MediaSessionImplTest : public RenderViewHostTestHarness { ...@@ -80,8 +82,10 @@ class MediaSessionImplTest : public RenderViewHostTestHarness {
base::CommandLine::ForCurrentProcess()->AppendSwitch( base::CommandLine::ForCurrentProcess()->AppendSwitch(
media_session::switches::kEnableAudioFocus); media_session::switches::kEnableAudioFocus);
RenderViewHostTestHarness::SetUp(); rph_factory_.reset(new MockRenderProcessHostFactory());
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.
...@@ -94,8 +98,9 @@ class MediaSessionImplTest : public RenderViewHostTestHarness { ...@@ -94,8 +98,9 @@ class MediaSessionImplTest : public RenderViewHostTestHarness {
void TearDown() override { void TearDown() override {
service_manager_context_.reset(); service_manager_context_.reset();
browser_context_.reset();
RenderViewHostTestHarness::TearDown(); RenderProcessHostImpl::set_render_process_host_factory_for_testing(nullptr);
rph_factory_.reset();
} }
void RequestAudioFocus(MediaSessionImpl* session, void RequestAudioFocus(MediaSessionImpl* session,
...@@ -123,6 +128,11 @@ class MediaSessionImplTest : public RenderViewHostTestHarness { ...@@ -123,6 +128,11 @@ class MediaSessionImplTest : public RenderViewHostTestHarness {
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>();
...@@ -143,15 +153,17 @@ class MediaSessionImplTest : public RenderViewHostTestHarness { ...@@ -143,15 +153,17 @@ class MediaSessionImplTest : public RenderViewHostTestHarness {
} }
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_;
DISALLOW_COPY_AND_ASSIGN(MediaSessionImplTest); std::unique_ptr<TestBrowserContext> browser_context_;
}; };
TEST_F(MediaSessionImplTest, SessionInfoState) { TEST_F(MediaSessionImplTest, SessionInfoState) {
std::unique_ptr<WebContents> web_contents(CreateTestWebContents()); std::unique_ptr<WebContents> web_contents(CreateWebContents());
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));
...@@ -217,7 +229,7 @@ TEST_F(MediaSessionImplTest, SessionInfoState) { ...@@ -217,7 +229,7 @@ TEST_F(MediaSessionImplTest, SessionInfoState) {
} }
TEST_F(MediaSessionImplTest, NotifyDelegateOnStateChange) { TEST_F(MediaSessionImplTest, NotifyDelegateOnStateChange) {
std::unique_ptr<WebContents> web_contents(CreateTestWebContents()); std::unique_ptr<WebContents> web_contents(CreateWebContents());
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);
...@@ -248,7 +260,7 @@ TEST_F(MediaSessionImplTest, NotifyDelegateOnStateChange) { ...@@ -248,7 +260,7 @@ TEST_F(MediaSessionImplTest, NotifyDelegateOnStateChange) {
} }
TEST_F(MediaSessionImplTest, PepperForcesDuckAndRequestsFocus) { TEST_F(MediaSessionImplTest, PepperForcesDuckAndRequestsFocus) {
std::unique_ptr<WebContents> web_contents(CreateTestWebContents()); std::unique_ptr<WebContents> web_contents(CreateWebContents());
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();
...@@ -272,7 +284,7 @@ TEST_F(MediaSessionImplTest, PepperForcesDuckAndRequestsFocus) { ...@@ -272,7 +284,7 @@ TEST_F(MediaSessionImplTest, PepperForcesDuckAndRequestsFocus) {
} }
TEST_F(MediaSessionImplTest, RegisterMojoObserver) { TEST_F(MediaSessionImplTest, RegisterMojoObserver) {
std::unique_ptr<WebContents> web_contents(CreateTestWebContents()); std::unique_ptr<WebContents> web_contents(CreateWebContents());
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));
...@@ -284,7 +296,7 @@ TEST_F(MediaSessionImplTest, RegisterMojoObserver) { ...@@ -284,7 +296,7 @@ TEST_F(MediaSessionImplTest, RegisterMojoObserver) {
} }
TEST_F(MediaSessionImplTest, SessionInfo_PlaybackState) { TEST_F(MediaSessionImplTest, SessionInfo_PlaybackState) {
std::unique_ptr<WebContents> web_contents(CreateTestWebContents()); std::unique_ptr<WebContents> web_contents(CreateWebContents());
MediaSessionImpl* media_session = MediaSessionImpl::Get(web_contents.get()); MediaSessionImpl* media_session = MediaSessionImpl::Get(web_contents.get());
EXPECT_EQ(MediaPlaybackState::kPaused, EXPECT_EQ(MediaPlaybackState::kPaused,
...@@ -310,7 +322,7 @@ TEST_F(MediaSessionImplTest, SessionInfo_PlaybackState) { ...@@ -310,7 +322,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(CreateTestWebContents()); std::unique_ptr<WebContents> web_contents(CreateWebContents());
MediaSessionImpl* media_session = MediaSessionImpl::Get(web_contents.get()); MediaSessionImpl* media_session = MediaSessionImpl::Get(web_contents.get());
{ {
...@@ -334,7 +346,7 @@ TEST_F(MediaSessionImplTest, WebContentsDestroyed_ReleasesFocus) { ...@@ -334,7 +346,7 @@ TEST_F(MediaSessionImplTest, WebContentsDestroyed_ReleasesFocus) {
} }
TEST_F(MediaSessionImplTest, WebContentsDestroyed_ReleasesTransients) { TEST_F(MediaSessionImplTest, WebContentsDestroyed_ReleasesTransients) {
std::unique_ptr<WebContents> web_contents(CreateTestWebContents()); std::unique_ptr<WebContents> web_contents(CreateWebContents());
MediaSessionImpl* media_session = MediaSessionImpl::Get(web_contents.get()); MediaSessionImpl* media_session = MediaSessionImpl::Get(web_contents.get());
{ {
...@@ -358,11 +370,11 @@ TEST_F(MediaSessionImplTest, WebContentsDestroyed_ReleasesTransients) { ...@@ -358,11 +370,11 @@ TEST_F(MediaSessionImplTest, WebContentsDestroyed_ReleasesTransients) {
} }
TEST_F(MediaSessionImplTest, WebContentsDestroyed_StopsDucking) { TEST_F(MediaSessionImplTest, WebContentsDestroyed_StopsDucking) {
std::unique_ptr<WebContents> web_contents_1(CreateTestWebContents()); std::unique_ptr<WebContents> web_contents_1(CreateWebContents());
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(CreateTestWebContents()); std::unique_ptr<WebContents> web_contents_2(CreateWebContents());
MediaSessionImpl* media_session_2 = MediaSessionImpl* media_session_2 =
MediaSessionImpl::Get(web_contents_2.get()); MediaSessionImpl::Get(web_contents_2.get());
......
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
#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"
...@@ -48,7 +47,6 @@ ...@@ -48,7 +47,6 @@
#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
...@@ -162,9 +160,6 @@ RenderViewHostTestEnabler::RenderViewHostTestEnabler() ...@@ -162,9 +160,6 @@ 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,7 +39,6 @@ class NetworkChangeNotifier; ...@@ -39,7 +39,6 @@ class NetworkChangeNotifier;
} }
namespace ui { namespace ui {
class InputDeviceManager;
class ScopedOleInitializer; class ScopedOleInitializer;
} }
...@@ -180,9 +179,6 @@ class RenderViewHostTestEnabler { ...@@ -180,9 +179,6 @@ 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,12 +10,32 @@ ...@@ -10,12 +10,32 @@
#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());
...@@ -43,11 +63,12 @@ void AuraTestSuiteSetup::ConfigureMus() { ...@@ -43,11 +63,12 @@ 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,6 +14,10 @@ namespace ui { ...@@ -14,6 +14,10 @@ namespace ui {
class ContextFactory; class ContextFactory;
} // namespace ui } // namespace ui
namespace ws {
class InputDeviceClient;
}
namespace aura { namespace aura {
class Env; class Env;
...@@ -44,6 +48,10 @@ class AuraTestSuiteSetup { ...@@ -44,6 +48,10 @@ 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,14 +10,6 @@ ...@@ -10,14 +10,6 @@
#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 {
...@@ -56,17 +48,5 @@ void DisableIME(WindowTreeHost* host) { ...@@ -56,17 +48,5 @@ 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,10 +13,6 @@ namespace gfx { ...@@ -13,10 +13,6 @@ namespace gfx {
class Point; class Point;
} }
namespace ui {
class InputDeviceManager;
}
namespace aura { namespace aura {
class WindowEventDispatcher; class WindowEventDispatcher;
class WindowTreeHost; class WindowTreeHost;
...@@ -28,8 +24,6 @@ void SetHostDispatcher(WindowTreeHost* host, ...@@ -28,8 +24,6 @@ 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,35 +3,41 @@ ...@@ -3,35 +3,41 @@
// 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* g_instance = nullptr; // InputDeviceManager singleton is thread-local so that different instances can
// 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() {
DCHECK(g_instance) << "InputDeviceManager::SetInstance must be called before " InputDeviceManager* instance = lazy_tls_ptr.Pointer()->Get();
"getting the instance of InputDeviceManager."; DCHECK(instance) << "InputDeviceManager::SetInstance must be called before "
return g_instance; "getting the instance of InputDeviceManager.";
return instance;
} }
// static // static
bool InputDeviceManager::HasInstance() { bool InputDeviceManager::HasInstance() {
return g_instance; return lazy_tls_ptr.Pointer()->Get() != nullptr;
} }
// static // static
void InputDeviceManager::SetInstance(InputDeviceManager* instance) { void InputDeviceManager::SetInstance(InputDeviceManager* instance) {
DCHECK(!g_instance); DCHECK(!lazy_tls_ptr.Pointer()->Get());
g_instance = instance; lazy_tls_ptr.Pointer()->Set(instance);
} }
// static // static
void InputDeviceManager::ClearInstance() { void InputDeviceManager::ClearInstance() {
g_instance = nullptr; lazy_tls_ptr.Pointer()->Set(nullptr);
} }
} // namespace ui } // namespace ui
...@@ -15,13 +15,13 @@ ...@@ -15,13 +15,13 @@
namespace ui { namespace ui {
// Interface to query available input devices. The implementation, which is a // Interface to query available input devices. Holds a thread-local pointer to
// singleton, could be DeviceDataManager or something that mirrors the necessary // an implementation that provides this service. The implementation could be
// state if DeviceDataManager is in a different process. // DeviceDataManager or something that mirrors the necessary state if
// DeviceDataManager is in a different process.
class EVENTS_DEVICES_EXPORT InputDeviceManager { class EVENTS_DEVICES_EXPORT InputDeviceManager {
public: public:
InputDeviceManager() = default; InputDeviceManager() {}
virtual ~InputDeviceManager() = default;
static InputDeviceManager* GetInstance(); static InputDeviceManager* GetInstance();
static bool HasInstance(); static bool HasInstance();
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#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"
...@@ -188,7 +187,6 @@ class WebViewUnitTest : public views::test::WidgetTest { ...@@ -188,7 +187,6 @@ 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