diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-29 19:06:32 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-29 19:06:32 +0000 |
commit | db9131601d13e57554df51916199eba371b7264b (patch) | |
tree | 28726f42e5ab82c95ff79a0167e1d71ab9682959 /ash | |
parent | f56b47dc4f7b68cd627d8cb874879bf80e01e50d (diff) | |
download | chromium_src-db9131601d13e57554df51916199eba371b7264b.zip chromium_src-db9131601d13e57554df51916199eba371b7264b.tar.gz chromium_src-db9131601d13e57554df51916199eba371b7264b.tar.bz2 |
Convert a bunch of AuraTestBase users to AshTestBase.
http://crbug.com/112131
TEST=none
Review URL: https://chromiumcodereview.appspot.com/9522012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124220 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/ash.gyp | 1 | ||||
-rw-r--r-- | ash/ime/input_method_event_filter_unittest.cc | 15 | ||||
-rw-r--r-- | ash/shell.cc | 11 | ||||
-rw-r--r-- | ash/shell.h | 2 | ||||
-rw-r--r-- | ash/shell/shell_main.cc | 5 | ||||
-rw-r--r-- | ash/shell_delegate.h | 6 | ||||
-rw-r--r-- | ash/test/ash_test_base.cc | 10 | ||||
-rw-r--r-- | ash/test/ash_test_base.h | 4 | ||||
-rw-r--r-- | ash/test/test_shell_delegate.cc | 18 | ||||
-rw-r--r-- | ash/test/test_shell_delegate.h | 9 | ||||
-rw-r--r-- | ash/wm/base_layout_manager_unittest.cc | 18 | ||||
-rw-r--r-- | ash/wm/root_window_event_filter_unittest.cc | 55 | ||||
-rw-r--r-- | ash/wm/toplevel_layout_manager_unittest.cc | 20 | ||||
-rw-r--r-- | ash/wm/workspace/workspace_manager_unittest.cc | 59 | ||||
-rw-r--r-- | ash/wm/workspace_controller_unittest.cc | 72 |
15 files changed, 134 insertions, 171 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp index 4da6364..d657c0e 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -300,7 +300,6 @@ 'wm/window_modality_controller_unittest.cc', 'wm/workspace/workspace_manager_unittest.cc', 'wm/workspace/workspace_window_resizer_unittest.cc', - 'wm/workspace_controller_unittest.cc', '<(SHARED_INTERMEDIATE_DIR)/ui/gfx/gfx_resources.rc', '<(SHARED_INTERMEDIATE_DIR)/ui/ui_resources/ui_resources.rc', diff --git a/ash/ime/input_method_event_filter_unittest.cc b/ash/ime/input_method_event_filter_unittest.cc index e72805b..37f3816 100644 --- a/ash/ime/input_method_event_filter_unittest.cc +++ b/ash/ime/input_method_event_filter_unittest.cc @@ -12,7 +12,6 @@ #include "testing/gtest/include/gtest/gtest.h" #include "ui/aura/client/aura_constants.h" #include "ui/aura/root_window.h" -#include "ui/aura/test/aura_test_base.h" #include "ui/aura/test/event_generator.h" #include "ui/aura/test/test_event_filter.h" #include "ui/aura/test/test_windows.h" @@ -26,23 +25,14 @@ DISABLED_TestInputMethodKeyEventPropagation #endif namespace ash { -namespace test { -typedef aura::test::AuraTestBase InputMethodEventFilterTestWithoutShell; -typedef AshTestBase InputMethodEventFilterTest; +typedef test::AshTestBase InputMethodEventFilterTest; // Tests if InputMethodEventFilter adds a window property on its construction. -TEST_F(InputMethodEventFilterTestWithoutShell, TestInputMethodProperty) { +TEST_F(InputMethodEventFilterTest, TestInputMethodProperty) { aura::RootWindow* root_window = Shell::GetRootWindow(); - scoped_ptr<internal::RootWindowEventFilter> root_filter( - new internal::RootWindowEventFilter); - EXPECT_FALSE( - root_window->GetProperty(aura::client::kRootWindowInputMethodKey)); - internal::InputMethodEventFilter ime_filter; - root_filter->AddFilter(&ime_filter); EXPECT_TRUE( root_window->GetProperty(aura::client::kRootWindowInputMethodKey)); - root_filter->RemoveFilter(&ime_filter); } // Tests if InputMethodEventFilter dispatches a ui::ET_TRANSLATED_KEY_* event to @@ -87,5 +77,4 @@ TEST_F(InputMethodEventFilterTest, TestInputMethodKeyEventPropagation) { window.reset(); } -} // namespace test } // namespace ash diff --git a/ash/shell.cc b/ash/shell.cc index 4eb8a21..8f93069 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -239,6 +239,14 @@ internal::RootWindowLayoutManager* Shell::TestApi::root_window_layout() { return shell_->root_window_layout_; } +internal::InputMethodEventFilter* Shell::TestApi::input_method_event_filter() { + return shell_->input_method_filter_.get(); +} + +internal::WorkspaceController* Shell::TestApi::workspace_controller() { + return shell_->workspace_controller_.get(); +} + //////////////////////////////////////////////////////////////////////////////// // Shell, public: @@ -353,7 +361,8 @@ void Shell::Init() { // Window mode must be set before computing containers or layout managers. CommandLine* command_line = CommandLine::ForCurrentProcess(); - window_mode_ = ComputeWindowMode(command_line); + if (!delegate_.get() || !delegate_->GetOverrideWindowMode(&window_mode_)) + window_mode_ = ComputeWindowMode(command_line); aura::RootWindow* root_window = GetRootWindow(); root_window->SetCursor(aura::kCursorPointer); diff --git a/ash/shell.h b/ash/shell.h index ab26d49..2413c4b 100644 --- a/ash/shell.h +++ b/ash/shell.h @@ -101,6 +101,8 @@ class ASH_EXPORT Shell { WindowMode ComputeWindowMode(CommandLine* cmd) const; internal::RootWindowLayoutManager* root_window_layout(); + internal::InputMethodEventFilter* input_method_event_filter(); + internal::WorkspaceController* workspace_controller(); private: Shell* shell_; // not owned diff --git a/ash/shell/shell_main.cc b/ash/shell/shell_main.cc index 0f2d5b4..34611d3 100644 --- a/ash/shell/shell_main.cc +++ b/ash/shell/shell_main.cc @@ -213,6 +213,11 @@ class ShellDelegateImpl : public ash::ShellDelegate { return NULL; } + virtual bool GetOverrideWindowMode( + ash::Shell::WindowMode* window_mode) OVERRIDE { + return false; + } + private: // Used to update Launcher. Owned by main. WindowWatcher* watcher_; diff --git a/ash/shell_delegate.h b/ash/shell_delegate.h index 123310b..08caa35 100644 --- a/ash/shell_delegate.h +++ b/ash/shell_delegate.h @@ -9,6 +9,7 @@ #include <vector> #include "ash/ash_export.h" +#include "ash/shell.h" #include "base/callback.h" #include "base/string16.h" @@ -89,6 +90,11 @@ class ASH_EXPORT ShellDelegate { // Creates a system-tray delegate. Shell takes ownership of the delegate. virtual SystemTrayDelegate* CreateSystemTrayDelegate(SystemTray* tray) = 0; + + // Returns true if the delegate wants to override the window mode. Used only + // by testing. Returning false causes the shell to determine the default. + // TODO(beng): This can probably be removed once we only have one window mode. + virtual bool GetOverrideWindowMode(Shell::WindowMode* window_mode) = 0; }; } // namespace ash diff --git a/ash/test/ash_test_base.cc b/ash/test/ash_test_base.cc index c562330..8b0f23e 100644 --- a/ash/test/ash_test_base.cc +++ b/ash/test/ash_test_base.cc @@ -26,7 +26,11 @@ void AshTestBase::SetUp() { helper_.SetUp(); // Creates Shell and hook with Desktop. - ash::Shell::CreateInstance(new TestShellDelegate); + TestShellDelegate* delegate = new TestShellDelegate; + Shell::WindowMode window_mode = Shell::MODE_OVERLAPPING; + if (GetOverrideWindowMode(&window_mode)) + delegate->SetOverrideWindowMode(window_mode); + ash::Shell::CreateInstance(delegate); // Disable animations during tests. ui::LayerAnimator::set_disable_animations_for_test(true); @@ -42,6 +46,10 @@ void AshTestBase::TearDown() { helper_.TearDown(); } +bool AshTestBase::GetOverrideWindowMode(Shell::WindowMode* window_mode) { + return false; +} + void AshTestBase::RunAllPendingInMessageLoop() { helper_.RunAllPendingInMessageLoop(Shell::GetRootWindow()); } diff --git a/ash/test/ash_test_base.h b/ash/test/ash_test_base.h index ef9c187..85a1f35 100644 --- a/ash/test/ash_test_base.h +++ b/ash/test/ash_test_base.h @@ -6,6 +6,7 @@ #define ASH_TEST_ASH_TEST_BASE_H_ #pragma once +#include "ash/shell.h" #include "base/compiler_specific.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/aura/test/aura_test_helper.h" @@ -23,6 +24,9 @@ class AshTestBase : public testing::Test { virtual void TearDown() OVERRIDE; protected: + // Overridden by test cases to specify what window mode to run the shell in. + virtual bool GetOverrideWindowMode(Shell::WindowMode* window_mode); + void RunAllPendingInMessageLoop(); private: diff --git a/ash/test/test_shell_delegate.cc b/ash/test/test_shell_delegate.cc index 719bd44..883f073 100644 --- a/ash/test/test_shell_delegate.cc +++ b/ash/test/test_shell_delegate.cc @@ -15,12 +15,19 @@ namespace ash { namespace test { -TestShellDelegate::TestShellDelegate() { +TestShellDelegate::TestShellDelegate() + : override_window_mode_(false), + window_mode_(Shell::MODE_OVERLAPPING) { } TestShellDelegate::~TestShellDelegate() { } +void TestShellDelegate::SetOverrideWindowMode(Shell::WindowMode window_mode) { + override_window_mode_ = true; + window_mode_ = window_mode; +} + views::Widget* TestShellDelegate::CreateStatusArea() { return NULL; } @@ -70,5 +77,14 @@ SystemTrayDelegate* TestShellDelegate::CreateSystemTrayDelegate( SystemTray* tray) { return NULL; } + +bool TestShellDelegate::GetOverrideWindowMode(Shell::WindowMode* window_mode) { + if (override_window_mode_) { + *window_mode = window_mode_; + return true; + } + return false; +} + } // namespace test } // namespace ash diff --git a/ash/test/test_shell_delegate.h b/ash/test/test_shell_delegate.h index 1a621fd..9455da0 100644 --- a/ash/test/test_shell_delegate.h +++ b/ash/test/test_shell_delegate.h @@ -17,6 +17,8 @@ class TestShellDelegate : public ShellDelegate { TestShellDelegate(); virtual ~TestShellDelegate(); + void SetOverrideWindowMode(Shell::WindowMode window_mode); + // Overridden from ShellDelegate: virtual views::Widget* CreateStatusArea() OVERRIDE; #if defined(OS_CHROMEOS) @@ -33,6 +35,13 @@ class TestShellDelegate : public ShellDelegate { virtual LauncherDelegate* CreateLauncherDelegate( ash::LauncherModel* model) OVERRIDE; virtual SystemTrayDelegate* CreateSystemTrayDelegate(SystemTray* t) OVERRIDE; + virtual bool GetOverrideWindowMode(Shell::WindowMode* window_mode) OVERRIDE; + + private: + bool override_window_mode_; + Shell::WindowMode window_mode_; + + DISALLOW_COPY_AND_ASSIGN(TestShellDelegate); }; } // namespace test diff --git a/ash/wm/base_layout_manager_unittest.cc b/ash/wm/base_layout_manager_unittest.cc index 19df383..4b7dfd3 100644 --- a/ash/wm/base_layout_manager_unittest.cc +++ b/ash/wm/base_layout_manager_unittest.cc @@ -5,12 +5,13 @@ #include "ash/wm/base_layout_manager.h" #include "ash/shell.h" +#include "ash/shell_window_ids.h" +#include "ash/test/ash_test_base.h" #include "base/basictypes.h" #include "base/compiler_specific.h" #include "ui/aura/client/aura_constants.h" #include "ui/aura/root_window.h" #include "ui/aura/screen_aura.h" -#include "ui/aura/test/aura_test_base.h" #include "ui/aura/test/test_windows.h" #include "ui/base/ui_base_types.h" #include "ui/aura/window.h" @@ -19,29 +20,26 @@ namespace ash { namespace { -class BaseLayoutManagerTest : public aura::test::AuraTestBase { +class BaseLayoutManagerTest : public test::AshTestBase { public: BaseLayoutManagerTest() {} virtual ~BaseLayoutManagerTest() {} virtual void SetUp() OVERRIDE { - aura::test::AuraTestBase::SetUp(); + test::AshTestBase::SetUp(); Shell::GetRootWindow()->screen()->set_work_area_insets( gfx::Insets(1, 2, 3, 4)); Shell::GetRootWindow()->SetHostSize(gfx::Size(800, 600)); - container_.reset(new aura::Window(NULL)); - container_->Init(ui::Layer::LAYER_NOT_DRAWN); - container_->SetBounds(gfx::Rect(0, 0, 500, 500)); - container_->SetLayoutManager(new internal::BaseLayoutManager()); + aura::Window* default_container = Shell::GetInstance()->GetContainer( + internal::kShellWindowId_DefaultContainer); + default_container->SetLayoutManager(new internal::BaseLayoutManager); } aura::Window* CreateTestWindow(const gfx::Rect& bounds) { - return aura::test::CreateTestWindowWithBounds(bounds, container_.get()); + return aura::test::CreateTestWindowWithBounds(bounds, NULL); } private: - scoped_ptr<aura::Window> container_; - DISALLOW_COPY_AND_ASSIGN(BaseLayoutManagerTest); }; diff --git a/ash/wm/root_window_event_filter_unittest.cc b/ash/wm/root_window_event_filter_unittest.cc index d6b07cdf..efc2820 100644 --- a/ash/wm/root_window_event_filter_unittest.cc +++ b/ash/wm/root_window_event_filter_unittest.cc @@ -4,8 +4,10 @@ #include "ash/wm/root_window_event_filter.h" +#include "ash/ime/input_method_event_filter.h" #include "ash/shell.h" #include "ash/shell_window_ids.h" +#include "ash/test/ash_test_base.h" #include "ash/test/test_activation_delegate.h" #include "ash/wm/activation_controller.h" #include "ash/wm/window_util.h" @@ -23,28 +25,8 @@ #include "ui/gfx/screen.h" namespace ash { -namespace test { -class RootWindowEventFilterTest : public aura::test::AuraTestBase { - public: - RootWindowEventFilterTest() { - Shell::GetRootWindow()->SetEventFilter(new internal::RootWindowEventFilter); - - Shell::GetRootWindow()->set_id( - internal::kShellWindowId_DefaultContainer); - activation_controller_.reset(new internal::ActivationController); - activation_controller_->set_default_container_for_test( - Shell::GetRootWindow()); - } - virtual ~RootWindowEventFilterTest() { - Shell::GetRootWindow()->SetEventFilter(NULL); - } - - private: - scoped_ptr<internal::ActivationController> activation_controller_; - - DISALLOW_COPY_AND_ASSIGN(RootWindowEventFilterTest); -}; +typedef test::AshTestBase RootWindowEventFilterTest; class NonFocusableDelegate : public aura::test::TestWindowDelegate { public: @@ -78,6 +60,12 @@ class HitTestWindowDelegate : public aura::test::TestWindowDelegate { }; TEST_F(RootWindowEventFilterTest, Focus) { + // The IME event filter interferes with the basic key event propagation we + // attempt to do here, so we remove it. + Shell::TestApi shell_test(Shell::GetInstance()); + Shell::GetInstance()->RemoveRootWindowEventFilter( + shell_test.input_method_event_filter()); + aura::RootWindow* root_window = Shell::GetRootWindow(); root_window->SetBounds(gfx::Rect(0, 0, 510, 510)); @@ -151,8 +139,8 @@ TEST_F(RootWindowEventFilterTest, Focus) { EXPECT_EQ(w12.get(), w12->GetFocusManager()->GetFocusedWindow()); // Set the focus to w123, but make the w1 not activatable. - TestActivationDelegate *activation_delegate = new - TestActivationDelegate(false); + test::TestActivationDelegate *activation_delegate = new + test::TestActivationDelegate(false); w123->Focus(); EXPECT_EQ(w123.get(), w12->GetFocusManager()->GetFocusedWindow()); aura::client::SetActivationDelegate(w1.get(), activation_delegate); @@ -182,12 +170,12 @@ TEST_F(RootWindowEventFilterTest, Focus) { TEST_F(RootWindowEventFilterTest, ActivateOnMouse) { aura::RootWindow* root_window = Shell::GetRootWindow(); - TestActivationDelegate d1; + test::TestActivationDelegate d1; aura::test::TestWindowDelegate wd; scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( &wd, -1, gfx::Rect(10, 10, 50, 50), NULL)); d1.SetWindow(w1.get()); - TestActivationDelegate d2; + test::TestActivationDelegate d2; scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( &wd, -1, gfx::Rect(70, 70, 50, 50), NULL)); d2.SetWindow(w2.get()); @@ -294,12 +282,12 @@ TEST_F(RootWindowEventFilterTest, ActivateOnMouse) { TEST_F(RootWindowEventFilterTest, ActivateOnTouch) { aura::RootWindow* root_window = Shell::GetRootWindow(); - TestActivationDelegate d1; + test::TestActivationDelegate d1; aura::test::TestWindowDelegate wd; scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( &wd, -1, gfx::Rect(10, 10, 50, 50), NULL)); d1.SetWindow(w1.get()); - TestActivationDelegate d2; + test::TestActivationDelegate d2; scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( &wd, -2, gfx::Rect(70, 70, 50, 50), NULL)); d2.SetWindow(w2.get()); @@ -383,8 +371,8 @@ TEST_F(RootWindowEventFilterTest, MouseEventCursors) { aura::Window::ConvertPointToWindow(window->parent(), root_window, &point2); aura::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 0x0); - // Cursor starts as null. - EXPECT_EQ(aura::kCursorNull, root_window->last_cursor()); + // Cursor starts as a pointer (set during Shell::Init()). + EXPECT_EQ(aura::kCursorPointer, root_window->last_cursor()); // Resize edges and corners show proper cursors. window_delegate.set_hittest_code(HTBOTTOM); @@ -437,7 +425,7 @@ TEST_F(RootWindowEventFilterTest, TransformActivate) { transform.ConcatTranslate(size.width(), 0); root_window->SetTransform(transform); - TestActivationDelegate d1; + test::TestActivationDelegate d1; aura::test::TestWindowDelegate wd; scoped_ptr<aura::Window> w1( CreateTestWindowWithDelegate(&wd, 1, gfx::Rect(0, 10, 50, 50), NULL)); @@ -470,6 +458,12 @@ TEST_F(RootWindowEventFilterTest, TransformActivate) { } TEST_F(RootWindowEventFilterTest, AdditionalFilters) { + // The IME event filter interferes with the basic key event propagation we + // attempt to do here, so we remove it. + Shell::TestApi shell_test(Shell::GetInstance()); + Shell::GetInstance()->RemoveRootWindowEventFilter( + shell_test.input_method_event_filter()); + aura::RootWindow* root_window = Shell::GetRootWindow(); // Creates a window and make it active @@ -575,5 +569,4 @@ TEST_F(RootWindowEventFilterTest, UpdateCursorVisibility) { EXPECT_TRUE(root_window->cursor_shown()); } -} // namespace test } // namespace ash diff --git a/ash/wm/toplevel_layout_manager_unittest.cc b/ash/wm/toplevel_layout_manager_unittest.cc index 1951c25..3129734 100644 --- a/ash/wm/toplevel_layout_manager_unittest.cc +++ b/ash/wm/toplevel_layout_manager_unittest.cc @@ -5,13 +5,14 @@ #include "ash/wm/toplevel_layout_manager.h" #include "ash/shell.h" +#include "ash/shell_window_ids.h" +#include "ash/test/ash_test_base.h" #include "ash/wm/shelf_layout_manager.h" #include "base/basictypes.h" #include "base/compiler_specific.h" #include "ui/aura/client/aura_constants.h" #include "ui/aura/root_window.h" #include "ui/aura/screen_aura.h" -#include "ui/aura/test/aura_test_base.h" #include "ui/aura/test/test_windows.h" #include "ui/base/ui_base_types.h" #include "ui/aura/window.h" @@ -21,7 +22,7 @@ namespace ash { namespace { -class ToplevelLayoutManagerTest : public aura::test::AuraTestBase { +class ToplevelLayoutManagerTest : public test::AshTestBase { public: ToplevelLayoutManagerTest() : layout_manager_(NULL) {} virtual ~ToplevelLayoutManagerTest() {} @@ -31,19 +32,18 @@ class ToplevelLayoutManagerTest : public aura::test::AuraTestBase { } virtual void SetUp() OVERRIDE { - aura::test::AuraTestBase::SetUp(); + test::AshTestBase::SetUp(); Shell::GetRootWindow()->screen()->set_work_area_insets( gfx::Insets(1, 2, 3, 4)); Shell::GetRootWindow()->SetHostSize(gfx::Size(800, 600)); - container_.reset(new aura::Window(NULL)); - container_->Init(ui::Layer::LAYER_NOT_DRAWN); - container_->SetBounds(gfx::Rect(0, 0, 500, 500)); + aura::Window* default_container = Shell::GetInstance()->GetContainer( + internal::kShellWindowId_DefaultContainer); layout_manager_ = new internal::ToplevelLayoutManager(); - container_->SetLayoutManager(layout_manager_); + default_container->SetLayoutManager(layout_manager_); } aura::Window* CreateTestWindow(const gfx::Rect& bounds) { - return aura::test::CreateTestWindowWithBounds(bounds, container_.get()); + return aura::test::CreateTestWindowWithBounds(bounds, NULL); } // Returns widget owned by its parent, so doesn't need scoped_ptr<>. @@ -57,11 +57,9 @@ class ToplevelLayoutManagerTest : public aura::test::AuraTestBase { } private: - // Owned by |container_|. + // Owned by the default container. internal::ToplevelLayoutManager* layout_manager_; - scoped_ptr<aura::Window> container_; - DISALLOW_COPY_AND_ASSIGN(ToplevelLayoutManagerTest); }; diff --git a/ash/wm/workspace/workspace_manager_unittest.cc b/ash/wm/workspace/workspace_manager_unittest.cc index 4addfd16..e136100 100644 --- a/ash/wm/workspace/workspace_manager_unittest.cc +++ b/ash/wm/workspace/workspace_manager_unittest.cc @@ -6,15 +6,16 @@ #include "ash/shell.h" #include "ash/shell_window_ids.h" +#include "ash/test/ash_test_base.h" #include "ash/wm/activation_controller.h" #include "ash/wm/property_util.h" #include "ash/wm/window_util.h" +#include "ash/wm/workspace_controller.h" #include "ash/wm/workspace/workspace.h" #include "ash/wm/workspace/workspace_layout_manager.h" #include "ui/aura/client/aura_constants.h" #include "ui/aura/root_window.h" #include "ui/aura/screen_aura.h" -#include "ui/aura/test/aura_test_base.h" #include "ui/aura/window.h" #include "ui/base/ui_base_types.h" #include "ui/gfx/screen.h" @@ -24,29 +25,11 @@ using aura::Window; namespace ash { namespace internal { -class WorkspaceManagerTest : public aura::test::AuraTestBase { +class WorkspaceManagerTest : public test::AshTestBase { public: - WorkspaceManagerTest() : layout_manager_(NULL) { - Shell::GetRootWindow()->set_id( - internal::kShellWindowId_DefaultContainer); - activation_controller_.reset(new internal::ActivationController); - activation_controller_->set_default_container_for_test( - Shell::GetRootWindow()); - } + WorkspaceManagerTest() {} virtual ~WorkspaceManagerTest() {} - virtual void SetUp() OVERRIDE { - aura::test::AuraTestBase::SetUp(); - manager_.reset(new WorkspaceManager(viewport())); - layout_manager_ = new WorkspaceLayoutManager(manager_.get()); - viewport()->SetLayoutManager(layout_manager_); - } - - virtual void TearDown() OVERRIDE { - manager_.reset(); - aura::test::AuraTestBase::TearDown(); - } - aura::Window* CreateTestWindowUnparented() { aura::Window* window = new aura::Window(NULL); window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); @@ -60,12 +43,13 @@ class WorkspaceManagerTest : public aura::test::AuraTestBase { window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); window->SetType(aura::client::WINDOW_TYPE_NORMAL); window->Init(ui::Layer::LAYER_TEXTURED); - window->SetParent(viewport()); + window->SetParent(GetViewport()); return window; } - aura::Window* viewport() { - return Shell::GetRootWindow(); + aura::Window* GetViewport() { + return Shell::GetInstance()->GetContainer( + internal::kShellWindowId_DefaultContainer); } const std::vector<Workspace*>& workspaces() const { @@ -88,12 +72,27 @@ class WorkspaceManagerTest : public aura::test::AuraTestBase { return manager_->FindBy(window); } - scoped_ptr<WorkspaceManager> manager_; + // Overridden from AshTestBase: + virtual void SetUp() OVERRIDE { + test::AshTestBase::SetUp(); + Shell::TestApi shell_test(Shell::GetInstance()); + manager_ = shell_test.workspace_controller()->workspace_manager(); + manager_->set_grid_size(0); + } + virtual void TearDown() OVERRIDE { + manager_ = NULL; + test::AshTestBase::TearDown(); + } - // Owned by viewport(). - WorkspaceLayoutManager* layout_manager_; + protected: + internal::WorkspaceManager* manager_; private: + virtual bool GetOverrideWindowMode(Shell::WindowMode* window_mode) OVERRIDE { + *window_mode = Shell::MODE_MANAGED; + return true; + } + scoped_ptr<internal::ActivationController> activation_controller_; DISALLOW_COPY_AND_ASSIGN(WorkspaceManagerTest); @@ -310,7 +309,7 @@ TEST_F(WorkspaceManagerTest, OpenNewWindowsMaximized) { // SHOW_STATE_DEFAULT should end up maximized. w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_DEFAULT); w1->SetBounds(gfx::Rect(50, 51, 52, 53)); - w1->SetParent(viewport()); + w1->SetParent(GetViewport()); // Maximized state and bounds should be set as soon as w1 is added to the // parent. EXPECT_TRUE(wm::IsWindowMaximized(w1.get())); @@ -340,7 +339,7 @@ TEST_F(WorkspaceManagerTest, OpenNewWindowsMaximized) { // false. w3->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_DEFAULT); w3->SetBounds(gfx::Rect(70, 71, 72, 73)); - w3->SetParent(viewport()); + w3->SetParent(GetViewport()); w3->Show(); EXPECT_EQ(gfx::Rect(70, 71, 72, 73), w3->bounds()); EXPECT_EQ(ui::SHOW_STATE_NORMAL, @@ -354,7 +353,7 @@ TEST_F(WorkspaceManagerTest, SnapToGrid) { // Verify snap to grid when bounds are set before parented. scoped_ptr<Window> w1(CreateTestWindowUnparented()); w1->SetBounds(gfx::Rect(1, 6, 25, 30)); - w1->SetParent(viewport()); + w1->SetParent(GetViewport()); EXPECT_EQ(gfx::Rect(0, 8, 24, 32), w1->bounds()); } diff --git a/ash/wm/workspace_controller_unittest.cc b/ash/wm/workspace_controller_unittest.cc deleted file mode 100644 index 9d093b3..0000000 --- a/ash/wm/workspace_controller_unittest.cc +++ /dev/null @@ -1,72 +0,0 @@ -// 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 "ash/wm/workspace_controller.h" - -#include "ash/shell.h" -#include "ash/shell_window_ids.h" -#include "ash/wm/activation_controller.h" -#include "ash/wm/window_util.h" -#include "ash/wm/workspace/workspace.h" -#include "ash/wm/workspace/workspace_manager.h" -#include "ui/aura/test/aura_test_base.h" -#include "ui/aura/root_window.h" -#include "ui/aura/window.h" - -namespace ash { -namespace internal { - -using aura::Window; - -class WorkspaceControllerTest : public aura::test::AuraTestBase { - public: - WorkspaceControllerTest() {} - virtual ~WorkspaceControllerTest() {} - - virtual void SetUp() OVERRIDE { - aura::test::AuraTestBase::SetUp(); - contents_view_ = Shell::GetRootWindow(); - // Activatable windows need to be in a container the ActivationController - // recognizes. - contents_view_->set_id( - ash::internal::kShellWindowId_DefaultContainer); - activation_controller_.reset(new ActivationController); - activation_controller_->set_default_container_for_test(contents_view_); - controller_.reset(new WorkspaceController(contents_view_)); - } - - virtual void TearDown() OVERRIDE { - activation_controller_.reset(); - controller_.reset(); - aura::test::AuraTestBase::TearDown(); - } - - aura::Window* CreateTestWindow() { - aura::Window* window = new aura::Window(NULL); - window->Init(ui::Layer::LAYER_NOT_DRAWN); - contents_view()->AddChild(window); - window->Show(); - return window; - } - - aura::Window* contents_view() { - return contents_view_; - } - - WorkspaceManager* workspace_manager() { - return controller_->workspace_manager(); - } - - scoped_ptr<WorkspaceController> controller_; - - private: - aura::Window* contents_view_; - - scoped_ptr<ActivationController> activation_controller_; - - DISALLOW_COPY_AND_ASSIGN(WorkspaceControllerTest); -}; - -} // namespace internal -} // namespace ash |