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 aura::Window* CreatePanelWindow(const gfx::Rect& bounds) { |
45 return Shell::GetInstance()->GetContainer( | 36 aura::Window* window = CreateTestWindowWithDelegateAndType( |
46 ash::internal::kShellWindowId_PanelContainer); | 37 &window_delegate_, |
38 aura::client::WINDOW_TYPE_PANEL, | |
39 0, | |
40 bounds, | |
41 NULL /* parent should automatically become GetPanelContainer */); | |
42 ash::test::TestLauncherDelegate* launcher_delegate = | |
43 ash::test::TestLauncherDelegate::instance(); | |
44 CHECK(launcher_delegate); | |
45 launcher_delegate->AddLauncherItem(window); | |
46 return window; | |
47 } | 47 } |
48 | 48 |
49 private: | 49 private: |
50 aura::test::TestWindowDelegate window_delegate_; | |
51 | |
50 DISALLOW_COPY_AND_ASSIGN(PanelLayoutManagerTest); | 52 DISALLOW_COPY_AND_ASSIGN(PanelLayoutManagerTest); |
51 }; | 53 }; |
52 | 54 |
53 void IsPanelAboveLauncherIcon(views::Widget* panel) { | 55 // TODO(dcheng): This should be const, but GetScreeNBoundsOfItemIconForWindow |
56 // takes a non-const Window. We can probably fix that. | |
57 void IsPanelAboveLauncherIcon(aura::Window* panel) { | |
54 Launcher* launcher = Shell::GetInstance()->launcher(); | 58 Launcher* launcher = Shell::GetInstance()->launcher(); |
55 aura::Window* window = panel->GetNativeWindow(); | 59 gfx::Rect icon_bounds = launcher->GetScreenBoundsOfItemIconForWindow(panel); |
56 gfx::Rect icon_bounds = launcher->GetScreenBoundsOfItemIconForWindow(window); | |
57 ASSERT_FALSE(icon_bounds.IsEmpty()); | 60 ASSERT_FALSE(icon_bounds.IsEmpty()); |
58 | 61 |
59 gfx::Rect window_bounds = panel->GetWindowScreenBounds(); | 62 gfx::Rect window_bounds = panel->GetBoundsInRootWindow(); |
60 | 63 |
61 // 1-pixel tolerance--since we center panels over their icons, panels with odd | 64 // 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 | 65 // pixel widths won't be perfectly lined up with even pixel width launcher |
63 // icons. | 66 // icons. |
64 EXPECT_NEAR( | 67 EXPECT_NEAR( |
65 window_bounds.CenterPoint().x(), icon_bounds.CenterPoint().x(), 1); | 68 window_bounds.CenterPoint().x(), icon_bounds.CenterPoint().x(), 1); |
66 EXPECT_EQ(window_bounds.bottom(), icon_bounds.y()); | 69 EXPECT_EQ(window_bounds.bottom(), icon_bounds.y()); |
67 } | 70 } |
68 | 71 |
69 } // namespace | 72 } // namespace |
70 | 73 |
71 // Tests that a created panel window is successfully added to the panel | 74 // Tests that a created panel window is successfully added to the panel |
72 // layout manager. | 75 // layout manager. |
73 TEST_F(PanelLayoutManagerTest, AddOnePanel) { | 76 TEST_F(PanelLayoutManagerTest, AddOnePanel) { |
74 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraPanelManager)) | 77 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraPanelManager)) |
sky
2012/04/26 04:30:31
Doesn't this mean none of these tests are going to
dcheng
2012/04/26 06:30:59
I've been under the impression that this wouldn't
| |
75 return; | 78 return; |
76 | 79 |
77 gfx::Rect bounds(0, 0, 201, 201); | 80 gfx::Rect bounds(0, 0, 201, 201); |
78 scoped_ptr<views::Widget> window(CreatePanelWindow(bounds)); | 81 scoped_ptr<aura::Window> window(CreatePanelWindow(bounds)); |
79 EXPECT_EQ(GetPanelContainer(), window->GetNativeWindow()->parent()); | 82 EXPECT_EQ(GetPanelContainer(), window->parent()); |
80 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(window.get())); | 83 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(window.get())); |
84 | |
85 LOG(ERROR) << "Running tests!"; | |
sky
2012/04/26 04:30:31
remove this.
dcheng
2012/04/26 06:30:59
Done.
| |
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 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraPanelManager)) |
86 return; | 91 return; |
87 | 92 |
88 gfx::Rect bounds(0, 0, 201, 201); | 93 gfx::Rect odd_bounds(0, 0, 201, 201); |
89 scoped_ptr<views::Widget> w1(CreatePanelWindow(bounds)); | 94 gfx::Rect even_bounds(0, 0, 200, 200); |
95 | |
96 scoped_ptr<aura::Window> w1(CreatePanelWindow(odd_bounds)); | |
90 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); | 97 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); |
91 scoped_ptr<views::Widget> w2(CreatePanelWindow(bounds)); | 98 |
99 scoped_ptr<aura::Window> w2(CreatePanelWindow(even_bounds)); | |
92 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); | 100 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); |
93 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w2.get())); | 101 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w2.get())); |
94 scoped_ptr<views::Widget> w3(CreatePanelWindow(bounds)); | 102 |
103 scoped_ptr<aura::Window> w3(CreatePanelWindow(odd_bounds)); | |
95 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); | 104 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); |
96 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w2.get())); | 105 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w2.get())); |
97 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w3.get())); | 106 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w3.get())); |
98 } | 107 } |
99 | 108 |
100 // Tests removing a panel. | 109 TEST_F(PanelLayoutManagerTest, MultiplePanelStacking) { |
101 TEST_F(PanelLayoutManagerTest, RemovePanel) { | |
102 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraPanelManager)) | 110 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraPanelManager)) |
103 return; | 111 return; |
104 | 112 |
105 gfx::Rect bounds(0, 0, 201, 201); | 113 gfx::Rect bounds(0, 0, 201, 201); |
106 scoped_ptr<views::Widget> w1(CreatePanelWindow(bounds)); | 114 scoped_ptr<aura::Window> w1(CreatePanelWindow(bounds)); |
107 scoped_ptr<views::Widget> w2(CreatePanelWindow(bounds)); | 115 scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds)); |
108 scoped_ptr<views::Widget> w3(CreatePanelWindow(bounds)); | 116 scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds)); |
109 | 117 |
110 GetPanelContainer()->RemoveChild(w2->GetNativeWindow()); | 118 // Default stacking order. |
119 ASSERT_EQ(3u, GetPanelContainer()->children().size()); | |
120 EXPECT_EQ(w1.get(), GetPanelContainer()->children()[0]); | |
121 EXPECT_EQ(w2.get(), GetPanelContainer()->children()[1]); | |
122 EXPECT_EQ(w3.get(), GetPanelContainer()->children()[2]); | |
111 | 123 |
124 // Changing the active window should update the stacking order. | |
125 wm::ActivateWindow(w1.get()); | |
126 ASSERT_EQ(3u, GetPanelContainer()->children().size()); | |
127 EXPECT_EQ(w3.get(), GetPanelContainer()->children()[0]); | |
128 EXPECT_EQ(w2.get(), GetPanelContainer()->children()[1]); | |
129 EXPECT_EQ(w1.get(), GetPanelContainer()->children()[2]); | |
130 | |
131 wm::ActivateWindow(w2.get()); | |
132 ASSERT_EQ(3u, GetPanelContainer()->children().size()); | |
133 EXPECT_EQ(w3.get(), GetPanelContainer()->children()[0]); | |
134 EXPECT_EQ(w1.get(), GetPanelContainer()->children()[1]); | |
135 EXPECT_EQ(w2.get(), GetPanelContainer()->children()[2]); | |
136 | |
137 wm::ActivateWindow(w3.get()); | |
138 ASSERT_EQ(3u, GetPanelContainer()->children().size()); | |
139 EXPECT_EQ(w1.get(), GetPanelContainer()->children()[0]); | |
140 EXPECT_EQ(w2.get(), GetPanelContainer()->children()[1]); | |
141 EXPECT_EQ(w3.get(), GetPanelContainer()->children()[2]); | |
142 } | |
143 | |
144 // Tests removing panels. | |
145 TEST_F(PanelLayoutManagerTest, RemoveLeftPanel) { | |
146 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraPanelManager)) | |
147 return; | |
148 | |
149 gfx::Rect bounds(0, 0, 201, 201); | |
150 scoped_ptr<aura::Window> w1(CreatePanelWindow(bounds)); | |
151 scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds)); | |
152 scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds)); | |
153 | |
154 wm::ActivateWindow(w1.get()); | |
155 w1.reset(); | |
156 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w2.get())); | |
157 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w3.get())); | |
158 ASSERT_EQ(2u, GetPanelContainer()->children().size()); | |
159 EXPECT_EQ(w3.get(), GetPanelContainer()->children()[0]); | |
160 EXPECT_EQ(w2.get(), GetPanelContainer()->children()[1]); | |
161 } | |
162 | |
163 TEST_F(PanelLayoutManagerTest, RemoveMiddlePanel) { | |
164 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraPanelManager)) | |
165 return; | |
166 | |
167 gfx::Rect bounds(0, 0, 201, 201); | |
168 scoped_ptr<aura::Window> w1(CreatePanelWindow(bounds)); | |
169 scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds)); | |
170 scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds)); | |
171 | |
172 wm::ActivateWindow(w2.get()); | |
173 w2.reset(); | |
112 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); | 174 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); |
113 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w3.get())); | 175 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w3.get())); |
176 ASSERT_EQ(2u, GetPanelContainer()->children().size()); | |
177 EXPECT_EQ(w1.get(), GetPanelContainer()->children()[0]); | |
178 EXPECT_EQ(w3.get(), GetPanelContainer()->children()[1]); | |
179 } | |
180 | |
181 TEST_F(PanelLayoutManagerTest, RemoveRightPanel) { | |
182 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraPanelManager)) | |
183 return; | |
184 | |
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(w3.get()); | |
191 w3.reset(); | |
192 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); | |
193 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w2.get())); | |
194 ASSERT_EQ(2u, GetPanelContainer()->children().size()); | |
195 EXPECT_EQ(w1.get(), GetPanelContainer()->children()[0]); | |
196 EXPECT_EQ(w2.get(), GetPanelContainer()->children()[1]); | |
197 } | |
198 | |
199 TEST_F(PanelLayoutManagerTest, RemoveNonActivePanel) { | |
200 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kAuraPanelManager)) | |
201 return; | |
202 | |
203 gfx::Rect bounds(0, 0, 201, 201); | |
204 scoped_ptr<aura::Window> w1(CreatePanelWindow(bounds)); | |
205 scoped_ptr<aura::Window> w2(CreatePanelWindow(bounds)); | |
206 scoped_ptr<aura::Window> w3(CreatePanelWindow(bounds)); | |
207 | |
208 wm::ActivateWindow(w2.get()); | |
209 w1.reset(); | |
210 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w2.get())); | |
211 EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w3.get())); | |
212 ASSERT_EQ(2u, GetPanelContainer()->children().size()); | |
213 EXPECT_EQ(w3.get(), GetPanelContainer()->children()[0]); | |
214 EXPECT_EQ(w2.get(), GetPanelContainer()->children()[1]); | |
114 } | 215 } |
115 | 216 |
116 } // namespace ash | 217 } // namespace ash |
OLD | NEW |