| 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/toplevel_window_event_handler.h" | 5 #include "ash/wm/toplevel_window_event_handler.h" |
| 6 | 6 |
| 7 #include "ash/ash_constants.h" | 7 #include "ash/ash_constants.h" |
| 8 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.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/wm/lock_state_controller_impl2.h" | 12 #include "ash/wm/lock_state_controller_impl2.h" |
| 13 #include "ash/wm/property_util.h" | |
| 14 #include "ash/wm/resize_shadow.h" | 13 #include "ash/wm/resize_shadow.h" |
| 15 #include "ash/wm/resize_shadow_controller.h" | 14 #include "ash/wm/resize_shadow_controller.h" |
| 15 #include "ash/wm/window_state.h" |
| 16 #include "ash/wm/window_util.h" | 16 #include "ash/wm/window_util.h" |
| 17 #include "ash/wm/workspace/snap_sizer.h" | 17 #include "ash/wm/workspace/snap_sizer.h" |
| 18 #include "ash/wm/workspace_controller.h" | 18 #include "ash/wm/workspace_controller.h" |
| 19 #include "base/basictypes.h" | 19 #include "base/basictypes.h" |
| 20 #include "base/compiler_specific.h" | 20 #include "base/compiler_specific.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "ui/aura/client/aura_constants.h" | 22 #include "ui/aura/client/aura_constants.h" |
| 23 #include "ui/aura/root_window.h" | 23 #include "ui/aura/root_window.h" |
| 24 #include "ui/aura/test/aura_test_base.h" | 24 #include "ui/aura/test/aura_test_base.h" |
| 25 #include "ui/aura/test/event_generator.h" | 25 #include "ui/aura/test/event_generator.h" |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 target->SetBounds(bounds_before_maximization); | 431 target->SetBounds(bounds_before_maximization); |
| 432 old_bounds = target->bounds(); | 432 old_bounds = target->bounds(); |
| 433 | 433 |
| 434 // Maximize. | 434 // Maximize. |
| 435 end = location = target->GetBoundsInRootWindow().CenterPoint(); | 435 end = location = target->GetBoundsInRootWindow().CenterPoint(); |
| 436 end.Offset(0, -100); | 436 end.Offset(0, -100); |
| 437 generator.GestureScrollSequence(location, end, | 437 generator.GestureScrollSequence(location, end, |
| 438 base::TimeDelta::FromMilliseconds(5), | 438 base::TimeDelta::FromMilliseconds(5), |
| 439 10); | 439 10); |
| 440 RunAllPendingInMessageLoop(); | 440 RunAllPendingInMessageLoop(); |
| 441 |
| 442 wm::WindowState* window_state = wm::GetWindowState(target.get()); |
| 441 EXPECT_NE(old_bounds.ToString(), target->bounds().ToString()); | 443 EXPECT_NE(old_bounds.ToString(), target->bounds().ToString()); |
| 442 EXPECT_TRUE(wm::IsWindowMaximized(target.get())); | 444 EXPECT_TRUE(window_state->IsMaximized()); |
| 443 EXPECT_EQ(old_bounds.ToString(), | 445 EXPECT_EQ(old_bounds.ToString(), |
| 444 GetRestoreBoundsInScreen(target.get())->ToString()); | 446 window_state->GetRestoreBoundsInScreen().ToString()); |
| 445 | 447 |
| 446 wm::RestoreWindow(target.get()); | 448 window_state->Restore(); |
| 447 target->SetBounds(old_bounds); | 449 target->SetBounds(old_bounds); |
| 448 | 450 |
| 449 // Minimize. | 451 // Minimize. |
| 450 end = location = target->GetBoundsInRootWindow().CenterPoint(); | 452 end = location = target->GetBoundsInRootWindow().CenterPoint(); |
| 451 end.Offset(0, 100); | 453 end.Offset(0, 100); |
| 452 generator.GestureScrollSequence(location, end, | 454 generator.GestureScrollSequence(location, end, |
| 453 base::TimeDelta::FromMilliseconds(5), | 455 base::TimeDelta::FromMilliseconds(5), |
| 454 10); | 456 10); |
| 455 RunAllPendingInMessageLoop(); | 457 RunAllPendingInMessageLoop(); |
| 456 EXPECT_NE(old_bounds.ToString(), target->bounds().ToString()); | 458 EXPECT_NE(old_bounds.ToString(), target->bounds().ToString()); |
| 457 EXPECT_TRUE(wm::IsWindowMinimized(target.get())); | 459 EXPECT_TRUE(window_state->IsMinimized()); |
| 458 EXPECT_TRUE(GetWindowAlwaysRestoresToRestoreBounds(target.get())); | 460 EXPECT_TRUE(window_state->always_restores_to_restore_bounds()); |
| 459 EXPECT_EQ(old_bounds.ToString(), | 461 EXPECT_EQ(old_bounds.ToString(), |
| 460 GetRestoreBoundsInScreen(target.get())->ToString()); | 462 window_state->GetRestoreBoundsInScreen().ToString()); |
| 461 } | 463 } |
| 462 | 464 |
| 463 // Tests that a gesture cannot minimize a window in login/lock screen. | 465 // Tests that a gesture cannot minimize a window in login/lock screen. |
| 464 TEST_F(ToplevelWindowEventHandlerTest, GestureDragMinimizeLoginScreen) { | 466 TEST_F(ToplevelWindowEventHandlerTest, GestureDragMinimizeLoginScreen) { |
| 465 LockStateControllerImpl2* state_controller = | 467 LockStateControllerImpl2* state_controller = |
| 466 static_cast<LockStateControllerImpl2*> | 468 static_cast<LockStateControllerImpl2*> |
| 467 (Shell::GetInstance()->lock_state_controller()); | 469 (Shell::GetInstance()->lock_state_controller()); |
| 468 state_controller->OnLoginStateChanged(user::LOGGED_IN_NONE); | 470 state_controller->OnLoginStateChanged(user::LOGGED_IN_NONE); |
| 469 state_controller->OnLockStateChanged(false); | 471 state_controller->OnLockStateChanged(false); |
| 470 SetUserLoggedIn(false); | 472 SetUserLoggedIn(false); |
| 471 | 473 |
| 472 scoped_ptr<aura::Window> target(CreateWindow(HTCAPTION)); | 474 scoped_ptr<aura::Window> target(CreateWindow(HTCAPTION)); |
| 473 aura::Window* lock = internal::RootWindowController::ForWindow(target.get())-> | 475 aura::Window* lock = internal::RootWindowController::ForWindow(target.get())-> |
| 474 GetContainer(internal::kShellWindowId_LockSystemModalContainer); | 476 GetContainer(internal::kShellWindowId_LockSystemModalContainer); |
| 475 lock->AddChild(target.get()); | 477 lock->AddChild(target.get()); |
| 476 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 478 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 477 target.get()); | 479 target.get()); |
| 478 gfx::Rect old_bounds = target->bounds(); | 480 gfx::Rect old_bounds = target->bounds(); |
| 479 gfx::Point location(5, 5); | 481 gfx::Point location(5, 5); |
| 480 target->SetProperty(aura::client::kCanMaximizeKey, true); | 482 target->SetProperty(aura::client::kCanMaximizeKey, true); |
| 481 | 483 |
| 482 gfx::Point end = location; | 484 gfx::Point end = location; |
| 483 end.Offset(0, 100); | 485 end.Offset(0, 100); |
| 484 generator.GestureScrollSequence(location, end, | 486 generator.GestureScrollSequence(location, end, |
| 485 base::TimeDelta::FromMilliseconds(5), | 487 base::TimeDelta::FromMilliseconds(5), |
| 486 10); | 488 10); |
| 487 RunAllPendingInMessageLoop(); | 489 RunAllPendingInMessageLoop(); |
| 488 EXPECT_FALSE(wm::IsWindowMinimized(target.get())); | 490 EXPECT_FALSE(wm::GetWindowState(target.get())->IsMinimized()); |
| 489 } | 491 } |
| 490 | 492 |
| 491 TEST_F(ToplevelWindowEventHandlerTest, GestureDragToRestore) { | 493 TEST_F(ToplevelWindowEventHandlerTest, GestureDragToRestore) { |
| 492 scoped_ptr<aura::Window> window( | 494 scoped_ptr<aura::Window> window( |
| 493 CreateTestWindowInShellWithDelegate( | 495 CreateTestWindowInShellWithDelegate( |
| 494 new TestWindowDelegate(HTCAPTION), | 496 new TestWindowDelegate(HTCAPTION), |
| 495 0, | 497 0, |
| 496 gfx::Rect(10, 20, 30, 40))); | 498 gfx::Rect(10, 20, 30, 40))); |
| 497 window->Show(); | 499 window->Show(); |
| 498 ash::wm::ActivateWindow(window.get()); | 500 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 501 window_state->Activate(); |
| 499 | 502 |
| 500 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 503 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 501 window.get()); | 504 window.get()); |
| 502 gfx::Rect old_bounds = window->bounds(); | 505 gfx::Rect old_bounds = window->bounds(); |
| 503 gfx::Point location, end; | 506 gfx::Point location, end; |
| 504 end = location = window->GetBoundsInRootWindow().CenterPoint(); | 507 end = location = window->GetBoundsInRootWindow().CenterPoint(); |
| 505 end.Offset(0, 100); | 508 end.Offset(0, 100); |
| 506 generator.GestureScrollSequence(location, end, | 509 generator.GestureScrollSequence(location, end, |
| 507 base::TimeDelta::FromMilliseconds(5), | 510 base::TimeDelta::FromMilliseconds(5), |
| 508 10); | 511 10); |
| 509 RunAllPendingInMessageLoop(); | 512 RunAllPendingInMessageLoop(); |
| 510 EXPECT_NE(old_bounds.ToString(), window->bounds().ToString()); | 513 EXPECT_NE(old_bounds.ToString(), window->bounds().ToString()); |
| 511 EXPECT_TRUE(wm::IsWindowMinimized(window.get())); | 514 EXPECT_TRUE(window_state->IsMinimized()); |
| 512 EXPECT_TRUE(GetWindowAlwaysRestoresToRestoreBounds(window.get())); | 515 EXPECT_TRUE(window_state->always_restores_to_restore_bounds()); |
| 513 EXPECT_EQ(old_bounds.ToString(), | 516 EXPECT_EQ(old_bounds.ToString(), |
| 514 GetRestoreBoundsInScreen(window.get())->ToString()); | 517 window_state->GetRestoreBoundsInScreen().ToString()); |
| 515 } | 518 } |
| 516 | 519 |
| 517 // Tests that an unresizable window cannot be dragged or snapped using gestures. | 520 // Tests that an unresizable window cannot be dragged or snapped using gestures. |
| 518 TEST_F(ToplevelWindowEventHandlerTest, GestureDragForUnresizableWindow) { | 521 TEST_F(ToplevelWindowEventHandlerTest, GestureDragForUnresizableWindow) { |
| 519 scoped_ptr<aura::Window> target(CreateWindow(HTCAPTION)); | 522 scoped_ptr<aura::Window> target(CreateWindow(HTCAPTION)); |
| 520 | 523 |
| 521 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 524 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 522 target.get()); | 525 target.get()); |
| 523 gfx::Rect old_bounds = target->bounds(); | 526 gfx::Rect old_bounds = target->bounds(); |
| 524 gfx::Point location(5, 5); | 527 gfx::Point location(5, 5); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 // Once window is minimized, window dragging completes. | 651 // Once window is minimized, window dragging completes. |
| 649 { | 652 { |
| 650 scoped_ptr<aura::Window> target(CreateWindow(HTCAPTION)); | 653 scoped_ptr<aura::Window> target(CreateWindow(HTCAPTION)); |
| 651 target->Focus(); | 654 target->Focus(); |
| 652 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 655 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 653 target.get()); | 656 target.get()); |
| 654 generator.PressLeftButton(); | 657 generator.PressLeftButton(); |
| 655 generator.MoveMouseBy(10, 11); | 658 generator.MoveMouseBy(10, 11); |
| 656 RunAllPendingInMessageLoop(); | 659 RunAllPendingInMessageLoop(); |
| 657 EXPECT_EQ("10,11 100x100", target->bounds().ToString()); | 660 EXPECT_EQ("10,11 100x100", target->bounds().ToString()); |
| 658 | 661 wm::WindowState* window_state = wm::GetWindowState(target.get()); |
| 659 wm::MinimizeWindow(target.get()); | 662 window_state->Minimize(); |
| 660 wm::RestoreWindow(target.get()); | 663 window_state->Restore(); |
| 661 | 664 |
| 662 generator.PressLeftButton(); | 665 generator.PressLeftButton(); |
| 663 generator.MoveMouseBy(10, 11); | 666 generator.MoveMouseBy(10, 11); |
| 664 RunAllPendingInMessageLoop(); | 667 RunAllPendingInMessageLoop(); |
| 665 EXPECT_EQ("10,11 100x100", target->bounds().ToString()); | 668 EXPECT_EQ("10,11 100x100", target->bounds().ToString()); |
| 666 } | 669 } |
| 667 | 670 |
| 668 // Once window is maximized, window dragging completes. | 671 // Once window is maximized, window dragging completes. |
| 669 { | 672 { |
| 670 scoped_ptr<aura::Window> target(CreateWindow(HTCAPTION)); | 673 scoped_ptr<aura::Window> target(CreateWindow(HTCAPTION)); |
| 671 target->Focus(); | 674 target->Focus(); |
| 672 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 675 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 673 target.get()); | 676 target.get()); |
| 674 generator.PressLeftButton(); | 677 generator.PressLeftButton(); |
| 675 generator.MoveMouseBy(10, 11); | 678 generator.MoveMouseBy(10, 11); |
| 676 RunAllPendingInMessageLoop(); | 679 RunAllPendingInMessageLoop(); |
| 677 EXPECT_EQ("10,11 100x100", target->bounds().ToString()); | 680 EXPECT_EQ("10,11 100x100", target->bounds().ToString()); |
| 678 | 681 wm::WindowState* window_state = wm::GetWindowState(target.get()); |
| 679 wm::MaximizeWindow(target.get()); | 682 window_state->Maximize(); |
| 680 wm::RestoreWindow(target.get()); | 683 window_state->Restore(); |
| 681 | 684 |
| 682 generator.PressLeftButton(); | 685 generator.PressLeftButton(); |
| 683 generator.MoveMouseBy(10, 11); | 686 generator.MoveMouseBy(10, 11); |
| 684 RunAllPendingInMessageLoop(); | 687 RunAllPendingInMessageLoop(); |
| 685 EXPECT_EQ("10,11 100x100", target->bounds().ToString()); | 688 EXPECT_EQ("10,11 100x100", target->bounds().ToString()); |
| 686 } | 689 } |
| 687 } | 690 } |
| 688 | 691 |
| 689 // Test class for mouse and touch resize shadow tests. | 692 // Test class for mouse and touch resize shadow tests. |
| 690 class ToplevelWindowEventHandlerResizeTest | 693 class ToplevelWindowEventHandlerResizeTest |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 | 810 |
| 808 // Move mouse out of the window. Shadows should disappear. | 811 // Move mouse out of the window. Shadows should disappear. |
| 809 generator.MoveMouseTo(150, 150); | 812 generator.MoveMouseTo(150, 150); |
| 810 EXPECT_FALSE(HasResizeShadow()); | 813 EXPECT_FALSE(HasResizeShadow()); |
| 811 | 814 |
| 812 RunAllPendingInMessageLoop(); | 815 RunAllPendingInMessageLoop(); |
| 813 } | 816 } |
| 814 | 817 |
| 815 } // namespace test | 818 } // namespace test |
| 816 } // namespace ash | 819 } // namespace ash |
| OLD | NEW |