diff options
-rw-r--r-- | ash/test/ash_test_base.cc | 13 | ||||
-rw-r--r-- | ash/test/ash_test_base.h | 6 | ||||
-rw-r--r-- | chrome/browser/printing/print_preview_unit_test_base.cc | 1 | ||||
-rw-r--r-- | chrome/browser/sessions/session_service_unittest.cc | 1 | ||||
-rw-r--r-- | chrome/browser/sync/sync_global_error_unittest.cc | 4 | ||||
-rw-r--r-- | chrome/browser/ui/views/accessibility_event_router_views_unittest.cc | 36 | ||||
-rw-r--r-- | chrome/test/base/browser_with_test_window_test.cc | 23 | ||||
-rw-r--r-- | chrome/test/base/browser_with_test_window_test.h | 8 | ||||
-rw-r--r-- | content/browser/renderer_host/render_widget_host_view_aura_unittest.cc | 22 | ||||
-rw-r--r-- | content/test/test_renderer_host.cc | 22 | ||||
-rw-r--r-- | content/test/test_renderer_host.h | 12 | ||||
-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 |
19 files changed, 132 insertions, 212 deletions
diff --git a/ash/test/ash_test_base.cc b/ash/test/ash_test_base.cc index b4b39b4..ca7b9fc 100644 --- a/ash/test/ash_test_base.cc +++ b/ash/test/ash_test_base.cc @@ -28,9 +28,8 @@ void AshTestBase::SetUp() { // Creates Shell and hook with Desktop. TestShellDelegate* delegate = new TestShellDelegate; ash::Shell::CreateInstance(delegate); - - helper_.SetUp(); - helper_.InitRootWindow(Shell::GetPrimaryRootWindow()); + Shell::GetPrimaryRootWindow()->Show(); + Shell::GetPrimaryRootWindow()->SetHostSize(gfx::Size(800, 600)); // Disable animations during tests. ui::LayerAnimator::set_disable_animations_for_test(true); @@ -40,10 +39,9 @@ void AshTestBase::TearDown() { // Flush the message loop to finish pending release tasks. RunAllPendingInMessageLoop(); - helper_.TearDown(); - // Tear down the shell. Shell::DeleteInstance(); + aura::Env::DeleteInstance(); } void AshTestBase::ChangeMonitorConfig(float scale, @@ -57,7 +55,10 @@ void AshTestBase::ChangeMonitorConfig(float scale, } void AshTestBase::RunAllPendingInMessageLoop() { - helper_.RunAllPendingInMessageLoop(Shell::GetPrimaryRootWindow()); +#if !defined(OS_MACOSX) + message_loop_.RunAllPendingWithDispatcher( + aura::Env::GetInstance()->GetDispatcher()); +#endif } } // namespace test diff --git a/ash/test/ash_test_base.h b/ash/test/ash_test_base.h index a9eae00..c118a8a 100644 --- a/ash/test/ash_test_base.h +++ b/ash/test/ash_test_base.h @@ -8,8 +8,8 @@ #include "ash/shell.h" #include "base/compiler_specific.h" +#include "base/message_loop.h" #include "testing/gtest/include/gtest/gtest.h" -#include "ui/aura/test/aura_test_helper.h" namespace ash { namespace test { @@ -19,7 +19,7 @@ class AshTestBase : public testing::Test { AshTestBase(); virtual ~AshTestBase(); - MessageLoopForUI* message_loop() { return helper_.message_loop(); } + MessageLoopForUI* message_loop() { return &message_loop_; } // testing::Test: virtual void SetUp() OVERRIDE; @@ -33,7 +33,7 @@ class AshTestBase : public testing::Test { void RunAllPendingInMessageLoop(); private: - aura::test::AuraTestHelper helper_; + MessageLoopForUI message_loop_; DISALLOW_COPY_AND_ASSIGN(AshTestBase); }; diff --git a/chrome/browser/printing/print_preview_unit_test_base.cc b/chrome/browser/printing/print_preview_unit_test_base.cc index ec30a18..2647e18 100644 --- a/chrome/browser/printing/print_preview_unit_test_base.cc +++ b/chrome/browser/printing/print_preview_unit_test_base.cc @@ -39,4 +39,5 @@ void PrintPreviewUnitTestBase::TearDown() { TestingBrowserProcess* testing_browser_process = static_cast<TestingBrowserProcess*>(g_browser_process); testing_browser_process->SetLocalState(NULL); + BrowserWithTestWindowTest::TearDown(); } diff --git a/chrome/browser/sessions/session_service_unittest.cc b/chrome/browser/sessions/session_service_unittest.cc index 0c1a728..773ca70 100644 --- a/chrome/browser/sessions/session_service_unittest.cc +++ b/chrome/browser/sessions/session_service_unittest.cc @@ -69,6 +69,7 @@ class SessionServiceTest : public BrowserWithTestWindowTest, virtual void TearDown() { helper_.set_service(NULL); + BrowserWithTestWindowTest::TearDown(); } void UpdateNavigation(const SessionID& window_id, diff --git a/chrome/browser/sync/sync_global_error_unittest.cc b/chrome/browser/sync/sync_global_error_unittest.cc index 87c7c4d..fabd88a 100644 --- a/chrome/browser/sync/sync_global_error_unittest.cc +++ b/chrome/browser/sync/sync_global_error_unittest.cc @@ -62,6 +62,10 @@ class SyncGlobalErrorTest : public BrowserWithTestWindowTest { browser()->SetWindowForTesting(window()); } + virtual void TearDown() OVERRIDE { + testing::Test::TearDown(); + } + private: DISALLOW_COPY_AND_ASSIGN(SyncGlobalErrorTest); }; diff --git a/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc b/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc index 121c652..bc99b10 100644 --- a/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc +++ b/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc @@ -25,17 +25,7 @@ #include "ui/views/widget/widget_delegate.h" #if defined(USE_AURA) -#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 #if defined(TOOLKIT_VIEWS) @@ -144,32 +134,19 @@ class AccessibilityEventRouterViewsTest public content::NotificationObserver { public: AccessibilityEventRouterViewsTest() { -#if defined(USE_AURA) - test_input_method_.reset(new ui::test::DummyInputMethod); -#endif } virtual void SetUp() { views::ViewsDelegate::views_delegate = new AccessibilityViewsDelegate(); #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 } virtual void TearDown() { #if defined(USE_AURA) - test_stacking_client_.reset(); - test_activation_client_.reset(); - root_window_.reset(); + aura_test_helper_->TearDown(); #endif delete views::ViewsDelegate::views_delegate; views::ViewsDelegate::views_delegate = NULL; @@ -205,10 +182,7 @@ class AccessibilityEventRouterViewsTest std::string last_control_name_; std::string last_control_context_; #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 }; diff --git a/chrome/test/base/browser_with_test_window_test.cc b/chrome/test/base/browser_with_test_window_test.cc index 9def227..7f05efb 100644 --- a/chrome/test/base/browser_with_test_window_test.cc +++ b/chrome/test/base/browser_with_test_window_test.cc @@ -18,14 +18,7 @@ #include "content/test/test_renderer_host.h" #if defined(USE_AURA) -#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/gfx/screen.h" +#include "ui/aura/test/aura_test_helper.h" #endif using content::BrowserThread; @@ -51,23 +44,15 @@ void BrowserWithTestWindowTest::SetUp() { window_.reset(new TestBrowserWindow(browser())); browser_->SetWindowForTesting(window_.get()); #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())); - 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(&ui_loop_)); + aura_test_helper_->SetUp(); #endif // USE_AURA } void BrowserWithTestWindowTest::TearDown() { testing::Test::TearDown(); #if defined(USE_AURA) - test_activation_client_.reset(); - test_stacking_client_.reset(); - root_window_.reset(); - aura::Env::DeleteInstance(); + aura_test_helper_->TearDown(); #endif } diff --git a/chrome/test/base/browser_with_test_window_test.h b/chrome/test/base/browser_with_test_window_test.h index ffcc3e7..b2ae96e 100644 --- a/chrome/test/base/browser_with_test_window_test.h +++ b/chrome/test/base/browser_with_test_window_test.h @@ -22,10 +22,8 @@ class GURL; #if defined(USE_AURA) namespace aura { -class RootWindow; namespace test { -class TestActivationClient; -class TestStackingClient; +class AuraTestHelper; } } #endif @@ -124,9 +122,7 @@ class BrowserWithTestWindowTest : public testing::Test { content::RenderViewHostTestEnabler rvh_test_enabler_; #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<aura::test::AuraTestHelper> aura_test_helper_; #endif #if defined(OS_WIN) diff --git a/content/browser/renderer_host/render_widget_host_view_aura_unittest.cc b/content/browser/renderer_host/render_widget_host_view_aura_unittest.cc index fdbacec..7c5dbdb 100644 --- a/content/browser/renderer_host/render_widget_host_view_aura_unittest.cc +++ b/content/browser/renderer_host/render_widget_host_view_aura_unittest.cc @@ -14,16 +14,11 @@ #include "testing/gtest/include/gtest/gtest.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_screen.h" -#include "ui/aura/test/test_stacking_client.h" +#include "ui/aura/test/aura_test_helper.h" #include "ui/aura/test/test_window_delegate.h" #include "ui/aura/window.h" #include "ui/aura/window_observer.h" #include "ui/base/ui_base_types.h" -#include "ui/gfx/screen.h" class MockRenderWidgetHostDelegate : public content::RenderWidgetHostDelegate { public: @@ -67,12 +62,8 @@ class RenderWidgetHostViewAuraTest : public testing::Test { RenderWidgetHostViewAuraTest() {} virtual void SetUp() { - aura::Env::GetInstance()->SetMonitorManager(new aura::SingleMonitorManager); - root_window_.reset( - aura::MonitorManager::CreateRootWindowForPrimaryMonitor()); - gfx::Screen::SetInstance(new aura::TestScreen(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(); browser_context_.reset(new TestBrowserContext); content::MockRenderProcessHost* process_host = @@ -89,9 +80,7 @@ class RenderWidgetHostViewAuraTest : public testing::Test { delete widget_host_; browser_context_.reset(); - test_stacking_client_.reset(); - root_window_.reset(); - aura::Env::DeleteInstance(); + aura_test_helper_->TearDown(); message_loop_.DeleteSoon(FROM_HERE, browser_context_.release()); message_loop_.RunAllPending(); @@ -99,8 +88,7 @@ class RenderWidgetHostViewAuraTest : public testing::Test { protected: 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_; scoped_ptr<content::BrowserContext> browser_context_; MockRenderWidgetHostDelegate delegate_; diff --git a/content/test/test_renderer_host.cc b/content/test/test_renderer_host.cc index 1a00150..b08722509 100644 --- a/content/test/test_renderer_host.cc +++ b/content/test/test_renderer_host.cc @@ -15,13 +15,7 @@ #include "content/test/test_render_view_host_factory.h" #if defined(USE_AURA) -#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/gfx/screen.h" +#include "ui/aura/test/aura_test_helper.h" #endif namespace content { @@ -134,23 +128,17 @@ void RenderViewHostTestHarness::Reload() { void RenderViewHostTestHarness::SetUp() { #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())); - test_stacking_client_.reset( - new aura::test::TestStackingClient(root_window_.get())); -#endif // USE_AURA + aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); + aura_test_helper_->SetUp(); +#endif SetContents(CreateTestWebContents()); } void RenderViewHostTestHarness::TearDown() { SetContents(NULL); #if defined(USE_AURA) - test_stacking_client_.reset(); - root_window_.reset(); - aura::Env::DeleteInstance(); + aura_test_helper_->TearDown(); #endif - // Make sure that we flush any messages related to WebContentsImpl destruction // before we destroy the browser context. MessageLoop::current()->RunAllPending(); diff --git a/content/test/test_renderer_host.h b/content/test/test_renderer_host.h index cedfe16..4ecca64 100644 --- a/content/test/test_renderer_host.h +++ b/content/test/test_renderer_host.h @@ -13,13 +13,14 @@ #include "testing/gtest/include/gtest/gtest.h" #if defined(USE_AURA) +#include "ui/aura/test/aura_test_helper.h" +#endif + namespace aura { -class RootWindow; namespace test { -class TestStackingClient; +class AuraTestHelper; } } -#endif namespace content { @@ -154,7 +155,7 @@ class RenderViewHostTestHarness : public testing::Test { virtual void TearDown() OVERRIDE; #if defined(USE_AURA) - aura::RootWindow* root_window() const { return root_window_.get(); } + aura::RootWindow* root_window() { return aura_test_helper_->root_window(); } #endif // Replaces the RPH being used. @@ -174,8 +175,7 @@ class RenderViewHostTestHarness : public testing::Test { // overridden by subclasses. scoped_ptr<WebContents> contents_; #if defined(USE_AURA) - scoped_ptr<aura::RootWindow> root_window_; - scoped_ptr<aura::test::TestStackingClient> test_stacking_client_; + scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; #endif RenderViewHostTestEnabler rvh_test_enabler_; 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); }; |