Commit 4e44f04f authored by tapted@chromium.org's avatar tapted@chromium.org

MacViews: Split ViewEventTestBase into platform-specific files.

I couldn't bring myself to add another #ifdef to
view_event_test_base.cc, so this splits out the platform-specific stuff
and paves the way to get interactive_ui_tests compiling on MacViews.

This is done by adding a ViewEventTestPlatFormPart interface, which is
implemented for (views platforms): chromeos, ash, and mac.

There was also code for a non-ash aura platform, but all build
configurations that would have used it are broken, so it's just rot and
is removed.

BUG=399191

Review URL: https://codereview.chromium.org/443553003

Cr-Commit-Position: refs/heads/master@{#288966}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288966 0039d316-1c4b-4281-b951-d872f2087c98
parent 91bf0c13
...@@ -157,6 +157,10 @@ ...@@ -157,6 +157,10 @@
'test/base/interactive_ui_tests_main.cc', 'test/base/interactive_ui_tests_main.cc',
'test/base/view_event_test_base.cc', 'test/base/view_event_test_base.cc',
'test/base/view_event_test_base.h', 'test/base/view_event_test_base.h',
'test/base/view_event_test_platform_part.h',
'test/base/view_event_test_platform_part_ash.cc',
'test/base/view_event_test_platform_part_chromeos.cc',
'test/base/view_event_test_platform_part_mac.mm',
'test/ppapi/ppapi_interactive_browsertest.cc', 'test/ppapi/ppapi_interactive_browsertest.cc',
], ],
'conditions': [ 'conditions': [
...@@ -238,6 +242,10 @@ ...@@ -238,6 +242,10 @@
'../ui/views/views.gyp:views_test_support', '../ui/views/views.gyp:views_test_support',
], ],
}, { # else: toolkit_views == 0 }, { # else: toolkit_views == 0
'sources!': [
'test/base/view_event_test_base.cc',
'test/base/view_event_test_base.h',
],
'sources/': [ 'sources/': [
['exclude', '^browser/ui/views/'], ['exclude', '^browser/ui/views/'],
['exclude', '^../ui/views/'], ['exclude', '^../ui/views/'],
...@@ -310,6 +318,9 @@ ...@@ -310,6 +318,9 @@
'browser/ui/panels/stacked_panel_browsertest.cc', 'browser/ui/panels/stacked_panel_browsertest.cc',
'browser/ui/views/message_center/web_notification_tray_browsertest.cc', 'browser/ui/views/message_center/web_notification_tray_browsertest.cc',
'browser/ui/views/panels/panel_view_browsertest.cc', 'browser/ui/views/panels/panel_view_browsertest.cc',
# Use only the _chromeos version on ChromeOS.
'test/base/view_event_test_platform_part_ash.cc',
], ],
}], }],
['OS=="win"', { ['OS=="win"', {
......
...@@ -5,42 +5,16 @@ ...@@ -5,42 +5,16 @@
#include "chrome/test/base/view_event_test_base.h" #include "chrome/test/base/view_event_test_base.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/test/base/chrome_unit_test_suite.h" #include "chrome/test/base/chrome_unit_test_suite.h"
#include "chrome/test/base/interactive_test_utils.h" #include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/view_event_test_platform_part.h"
#include "ui/aura/client/event_client.h"
#include "ui/aura/env.h"
#include "ui/aura/test/aura_test_helper.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/ime/input_method_initializer.h" #include "ui/base/ime/input_method_initializer.h"
#include "ui/base/test/ui_controls.h" #include "ui/base/test/ui_controls.h"
#include "ui/compositor/test/context_factories_for_test.h" #include "ui/compositor/test/context_factories_for_test.h"
#include "ui/compositor/test/context_factories_for_test.h"
#include "ui/message_center/message_center.h"
#include "ui/views/view.h" #include "ui/views/view.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include "ui/wm/core/default_activation_client.h"
#include "ui/wm/core/wm_state.h"
#if defined(USE_ASH)
#include "ash/shell.h"
#include "ash/shell_init_params.h"
#include "ash/test/test_session_state_delegate.h"
#include "ash/test/test_shell_delegate.h"
#endif
#if defined(OS_CHROMEOS)
#include "chromeos/audio/cras_audio_handler.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/network/network_handler.h"
#else // !defined(OS_CHROMEOS)
#include "ui/views/widget/desktop_aura/desktop_screen.h"
#endif
namespace { namespace {
...@@ -101,51 +75,16 @@ void ViewEventTestBase::SetUpTestCase() { ...@@ -101,51 +75,16 @@ void ViewEventTestBase::SetUpTestCase() {
} }
void ViewEventTestBase::SetUp() { void ViewEventTestBase::SetUp() {
wm_state_.reset(new wm::WMState);
views::ViewsDelegate::views_delegate = &views_delegate_; views::ViewsDelegate::views_delegate = &views_delegate_;
ui::InitializeInputMethodForTesting(); ui::InitializeInputMethodForTesting();
gfx::NativeView context = NULL;
// The ContextFactory must exist before any Compositors are created. // The ContextFactory must exist before any Compositors are created.
bool enable_pixel_output = false; bool enable_pixel_output = false;
ui::ContextFactory* context_factory = ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output); ui::InitializeContextFactoryForTests(enable_pixel_output);
#if defined(OS_CHROMEOS) platform_part_.reset(ViewEventTestPlatformPart::Create(context_factory));
// Ash Shell can't just live on its own without a browser process, we need to gfx::NativeWindow context = platform_part_->GetContext();
// also create the message center.
message_center::MessageCenter::Initialize();
chromeos::DBusThreadManager::InitializeWithStub();
chromeos::CrasAudioHandler::InitializeForTesting();
chromeos::NetworkHandler::Initialize();
ash::test::TestShellDelegate* shell_delegate =
new ash::test::TestShellDelegate();
ash::ShellInitParams init_params;
init_params.delegate = shell_delegate;
init_params.context_factory = context_factory;
ash::Shell::CreateInstance(init_params);
shell_delegate->test_session_state_delegate()
->SetActiveUserSessionStarted(true);
context = ash::Shell::GetPrimaryRootWindow();
context->GetHost()->Show();
#elif defined(USE_ASH)
// http://crbug.com/154081 use ash::Shell code path below on win_ash bots when
// interactive_ui_tests is brought up on that platform.
gfx::Screen::SetScreenInstance(
gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen());
aura::Env::CreateInstance(true);
aura::Env::GetInstance()->set_context_factory(context_factory);
#elif defined(USE_AURA)
// Instead of using the ash shell, use an AuraTestHelper to create and manage
// the test screen.
aura_test_helper_.reset(
new aura::test::AuraTestHelper(base::MessageLoopForUI::current()));
aura_test_helper_->SetUp(context_factory);
new wm::DefaultActivationClient(aura_test_helper_->root_window());
context = aura_test_helper_->root_window();
#endif
window_ = views::Widget::CreateWindowWithContext(this, context); window_ = views::Widget::CreateWindowWithContext(this, context);
} }
...@@ -157,28 +96,12 @@ void ViewEventTestBase::TearDown() { ...@@ -157,28 +96,12 @@ void ViewEventTestBase::TearDown() {
} }
ui::Clipboard::DestroyClipboardForCurrentThread(); ui::Clipboard::DestroyClipboardForCurrentThread();
platform_part_.reset();
#if defined(USE_ASH)
#if defined(OS_CHROMEOS)
ash::Shell::DeleteInstance();
chromeos::NetworkHandler::Shutdown();
chromeos::CrasAudioHandler::Shutdown();
chromeos::DBusThreadManager::Shutdown();
// Ash Shell can't just live on its own without a browser process, we need to
// also shut down the message center.
message_center::MessageCenter::Shutdown();
#endif
aura::Env::DeleteInstance();
#elif defined(USE_AURA)
aura_test_helper_->TearDown();
#endif // !USE_ASH && USE_AURA
ui::TerminateContextFactoryForTests(); ui::TerminateContextFactoryForTests();
ui::ShutdownInputMethodForTesting(); ui::ShutdownInputMethodForTesting();
views::ViewsDelegate::views_delegate = NULL; views::ViewsDelegate::views_delegate = NULL;
wm_state_.reset();
} }
bool ViewEventTestBase::CanResize() const { bool ViewEventTestBase::CanResize() const {
......
...@@ -24,19 +24,11 @@ ...@@ -24,19 +24,11 @@
#include "ui/base/win/scoped_ole_initializer.h" #include "ui/base/win/scoped_ole_initializer.h"
#endif #endif
namespace aura {
namespace test {
class AuraTestHelper;
}
}
namespace gfx { namespace gfx {
class Size; class Size;
} }
namespace wm { class ViewEventTestPlatformPart;
class WMState;
}
// Base class for Views based tests that dispatch events. // Base class for Views based tests that dispatch events.
// //
...@@ -154,10 +146,7 @@ class ViewEventTestBase : public views::WidgetDelegate, ...@@ -154,10 +146,7 @@ class ViewEventTestBase : public views::WidgetDelegate,
ui::ScopedOleInitializer ole_initializer_; ui::ScopedOleInitializer ole_initializer_;
#endif #endif
#if defined(USE_AURA) scoped_ptr<ViewEventTestPlatformPart> platform_part_;
scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_;
scoped_ptr<wm::WMState> wm_state_;
#endif
ChromeViewsDelegate views_delegate_; ChromeViewsDelegate views_delegate_;
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_TEST_BASE_VIEW_EVENT_TEST_PLATFORM_PART_H_
#define CHROME_TEST_BASE_VIEW_EVENT_TEST_PLATFORM_PART_H_
#include "base/macros.h"
#include "ui/gfx/native_widget_types.h"
namespace ui {
class ContextFactory;
}
// A helper class owned by tests that performs platform specific initialization.
// ViewEventTestPlatformPart behaves a bit like views::ViewsTestHelper, but on
// ChromeOS it will create an Ash shell environment, rather than using an
// AuraTestHelper.
class ViewEventTestPlatformPart {
public:
virtual ~ViewEventTestPlatformPart() {}
// Set up the platform-specific environment. Teardown is performed in the
// destructor.
static ViewEventTestPlatformPart* Create(ui::ContextFactory* context_factory);
// The Widget context for creating the test window. This will be the Ash root
// window on ChromeOS environments. Otherwise it should return NULL.
virtual gfx::NativeWindow GetContext() = 0;
protected:
ViewEventTestPlatformPart() {}
private:
DISALLOW_COPY_AND_ASSIGN(ViewEventTestPlatformPart);
};
#endif // CHROME_TEST_BASE_VIEW_EVENT_TEST_PLATFORM_PART_H_
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/test/base/view_event_test_platform_part.h"
#include "ui/aura/env.h"
#include "ui/gfx/screen.h"
#include "ui/views/widget/desktop_aura/desktop_screen.h"
#include "ui/wm/core/wm_state.h"
namespace {
// ChromeViewsTestHelper implementation for non-ChromeOS environments, where the
// Ash desktop environment is available (use_ash=1, chromeos=0).
class ViewEventTestPlatformPartAsh : public ViewEventTestPlatformPart {
public:
explicit ViewEventTestPlatformPartAsh(ui::ContextFactory* context_factory);
virtual ~ViewEventTestPlatformPartAsh();
// Overridden from ViewEventTestPlatformPart:
virtual gfx::NativeWindow GetContext() OVERRIDE {
return NULL; // No context, so that desktop tree hosts are used by default.
}
private:
wm::WMState wm_state_;
DISALLOW_COPY_AND_ASSIGN(ViewEventTestPlatformPartAsh);
};
ViewEventTestPlatformPartAsh::ViewEventTestPlatformPartAsh(
ui::ContextFactory* context_factory) {
// http://crbug.com/154081 use ash::Shell code path below on win_ash bots when
// interactive_ui_tests is brought up on that platform.
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE,
views::CreateDesktopScreen());
aura::Env::CreateInstance(true);
aura::Env::GetInstance()->set_context_factory(context_factory);
}
ViewEventTestPlatformPartAsh::~ViewEventTestPlatformPartAsh() {
aura::Env::DeleteInstance();
}
} // namespace
// static
ViewEventTestPlatformPart* ViewEventTestPlatformPart::Create(
ui::ContextFactory* context_factory) {
return new ViewEventTestPlatformPartAsh(context_factory);
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/test/base/view_event_test_platform_part.h"
#include "ash/shell.h"
#include "ash/shell_init_params.h"
#include "ash/test/test_session_state_delegate.h"
#include "ash/test/test_shell_delegate.h"
#include "chromeos/audio/cras_audio_handler.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/network/network_handler.h"
#include "ui/aura/env.h"
#include "ui/aura/window_tree_host.h"
#include "ui/message_center/message_center.h"
#include "ui/wm/core/wm_state.h"
namespace {
// ViewEventTestPlatformPart implementation for ChromeOS (chromeos=1).
class ViewEventTestPlatformPartChromeOS : public ViewEventTestPlatformPart {
public:
explicit ViewEventTestPlatformPartChromeOS(
ui::ContextFactory* context_factory);
virtual ~ViewEventTestPlatformPartChromeOS();
// Overridden from ViewEventTestPlatformPart:
virtual gfx::NativeWindow GetContext() OVERRIDE {
return ash::Shell::GetPrimaryRootWindow();
}
private:
wm::WMState wm_state_;
DISALLOW_COPY_AND_ASSIGN(ViewEventTestPlatformPartChromeOS);
};
ViewEventTestPlatformPartChromeOS::ViewEventTestPlatformPartChromeOS(
ui::ContextFactory* context_factory) {
// Ash Shell can't just live on its own without a browser process, we need to
// also create the message center.
message_center::MessageCenter::Initialize();
chromeos::DBusThreadManager::InitializeWithStub();
chromeos::CrasAudioHandler::InitializeForTesting();
chromeos::NetworkHandler::Initialize();
ash::test::TestShellDelegate* shell_delegate =
new ash::test::TestShellDelegate();
ash::ShellInitParams init_params;
init_params.delegate = shell_delegate;
init_params.context_factory = context_factory;
ash::Shell::CreateInstance(init_params);
shell_delegate->test_session_state_delegate()->SetActiveUserSessionStarted(
true);
GetContext()->GetHost()->Show();
}
ViewEventTestPlatformPartChromeOS::~ViewEventTestPlatformPartChromeOS() {
ash::Shell::DeleteInstance();
chromeos::NetworkHandler::Shutdown();
chromeos::CrasAudioHandler::Shutdown();
chromeos::DBusThreadManager::Shutdown();
// Ash Shell can't just live on its own without a browser process, we need to
// also shut down the message center.
message_center::MessageCenter::Shutdown();
aura::Env::DeleteInstance();
}
} // namespace
// static
ViewEventTestPlatformPart* ViewEventTestPlatformPart::Create(
ui::ContextFactory* context_factory) {
return new ViewEventTestPlatformPartChromeOS(context_factory);
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/test/base/view_event_test_platform_part.h"
namespace {
// ViewEventTestPlatformPart implementation for toolkit-views on Mac.
class ViewEventTestPlatformPartMac : public ViewEventTestPlatformPart {
public:
ViewEventTestPlatformPartMac() {}
// Overridden from ViewEventTestPlatformPart:
virtual gfx::NativeWindow GetContext() OVERRIDE { return NULL; }
private:
DISALLOW_COPY_AND_ASSIGN(ViewEventTestPlatformPartMac);
};
} // namespace
// static
ViewEventTestPlatformPart* ViewEventTestPlatformPart::Create(
ui::ContextFactory* context_factory) {
return new ViewEventTestPlatformPartMac();
}
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