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(WindowCycleControllerTest, AlwaysOnTopMultiWindow) { |
| 317 WindowCycleController* controller = |
| 318 Shell::GetInstance()->window_cycle_controller(); |
| 319 |
| 320 // Set up several windows to use to test cycling. |
| 321 Window* default_container = |
| 322 Shell::GetContainer( |
| 323 Shell::GetPrimaryRootWindow(), |
| 324 internal::kShellWindowId_DefaultContainer); |
| 325 scoped_ptr<Window> window0(CreateTestWindowWithId(0, default_container)); |
| 326 scoped_ptr<Window> window1(CreateTestWindowWithId(1, default_container)); |
| 327 |
| 328 Window* top_container = |
| 329 Shell::GetContainer( |
| 330 Shell::GetPrimaryRootWindow(), |
| 331 internal::kShellWindowId_AlwaysOnTopContainer); |
| 332 scoped_ptr<Window> window2(CreateTestWindowWithId(2, top_container)); |
| 333 scoped_ptr<Window> window3(CreateTestWindowWithId(3, top_container)); |
| 334 wm::ActivateWindow(window0.get()); |
| 335 |
| 336 // Simulate pressing and releasing Alt-tab. |
| 337 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 338 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 339 |
| 340 // Window lists should return the topmost window in front. |
| 341 ASSERT_TRUE(controller->windows()); |
| 342 ASSERT_EQ(4u, controller->windows()->windows().size()); |
| 343 EXPECT_EQ(window0.get(), controller->windows()->windows()[0]); |
| 344 EXPECT_EQ(window3.get(), controller->windows()->windows()[1]); |
| 345 EXPECT_EQ(window2.get(), controller->windows()->windows()[2]); |
| 346 EXPECT_EQ(window1.get(), controller->windows()->windows()[3]); |
| 347 |
| 348 controller->AltKeyReleased(); |
| 349 EXPECT_TRUE(wm::IsActiveWindow(window3.get())); |
| 350 |
| 351 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 352 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 353 |
| 354 controller->AltKeyReleased(); |
| 355 |
| 356 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 357 EXPECT_TRUE(wm::IsActiveWindow(window3.get())); |
| 358 |
| 359 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 360 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); |
| 361 |
| 362 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 363 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); |
| 364 |
| 365 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 366 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 367 } |
| 368 |
| 369 TEST_F(WindowCycleControllerExtendedDesktopTest, |
| 370 AlwaysOnTopMultipleRootWindows) { |
| 371 // Set up a second root window |
| 372 UpdateDisplay("0+0-1000x600,1001+0-600x400"); |
| 373 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 374 ASSERT_EQ(2U, root_windows.size()); |
| 375 |
| 376 // Move the active root window to the secondary. |
| 377 Shell::GetInstance()->set_active_root_window(root_windows[1]); |
| 378 |
| 379 WindowCycleController* controller = |
| 380 Shell::GetInstance()->window_cycle_controller(); |
| 381 |
| 382 // Set up several windows to use to test cycling. |
| 383 Window* default_container0 = |
| 384 Shell::GetContainer( |
| 385 root_windows[0], |
| 386 internal::kShellWindowId_DefaultContainer); |
| 387 scoped_ptr<Window> window0(CreateTestWindowWithId(0, default_container0)); |
| 388 |
| 389 Window* top_container0 = |
| 390 Shell::GetContainer( |
| 391 root_windows[0], |
| 392 internal::kShellWindowId_AlwaysOnTopContainer); |
| 393 scoped_ptr<Window> window1(CreateTestWindowWithId(1, top_container0)); |
| 394 |
| 395 // Set up several windows to use to test cycling. |
| 396 Window* default_container1 = |
| 397 Shell::GetContainer( |
| 398 root_windows[1], |
| 399 internal::kShellWindowId_DefaultContainer); |
| 400 scoped_ptr<Window> window2(CreateTestWindowWithId(2, default_container1)); |
| 401 |
| 402 Window* top_container1 = |
| 403 Shell::GetContainer( |
| 404 root_windows[1], |
| 405 internal::kShellWindowId_AlwaysOnTopContainer); |
| 406 scoped_ptr<Window> window3(CreateTestWindowWithId(3, top_container1)); |
| 407 |
| 408 |
| 409 wm::ActivateWindow(window2.get()); |
| 410 |
| 411 // Simulate pressing and releasing Alt-tab. |
| 412 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); |
| 413 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 414 |
| 415 // Window lists should return the topmost window in front. |
| 416 ASSERT_TRUE(controller->windows()); |
| 417 ASSERT_EQ(4u, controller->windows()->windows().size()); |
| 418 EXPECT_EQ(window2.get(), controller->windows()->windows()[0]); |
| 419 EXPECT_EQ(window3.get(), controller->windows()->windows()[1]); |
| 420 EXPECT_EQ(window1.get(), controller->windows()->windows()[2]); |
| 421 EXPECT_EQ(window0.get(), controller->windows()->windows()[3]); |
| 422 |
| 423 controller->AltKeyReleased(); |
| 424 EXPECT_TRUE(wm::IsActiveWindow(window3.get())); |
| 425 |
| 426 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 427 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); |
| 428 |
| 429 controller->AltKeyReleased(); |
| 430 |
| 431 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 432 EXPECT_TRUE(wm::IsActiveWindow(window3.get())); |
| 433 |
| 434 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 435 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); |
| 436 |
| 437 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 438 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 439 |
| 440 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 441 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); |
| 442 } |
| 443 |
| 444 TEST_F(WindowCycleControllerTest, MostRecentlyUsed) { |
| 445 WindowCycleController* controller = |
| 446 Shell::GetInstance()->window_cycle_controller(); |
| 447 |
| 448 // Set up several windows to use to test cycling. |
| 449 Window* container = |
| 450 Shell::GetContainer( |
| 451 Shell::GetPrimaryRootWindow(), |
| 452 internal::kShellWindowId_DefaultContainer); |
| 453 scoped_ptr<Window> window0(CreateTestWindowWithId(0, container)); |
| 454 scoped_ptr<Window> window1(CreateTestWindowWithId(1, container)); |
| 455 scoped_ptr<Window> window2(CreateTestWindowWithId(2, container)); |
| 456 |
| 457 wm::ActivateWindow(window0.get()); |
| 458 |
| 459 // Simulate pressing and releasing Alt-tab. |
| 460 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 461 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 462 |
| 463 // Window lists should return the topmost window in front. |
| 464 ASSERT_TRUE(controller->windows()); |
| 465 ASSERT_EQ(3u, controller->windows()->windows().size()); |
| 466 EXPECT_EQ(window0.get(), controller->windows()->windows()[0]); |
| 467 EXPECT_EQ(window2.get(), controller->windows()->windows()[1]); |
| 468 EXPECT_EQ(window1.get(), controller->windows()->windows()[2]); |
| 469 |
| 470 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 471 controller->AltKeyReleased(); |
| 472 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); |
| 473 |
| 474 |
| 475 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 476 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 477 |
| 478 controller->AltKeyReleased(); |
| 479 |
| 480 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 481 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); |
| 482 |
| 483 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 484 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); |
| 485 |
| 486 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 487 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 488 } |
| 489 |
| 490 |
240 } // namespace | 491 } // namespace |
241 | 492 |
242 } // namespace ash | 493 } // namespace ash |
OLD | NEW |