| 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..9e1f8c40c8412870ced37053be19817c9af288c1 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,39 @@ class PanelLayoutManagerTest : public ash::test::AshTestBase {
|
| PanelLayoutManagerTest() {}
|
| virtual ~PanelLayoutManagerTest() {}
|
|
|
| - aura::Window* GetPanelContainer() {
|
| - return Shell::GetInstance()->GetContainer(
|
| - ash::internal::kShellWindowId_PanelContainer);
|
| + virtual void SetUp() OVERRIDE {
|
| + CommandLine::ForCurrentProcess()->AppendSwitch(switches::kAuraPanelManager);
|
| + ash::test::AshTestBase::SetUp();
|
| + ASSERT_TRUE(ash::test::TestLauncherDelegate::instance());
|
| + }
|
| +
|
| + 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();
|
| + 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
|
| @@ -71,46 +79,121 @@ void IsPanelAboveLauncherIcon(views::Widget* panel) {
|
| // Tests that a created panel window is successfully added to the panel
|
| // layout manager.
|
| TEST_F(PanelLayoutManagerTest, AddOnePanel) {
|
| - if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraPanelManager))
|
| - 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()));
|
| }
|
|
|
| -// Tests that panels are ordered right-to-left.
|
| -TEST_F(PanelLayoutManagerTest, PanelAboveLauncherIcons) {
|
| - if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraPanelManager))
|
| - return;
|
| +// Tests interactions between multiple panels
|
| +TEST_F(PanelLayoutManagerTest, MultiplePanelsAreAboveIcons) {
|
| + gfx::Rect odd_bounds(0, 0, 201, 201);
|
| + gfx::Rect even_bounds(0, 0, 200, 200);
|
|
|
| - gfx::Rect bounds(0, 0, 201, 201);
|
| - scoped_ptr<views::Widget> w1(CreatePanelWindow(bounds));
|
| + 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) {
|
| - if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraPanelManager))
|
| - return;
|
| +TEST_F(PanelLayoutManagerTest, MultiplePanelStacking) {
|
| + 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) {
|
| + 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) {
|
| 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));
|
|
|
| - GetPanelContainer()->RemoveChild(w2->GetNativeWindow());
|
| + 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]);
|
| +}
|
| +
|
| +TEST_F(PanelLayoutManagerTest, RemoveRightPanel) {
|
| + 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) {
|
| + 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
|
|
|