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/window_cycle_controller.h" | 5 #include "ash/wm/window_cycle_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
| 9 #include "ash/display/display_controller.h" |
| 10 #include "ash/display/multi_display_manager.h" |
9 #include "ash/shell.h" | 11 #include "ash/shell.h" |
10 #include "ash/shell_window_ids.h" | 12 #include "ash/shell_window_ids.h" |
11 #include "ash/test/ash_test_base.h" | 13 #include "ash/test/ash_test_base.h" |
12 #include "ash/test/test_shell_delegate.h" | 14 #include "ash/test/test_shell_delegate.h" |
13 #include "ash/wm/window_cycle_list.h" | 15 #include "ash/wm/window_cycle_list.h" |
14 #include "ash/wm/window_util.h" | 16 #include "ash/wm/window_util.h" |
15 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "ui/aura/env.h" |
16 #include "ui/aura/test/test_windows.h" | 19 #include "ui/aura/test/test_windows.h" |
17 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
18 #include "ui/gfx/rect.h" | 21 #include "ui/gfx/rect.h" |
19 | 22 |
20 namespace ash { | 23 namespace ash { |
21 | 24 |
22 namespace { | 25 namespace { |
23 | 26 |
24 using aura::test::CreateTestWindowWithId; | 27 using aura::test::CreateTestWindowWithId; |
25 using aura::test::TestWindowDelegate; | 28 using aura::test::TestWindowDelegate; |
26 using aura::Window; | 29 using aura::Window; |
27 | 30 |
28 typedef test::AshTestBase WindowCycleControllerTest; | 31 typedef test::AshTestBase WindowCycleControllerTest; |
29 | 32 |
| 33 class WindowCycleControllerExtendedDesktopTest : public test::AshTestBase { |
| 34 public: |
| 35 WindowCycleControllerExtendedDesktopTest() {} |
| 36 virtual ~WindowCycleControllerExtendedDesktopTest() {} |
| 37 |
| 38 virtual void SetUp() OVERRIDE { |
| 39 internal::DisplayController::SetExtendedDesktopEnabled(true); |
| 40 AshTestBase::SetUp(); |
| 41 } |
| 42 |
| 43 virtual void TearDown() OVERRIDE { |
| 44 AshTestBase::TearDown(); |
| 45 internal::DisplayController::SetExtendedDesktopEnabled(false); |
| 46 } |
| 47 |
| 48 protected: |
| 49 internal::MultiDisplayManager* display_manager() { |
| 50 return static_cast<internal::MultiDisplayManager*>( |
| 51 aura::Env::GetInstance()->display_manager()); |
| 52 } |
| 53 |
| 54 private: |
| 55 DISALLOW_COPY_AND_ASSIGN(WindowCycleControllerExtendedDesktopTest); |
| 56 }; |
| 57 |
30 TEST_F(WindowCycleControllerTest, HandleCycleWindowBaseCases) { | 58 TEST_F(WindowCycleControllerTest, HandleCycleWindowBaseCases) { |
31 WindowCycleController* controller = | 59 WindowCycleController* controller = |
32 Shell::GetInstance()->window_cycle_controller(); | 60 Shell::GetInstance()->window_cycle_controller(); |
33 | 61 |
34 // Cycling doesn't crash if there are no windows. | 62 // Cycling doesn't crash if there are no windows. |
35 controller->HandleCycleWindow(WindowCycleController::FORWARD, false); | 63 controller->HandleCycleWindow(WindowCycleController::FORWARD, false); |
36 | 64 |
37 // Create a single test window. | 65 // Create a single test window. |
38 Window* default_container = | 66 Window* default_container = |
39 ash::Shell::GetContainer( | 67 ash::Shell::GetContainer( |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 Shell::GetInstance()->window_cycle_controller(); | 258 Shell::GetInstance()->window_cycle_controller(); |
231 controller->HandleCycleWindow(WindowCycleController::FORWARD, false); | 259 controller->HandleCycleWindow(WindowCycleController::FORWARD, false); |
232 EXPECT_FALSE(wm::IsWindowMinimized(window1.get())); | 260 EXPECT_FALSE(wm::IsWindowMinimized(window1.get())); |
233 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); | 261 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); |
234 | 262 |
235 // One more time back to w0. | 263 // One more time back to w0. |
236 controller->HandleCycleWindow(WindowCycleController::FORWARD, false); | 264 controller->HandleCycleWindow(WindowCycleController::FORWARD, false); |
237 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 265 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
238 } | 266 } |
239 | 267 |
| 268 TEST_F(WindowCycleControllerTest, AlwaysOnTopWindow) { |
| 269 WindowCycleController* controller = |
| 270 Shell::GetInstance()->window_cycle_controller(); |
| 271 |
| 272 // Set up several windows to use to test cycling. |
| 273 Window* default_container = |
| 274 Shell::GetContainer( |
| 275 Shell::GetPrimaryRootWindow(), |
| 276 internal::kShellWindowId_DefaultContainer); |
| 277 scoped_ptr<Window> window0(CreateTestWindowWithId(0, default_container)); |
| 278 scoped_ptr<Window> window1(CreateTestWindowWithId(1, default_container)); |
| 279 |
| 280 Window* top_container = |
| 281 Shell::GetContainer( |
| 282 Shell::GetPrimaryRootWindow(), |
| 283 internal::kShellWindowId_AlwaysOnTopContainer); |
| 284 scoped_ptr<Window> window2(CreateTestWindowWithId(2, top_container)); |
| 285 wm::ActivateWindow(window0.get()); |
| 286 |
| 287 // Simulate pressing and releasing Alt-tab. |
| 288 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 289 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 290 |
| 291 // Window lists should return the topmost window in front. |
| 292 ASSERT_TRUE(controller->windows()); |
| 293 ASSERT_EQ(3u, controller->windows()->windows().size()); |
| 294 EXPECT_EQ(window0.get(), controller->windows()->windows()[0]); |
| 295 EXPECT_EQ(window2.get(), controller->windows()->windows()[1]); |
| 296 EXPECT_EQ(window1.get(), controller->windows()->windows()[2]); |
| 297 |
| 298 controller->AltKeyReleased(); |
| 299 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); |
| 300 |
| 301 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 302 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 303 |
| 304 controller->AltKeyReleased(); |
| 305 |
| 306 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 307 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); |
| 308 |
| 309 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 310 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); |
| 311 |
| 312 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 313 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 314 } |
| 315 |
| 316 TEST_F(WindowCycleControllerExtendedDesktopTest, |
| 317 AlwaysOnTopMultipleRootWindows) { |
| 318 // Set up a second root window |
| 319 UpdateDisplay("0+0-1000x600,1001+0-600x400"); |
| 320 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 321 ASSERT_EQ(2U, root_windows.size()); |
| 322 |
| 323 // Move the active root window to the secondary. |
| 324 Shell::GetInstance()->set_active_root_window(root_windows[1]); |
| 325 |
| 326 WindowCycleController* controller = |
| 327 Shell::GetInstance()->window_cycle_controller(); |
| 328 |
| 329 // Set up several windows to use to test cycling. |
| 330 Window* default_container0 = |
| 331 Shell::GetContainer( |
| 332 root_windows[0], |
| 333 internal::kShellWindowId_DefaultContainer); |
| 334 scoped_ptr<Window> window0(CreateTestWindowWithId(0, default_container0)); |
| 335 |
| 336 Window* top_container0 = |
| 337 Shell::GetContainer( |
| 338 root_windows[0], |
| 339 internal::kShellWindowId_AlwaysOnTopContainer); |
| 340 scoped_ptr<Window> window1(CreateTestWindowWithId(1, top_container0)); |
| 341 |
| 342 // Set up several windows to use to test cycling. |
| 343 Window* default_container1 = |
| 344 Shell::GetContainer( |
| 345 root_windows[1], |
| 346 internal::kShellWindowId_DefaultContainer); |
| 347 scoped_ptr<Window> window2(CreateTestWindowWithId(2, default_container1)); |
| 348 |
| 349 Window* top_container1 = |
| 350 Shell::GetContainer( |
| 351 root_windows[1], |
| 352 internal::kShellWindowId_AlwaysOnTopContainer); |
| 353 scoped_ptr<Window> window3(CreateTestWindowWithId(3, top_container1)); |
| 354 |
| 355 |
| 356 wm::ActivateWindow(window2.get()); |
| 357 |
| 358 // Simulate pressing and releasing Alt-tab. |
| 359 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); |
| 360 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 361 |
| 362 // Window lists should return the topmost window in front. |
| 363 ASSERT_TRUE(controller->windows()); |
| 364 ASSERT_EQ(4u, controller->windows()->windows().size()); |
| 365 EXPECT_EQ(window2.get(), controller->windows()->windows()[0]); |
| 366 EXPECT_EQ(window3.get(), controller->windows()->windows()[1]); |
| 367 EXPECT_EQ(window1.get(), controller->windows()->windows()[2]); |
| 368 EXPECT_EQ(window0.get(), controller->windows()->windows()[3]); |
| 369 |
| 370 controller->AltKeyReleased(); |
| 371 EXPECT_TRUE(wm::IsActiveWindow(window3.get())); |
| 372 |
| 373 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 374 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); |
| 375 |
| 376 controller->AltKeyReleased(); |
| 377 |
| 378 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 379 EXPECT_TRUE(wm::IsActiveWindow(window3.get())); |
| 380 |
| 381 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 382 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); |
| 383 |
| 384 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 385 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 386 |
| 387 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 388 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); |
| 389 } |
| 390 |
240 } // namespace | 391 } // namespace |
241 | 392 |
242 } // namespace ash | 393 } // namespace ash |
OLD | NEW |