OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/wm/panel_layout_manager.h" | 5 #include "ash/wm/panel_layout_manager.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/launcher/launcher.h" |
8 #include "ash/shell.h" | 9 #include "ash/shell.h" |
9 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
10 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
| 12 #include "ash/test/test_launcher_delegate.h" |
11 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
12 #include "base/command_line.h" | 14 #include "base/command_line.h" |
13 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
14 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
15 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
16 #include "ui/views/widget/widget_delegate.h" | 18 #include "ui/views/widget/widget_delegate.h" |
17 | 19 |
18 namespace ash { | 20 namespace ash { |
19 | 21 |
20 namespace { | 22 namespace { |
21 | 23 |
22 views::Widget* CreatePanelWindow(const gfx::Rect& rect) { | 24 views::Widget* CreatePanelWindow(const gfx::Rect& rect) { |
23 views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL); | 25 views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL); |
24 params.bounds = rect; | 26 params.bounds = rect; |
25 views::Widget* widget = new views::Widget(); | 27 views::Widget* widget = new views::Widget(); |
26 widget->Init(params); | 28 widget->Init(params); |
| 29 ash::test::TestLauncherDelegate* launcher_delegate = |
| 30 static_cast<ash::test::TestLauncherDelegate*>( |
| 31 Shell::GetInstance()->launcher()->delegate()); |
| 32 launcher_delegate->AddLauncherItem(widget->GetNativeWindow()); |
27 widget->Show(); | 33 widget->Show(); |
28 return widget; | 34 return widget; |
29 } | 35 } |
30 | 36 |
31 class PanelLayoutManagerTest : public ash::test::AshTestBase { | 37 class PanelLayoutManagerTest : public ash::test::AshTestBase { |
32 public: | 38 public: |
33 PanelLayoutManagerTest() {} | 39 PanelLayoutManagerTest() {} |
34 virtual ~PanelLayoutManagerTest() {} | 40 virtual ~PanelLayoutManagerTest() {} |
35 | 41 |
36 aura::Window* GetPanelContainer() { | 42 aura::Window* GetPanelContainer() { |
37 return Shell::GetInstance()->GetContainer( | 43 return Shell::GetInstance()->GetContainer( |
38 ash::internal::kShellWindowId_PanelContainer); | 44 ash::internal::kShellWindowId_PanelContainer); |
39 } | 45 } |
40 | 46 |
41 private: | 47 private: |
42 DISALLOW_COPY_AND_ASSIGN(PanelLayoutManagerTest); | 48 DISALLOW_COPY_AND_ASSIGN(PanelLayoutManagerTest); |
43 }; | 49 }; |
44 | 50 |
| 51 void AssertPanelAboveLauncherIcon(views::Widget* panel) { |
| 52 Launcher* launcher = Shell::GetInstance()->launcher(); |
| 53 aura::Window* window = panel->GetNativeWindow(); |
| 54 gfx::Rect icon_rect = launcher->GetScreenBoundsOfItemIconForWindow(window); |
| 55 EXPECT_FALSE(icon_rect.IsEmpty()); |
| 56 } |
| 57 |
45 } // namespace | 58 } // namespace |
46 | 59 |
47 // Tests that a created panel window is successfully added to the panel | 60 // Tests that a created panel window is successfully added to the panel |
48 // layout manager. | 61 // layout manager. |
49 TEST_F(PanelLayoutManagerTest, AddOnePanel) { | 62 TEST_F(PanelLayoutManagerTest, AddOnePanel) { |
50 gfx::Rect bounds(1, 1, 200, 200); | 63 gfx::Rect bounds(1, 1, 200, 200); |
51 views::Widget* w1 = CreatePanelWindow(bounds); | 64 views::Widget* w1 = CreatePanelWindow(bounds); |
52 EXPECT_EQ(GetPanelContainer(), w1->GetNativeWindow()->parent()); | 65 EXPECT_EQ(GetPanelContainer(), w1->GetNativeWindow()->parent()); |
| 66 AssertPanelAboveLauncherIcon(w1); |
53 } | 67 } |
54 | 68 |
55 // Tests that panels are ordered right-to-left. | 69 // Tests that panels are ordered right-to-left. |
56 TEST_F(PanelLayoutManagerTest, PanelOrderRightToLeft) { | 70 TEST_F(PanelLayoutManagerTest, PanelAboveLauncherIcons) { |
57 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 71 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
58 switches::kAuraPanelManager)) | 72 switches::kAuraPanelManager)) |
59 return; | 73 return; |
60 gfx::Rect bounds(1, 1, 200, 200); | 74 gfx::Rect bounds(1, 1, 200, 200); |
61 views::Widget* w1 = CreatePanelWindow(bounds); | 75 views::Widget* w1 = CreatePanelWindow(bounds); |
| 76 AssertPanelAboveLauncherIcon(w1); |
62 views::Widget* w2 = CreatePanelWindow(bounds); | 77 views::Widget* w2 = CreatePanelWindow(bounds); |
63 EXPECT_LT(w2->GetWindowScreenBounds().x(), w1->GetWindowScreenBounds().x()); | 78 AssertPanelAboveLauncherIcon(w2); |
64 | |
65 views::Widget* w3 = CreatePanelWindow(bounds); | 79 views::Widget* w3 = CreatePanelWindow(bounds); |
66 EXPECT_LT(w3->GetWindowScreenBounds().x(), w2->GetWindowScreenBounds().x()); | 80 AssertPanelAboveLauncherIcon(w3); |
67 EXPECT_LT(w2->GetWindowScreenBounds().x(), w1->GetWindowScreenBounds().x()); | 81 AssertPanelAboveLauncherIcon(w1); |
| 82 AssertPanelAboveLauncherIcon(w2); |
68 } | 83 } |
69 | 84 |
70 // Tests removing a panel. | 85 // Tests removing a panel. |
71 TEST_F(PanelLayoutManagerTest, RemovePanel) { | 86 TEST_F(PanelLayoutManagerTest, RemovePanel) { |
72 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 87 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
73 switches::kAuraPanelManager)) | 88 switches::kAuraPanelManager)) |
74 return; | 89 return; |
75 | 90 |
76 gfx::Rect bounds(1, 1, 200, 200); | 91 gfx::Rect bounds(1, 1, 200, 200); |
77 views::Widget* w1 = CreatePanelWindow(bounds); | 92 views::Widget* w1 = CreatePanelWindow(bounds); |
78 views::Widget* w2 = CreatePanelWindow(bounds); | 93 views::Widget* w2 = CreatePanelWindow(bounds); |
79 views::Widget* w3 = CreatePanelWindow(bounds); | 94 views::Widget* w3 = CreatePanelWindow(bounds); |
80 | 95 |
81 gfx::Rect w3bounds = w3->GetWindowScreenBounds(); | 96 gfx::Rect w3bounds = w3->GetWindowScreenBounds(); |
82 | 97 |
83 GetPanelContainer()->RemoveChild(w2->GetNativeWindow()); | 98 GetPanelContainer()->RemoveChild(w2->GetNativeWindow()); |
84 | 99 |
85 // Verify that w3 has moved. | 100 AssertPanelAboveLauncherIcon(w3); |
86 EXPECT_NE(w3->GetWindowScreenBounds(), w3bounds); | 101 AssertPanelAboveLauncherIcon(w1); |
87 // Verify that w3 is still left of w1. | |
88 EXPECT_LT(w3->GetWindowScreenBounds().x(), w1->GetWindowScreenBounds().x()); | |
89 } | 102 } |
90 | 103 |
91 } // namespace ash | 104 } // namespace ash |
OLD | NEW |