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/launcher/launcher.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
11 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
12 #include "ash/test/test_launcher_delegate.h" | 12 #include "ash/test/test_launcher_delegate.h" |
13 #include "ash/wm/window_util.h" | |
13 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
14 #include "base/command_line.h" | 15 #include "base/command_line.h" |
15 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
16 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
17 #include "ui/views/widget/widget.h" | 18 #include "ui/aura/test/test_windows.h" |
18 #include "ui/views/widget/widget_delegate.h" | 19 #include "ui/aura/test/test_window_delegate.h" |
19 | 20 |
20 namespace ash { | 21 namespace ash { |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 views::Widget* CreatePanelWindow(const gfx::Rect& rect) { | 25 aura::Window* GetPanelContainer() { |
25 views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL); | 26 return Shell::GetInstance()->GetContainer( |
26 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 27 ash::internal::kShellWindowId_PanelContainer); |
27 params.bounds = rect; | |
28 params.child = true; | |
29 views::Widget* widget = new views::Widget(); | |
30 widget->Init(params); | |
31 ash::test::TestLauncherDelegate* launcher_delegate = | |
32 ash::test::TestLauncherDelegate::instance(); | |
33 CHECK(launcher_delegate); | |
34 launcher_delegate->AddLauncherItem(widget->GetNativeWindow()); | |
35 widget->Show(); | |
36 return widget; | |
37 } | 28 } |
38 | 29 |
39 class PanelLayoutManagerTest : public ash::test::AshTestBase { | 30 class PanelLayoutManagerTest : public ash::test::AshTestBase { |
40 public: | 31 public: |
41 PanelLayoutManagerTest() {} | 32 PanelLayoutManagerTest() {} |
42 virtual ~PanelLayoutManagerTest() {} | 33 virtual ~PanelLayoutManagerTest() {} |
43 | 34 |
44 aura::Window* GetPanelContainer() { | 35 virtual void SetUp() OVERRIDE { |
45 return Shell::GetInstance()->GetContainer( | 36 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kAuraPanelManager); |
46 ash::internal::kShellWindowId_PanelContainer); | 37 ash::test::AshTestBase::SetUp(); |
38 } | |
39 | |
40 aura::Window* CreatePanelWindow(const gfx::Rect& bounds) { | |
41 aura::Window* window = CreateTestWindowWithDelegateAndType( | |
42 &window_delegate_, | |
43 aura::client::WINDOW_TYPE_PANEL, | |
44 0, | |
45 bounds, | |
46 NULL /* parent should automatically become GetPanelContainer */); | |
47 ash::test::TestLauncherDelegate* launcher_delegate = | |
48 ash::test::TestLauncherDelegate::instance(); | |
49 CHECK(launcher_delegate); | |
sky
2012/04/26 16:05:10
Don't CHECK in tests (it would make all the unit t
dcheng
2012/04/26 18:10:25
I feel like this makes the unit test look really c
sky
2012/04/26 19:06:59
That's an important assert to keep. But, you can m
dcheng
2012/04/26 23:00:59
Done.
| |
50 launcher_delegate->AddLauncherItem(window); | |
51 return window; | |
47 } | 52 } |
48 | 53 |
49 private: | 54 private: |
55 aura::test::TestWindowDelegate window_delegate_; | |
56 | |
50 DISALLOW_COPY_AND_ASSIGN(PanelLayoutManagerTest); | 57 DISALLOW_COPY_AND_ASSIGN(PanelLayoutManagerTest); |
51 }; | 58 }; |
52 | 59 |
53 void IsPanelAboveLauncherIcon(views::Widget* panel) { | 60 // TODO(dcheng): This should be const, but GetScreenBoundsOfItemIconForWindow |
61 // takes a non-const Window. We can probably fix that. | |
62 void IsPanelAboveLauncherIcon(aura::Window* panel) { | |
54 Launcher* launcher = Shell::GetInstance()->launcher(); | 63 Launcher* launcher = Shell::GetInstance()->launcher(); |
55 aura::Window* window = panel->GetNativeWindow(); | 64 gfx::Rect icon_bounds = launcher->GetScreenBoundsOfItemIconForWindow(panel); |
56 gfx::Rect icon_bounds = launcher->GetScreenBoundsOfItemIconForWindow(window); | |
57 ASSERT_FALSE(icon_bounds.IsEmpty()); | 65 ASSERT_FALSE(icon_bounds.IsEmpty()); |
58 | 66 |
59 gfx::Rect window_bounds = panel->GetWindowScreenBounds(); | 67 gfx::Rect window_bounds = panel->GetBoundsInRootWindow(); |
60 | 68 |
61 // 1-pixel tolerance--since we center panels over their icons, panels with odd | 69 // 1-pixel tolerance--since we center panels over their icons, panels with odd |
62 // pixel widths won't be perfectly lined up with even pixel width launcher | 70 // pixel widths won't be perfectly lined up with even pixel width launcher |
63 // icons. | 71 // icons. |
64 EXPECT_NEAR( | 72 EXPECT_NEAR( |
65 window_bounds.CenterPoint().x(), icon_bounds.CenterPoint().x(), 1); | 73 window_bounds.CenterPoint().x(), icon_bounds.CenterPoint().x(), 1); |
66 EXPECT_EQ(window_bounds.bottom(), icon_bounds.y()); | 74 EXPECT_EQ(window_bounds.bottom(), icon_bounds.y()); |
67 } | 75 } |
68 | 76 |
69 } // namespace | 77 } // namespace |
70 | 78 |
71 // Tests that a created panel window is successfully added to the panel | 79 // Tests that a created panel window is successfully added to the panel |
72 // layout manager. | 80 // layout manager. |
73 TEST_F(PanelLayoutManagerTest, AddOnePanel) { | 81 TEST_F(PanelLayoutManagerTest, AddOnePanel) { |
74 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraPanelManager)) | |
75 return; | |
76 | |
77 gfx::Rect bounds(0, 0, 201, 201); | 82 gfx::Rect bounds(0, 0, 201, 201); |
78 scoped_ptr<views::Widget> window(CreatePanelWindow(bounds)); | 83 scoped_ptr<aura::Window> window(CreatePanelWindow(bounds)); |
79 EXPECT_EQ(GetPanelContainer(), window->GetNativeWindow()->parent()); | 84 EXPECT_EQ(GetPanelContainer(), window->parent()); |
80 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(window.get())); | 85 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(window.get())); |
81 } | 86 } |
82 | 87 |
83 // Tests that panels are ordered right-to-left. | 88 // Tests interactions between multiple panels |
84 TEST_F(PanelLayoutManagerTest, PanelAboveLauncherIcons) { | 89 TEST_F(PanelLayoutManagerTest, MultiplePanelsAreAboveIcons) { |
85 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraPanelManager)) | 90 gfx::Rect odd_bounds(0, 0, 201, 201); |
86 return; | 91 gfx::Rect even_bounds(0, 0, 200, 200); |
87 | 92 |
88 gfx::Rect bounds(0, 0, 201, 201); | 93 scoped_ptr<aura::Window> w1(CreatePanelWindow(odd_bounds)); |
89 scoped_ptr<views::Widget> w1(CreatePanelWindow(bounds)); | |
90 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); | 94 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); |
91 scoped_ptr<views::Widget> w2(CreatePanelWindow(bounds)); | 95 |
96 scoped_ptr<aura::Window> w2(CreatePanelWindow(even_bounds)); | |
92 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); | 97 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); |
93 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w2.get())); | 98 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w2.get())); |
94 scoped_ptr<views::Widget> w3(CreatePanelWindow(bounds)); | 99 |
100 scoped_ptr<aura::Window> w3(CreatePanelWindow(odd_bounds)); | |
95 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); | 101 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); |
96 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w2.get())); | 102 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w2.get())); |
97 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w3.get())); | 103 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w3.get())); |
98 } | 104 } |
99 | 105 |
100 // Tests removing a panel. | 106 TEST_F(PanelLayoutManagerTest, MultiplePanelStacking) { |
101 TEST_F(PanelLayoutManagerTest, RemovePanel) { | 107 gfx::Rect bounds(0, 0, 201, 201); |
102 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraPanelManager)) | 108 scoped_ptr<aura::Window> w1(CreatePanelWindow(bounds)); |
103 return; | 109 scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds)); |
110 scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds)); | |
104 | 111 |
112 // Default stacking order. | |
113 ASSERT_EQ(3u, GetPanelContainer()->children().size()); | |
114 EXPECT_EQ(w1.get(), GetPanelContainer()->children()[0]); | |
115 EXPECT_EQ(w2.get(), GetPanelContainer()->children()[1]); | |
116 EXPECT_EQ(w3.get(), GetPanelContainer()->children()[2]); | |
117 | |
118 // Changing the active window should update the stacking order. | |
119 wm::ActivateWindow(w1.get()); | |
120 ASSERT_EQ(3u, GetPanelContainer()->children().size()); | |
121 EXPECT_EQ(w3.get(), GetPanelContainer()->children()[0]); | |
122 EXPECT_EQ(w2.get(), GetPanelContainer()->children()[1]); | |
123 EXPECT_EQ(w1.get(), GetPanelContainer()->children()[2]); | |
124 | |
125 wm::ActivateWindow(w2.get()); | |
126 ASSERT_EQ(3u, GetPanelContainer()->children().size()); | |
127 EXPECT_EQ(w3.get(), GetPanelContainer()->children()[0]); | |
128 EXPECT_EQ(w1.get(), GetPanelContainer()->children()[1]); | |
129 EXPECT_EQ(w2.get(), GetPanelContainer()->children()[2]); | |
130 | |
131 wm::ActivateWindow(w3.get()); | |
132 ASSERT_EQ(3u, GetPanelContainer()->children().size()); | |
133 EXPECT_EQ(w1.get(), GetPanelContainer()->children()[0]); | |
134 EXPECT_EQ(w2.get(), GetPanelContainer()->children()[1]); | |
135 EXPECT_EQ(w3.get(), GetPanelContainer()->children()[2]); | |
136 } | |
137 | |
138 // Tests removing panels. | |
139 TEST_F(PanelLayoutManagerTest, RemoveLeftPanel) { | |
105 gfx::Rect bounds(0, 0, 201, 201); | 140 gfx::Rect bounds(0, 0, 201, 201); |
106 scoped_ptr<views::Widget> w1(CreatePanelWindow(bounds)); | 141 scoped_ptr<aura::Window> w1(CreatePanelWindow(bounds)); |
107 scoped_ptr<views::Widget> w2(CreatePanelWindow(bounds)); | 142 scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds)); |
108 scoped_ptr<views::Widget> w3(CreatePanelWindow(bounds)); | 143 scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds)); |
109 | 144 |
110 GetPanelContainer()->RemoveChild(w2->GetNativeWindow()); | 145 wm::ActivateWindow(w1.get()); |
146 w1.reset(); | |
147 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w2.get())); | |
148 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w3.get())); | |
149 ASSERT_EQ(2u, GetPanelContainer()->children().size()); | |
150 EXPECT_EQ(w3.get(), GetPanelContainer()->children()[0]); | |
151 EXPECT_EQ(w2.get(), GetPanelContainer()->children()[1]); | |
152 } | |
111 | 153 |
154 TEST_F(PanelLayoutManagerTest, RemoveMiddlePanel) { | |
155 gfx::Rect bounds(0, 0, 201, 201); | |
156 scoped_ptr<aura::Window> w1(CreatePanelWindow(bounds)); | |
157 scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds)); | |
158 scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds)); | |
159 | |
160 wm::ActivateWindow(w2.get()); | |
161 w2.reset(); | |
112 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); | 162 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); |
113 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w3.get())); | 163 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w3.get())); |
164 ASSERT_EQ(2u, GetPanelContainer()->children().size()); | |
165 EXPECT_EQ(w1.get(), GetPanelContainer()->children()[0]); | |
166 EXPECT_EQ(w3.get(), GetPanelContainer()->children()[1]); | |
167 } | |
168 | |
169 TEST_F(PanelLayoutManagerTest, RemoveRightPanel) { | |
170 gfx::Rect bounds(0, 0, 201, 201); | |
171 scoped_ptr<aura::Window> w1(CreatePanelWindow(bounds)); | |
172 scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds)); | |
173 scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds)); | |
174 | |
175 wm::ActivateWindow(w3.get()); | |
176 w3.reset(); | |
177 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); | |
178 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w2.get())); | |
179 ASSERT_EQ(2u, GetPanelContainer()->children().size()); | |
180 EXPECT_EQ(w1.get(), GetPanelContainer()->children()[0]); | |
181 EXPECT_EQ(w2.get(), GetPanelContainer()->children()[1]); | |
182 } | |
183 | |
184 TEST_F(PanelLayoutManagerTest, RemoveNonActivePanel) { | |
185 gfx::Rect bounds(0, 0, 201, 201); | |
186 scoped_ptr<aura::Window> w1(CreatePanelWindow(bounds)); | |
187 scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds)); | |
188 scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds)); | |
189 | |
190 wm::ActivateWindow(w2.get()); | |
191 w1.reset(); | |
192 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w2.get())); | |
193 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w3.get())); | |
194 ASSERT_EQ(2u, GetPanelContainer()->children().size()); | |
195 EXPECT_EQ(w3.get(), GetPanelContainer()->children()[0]); | |
196 EXPECT_EQ(w2.get(), GetPanelContainer()->children()[1]); | |
114 } | 197 } |
115 | 198 |
116 } // namespace ash | 199 } // namespace ash |
OLD | NEW |