OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/launcher/launcher.h" |
5 #include "ash/root_window_controller.h" | 6 #include "ash/root_window_controller.h" |
6 #include "ash/screen_ash.h" | 7 #include "ash/screen_ash.h" |
7 #include "ash/shell.h" | 8 #include "ash/shell.h" |
8 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
| 10 #include "ash/test/launcher_view_test_api.h" |
9 #include "ash/test/shell_test_api.h" | 11 #include "ash/test/shell_test_api.h" |
| 12 #include "ash/test/test_launcher_delegate.h" |
10 #include "ash/wm/mru_window_tracker.h" | 13 #include "ash/wm/mru_window_tracker.h" |
11 #include "ash/wm/overview/window_selector.h" | 14 #include "ash/wm/overview/window_selector.h" |
12 #include "ash/wm/overview/window_selector_controller.h" | 15 #include "ash/wm/overview/window_selector_controller.h" |
13 #include "ash/wm/window_util.h" | 16 #include "ash/wm/window_util.h" |
14 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
15 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
16 #include "base/memory/scoped_vector.h" | 19 #include "base/memory/scoped_vector.h" |
17 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
18 #include "ui/aura/client/aura_constants.h" | 21 #include "ui/aura/client/aura_constants.h" |
19 #include "ui/aura/client/focus_client.h" | 22 #include "ui/aura/client/focus_client.h" |
20 #include "ui/aura/root_window.h" | 23 #include "ui/aura/root_window.h" |
21 #include "ui/aura/test/event_generator.h" | 24 #include "ui/aura/test/event_generator.h" |
22 #include "ui/aura/test/test_window_delegate.h" | 25 #include "ui/aura/test/test_window_delegate.h" |
23 #include "ui/aura/test/test_windows.h" | 26 #include "ui/aura/test/test_windows.h" |
24 #include "ui/aura/window.h" | 27 #include "ui/aura/window.h" |
25 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 28 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
26 #include "ui/gfx/rect_conversions.h" | 29 #include "ui/gfx/rect_conversions.h" |
27 #include "ui/gfx/transform.h" | 30 #include "ui/gfx/transform.h" |
28 | 31 |
29 namespace ash { | 32 namespace ash { |
30 namespace internal { | 33 namespace internal { |
31 | 34 |
32 class WindowSelectorTest : public test::AshTestBase { | 35 class WindowSelectorTest : public test::AshTestBase { |
33 public: | 36 public: |
34 WindowSelectorTest() {} | 37 WindowSelectorTest() {} |
35 virtual ~WindowSelectorTest() {} | 38 virtual ~WindowSelectorTest() {} |
36 | 39 |
| 40 virtual void SetUp() OVERRIDE { |
| 41 test::AshTestBase::SetUp(); |
| 42 ASSERT_TRUE(test::TestLauncherDelegate::instance()); |
| 43 |
| 44 launcher_view_test_.reset(new test::LauncherViewTestAPI( |
| 45 Launcher::ForPrimaryDisplay()->GetLauncherViewForTest())); |
| 46 launcher_view_test_->SetAnimationDuration(1); |
| 47 } |
| 48 |
37 aura::Window* CreateWindow(const gfx::Rect& bounds) { | 49 aura::Window* CreateWindow(const gfx::Rect& bounds) { |
38 return CreateTestWindowInShellWithDelegate(&wd, -1, bounds); | 50 return CreateTestWindowInShellWithDelegate(&wd, -1, bounds); |
39 } | 51 } |
40 | 52 |
| 53 aura::Window* CreatePanelWindow(const gfx::Rect& bounds) { |
| 54 aura::Window* window = CreateTestWindowInShellWithDelegateAndType( |
| 55 NULL, aura::client::WINDOW_TYPE_PANEL, 0, bounds); |
| 56 test::TestLauncherDelegate::instance()->AddLauncherItem(window); |
| 57 launcher_view_test()->RunMessageLoopUntilAnimationsDone(); |
| 58 return window; |
| 59 } |
| 60 |
41 bool WindowsOverlapping(aura::Window* window1, aura::Window* window2) { | 61 bool WindowsOverlapping(aura::Window* window1, aura::Window* window2) { |
42 gfx::RectF window1_bounds = GetTransformedTargetBounds(window1); | 62 gfx::RectF window1_bounds = GetTransformedTargetBounds(window1); |
43 gfx::RectF window2_bounds = GetTransformedTargetBounds(window2); | 63 gfx::RectF window2_bounds = GetTransformedTargetBounds(window2); |
44 return window1_bounds.Intersects(window2_bounds); | 64 return window1_bounds.Intersects(window2_bounds); |
45 } | 65 } |
46 | 66 |
47 void ToggleOverview() { | 67 void ToggleOverview() { |
48 ash::Shell::GetInstance()->window_selector_controller()->ToggleOverview(); | 68 ash::Shell::GetInstance()->window_selector_controller()->ToggleOverview(); |
49 } | 69 } |
50 | 70 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 bool IsSelecting() { | 108 bool IsSelecting() { |
89 return ash::Shell::GetInstance()->window_selector_controller()-> | 109 return ash::Shell::GetInstance()->window_selector_controller()-> |
90 IsSelecting(); | 110 IsSelecting(); |
91 } | 111 } |
92 | 112 |
93 aura::Window* GetFocusedWindow() { | 113 aura::Window* GetFocusedWindow() { |
94 return aura::client::GetFocusClient( | 114 return aura::client::GetFocusClient( |
95 Shell::GetActiveRootWindow())->GetFocusedWindow(); | 115 Shell::GetActiveRootWindow())->GetFocusedWindow(); |
96 } | 116 } |
97 | 117 |
| 118 test::LauncherViewTestAPI* launcher_view_test() { |
| 119 return launcher_view_test_.get(); |
| 120 } |
| 121 |
98 private: | 122 private: |
99 aura::test::TestWindowDelegate wd; | 123 aura::test::TestWindowDelegate wd; |
| 124 scoped_ptr<test::LauncherViewTestAPI> launcher_view_test_; |
100 | 125 |
101 DISALLOW_COPY_AND_ASSIGN(WindowSelectorTest); | 126 DISALLOW_COPY_AND_ASSIGN(WindowSelectorTest); |
102 }; | 127 }; |
103 | 128 |
104 // Tests entering overview mode with two windows and selecting one. | 129 // Tests entering overview mode with two windows and selecting one. |
105 TEST_F(WindowSelectorTest, Basic) { | 130 TEST_F(WindowSelectorTest, Basic) { |
106 gfx::Rect bounds(0, 0, 400, 400); | 131 gfx::Rect bounds(0, 0, 400, 400); |
107 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); | 132 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); |
108 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); | 133 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); |
| 134 scoped_ptr<aura::Window> panel1(CreatePanelWindow(bounds)); |
| 135 scoped_ptr<aura::Window> panel2(CreatePanelWindow(bounds)); |
109 EXPECT_TRUE(WindowsOverlapping(window1.get(), window2.get())); | 136 EXPECT_TRUE(WindowsOverlapping(window1.get(), window2.get())); |
| 137 EXPECT_TRUE(WindowsOverlapping(window1.get(), panel1.get())); |
| 138 EXPECT_TRUE(WindowsOverlapping(panel1.get(), panel2.get())); |
110 wm::ActivateWindow(window2.get()); | 139 wm::ActivateWindow(window2.get()); |
111 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); | 140 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); |
112 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); | 141 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); |
113 EXPECT_EQ(window2.get(), GetFocusedWindow()); | 142 EXPECT_EQ(window2.get(), GetFocusedWindow()); |
114 | 143 |
115 // In overview mode the windows should no longer overlap and focus should | 144 // In overview mode the windows should no longer overlap and focus should |
116 // be removed from the window. | 145 // be removed from the window. |
117 ToggleOverview(); | 146 ToggleOverview(); |
118 EXPECT_EQ(NULL, GetFocusedWindow()); | 147 EXPECT_EQ(NULL, GetFocusedWindow()); |
119 EXPECT_FALSE(WindowsOverlapping(window1.get(), window2.get())); | 148 EXPECT_FALSE(WindowsOverlapping(window1.get(), window2.get())); |
| 149 EXPECT_FALSE(WindowsOverlapping(window1.get(), panel1.get())); |
| 150 // Panels 1 and 2 should still be overlapping being in a single selector |
| 151 // item. |
| 152 EXPECT_TRUE(WindowsOverlapping(panel1.get(), panel2.get())); |
120 | 153 |
121 // Clicking window 1 should activate it. | 154 // Clicking window 1 should activate it. |
122 ClickWindow(window1.get()); | 155 ClickWindow(window1.get()); |
123 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); | 156 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); |
124 EXPECT_FALSE(wm::IsActiveWindow(window2.get())); | 157 EXPECT_FALSE(wm::IsActiveWindow(window2.get())); |
125 EXPECT_EQ(window1.get(), GetFocusedWindow()); | 158 EXPECT_EQ(window1.get(), GetFocusedWindow()); |
126 } | 159 } |
127 | 160 |
128 // Tests entering overview mode with three windows and cycling through them. | 161 // Tests entering overview mode with three windows and cycling through them. |
129 TEST_F(WindowSelectorTest, BasicCycle) { | 162 TEST_F(WindowSelectorTest, BasicCycle) { |
(...skipping 11 matching lines...) Expand all Loading... |
141 Cycle(WindowSelector::FORWARD); | 174 Cycle(WindowSelector::FORWARD); |
142 EXPECT_TRUE(IsSelecting()); | 175 EXPECT_TRUE(IsSelecting()); |
143 Cycle(WindowSelector::FORWARD); | 176 Cycle(WindowSelector::FORWARD); |
144 StopCycling(); | 177 StopCycling(); |
145 EXPECT_FALSE(IsSelecting()); | 178 EXPECT_FALSE(IsSelecting()); |
146 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); | 179 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); |
147 EXPECT_FALSE(wm::IsActiveWindow(window2.get())); | 180 EXPECT_FALSE(wm::IsActiveWindow(window2.get())); |
148 EXPECT_TRUE(wm::IsActiveWindow(window3.get())); | 181 EXPECT_TRUE(wm::IsActiveWindow(window3.get())); |
149 } | 182 } |
150 | 183 |
| 184 // Tests cycles between panel and normal windows. |
| 185 TEST_F(WindowSelectorTest, CyclePanels) { |
| 186 gfx::Rect bounds(0, 0, 400, 400); |
| 187 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); |
| 188 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); |
| 189 scoped_ptr<aura::Window> panel1(CreatePanelWindow(bounds)); |
| 190 scoped_ptr<aura::Window> panel2(CreatePanelWindow(bounds)); |
| 191 wm::ActivateWindow(window2.get()); |
| 192 wm::ActivateWindow(window1.get()); |
| 193 wm::ActivateWindow(panel2.get()); |
| 194 wm::ActivateWindow(panel1.get()); |
| 195 EXPECT_TRUE(wm::IsActiveWindow(panel1.get())); |
| 196 |
| 197 // Cycling once should select window1 since the panels are grouped into a |
| 198 // single selectable item. |
| 199 Cycle(WindowSelector::FORWARD); |
| 200 StopCycling(); |
| 201 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); |
| 202 |
| 203 // Cycling again should select the most recently used panel. |
| 204 Cycle(WindowSelector::FORWARD); |
| 205 StopCycling(); |
| 206 EXPECT_TRUE(wm::IsActiveWindow(panel1.get())); |
| 207 } |
| 208 |
| 209 // Tests cycles between panel and normal windows. |
| 210 TEST_F(WindowSelectorTest, CyclePanelsDestroyed) { |
| 211 gfx::Rect bounds(0, 0, 400, 400); |
| 212 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); |
| 213 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); |
| 214 scoped_ptr<aura::Window> window3(CreateWindow(bounds)); |
| 215 scoped_ptr<aura::Window> panel1(CreatePanelWindow(bounds)); |
| 216 scoped_ptr<aura::Window> panel2(CreatePanelWindow(bounds)); |
| 217 wm::ActivateWindow(window3.get()); |
| 218 wm::ActivateWindow(panel2.get()); |
| 219 wm::ActivateWindow(panel1.get()); |
| 220 wm::ActivateWindow(window2.get()); |
| 221 wm::ActivateWindow(window1.get()); |
| 222 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); |
| 223 |
| 224 // Cycling once highlights window2. |
| 225 Cycle(WindowSelector::FORWARD); |
| 226 // All panels are destroyed. |
| 227 panel1.reset(); |
| 228 panel2.reset(); |
| 229 // Cycling again should now select window3. |
| 230 Cycle(WindowSelector::FORWARD); |
| 231 StopCycling(); |
| 232 EXPECT_TRUE(wm::IsActiveWindow(window3.get())); |
| 233 } |
| 234 |
| 235 // Tests cycles between panel and normal windows. |
| 236 TEST_F(WindowSelectorTest, CycleMruPanelDestroyed) { |
| 237 gfx::Rect bounds(0, 0, 400, 400); |
| 238 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); |
| 239 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); |
| 240 scoped_ptr<aura::Window> panel1(CreatePanelWindow(bounds)); |
| 241 scoped_ptr<aura::Window> panel2(CreatePanelWindow(bounds)); |
| 242 wm::ActivateWindow(panel2.get()); |
| 243 wm::ActivateWindow(panel1.get()); |
| 244 wm::ActivateWindow(window2.get()); |
| 245 wm::ActivateWindow(window1.get()); |
| 246 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); |
| 247 |
| 248 // Cycling once highlights window2. |
| 249 Cycle(WindowSelector::FORWARD); |
| 250 // Panel 1 is the next item as the MRU panel, removing it should make panel 2 |
| 251 // the next window to be selected. |
| 252 panel1.reset(); |
| 253 // Cycling again should now select window3. |
| 254 Cycle(WindowSelector::FORWARD); |
| 255 StopCycling(); |
| 256 EXPECT_TRUE(wm::IsActiveWindow(panel2.get())); |
| 257 } |
| 258 |
151 // Tests that a newly created window aborts overview. | 259 // Tests that a newly created window aborts overview. |
152 TEST_F(WindowSelectorTest, NewWindowCancelsOveriew) { | 260 TEST_F(WindowSelectorTest, NewWindowCancelsOveriew) { |
153 gfx::Rect bounds(0, 0, 400, 400); | 261 gfx::Rect bounds(0, 0, 400, 400); |
154 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); | 262 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); |
155 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); | 263 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); |
156 ToggleOverview(); | 264 ToggleOverview(); |
157 EXPECT_TRUE(IsSelecting()); | 265 EXPECT_TRUE(IsSelecting()); |
158 | 266 |
159 // A window being created should exit overview mode. | 267 // A window being created should exit overview mode. |
160 scoped_ptr<aura::Window> window3(CreateWindow(bounds)); | 268 scoped_ptr<aura::Window> window3(CreateWindow(bounds)); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 EXPECT_EQ(initial_bounds, ToEnclosingRect( | 358 EXPECT_EQ(initial_bounds, ToEnclosingRect( |
251 GetTransformedTargetBounds(window.get()))); | 359 GetTransformedTargetBounds(window.get()))); |
252 } | 360 } |
253 | 361 |
254 // Tests that windows remain on the display they are currently on in overview | 362 // Tests that windows remain on the display they are currently on in overview |
255 // mode. | 363 // mode. |
256 TEST_F(WindowSelectorTest, MultipleDisplays) { | 364 TEST_F(WindowSelectorTest, MultipleDisplays) { |
257 if (!SupportsMultipleDisplays()) | 365 if (!SupportsMultipleDisplays()) |
258 return; | 366 return; |
259 | 367 |
260 UpdateDisplay("400x400,400x400"); | 368 UpdateDisplay("600x400,600x400"); |
261 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 369 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 370 gfx::Rect bounds1(0, 0, 200, 200); |
| 371 gfx::Rect bounds2(650, 0, 200, 200); |
262 | 372 |
263 scoped_ptr<aura::Window> window1(CreateWindow(gfx::Rect(0, 0, 100, 100))); | 373 scoped_ptr<aura::Window> window1(CreateWindow(bounds1)); |
264 scoped_ptr<aura::Window> window2(CreateWindow(gfx::Rect(0, 0, 100, 100))); | 374 scoped_ptr<aura::Window> window2(CreateWindow(bounds1)); |
265 scoped_ptr<aura::Window> window3(CreateWindow(gfx::Rect(450, 0, 100, 100))); | 375 scoped_ptr<aura::Window> window3(CreateWindow(bounds2)); |
266 scoped_ptr<aura::Window> window4(CreateWindow(gfx::Rect(450, 0, 100, 100))); | 376 scoped_ptr<aura::Window> window4(CreateWindow(bounds2)); |
| 377 scoped_ptr<aura::Window> panel1(CreatePanelWindow(bounds1)); |
| 378 scoped_ptr<aura::Window> panel2(CreatePanelWindow(bounds1)); |
| 379 scoped_ptr<aura::Window> panel3(CreatePanelWindow(bounds2)); |
| 380 scoped_ptr<aura::Window> panel4(CreatePanelWindow(bounds2)); |
267 EXPECT_EQ(root_windows[0], window1->GetRootWindow()); | 381 EXPECT_EQ(root_windows[0], window1->GetRootWindow()); |
268 EXPECT_EQ(root_windows[0], window2->GetRootWindow()); | 382 EXPECT_EQ(root_windows[0], window2->GetRootWindow()); |
269 EXPECT_EQ(root_windows[1], window3->GetRootWindow()); | 383 EXPECT_EQ(root_windows[1], window3->GetRootWindow()); |
270 EXPECT_EQ(root_windows[1], window4->GetRootWindow()); | 384 EXPECT_EQ(root_windows[1], window4->GetRootWindow()); |
271 | 385 |
| 386 EXPECT_EQ(root_windows[0], panel1->GetRootWindow()); |
| 387 EXPECT_EQ(root_windows[0], panel2->GetRootWindow()); |
| 388 EXPECT_EQ(root_windows[1], panel3->GetRootWindow()); |
| 389 EXPECT_EQ(root_windows[1], panel4->GetRootWindow()); |
| 390 |
272 // In overview mode, each window remains in the same root window. | 391 // In overview mode, each window remains in the same root window. |
273 ToggleOverview(); | 392 ToggleOverview(); |
274 EXPECT_EQ(root_windows[0], window1->GetRootWindow()); | 393 EXPECT_EQ(root_windows[0], window1->GetRootWindow()); |
275 EXPECT_EQ(root_windows[0], window2->GetRootWindow()); | 394 EXPECT_EQ(root_windows[0], window2->GetRootWindow()); |
276 EXPECT_EQ(root_windows[1], window3->GetRootWindow()); | 395 EXPECT_EQ(root_windows[1], window3->GetRootWindow()); |
277 EXPECT_EQ(root_windows[1], window4->GetRootWindow()); | 396 EXPECT_EQ(root_windows[1], window4->GetRootWindow()); |
| 397 EXPECT_EQ(root_windows[0], panel1->GetRootWindow()); |
| 398 EXPECT_EQ(root_windows[0], panel2->GetRootWindow()); |
| 399 EXPECT_EQ(root_windows[1], panel3->GetRootWindow()); |
| 400 EXPECT_EQ(root_windows[1], panel4->GetRootWindow()); |
| 401 |
278 root_windows[0]->bounds().Contains( | 402 root_windows[0]->bounds().Contains( |
279 ToEnclosingRect(GetTransformedBounds(window1.get()))); | 403 ToEnclosingRect(GetTransformedBounds(window1.get()))); |
280 root_windows[0]->bounds().Contains( | 404 root_windows[0]->bounds().Contains( |
281 ToEnclosingRect(GetTransformedBounds(window2.get()))); | 405 ToEnclosingRect(GetTransformedBounds(window2.get()))); |
282 root_windows[1]->bounds().Contains( | 406 root_windows[1]->bounds().Contains( |
283 ToEnclosingRect(GetTransformedBounds(window3.get()))); | 407 ToEnclosingRect(GetTransformedBounds(window3.get()))); |
284 root_windows[1]->bounds().Contains( | 408 root_windows[1]->bounds().Contains( |
285 ToEnclosingRect(GetTransformedBounds(window4.get()))); | 409 ToEnclosingRect(GetTransformedBounds(window4.get()))); |
| 410 |
| 411 root_windows[0]->bounds().Contains( |
| 412 ToEnclosingRect(GetTransformedBounds(panel1.get()))); |
| 413 root_windows[0]->bounds().Contains( |
| 414 ToEnclosingRect(GetTransformedBounds(panel2.get()))); |
| 415 root_windows[1]->bounds().Contains( |
| 416 ToEnclosingRect(GetTransformedBounds(panel3.get()))); |
| 417 root_windows[1]->bounds().Contains( |
| 418 ToEnclosingRect(GetTransformedBounds(panel4.get()))); |
| 419 EXPECT_TRUE(WindowsOverlapping(panel1.get(), panel2.get())); |
| 420 EXPECT_TRUE(WindowsOverlapping(panel3.get(), panel4.get())); |
| 421 EXPECT_FALSE(WindowsOverlapping(panel1.get(), panel3.get())); |
286 } | 422 } |
287 | 423 |
288 } // namespace internal | 424 } // namespace internal |
289 } // namespace ash | 425 } // namespace ash |
OLD | NEW |