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 9e1f8c40c8412870ced37053be19817c9af288c1..a7d0ce3fdec1410bcf59edf7e598b3b4c42e2a84 100644 |
--- a/ash/wm/panel_layout_manager_unittest.cc |
+++ b/ash/wm/panel_layout_manager_unittest.cc |
@@ -16,16 +16,13 @@ |
#include "base/compiler_specific.h" |
#include "ui/aura/window.h" |
#include "ui/aura/test/test_windows.h" |
-#include "ui/aura/test/test_window_delegate.h" |
+#include "ui/views/widget/widget.h" |
namespace ash { |
-namespace { |
+namespace internal { |
-aura::Window* GetPanelContainer() { |
- return Shell::GetInstance()->GetContainer( |
- ash::internal::kShellWindowId_PanelContainer); |
-} |
+using aura::test::WindowIsAbove; |
class PanelLayoutManagerTest : public ash::test::AshTestBase { |
public: |
@@ -38,9 +35,13 @@ class PanelLayoutManagerTest : public ash::test::AshTestBase { |
ASSERT_TRUE(ash::test::TestLauncherDelegate::instance()); |
} |
+ aura::Window* CreateNormalWindow() { |
+ return aura::test::CreateTestWindowWithBounds(gfx::Rect(), NULL); |
+ } |
+ |
aura::Window* CreatePanelWindow(const gfx::Rect& bounds) { |
- aura::Window* window = CreateTestWindowWithDelegateAndType( |
- &window_delegate_, |
+ aura::Window* window = aura::test::CreateTestWindowWithDelegateAndType( |
+ NULL, |
aura::client::WINDOW_TYPE_PANEL, |
0, |
bounds, |
@@ -51,30 +52,60 @@ class PanelLayoutManagerTest : public ash::test::AshTestBase { |
return window; |
} |
- private: |
- aura::test::TestWindowDelegate window_delegate_; |
+ aura::Window* GetPanelContainer() { |
+ return Shell::GetInstance()->GetContainer( |
+ ash::internal::kShellWindowId_PanelContainer); |
+ } |
- DISALLOW_COPY_AND_ASSIGN(PanelLayoutManagerTest); |
-}; |
+ void GetCalloutWidget(views::Widget** widget) { |
+ PanelLayoutManager* manager = |
+ static_cast<PanelLayoutManager*>(GetPanelContainer()->layout_manager()); |
+ ASSERT_TRUE(manager); |
+ ASSERT_TRUE(manager->callout_widget()); |
+ *widget = manager->callout_widget(); |
+ } |
-// 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(); |
- gfx::Rect icon_bounds = launcher->GetScreenBoundsOfItemIconForWindow(panel); |
- ASSERT_FALSE(icon_bounds.IsEmpty()); |
- |
- 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 |
- // icons. |
- EXPECT_NEAR( |
- window_bounds.CenterPoint().x(), icon_bounds.CenterPoint().x(), 1); |
- EXPECT_EQ(window_bounds.bottom(), icon_bounds.y()); |
-} |
+ // 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(); |
+ gfx::Rect icon_bounds = launcher->GetScreenBoundsOfItemIconForWindow(panel); |
+ ASSERT_FALSE(icon_bounds.IsEmpty()); |
+ |
+ 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 icons. |
+ EXPECT_NEAR(icon_bounds.CenterPoint().x(), |
+ window_bounds.CenterPoint().x(), |
+ 1); |
+ EXPECT_EQ(launcher->widget()->GetWindowScreenBounds().y(), |
+ window_bounds.bottom()); |
+ } |
-} // namespace |
+ void IsCalloutAbovePanel(aura::Window* panel) { |
+ // Flush the message loop, since callout updates use a delayed task. |
+ MessageLoop::current()->RunAllPending(); |
+ views::Widget* widget = NULL; |
+ GetCalloutWidget(&widget); |
+ EXPECT_TRUE(widget->IsVisible()); |
+ EXPECT_EQ(panel->GetBoundsInRootWindow().bottom(), |
+ widget->GetWindowScreenBounds().y()); |
+ EXPECT_NEAR(panel->GetBoundsInRootWindow().CenterPoint().x(), |
+ widget->GetWindowScreenBounds().CenterPoint().x(), |
+ 1); |
+ } |
+ |
+ bool IsCalloutVisible() { |
+ views::Widget* widget = NULL; |
+ GetCalloutWidget(&widget); |
+ return widget->IsVisible(); |
+ } |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(PanelLayoutManagerTest); |
+}; |
// Tests that a created panel window is successfully added to the panel |
// layout manager. |
@@ -110,29 +141,44 @@ TEST_F(PanelLayoutManagerTest, MultiplePanelStacking) { |
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]); |
+ EXPECT_TRUE(WindowIsAbove(w3.get(), w2.get())); |
+ EXPECT_TRUE(WindowIsAbove(w2.get(), w1.get())); |
// 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]); |
+ EXPECT_TRUE(WindowIsAbove(w1.get(), w2.get())); |
+ EXPECT_TRUE(WindowIsAbove(w2.get(), w3.get())); |
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]); |
+ EXPECT_TRUE(WindowIsAbove(w1.get(), w3.get())); |
+ EXPECT_TRUE(WindowIsAbove(w2.get(), w3.get())); |
+ EXPECT_TRUE(WindowIsAbove(w2.get(), w1.get())); |
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]); |
+ EXPECT_TRUE(WindowIsAbove(w3.get(), w2.get())); |
+ EXPECT_TRUE(WindowIsAbove(w2.get(), w1.get())); |
+} |
+ |
+TEST_F(PanelLayoutManagerTest, MultiplePanelCallout) { |
+ gfx::Rect bounds(0, 0, 200, 200); |
+ scoped_ptr<aura::Window> w1(CreatePanelWindow(bounds)); |
+ scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds)); |
+ scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds)); |
+ scoped_ptr<aura::Window> w4(CreateNormalWindow()); |
+ EXPECT_FALSE(IsCalloutVisible()); |
+ wm::ActivateWindow(w1.get()); |
+ EXPECT_NO_FATAL_FAILURE(IsCalloutAbovePanel(w1.get())); |
+ wm::ActivateWindow(w2.get()); |
+ EXPECT_NO_FATAL_FAILURE(IsCalloutAbovePanel(w2.get())); |
+ wm::ActivateWindow(w3.get()); |
+ EXPECT_NO_FATAL_FAILURE(IsCalloutAbovePanel(w3.get())); |
+ wm::ActivateWindow(w4.get()); |
+ EXPECT_FALSE(IsCalloutVisible()); |
+ wm::ActivateWindow(w3.get()); |
+ EXPECT_NO_FATAL_FAILURE(IsCalloutAbovePanel(w3.get())); |
+ w3.reset(); |
+ EXPECT_FALSE(IsCalloutVisible()); |
+ |
} |
// Tests removing panels. |
@@ -142,13 +188,13 @@ TEST_F(PanelLayoutManagerTest, RemoveLeftPanel) { |
scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds)); |
scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds)); |
+ // At this point, windows should be stacked with 1 < 2 < 3 |
wm::ActivateWindow(w1.get()); |
+ // Now, windows should be stacked 1 > 2 > 3 |
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]); |
+ EXPECT_TRUE(WindowIsAbove(w2.get(), w3.get())); |
} |
TEST_F(PanelLayoutManagerTest, RemoveMiddlePanel) { |
@@ -157,13 +203,13 @@ TEST_F(PanelLayoutManagerTest, RemoveMiddlePanel) { |
scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds)); |
scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds)); |
+ // At this point, windows should be stacked with 1 < 2 < 3 |
wm::ActivateWindow(w2.get()); |
+ // Windows should be stacked 1 < 2 > 3 |
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]); |
+ EXPECT_TRUE(WindowIsAbove(w3.get(), w1.get())); |
} |
TEST_F(PanelLayoutManagerTest, RemoveRightPanel) { |
@@ -172,13 +218,13 @@ TEST_F(PanelLayoutManagerTest, RemoveRightPanel) { |
scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds)); |
scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds)); |
+ // At this point, windows should be stacked with 1 < 2 < 3 |
wm::ActivateWindow(w3.get()); |
+ // Order shouldn't change. |
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]); |
+ EXPECT_TRUE(WindowIsAbove(w2.get(), w1.get())); |
} |
TEST_F(PanelLayoutManagerTest, RemoveNonActivePanel) { |
@@ -187,13 +233,15 @@ TEST_F(PanelLayoutManagerTest, RemoveNonActivePanel) { |
scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds)); |
scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds)); |
+ // At this point, windows should be stacked with 1 < 2 < 3 |
wm::ActivateWindow(w2.get()); |
+ // Windows should be stacked 1 < 2 > 3 |
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]); |
+ EXPECT_TRUE(WindowIsAbove(w2.get(), w3.get())); |
} |
+} // namespace internal |
+ |
} // namespace ash |