diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-17 22:04:47 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-17 22:04:47 +0000 |
commit | 1dd1c1bdf2effafeeb883c8318e5cf02404ac6b2 (patch) | |
tree | 3e04b2dec007f582266c14a66e0470eae5a66d03 /ui/aura | |
parent | 9e306c39f14c440f67c78c6d7890a754f9a7d226 (diff) | |
download | chromium_src-1dd1c1bdf2effafeeb883c8318e5cf02404ac6b2.zip chromium_src-1dd1c1bdf2effafeeb883c8318e5cf02404ac6b2.tar.gz chromium_src-1dd1c1bdf2effafeeb883c8318e5cf02404ac6b2.tar.bz2 |
A bevy of Aura test changes:
- renames aura_shell_test_base to ash_test_base
- AshTestBase no longer subclasses AuraTestBase, instead now it and AuraTestBase both own a helper that does common initialization. This is necessary because in subsequent changes ash::Shell will be responsible for creating and owning its own RootWindow, whereas Aura code could have N RootWindows.
- Makes ScreenAura take a RootWindow instead of using RootWindow::GetInstance()
http://crbug.com/112131
TEST=none
Review URL: https://chromiumcodereview.appspot.com/9425015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@122597 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/aura')
-rw-r--r-- | ui/aura/aura.gyp | 2 | ||||
-rw-r--r-- | ui/aura/root_window.cc | 2 | ||||
-rw-r--r-- | ui/aura/screen_aura.cc | 8 | ||||
-rw-r--r-- | ui/aura/screen_aura.h | 6 | ||||
-rw-r--r-- | ui/aura/test/aura_test_base.cc | 42 | ||||
-rw-r--r-- | ui/aura/test/aura_test_base.h | 14 | ||||
-rw-r--r-- | ui/aura/test/aura_test_helper.cc | 61 | ||||
-rw-r--r-- | ui/aura/test/aura_test_helper.h | 45 |
8 files changed, 129 insertions, 51 deletions
diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp index 22d78b3..d2a246c 100644 --- a/ui/aura/aura.gyp +++ b/ui/aura/aura.gyp @@ -111,6 +111,8 @@ 'sources': [ 'test/aura_test_base.cc', 'test/aura_test_base.h', + 'test/aura_test_helper.cc', + 'test/aura_test_helper.h', 'test/event_generator.cc', 'test/event_generator.h', 'test/test_activation_client.cc', diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc index ffa6aa2..9ec0f8b 100644 --- a/ui/aura/root_window.cc +++ b/ui/aura/root_window.cc @@ -433,7 +433,7 @@ RootWindow::RootWindow() mouse_button_flags_(0), last_cursor_(kCursorNull), cursor_shown_(true), - screen_(new ScreenAura), + ALLOW_THIS_IN_INITIALIZER_LIST(screen_(new ScreenAura(this))), capture_window_(NULL), mouse_pressed_handler_(NULL), mouse_moved_handler_(NULL), diff --git a/ui/aura/screen_aura.cc b/ui/aura/screen_aura.cc index 36b493d..ef906fb 100644 --- a/ui/aura/screen_aura.cc +++ b/ui/aura/screen_aura.cc @@ -11,14 +11,14 @@ namespace aura { -ScreenAura::ScreenAura() { +ScreenAura::ScreenAura(RootWindow* root_window) : root_window_(root_window) { } ScreenAura::~ScreenAura() { } gfx::Point ScreenAura::GetCursorScreenPointImpl() { - return RootWindow::GetInstance()->last_mouse_location(); + return root_window_->last_mouse_location(); } gfx::Rect ScreenAura::GetMonitorWorkAreaNearestWindowImpl( @@ -42,11 +42,11 @@ gfx::Rect ScreenAura::GetMonitorAreaNearestPointImpl(const gfx::Point& point) { gfx::NativeWindow ScreenAura::GetWindowAtCursorScreenPointImpl() { const gfx::Point point = GetCursorScreenPoint(); - return RootWindow::GetInstance()->GetTopWindowContainingPoint(point); + return root_window_->GetTopWindowContainingPoint(point); } gfx::Rect ScreenAura::GetBounds() { - return gfx::Rect(aura::RootWindow::GetInstance()->GetHostSize()); + return gfx::Rect(root_window_->GetHostSize()); } gfx::Rect ScreenAura::GetWorkAreaBounds() { diff --git a/ui/aura/screen_aura.h b/ui/aura/screen_aura.h index e27b462..ee1540d 100644 --- a/ui/aura/screen_aura.h +++ b/ui/aura/screen_aura.h @@ -13,11 +13,13 @@ namespace aura { +class RootWindow; + // Aura implementation of gfx::Screen. Implemented here to avoid circular // dependencies. class AURA_EXPORT ScreenAura : public gfx::Screen { public: - ScreenAura(); + explicit ScreenAura(RootWindow* root_window); virtual ~ScreenAura(); void set_work_area_insets(const gfx::Insets& insets) { @@ -48,6 +50,8 @@ class AURA_EXPORT ScreenAura : public gfx::Screen { // Insets for the work area. gfx::Insets work_area_insets_; + RootWindow* root_window_; + DISALLOW_COPY_AND_ASSIGN(ScreenAura); }; diff --git a/ui/aura/test/aura_test_base.cc b/ui/aura/test/aura_test_base.cc index da126e8..57316c7 100644 --- a/ui/aura/test/aura_test_base.cc +++ b/ui/aura/test/aura_test_base.cc @@ -4,66 +4,38 @@ #include "ui/aura/test/aura_test_base.h" -#if defined(OS_WIN) -#include <ole2.h> -#endif - #include "ui/aura/env.h" #include "ui/aura/root_window.h" -#include "ui/gfx/compositor/layer_animator.h" namespace aura { namespace test { -AuraTestBase::AuraTestBase() - : setup_called_(false), - teardown_called_(false) { -#if defined(OS_WIN) - OleInitialize(NULL); -#endif - - RootWindow::GetInstance()->Show(); - // Ensure width != height so tests won't confuse them. - RootWindow::GetInstance()->SetHostSize(gfx::Size(800, 600)); - - // Disable animations during tests. - ui::LayerAnimator::set_disable_animations_for_test(true); +AuraTestBase::AuraTestBase() { + helper_.InitRootWindow(RootWindow::GetInstance()); } AuraTestBase::~AuraTestBase() { -#if defined(OS_WIN) - OleUninitialize(); -#endif - CHECK(setup_called_) - << "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"; - // Flush the message loop because we have pending release tasks // and these tasks if un-executed would upset Valgrind. - RunAllPendingInMessageLoop(); + helper_.RunAllPendingInMessageLoop(RootWindow::GetInstance()); // Ensure that we don't use the previously-allocated static RootWindow object // later -- on Linux, it holds a reference to our message loop's X connection. - aura::RootWindow::DeleteInstance(); - aura::Env::DeleteInstance(); + RootWindow::DeleteInstance(); } void AuraTestBase::SetUp() { testing::Test::SetUp(); - setup_called_ = true; + helper_.SetUp(); } void AuraTestBase::TearDown() { - teardown_called_ = true; + helper_.TearDown(); testing::Test::TearDown(); } void AuraTestBase::RunAllPendingInMessageLoop() { -#if !defined(OS_MACOSX) - message_loop_.RunAllPendingWithDispatcher( - RootWindow::GetInstance()->GetDispatcher()); -#endif + helper_.RunAllPendingInMessageLoop(RootWindow::GetInstance()); } } // namespace test diff --git a/ui/aura/test/aura_test_base.h b/ui/aura/test/aura_test_base.h index 8986a2f..a35f777 100644 --- a/ui/aura/test/aura_test_base.h +++ b/ui/aura/test/aura_test_base.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -8,34 +8,28 @@ #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 { namespace test { -class TestStackingClient; - // A base class for aura unit tests. +// TODO(beng): Instances of this test will create and own a RootWindow. class AuraTestBase : public testing::Test { public: AuraTestBase(); virtual ~AuraTestBase(); - TestStackingClient* GetTestStackingClient(); - // testing::Test: virtual void SetUp() OVERRIDE; virtual void TearDown() OVERRIDE; protected: - // Flushes message loop. void RunAllPendingInMessageLoop(); private: - MessageLoopForUI message_loop_; - bool setup_called_; - bool teardown_called_; + 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 new file mode 100644 index 0000000..cdc513c --- /dev/null +++ b/ui/aura/test/aura_test_helper.cc @@ -0,0 +1,61 @@ +// Copyright (c) 2012 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 "ui/aura/test/aura_test_helper.h" + +#if defined(OS_WIN) +#include <ole2.h> +#endif + +#include "ui/aura/env.h" +#include "ui/aura/root_window.h" +#include "ui/gfx/compositor/layer_animator.h" + +namespace aura { +namespace test { + +AuraTestHelper::AuraTestHelper() + : setup_called_(false), + teardown_called_(false) { +#if defined(OS_WIN) + OleInitialize(NULL); +#endif + + // Disable animations during tests. + ui::LayerAnimator::set_disable_animations_for_test(true); +} + +AuraTestHelper::~AuraTestHelper() { +#if defined(OS_WIN) + OleUninitialize(); +#endif + CHECK(setup_called_) + << "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; +} + +void AuraTestHelper::TearDown() { + teardown_called_ = true; +} + +void AuraTestHelper::RunAllPendingInMessageLoop(RootWindow* root_window) { +#if !defined(OS_MACOSX) + message_loop_.RunAllPendingWithDispatcher(root_window->GetDispatcher()); +#endif +} + +} // namespace test +} // namespace aura diff --git a/ui/aura/test/aura_test_helper.h b/ui/aura/test/aura_test_helper.h new file mode 100644 index 0000000..86ed52e --- /dev/null +++ b/ui/aura/test/aura_test_helper.h @@ -0,0 +1,45 @@ +// Copyright (c) 2012 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 UI_AURA_TEST_AURA_TEST_HELPER_H_ +#define UI_AURA_TEST_AURA_TEST_HELPER_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/message_loop.h" + +namespace aura { +class RootWindow; +namespace test { + +// 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. +class AuraTestHelper { + public: + AuraTestHelper(); + virtual ~AuraTestHelper(); + + // Initializes (shows and sizes) the provided RootWindow for use in tests. + void InitRootWindow(RootWindow* root_window); + + void SetUp(); + void TearDown(); + + // Flushes message loop. + void RunAllPendingInMessageLoop(RootWindow* root_window); + + private: + MessageLoopForUI message_loop_; + bool setup_called_; + bool teardown_called_; + + DISALLOW_COPY_AND_ASSIGN(AuraTestHelper); +}; + +} // namespace test +} // namespace aura + +#endif // UI_AURA_TEST_AURA_TEST_HELPER_H_ |