Chromium Code Reviews| Index: ash/wm/panel_layout_manager_unittest.cc |
| diff --git a/ash/wm/panel_layout_manager_unittest.cc b/ash/wm/panel_layout_manager_unittest.cc |
| index 2fdf9ea3b7df8cde9bb478b687588bc24723ada5..16d81cc0f7d28a7f01e6f857e29174654d5050c3 100644 |
| --- a/ash/wm/panel_layout_manager_unittest.cc |
| +++ b/ash/wm/panel_layout_manager_unittest.cc |
| @@ -10,30 +10,21 @@ |
| #include "ash/shell_window_ids.h" |
| #include "ash/test/ash_test_base.h" |
| #include "ash/test/test_launcher_delegate.h" |
| +#include "ash/wm/window_util.h" |
| #include "base/basictypes.h" |
| #include "base/command_line.h" |
| #include "base/compiler_specific.h" |
| #include "ui/aura/window.h" |
| -#include "ui/views/widget/widget.h" |
| -#include "ui/views/widget/widget_delegate.h" |
| +#include "ui/aura/test/test_windows.h" |
| +#include "ui/aura/test/test_window_delegate.h" |
| namespace ash { |
| namespace { |
| -views::Widget* CreatePanelWindow(const gfx::Rect& rect) { |
| - views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL); |
| - params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| - params.bounds = rect; |
| - params.child = true; |
| - views::Widget* widget = new views::Widget(); |
| - widget->Init(params); |
| - ash::test::TestLauncherDelegate* launcher_delegate = |
| - ash::test::TestLauncherDelegate::instance(); |
| - CHECK(launcher_delegate); |
| - launcher_delegate->AddLauncherItem(widget->GetNativeWindow()); |
| - widget->Show(); |
| - return widget; |
| +aura::Window* GetPanelContainer() { |
| + return Shell::GetInstance()->GetContainer( |
| + ash::internal::kShellWindowId_PanelContainer); |
| } |
| class PanelLayoutManagerTest : public ash::test::AshTestBase { |
| @@ -41,22 +32,34 @@ class PanelLayoutManagerTest : public ash::test::AshTestBase { |
| PanelLayoutManagerTest() {} |
| virtual ~PanelLayoutManagerTest() {} |
| - aura::Window* GetPanelContainer() { |
| - return Shell::GetInstance()->GetContainer( |
| - ash::internal::kShellWindowId_PanelContainer); |
| + aura::Window* CreatePanelWindow(const gfx::Rect& bounds) { |
| + aura::Window* window = CreateTestWindowWithDelegateAndType( |
| + &window_delegate_, |
| + aura::client::WINDOW_TYPE_PANEL, |
| + 0, |
| + bounds, |
| + NULL /* parent should automatically become GetPanelContainer */); |
| + ash::test::TestLauncherDelegate* launcher_delegate = |
| + ash::test::TestLauncherDelegate::instance(); |
| + CHECK(launcher_delegate); |
| + launcher_delegate->AddLauncherItem(window); |
| + return window; |
| } |
| private: |
| + aura::test::TestWindowDelegate window_delegate_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(PanelLayoutManagerTest); |
| }; |
| -void IsPanelAboveLauncherIcon(views::Widget* panel) { |
| +// TODO(dcheng): This should be const, but GetScreeNBoundsOfItemIconForWindow |
| +// takes a non-const Window. We can probably fix that. |
| +void IsPanelAboveLauncherIcon(aura::Window* panel) { |
| Launcher* launcher = Shell::GetInstance()->launcher(); |
| - aura::Window* window = panel->GetNativeWindow(); |
| - gfx::Rect icon_bounds = launcher->GetScreenBoundsOfItemIconForWindow(window); |
| + gfx::Rect icon_bounds = launcher->GetScreenBoundsOfItemIconForWindow(panel); |
| ASSERT_FALSE(icon_bounds.IsEmpty()); |
| - gfx::Rect window_bounds = panel->GetWindowScreenBounds(); |
| + gfx::Rect window_bounds = panel->GetBoundsInRootWindow(); |
| // 1-pixel tolerance--since we center panels over their icons, panels with odd |
| // pixel widths won't be perfectly lined up with even pixel width launcher |
| @@ -75,42 +78,140 @@ TEST_F(PanelLayoutManagerTest, AddOnePanel) { |
| return; |
| gfx::Rect bounds(0, 0, 201, 201); |
| - scoped_ptr<views::Widget> window(CreatePanelWindow(bounds)); |
| - EXPECT_EQ(GetPanelContainer(), window->GetNativeWindow()->parent()); |
| + scoped_ptr<aura::Window> window(CreatePanelWindow(bounds)); |
| + EXPECT_EQ(GetPanelContainer(), window->parent()); |
| EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(window.get())); |
| + |
| + LOG(ERROR) << "Running tests!"; |
|
sky
2012/04/26 04:30:31
remove this.
dcheng
2012/04/26 06:30:59
Done.
|
| } |
| -// Tests that panels are ordered right-to-left. |
| -TEST_F(PanelLayoutManagerTest, PanelAboveLauncherIcons) { |
| +// Tests interactions between multiple panels |
| +TEST_F(PanelLayoutManagerTest, MultiplePanelsAreAboveIcons) { |
| if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraPanelManager)) |
| return; |
| - gfx::Rect bounds(0, 0, 201, 201); |
| - scoped_ptr<views::Widget> w1(CreatePanelWindow(bounds)); |
| + gfx::Rect odd_bounds(0, 0, 201, 201); |
| + gfx::Rect even_bounds(0, 0, 200, 200); |
| + |
| + scoped_ptr<aura::Window> w1(CreatePanelWindow(odd_bounds)); |
| EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); |
| - scoped_ptr<views::Widget> w2(CreatePanelWindow(bounds)); |
| + |
| + scoped_ptr<aura::Window> w2(CreatePanelWindow(even_bounds)); |
| EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); |
| EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w2.get())); |
| - scoped_ptr<views::Widget> w3(CreatePanelWindow(bounds)); |
| + |
| + scoped_ptr<aura::Window> w3(CreatePanelWindow(odd_bounds)); |
| EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); |
| EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w2.get())); |
| EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w3.get())); |
| } |
| -// Tests removing a panel. |
| -TEST_F(PanelLayoutManagerTest, RemovePanel) { |
| +TEST_F(PanelLayoutManagerTest, MultiplePanelStacking) { |
| + if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraPanelManager)) |
| + return; |
| + |
| + gfx::Rect bounds(0, 0, 201, 201); |
| + scoped_ptr<aura::Window> w1(CreatePanelWindow(bounds)); |
| + scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds)); |
| + scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds)); |
| + |
| + // Default stacking order. |
| + ASSERT_EQ(3u, GetPanelContainer()->children().size()); |
| + EXPECT_EQ(w1.get(), GetPanelContainer()->children()[0]); |
| + EXPECT_EQ(w2.get(), GetPanelContainer()->children()[1]); |
| + EXPECT_EQ(w3.get(), GetPanelContainer()->children()[2]); |
| + |
| + // Changing the active window should update the stacking order. |
| + wm::ActivateWindow(w1.get()); |
| + ASSERT_EQ(3u, GetPanelContainer()->children().size()); |
| + EXPECT_EQ(w3.get(), GetPanelContainer()->children()[0]); |
| + EXPECT_EQ(w2.get(), GetPanelContainer()->children()[1]); |
| + EXPECT_EQ(w1.get(), GetPanelContainer()->children()[2]); |
| + |
| + wm::ActivateWindow(w2.get()); |
| + ASSERT_EQ(3u, GetPanelContainer()->children().size()); |
| + EXPECT_EQ(w3.get(), GetPanelContainer()->children()[0]); |
| + EXPECT_EQ(w1.get(), GetPanelContainer()->children()[1]); |
| + EXPECT_EQ(w2.get(), GetPanelContainer()->children()[2]); |
| + |
| + wm::ActivateWindow(w3.get()); |
| + ASSERT_EQ(3u, GetPanelContainer()->children().size()); |
| + EXPECT_EQ(w1.get(), GetPanelContainer()->children()[0]); |
| + EXPECT_EQ(w2.get(), GetPanelContainer()->children()[1]); |
| + EXPECT_EQ(w3.get(), GetPanelContainer()->children()[2]); |
| +} |
| + |
| +// Tests removing panels. |
| +TEST_F(PanelLayoutManagerTest, RemoveLeftPanel) { |
| + if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraPanelManager)) |
| + return; |
| + |
| + gfx::Rect bounds(0, 0, 201, 201); |
| + scoped_ptr<aura::Window> w1(CreatePanelWindow(bounds)); |
| + scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds)); |
| + scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds)); |
| + |
| + wm::ActivateWindow(w1.get()); |
| + w1.reset(); |
| + EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w2.get())); |
| + EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w3.get())); |
| + ASSERT_EQ(2u, GetPanelContainer()->children().size()); |
| + EXPECT_EQ(w3.get(), GetPanelContainer()->children()[0]); |
| + EXPECT_EQ(w2.get(), GetPanelContainer()->children()[1]); |
| +} |
| + |
| +TEST_F(PanelLayoutManagerTest, RemoveMiddlePanel) { |
| if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraPanelManager)) |
| return; |
| gfx::Rect bounds(0, 0, 201, 201); |
| - scoped_ptr<views::Widget> w1(CreatePanelWindow(bounds)); |
| - scoped_ptr<views::Widget> w2(CreatePanelWindow(bounds)); |
| - scoped_ptr<views::Widget> w3(CreatePanelWindow(bounds)); |
| + scoped_ptr<aura::Window> w1(CreatePanelWindow(bounds)); |
| + scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds)); |
| + scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds)); |
| + |
| + wm::ActivateWindow(w2.get()); |
| + w2.reset(); |
| + EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); |
| + EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w3.get())); |
| + ASSERT_EQ(2u, GetPanelContainer()->children().size()); |
| + EXPECT_EQ(w1.get(), GetPanelContainer()->children()[0]); |
| + EXPECT_EQ(w3.get(), GetPanelContainer()->children()[1]); |
| +} |
| - GetPanelContainer()->RemoveChild(w2->GetNativeWindow()); |
| +TEST_F(PanelLayoutManagerTest, RemoveRightPanel) { |
| + if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraPanelManager)) |
| + return; |
| + |
| + gfx::Rect bounds(0, 0, 201, 201); |
| + scoped_ptr<aura::Window> w1(CreatePanelWindow(bounds)); |
| + scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds)); |
| + scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds)); |
| + wm::ActivateWindow(w3.get()); |
| + w3.reset(); |
| EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); |
| + EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w2.get())); |
| + ASSERT_EQ(2u, GetPanelContainer()->children().size()); |
| + EXPECT_EQ(w1.get(), GetPanelContainer()->children()[0]); |
| + EXPECT_EQ(w2.get(), GetPanelContainer()->children()[1]); |
| +} |
| + |
| +TEST_F(PanelLayoutManagerTest, RemoveNonActivePanel) { |
| + if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraPanelManager)) |
| + return; |
| + |
| + gfx::Rect bounds(0, 0, 201, 201); |
| + scoped_ptr<aura::Window> w1(CreatePanelWindow(bounds)); |
| + scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds)); |
| + scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds)); |
| + |
| + wm::ActivateWindow(w2.get()); |
| + w1.reset(); |
| + EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w2.get())); |
| EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w3.get())); |
| + ASSERT_EQ(2u, GetPanelContainer()->children().size()); |
| + EXPECT_EQ(w3.get(), GetPanelContainer()->children()[0]); |
| + EXPECT_EQ(w2.get(), GetPanelContainer()->children()[1]); |
| } |
| } // namespace ash |