diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-30 02:19:17 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-30 02:19:17 +0000 |
commit | eff8b2f8d3c4b58b9ea4924f57be9a9612fd8524 (patch) | |
tree | da59c3e2adbb49cd0a59c90265a154fb197aec56 /ui | |
parent | 46e51dfab2ebc1f139d306182be3d18810141f78 (diff) | |
download | chromium_src-eff8b2f8d3c4b58b9ea4924f57be9a9612fd8524.zip chromium_src-eff8b2f8d3c4b58b9ea4924f57be9a9612fd8524.tar.gz chromium_src-eff8b2f8d3c4b58b9ea4924f57be9a9612fd8524.tar.bz2 |
Use AuraTestHelper to initialize aura environment in test
- Moved common initialization code to AuraTestHelper.
- Removed AuraTestHelper from ash_test_base because
it should use ash environment.
- Changed tests to use AuraTestHelper
BUG=none
TEST=none
Review URL: https://chromiumcodereview.appspot.com/10452039
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139454 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/aura/aura.gyp | 1 | ||||
-rw-r--r-- | ui/aura/test/aura_test_base.cc | 27 | ||||
-rw-r--r-- | ui/aura/test/aura_test_base.h | 9 | ||||
-rw-r--r-- | ui/aura/test/aura_test_helper.cc | 51 | ||||
-rw-r--r-- | ui/aura/test/aura_test_helper.h | 37 | ||||
-rw-r--r-- | ui/views/test/views_test_base.cc | 32 | ||||
-rw-r--r-- | ui/views/test/views_test_base.h | 15 | ||||
-rw-r--r-- | ui/views/widget/native_widget_aura_unittest.cc | 24 |
8 files changed, 89 insertions, 107 deletions
diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp index 5bff221..b77e7e7 100644 --- a/ui/aura/aura.gyp +++ b/ui/aura/aura.gyp @@ -136,6 +136,7 @@ '../../skia/skia.gyp:skia', '../../testing/gtest.gyp:gtest', '../ui.gyp:ui', + '../ui.gyp:ui_test_support', 'aura', 'test_support_aura_pak', ], diff --git a/ui/aura/test/aura_test_base.cc b/ui/aura/test/aura_test_base.cc index 9784981..e1fe5b8 100644 --- a/ui/aura/test/aura_test_base.cc +++ b/ui/aura/test/aura_test_base.cc @@ -4,16 +4,8 @@ #include "ui/aura/test/aura_test_base.h" -#include "ui/aura/env.h" -#include "ui/aura/monitor_manager.h" -#include "ui/aura/root_window.h" -#include "ui/aura/single_monitor_manager.h" -#include "ui/aura/test/test_screen.h" -#include "ui/aura/test/test_stacking_client.h" -#include "ui/aura/ui_controls_aura.h" +#include "ui/aura/test/aura_test_helper.h" #include "ui/base/gestures/gesture_configuration.h" -#include "ui/gfx/screen.h" -#include "ui/ui_controls/ui_controls.h" namespace aura { namespace test { @@ -47,15 +39,8 @@ void AuraTestBase::SetUp() { ui::GestureConfiguration::set_points_buffered_for_velocity(10); ui::GestureConfiguration::set_rail_break_proportion(15); ui::GestureConfiguration::set_rail_start_proportion(2); - - Env::GetInstance()->SetMonitorManager(new SingleMonitorManager); - root_window_.reset(Env::GetInstance()->monitor_manager()-> - CreateRootWindowForPrimaryMonitor()); - gfx::Screen::SetInstance(new aura::TestScreen(root_window_.get())); - ui_controls::InstallUIControlsAura(CreateUIControlsAura(root_window_.get())); - helper_.InitRootWindow(root_window()); - helper_.SetUp(); - stacking_client_.reset(new TestStackingClient(root_window())); + helper_.reset(new AuraTestHelper(&message_loop_)); + helper_->SetUp(); } void AuraTestBase::TearDown() { @@ -63,14 +48,12 @@ void AuraTestBase::TearDown() { // and these tasks if un-executed would upset Valgrind. RunAllPendingInMessageLoop(); - stacking_client_.reset(); - helper_.TearDown(); - root_window_.reset(); + helper_->TearDown(); testing::Test::TearDown(); } void AuraTestBase::RunAllPendingInMessageLoop() { - helper_.RunAllPendingInMessageLoop(root_window()); + helper_->RunAllPendingInMessageLoop(); } } // namespace test diff --git a/ui/aura/test/aura_test_base.h b/ui/aura/test/aura_test_base.h index 14bd3f9..5108e20 100644 --- a/ui/aura/test/aura_test_base.h +++ b/ui/aura/test/aura_test_base.h @@ -8,13 +8,13 @@ #include "base/compiler_specific.h" #include "base/basictypes.h" +#include "base/message_loop.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/aura/test/aura_test_helper.h" namespace aura { class RootWindow; namespace test { -class TestStackingClient; // A base class for aura unit tests. // TODO(beng): Instances of this test will create and own a RootWindow. @@ -30,12 +30,11 @@ class AuraTestBase : public testing::Test { protected: void RunAllPendingInMessageLoop(); - RootWindow* root_window() { return root_window_.get(); } + RootWindow* root_window() { return helper_->root_window(); } private: - AuraTestHelper helper_; - scoped_ptr<RootWindow> root_window_; - scoped_ptr<TestStackingClient> stacking_client_; + MessageLoopForUI message_loop_; + scoped_ptr<AuraTestHelper> helper_; DISALLOW_COPY_AND_ASSIGN(AuraTestBase); }; diff --git a/ui/aura/test/aura_test_helper.cc b/ui/aura/test/aura_test_helper.cc index f381689..c4e094c 100644 --- a/ui/aura/test/aura_test_helper.cc +++ b/ui/aura/test/aura_test_helper.cc @@ -4,16 +4,31 @@ #include "ui/aura/test/aura_test_helper.h" +#include "base/message_loop.h" #include "ui/aura/env.h" #include "ui/aura/root_window.h" #include "ui/compositor/layer_animator.h" +#include "ui/gfx/screen.h" +#include "ui/aura/client/aura_constants.h" +#include "ui/aura/single_monitor_manager.h" +#include "ui/aura/monitor_manager.h" +#include "ui/aura/test/test_screen.h" +#include "ui/aura/test/test_activation_client.h" +#include "ui/aura/test/test_stacking_client.h" +#include "ui/aura/ui_controls_aura.h" +#include "ui/base/test/dummy_input_method.h" +#include "ui/ui_controls/ui_controls.h" namespace aura { namespace test { -AuraTestHelper::AuraTestHelper() + +AuraTestHelper::AuraTestHelper(MessageLoopForUI* message_loop) : setup_called_(false), - teardown_called_(false) { + teardown_called_(false), + owns_root_window_(false) { + DCHECK(message_loop); + message_loop_ = message_loop; // Disable animations during tests. ui::LayerAnimator::set_disable_animations_for_test(true); } @@ -23,26 +38,40 @@ AuraTestHelper::~AuraTestHelper() { << "You have overridden SetUp but never called super class's SetUp"; CHECK(teardown_called_) << "You have overridden TearDown but never called super class's TearDown"; - aura::Env::DeleteInstance(); -} - -void AuraTestHelper::InitRootWindow(RootWindow* root_window) { - root_window->Show(); - // Ensure width != height so tests won't confuse them. - root_window->SetHostSize(gfx::Size(800, 600)); } void AuraTestHelper::SetUp() { setup_called_ = true; + Env::GetInstance()->SetMonitorManager(new SingleMonitorManager); + root_window_.reset(aura::MonitorManager::CreateRootWindowForPrimaryMonitor()); + gfx::Screen::SetInstance(new aura::TestScreen(root_window_.get())); + ui_controls::InstallUIControlsAura(CreateUIControlsAura(root_window_.get())); + + stacking_client_.reset(new TestStackingClient(root_window_.get())); + test_activation_client_.reset( + new aura::test::TestActivationClient(root_window_.get())); + test_input_method_.reset(new ui::test::DummyInputMethod); + root_window_->SetProperty( + aura::client::kRootWindowInputMethodKey, + test_input_method_.get()); + + root_window_->Show(); + // Ensure width != height so tests won't confuse them. + root_window_->SetHostSize(gfx::Size(800, 600)); } void AuraTestHelper::TearDown() { teardown_called_ = true; + test_input_method_.reset(); + stacking_client_.reset(); + test_activation_client_.reset(); + root_window_.reset(); + aura::Env::DeleteInstance(); } -void AuraTestHelper::RunAllPendingInMessageLoop(RootWindow* root_window) { +void AuraTestHelper::RunAllPendingInMessageLoop() { #if !defined(OS_MACOSX) - message_loop_.RunAllPendingWithDispatcher( + message_loop_->RunAllPendingWithDispatcher( Env::GetInstance()->GetDispatcher()); #endif } diff --git a/ui/aura/test/aura_test_helper.h b/ui/aura/test/aura_test_helper.h index 05dff10..4d2fa46 100644 --- a/ui/aura/test/aura_test_helper.h +++ b/ui/aura/test/aura_test_helper.h @@ -7,40 +7,53 @@ #pragma once #include "base/basictypes.h" -#include "base/message_loop.h" +#include "base/memory/scoped_ptr.h" #if defined(OS_WIN) #include "ui/base/win/scoped_ole_initializer.h" #endif +class MessageLoopForUI; + +namespace ui { +class InputMethod; +} + namespace aura { class RootWindow; namespace test { +class TestStackingClient; +class TestActivationClient; // A helper class owned by tests that does common initialization required for -// Aura use. This class must create no special environment (e.g. no RootWindow) -// since different users will want their own specific environments and will -// set that up themselves. +// Aura use. This class creates a root window with clients and other objects +// that are necessary to run test on Aura. class AuraTestHelper { public: - AuraTestHelper(); - virtual ~AuraTestHelper(); - - // Initializes (shows and sizes) the provided RootWindow for use in tests. - void InitRootWindow(RootWindow* root_window); + explicit AuraTestHelper(MessageLoopForUI* message_loop); + ~AuraTestHelper(); + // Creates and initializes (shows and sizes) the RootWindow for use in tests. void SetUp(); + + // Clean up objects that are created for tests. This also delete + // aura::Env object. void TearDown(); // Flushes message loop. - void RunAllPendingInMessageLoop(RootWindow* root_window); + void RunAllPendingInMessageLoop(); - MessageLoopForUI* message_loop() { return &message_loop_; } + RootWindow* root_window() { return root_window_.get(); } private: - MessageLoopForUI message_loop_; + MessageLoopForUI* message_loop_; bool setup_called_; bool teardown_called_; + bool owns_root_window_; + scoped_ptr<RootWindow> root_window_; + scoped_ptr<TestStackingClient> stacking_client_; + scoped_ptr<TestActivationClient> test_activation_client_; + scoped_ptr<ui::InputMethod> test_input_method_; #if defined(OS_WIN) ui::ScopedOleInitializer ole_initializer_; diff --git a/ui/views/test/views_test_base.cc b/ui/views/test/views_test_base.cc index c58f091..329c9f3 100644 --- a/ui/views/test/views_test_base.cc +++ b/ui/views/test/views_test_base.cc @@ -5,18 +5,8 @@ #include "ui/views/test/views_test_base.h" #if defined(USE_AURA) -#include "base/compiler_specific.h" -#include "ui/aura/client/aura_constants.h" #include "ui/aura/env.h" -#include "ui/aura/monitor_manager.h" -#include "ui/aura/root_window.h" -#include "ui/aura/single_monitor_manager.h" -#include "ui/aura/test/test_activation_client.h" -#include "ui/aura/test/test_screen.h" -#include "ui/aura/test/test_stacking_client.h" -#include "ui/base/ime/input_method.h" -#include "ui/base/test/dummy_input_method.h" -#include "ui/gfx/screen.h" +#include "ui/aura/test/aura_test_helper.h" #endif namespace views { @@ -24,9 +14,6 @@ namespace views { ViewsTestBase::ViewsTestBase() : setup_called_(false), teardown_called_(false) { -#if defined(USE_AURA) - test_input_method_.reset(new ui::test::DummyInputMethod); -#endif } ViewsTestBase::~ViewsTestBase() { @@ -42,16 +29,8 @@ void ViewsTestBase::SetUp() { if (!views_delegate_.get()) views_delegate_.reset(new TestViewsDelegate()); #if defined(USE_AURA) - aura::Env::GetInstance()->SetMonitorManager(new aura::SingleMonitorManager); - root_window_.reset(aura::MonitorManager::CreateRootWindowForPrimaryMonitor()); - gfx::Screen::SetInstance(new aura::TestScreen(root_window_.get())); - root_window_->SetProperty( - aura::client::kRootWindowInputMethodKey, - test_input_method_.get()); - test_activation_client_.reset( - new aura::test::TestActivationClient(root_window_.get())); - test_stacking_client_.reset( - new aura::test::TestStackingClient(root_window_.get())); + aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); + aura_test_helper_->SetUp(); #endif // USE_AURA } @@ -63,10 +42,7 @@ void ViewsTestBase::TearDown() { views_delegate_.reset(); testing::Test::TearDown(); #if defined(USE_AURA) - test_stacking_client_.reset(); - test_activation_client_.reset(); - root_window_.reset(); - aura::Env::DeleteInstance(); + aura_test_helper_->TearDown(); #endif } diff --git a/ui/views/test/views_test_base.h b/ui/views/test/views_test_base.h index 71f6bbd..be94a0a 100644 --- a/ui/views/test/views_test_base.h +++ b/ui/views/test/views_test_base.h @@ -16,21 +16,13 @@ #endif namespace aura { -class RootWindow; namespace test { -class TestActivationClient; -class TestStackingClient; +class AuraTestHelper; } } -namespace ui { -class InputMethod; -} - namespace views { -class TestViewsDelegate; - // A base class for views unit test. It creates a message loop necessary // to drive UI events and takes care of OLE initialization for windows. class ViewsTestBase : public testing::Test { @@ -57,10 +49,7 @@ class ViewsTestBase : public testing::Test { MessageLoopForUI message_loop_; scoped_ptr<TestViewsDelegate> views_delegate_; #if defined(USE_AURA) - scoped_ptr<aura::RootWindow> root_window_; - scoped_ptr<aura::test::TestActivationClient> test_activation_client_; - scoped_ptr<aura::test::TestStackingClient> test_stacking_client_; - scoped_ptr<ui::InputMethod> test_input_method_; + scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; #endif bool setup_called_; bool teardown_called_; diff --git a/ui/views/widget/native_widget_aura_unittest.cc b/ui/views/widget/native_widget_aura_unittest.cc index 8778462..ca10d97 100644 --- a/ui/views/widget/native_widget_aura_unittest.cc +++ b/ui/views/widget/native_widget_aura_unittest.cc @@ -13,8 +13,7 @@ #include "ui/aura/monitor_manager.h" #include "ui/aura/root_window.h" #include "ui/aura/single_monitor_manager.h" -#include "ui/aura/test/test_screen.h" -#include "ui/aura/test/test_stacking_client.h" +#include "ui/aura/test/aura_test_helper.h" #include "ui/aura/window.h" #include "ui/gfx/screen.h" #include "ui/views/widget/root_view.h" @@ -38,29 +37,22 @@ class NativeWidgetAuraTest : public testing::Test { // testing::Test overrides: virtual void SetUp() OVERRIDE { - aura::Env::GetInstance()->SetMonitorManager(new aura::SingleMonitorManager); - root_window_.reset( - aura::MonitorManager::CreateRootWindowForPrimaryMonitor()); - gfx::Screen::SetInstance(new aura::TestScreen(root_window_.get())); - root_window_->SetBounds(gfx::Rect(0, 0, 640, 480)); - root_window_->SetHostSize(gfx::Size(640, 480)); - test_stacking_client_.reset( - new aura::test::TestStackingClient(root_window_.get())); + aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); + aura_test_helper_->SetUp(); + root_window()->SetBounds(gfx::Rect(0, 0, 640, 480)); + root_window()->SetHostSize(gfx::Size(640, 480)); } virtual void TearDown() OVERRIDE { message_loop_.RunAllPending(); - test_stacking_client_.reset(); - root_window_.reset(); - aura::Env::DeleteInstance(); + aura_test_helper_->TearDown(); } protected: - aura::RootWindow* root_window() { return root_window_.get(); } + aura::RootWindow* root_window() { return aura_test_helper_->root_window(); } private: MessageLoopForUI message_loop_; - scoped_ptr<aura::RootWindow> root_window_; - scoped_ptr<aura::test::TestStackingClient> test_stacking_client_; + scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; DISALLOW_COPY_AND_ASSIGN(NativeWidgetAuraTest); }; |