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