| 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/common/accelerators/accelerator_controller.h" | 5 #include "ash/common/accelerators/accelerator_controller.h" |
| 6 | 6 |
| 7 #include "ash/common/accelerators/accelerator_table.h" | 7 #include "ash/common/accelerators/accelerator_table.h" |
| 8 #include "ash/common/accessibility_delegate.h" | 8 #include "ash/common/accessibility_delegate.h" |
| 9 #include "ash/common/accessibility_types.h" | 9 #include "ash/common/accessibility_types.h" |
| 10 #include "ash/common/ash_switches.h" | 10 #include "ash/common/ash_switches.h" |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 } | 434 } |
| 435 | 435 |
| 436 TEST_F(AcceleratorControllerTest, WindowSnap) { | 436 TEST_F(AcceleratorControllerTest, WindowSnap) { |
| 437 std::unique_ptr<aura::Window> window( | 437 std::unique_ptr<aura::Window> window( |
| 438 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | 438 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); |
| 439 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 439 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 440 | 440 |
| 441 window_state->Activate(); | 441 window_state->Activate(); |
| 442 | 442 |
| 443 { | 443 { |
| 444 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | 444 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_LEFT); |
| 445 gfx::Rect expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent( | 445 gfx::Rect expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent( |
| 446 WmWindow::Get(window.get())); | 446 WmWindow::Get(window.get())); |
| 447 EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString()); | 447 EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString()); |
| 448 } | 448 } |
| 449 { | 449 { |
| 450 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | 450 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_RIGHT); |
| 451 gfx::Rect expected_bounds = wm::GetDefaultRightSnappedWindowBoundsInParent( | 451 gfx::Rect expected_bounds = wm::GetDefaultRightSnappedWindowBoundsInParent( |
| 452 WmWindow::Get(window.get())); | 452 WmWindow::Get(window.get())); |
| 453 EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString()); | 453 EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString()); |
| 454 } | 454 } |
| 455 { | 455 { |
| 456 gfx::Rect normal_bounds = window_state->GetRestoreBoundsInParent(); | 456 gfx::Rect normal_bounds = window_state->GetRestoreBoundsInParent(); |
| 457 | 457 |
| 458 GetController()->PerformActionIfEnabled(TOGGLE_MAXIMIZED); | 458 GetController()->PerformActionIfEnabled(TOGGLE_MAXIMIZED); |
| 459 EXPECT_TRUE(window_state->IsMaximized()); | 459 EXPECT_TRUE(window_state->IsMaximized()); |
| 460 EXPECT_NE(normal_bounds.ToString(), window->bounds().ToString()); | 460 EXPECT_NE(normal_bounds.ToString(), window->bounds().ToString()); |
| 461 | 461 |
| 462 GetController()->PerformActionIfEnabled(TOGGLE_MAXIMIZED); | 462 GetController()->PerformActionIfEnabled(TOGGLE_MAXIMIZED); |
| 463 EXPECT_FALSE(window_state->IsMaximized()); | 463 EXPECT_FALSE(window_state->IsMaximized()); |
| 464 // Window gets restored to its restore bounds since side-maximized state | 464 // Window gets restored to its restore bounds since side-maximized state |
| 465 // is treated as a "maximized" state. | 465 // is treated as a "maximized" state. |
| 466 EXPECT_EQ(normal_bounds.ToString(), window->bounds().ToString()); | 466 EXPECT_EQ(normal_bounds.ToString(), window->bounds().ToString()); |
| 467 | 467 |
| 468 GetController()->PerformActionIfEnabled(TOGGLE_MAXIMIZED); | 468 GetController()->PerformActionIfEnabled(TOGGLE_MAXIMIZED); |
| 469 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | 469 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_LEFT); |
| 470 EXPECT_FALSE(window_state->IsMaximized()); | 470 EXPECT_FALSE(window_state->IsMaximized()); |
| 471 | 471 |
| 472 GetController()->PerformActionIfEnabled(TOGGLE_MAXIMIZED); | 472 GetController()->PerformActionIfEnabled(TOGGLE_MAXIMIZED); |
| 473 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | 473 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_RIGHT); |
| 474 EXPECT_FALSE(window_state->IsMaximized()); | 474 EXPECT_FALSE(window_state->IsMaximized()); |
| 475 | 475 |
| 476 GetController()->PerformActionIfEnabled(TOGGLE_MAXIMIZED); | 476 GetController()->PerformActionIfEnabled(TOGGLE_MAXIMIZED); |
| 477 EXPECT_TRUE(window_state->IsMaximized()); | 477 EXPECT_TRUE(window_state->IsMaximized()); |
| 478 GetController()->PerformActionIfEnabled(WINDOW_MINIMIZE); | 478 GetController()->PerformActionIfEnabled(WINDOW_MINIMIZE); |
| 479 EXPECT_FALSE(window_state->IsMaximized()); | 479 EXPECT_FALSE(window_state->IsMaximized()); |
| 480 EXPECT_TRUE(window_state->IsMinimized()); | 480 EXPECT_TRUE(window_state->IsMinimized()); |
| 481 window_state->Restore(); | 481 window_state->Restore(); |
| 482 window_state->Activate(); | 482 window_state->Activate(); |
| 483 } | 483 } |
| 484 { | 484 { |
| 485 GetController()->PerformActionIfEnabled(WINDOW_MINIMIZE); | 485 GetController()->PerformActionIfEnabled(WINDOW_MINIMIZE); |
| 486 EXPECT_TRUE(window_state->IsMinimized()); | 486 EXPECT_TRUE(window_state->IsMinimized()); |
| 487 } | 487 } |
| 488 } | 488 } |
| 489 | 489 |
| 490 // Tests that when window docking is disabled, only snapping windows works. | 490 // Tests that window snapping works. |
| 491 TEST_F(AcceleratorControllerTest, WindowSnapWithoutDocking) { | 491 TEST_F(AcceleratorControllerTest, TestRepeatedSnap) { |
| 492 ASSERT_FALSE(ash::switches::DockedWindowsEnabled()); | |
| 493 std::unique_ptr<aura::Window> window( | 492 std::unique_ptr<aura::Window> window( |
| 494 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | 493 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); |
| 495 | 494 |
| 496 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 495 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 497 window_state->Activate(); | 496 window_state->Activate(); |
| 498 | 497 |
| 499 // Snap right. | 498 // Snap right. |
| 500 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | 499 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_RIGHT); |
| 501 gfx::Rect normal_bounds = window_state->GetRestoreBoundsInParent(); | 500 gfx::Rect normal_bounds = window_state->GetRestoreBoundsInParent(); |
| 502 gfx::Rect expected_bounds = wm::GetDefaultRightSnappedWindowBoundsInParent( | 501 gfx::Rect expected_bounds = wm::GetDefaultRightSnappedWindowBoundsInParent( |
| 503 WmWindow::Get(window.get())); | 502 WmWindow::Get(window.get())); |
| 504 EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString()); | 503 EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString()); |
| 505 EXPECT_TRUE(window_state->IsSnapped()); | 504 EXPECT_TRUE(window_state->IsSnapped()); |
| 506 // Snap right again ->> becomes normal. | 505 // Snap right again ->> becomes normal. |
| 507 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | 506 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_RIGHT); |
| 508 EXPECT_TRUE(window_state->IsNormalStateType()); | 507 EXPECT_TRUE(window_state->IsNormalStateType()); |
| 509 EXPECT_FALSE(window_state->IsDocked()); | |
| 510 EXPECT_EQ(normal_bounds.ToString(), window->bounds().ToString()); | 508 EXPECT_EQ(normal_bounds.ToString(), window->bounds().ToString()); |
| 511 // Snap right. | 509 // Snap right. |
| 512 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | 510 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_RIGHT); |
| 513 EXPECT_TRUE(window_state->IsSnapped()); | 511 EXPECT_TRUE(window_state->IsSnapped()); |
| 514 EXPECT_FALSE(window_state->IsDocked()); | |
| 515 // Snap left. | 512 // Snap left. |
| 516 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | 513 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_LEFT); |
| 517 EXPECT_TRUE(window_state->IsSnapped()); | 514 EXPECT_TRUE(window_state->IsSnapped()); |
| 518 EXPECT_FALSE(window_state->IsDocked()); | |
| 519 expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent( | 515 expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent( |
| 520 WmWindow::Get(window.get())); | 516 WmWindow::Get(window.get())); |
| 521 EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString()); | 517 EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString()); |
| 522 // Snap left again ->> becomes normal. | 518 // Snap left again ->> becomes normal. |
| 523 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | 519 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_LEFT); |
| 524 EXPECT_TRUE(window_state->IsNormalStateType()); | 520 EXPECT_TRUE(window_state->IsNormalStateType()); |
| 525 EXPECT_FALSE(window_state->IsDocked()); | |
| 526 EXPECT_EQ(normal_bounds.ToString(), window->bounds().ToString()); | 521 EXPECT_EQ(normal_bounds.ToString(), window->bounds().ToString()); |
| 527 } | 522 } |
| 528 | 523 |
| 529 TEST_F(AcceleratorControllerTest, RotateScreen) { | 524 TEST_F(AcceleratorControllerTest, RotateScreen) { |
| 530 // TODO: needs GetDisplayInfo http://crbug.com/622480. | 525 // TODO: needs GetDisplayInfo http://crbug.com/622480. |
| 531 if (WmShell::Get()->IsRunningInMash()) | 526 if (WmShell::Get()->IsRunningInMash()) |
| 532 return; | 527 return; |
| 533 | 528 |
| 534 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay(); | 529 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 535 display::Display::Rotation initial_rotation = | 530 display::Display::Rotation initial_rotation = |
| 536 GetActiveDisplayRotation(display.id()); | 531 GetActiveDisplayRotation(display.id()); |
| 537 ui::test::EventGenerator& generator = GetEventGenerator(); | 532 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 538 generator.PressKey(ui::VKEY_BROWSER_REFRESH, | 533 generator.PressKey(ui::VKEY_BROWSER_REFRESH, |
| 539 ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN); | 534 ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN); |
| 540 generator.ReleaseKey(ui::VKEY_BROWSER_REFRESH, | 535 generator.ReleaseKey(ui::VKEY_BROWSER_REFRESH, |
| 541 ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN); | 536 ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN); |
| 542 display::Display::Rotation new_rotation = | 537 display::Display::Rotation new_rotation = |
| 543 GetActiveDisplayRotation(display.id()); | 538 GetActiveDisplayRotation(display.id()); |
| 544 // |new_rotation| is determined by the AcceleratorControllerDelegate. | 539 // |new_rotation| is determined by the AcceleratorControllerDelegate. |
| 545 EXPECT_NE(initial_rotation, new_rotation); | 540 EXPECT_NE(initial_rotation, new_rotation); |
| 546 } | 541 } |
| 547 | 542 |
| 548 // Test class used for testing docked windows. | |
| 549 class EnabledDockedWindowsAcceleratorControllerTest | |
| 550 : public AcceleratorControllerTest { | |
| 551 public: | |
| 552 EnabledDockedWindowsAcceleratorControllerTest() = default; | |
| 553 ~EnabledDockedWindowsAcceleratorControllerTest() override = default; | |
| 554 | |
| 555 void SetUp() override { | |
| 556 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 557 ash::switches::kAshEnableDockedWindows); | |
| 558 AcceleratorControllerTest::SetUp(); | |
| 559 } | |
| 560 | |
| 561 private: | |
| 562 DISALLOW_COPY_AND_ASSIGN(EnabledDockedWindowsAcceleratorControllerTest); | |
| 563 }; | |
| 564 | |
| 565 TEST_F(EnabledDockedWindowsAcceleratorControllerTest, | |
| 566 WindowSnapLeftDockLeftRestore) { | |
| 567 std::unique_ptr<aura::Window> window0( | |
| 568 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
| 569 std::unique_ptr<aura::Window> window1( | |
| 570 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
| 571 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | |
| 572 window1_state->Activate(); | |
| 573 | |
| 574 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
| 575 gfx::Rect normal_bounds = window1_state->GetRestoreBoundsInParent(); | |
| 576 gfx::Rect expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent( | |
| 577 WmWindow::Get(window1.get())); | |
| 578 EXPECT_EQ(expected_bounds.ToString(), window1->bounds().ToString()); | |
| 579 EXPECT_TRUE(window1_state->IsSnapped()); | |
| 580 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
| 581 EXPECT_FALSE(window1_state->IsNormalOrSnapped()); | |
| 582 EXPECT_TRUE(window1_state->IsDocked()); | |
| 583 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
| 584 EXPECT_FALSE(window1_state->IsDocked()); | |
| 585 EXPECT_EQ(normal_bounds.ToString(), window1->bounds().ToString()); | |
| 586 } | |
| 587 | |
| 588 TEST_F(EnabledDockedWindowsAcceleratorControllerTest, | |
| 589 WindowSnapRightDockRightRestore) { | |
| 590 std::unique_ptr<aura::Window> window0( | |
| 591 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
| 592 std::unique_ptr<aura::Window> window1( | |
| 593 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
| 594 | |
| 595 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | |
| 596 window1_state->Activate(); | |
| 597 | |
| 598 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | |
| 599 gfx::Rect normal_bounds = window1_state->GetRestoreBoundsInParent(); | |
| 600 gfx::Rect expected_bounds = wm::GetDefaultRightSnappedWindowBoundsInParent( | |
| 601 WmWindow::Get(window1.get())); | |
| 602 EXPECT_EQ(expected_bounds.ToString(), window1->bounds().ToString()); | |
| 603 EXPECT_TRUE(window1_state->IsSnapped()); | |
| 604 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | |
| 605 EXPECT_FALSE(window1_state->IsNormalOrSnapped()); | |
| 606 EXPECT_TRUE(window1_state->IsDocked()); | |
| 607 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | |
| 608 EXPECT_FALSE(window1_state->IsDocked()); | |
| 609 EXPECT_EQ(normal_bounds.ToString(), window1->bounds().ToString()); | |
| 610 } | |
| 611 | |
| 612 TEST_F(EnabledDockedWindowsAcceleratorControllerTest, | |
| 613 WindowSnapLeftDockLeftSnapRight) { | |
| 614 std::unique_ptr<aura::Window> window0( | |
| 615 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
| 616 std::unique_ptr<aura::Window> window1( | |
| 617 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
| 618 | |
| 619 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | |
| 620 window1_state->Activate(); | |
| 621 | |
| 622 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
| 623 gfx::Rect expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent( | |
| 624 WmWindow::Get(window1.get())); | |
| 625 gfx::Rect expected_bounds2 = wm::GetDefaultRightSnappedWindowBoundsInParent( | |
| 626 WmWindow::Get(window1.get())); | |
| 627 EXPECT_EQ(expected_bounds.ToString(), window1->bounds().ToString()); | |
| 628 EXPECT_TRUE(window1_state->IsSnapped()); | |
| 629 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
| 630 EXPECT_FALSE(window1_state->IsNormalOrSnapped()); | |
| 631 EXPECT_TRUE(window1_state->IsDocked()); | |
| 632 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | |
| 633 EXPECT_FALSE(window1_state->IsDocked()); | |
| 634 EXPECT_TRUE(window1_state->IsSnapped()); | |
| 635 EXPECT_EQ(expected_bounds2.ToString(), window1->bounds().ToString()); | |
| 636 } | |
| 637 | |
| 638 TEST_F(EnabledDockedWindowsAcceleratorControllerTest, | |
| 639 WindowDockLeftMinimizeWindowWithRestore) { | |
| 640 std::unique_ptr<aura::Window> window0( | |
| 641 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
| 642 std::unique_ptr<aura::Window> window1( | |
| 643 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
| 644 | |
| 645 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | |
| 646 window1_state->Activate(); | |
| 647 | |
| 648 std::unique_ptr<aura::Window> window2( | |
| 649 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
| 650 | |
| 651 wm::WindowState* window2_state = wm::GetWindowState(window2.get()); | |
| 652 | |
| 653 std::unique_ptr<aura::Window> window3( | |
| 654 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
| 655 | |
| 656 wm::WindowState* window3_state = wm::GetWindowState(window3.get()); | |
| 657 window3_state->Activate(); | |
| 658 | |
| 659 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
| 660 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
| 661 gfx::Rect window3_docked_bounds = window3->bounds(); | |
| 662 | |
| 663 window2_state->Activate(); | |
| 664 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
| 665 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
| 666 window1_state->Activate(); | |
| 667 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
| 668 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
| 669 | |
| 670 EXPECT_TRUE(window3_state->IsDocked()); | |
| 671 EXPECT_TRUE(window2_state->IsDocked()); | |
| 672 EXPECT_TRUE(window1_state->IsDocked()); | |
| 673 EXPECT_TRUE(window3_state->IsMinimized()); | |
| 674 | |
| 675 window1_state->Activate(); | |
| 676 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
| 677 window2_state->Activate(); | |
| 678 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
| 679 window3_state->Unminimize(); | |
| 680 EXPECT_FALSE(window1_state->IsDocked()); | |
| 681 EXPECT_FALSE(window2_state->IsDocked()); | |
| 682 EXPECT_TRUE(window3_state->IsDocked()); | |
| 683 EXPECT_EQ(window3_docked_bounds.ToString(), window3->bounds().ToString()); | |
| 684 } | |
| 685 | |
| 686 TEST_F(EnabledDockedWindowsAcceleratorControllerTest, | |
| 687 WindowPanelDockLeftDockRightRestore) { | |
| 688 // TODO: http://crbug.com/632209. | |
| 689 if (WmShell::Get()->IsRunningInMash()) | |
| 690 return; | |
| 691 std::unique_ptr<aura::Window> window0( | |
| 692 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
| 693 | |
| 694 std::unique_ptr<aura::Window> window(CreatePanel()); | |
| 695 wm::WindowState* window_state = wm::GetWindowState(window.get()); | |
| 696 window_state->Activate(); | |
| 697 | |
| 698 gfx::Rect window_restore_bounds2 = window->bounds(); | |
| 699 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
| 700 gfx::Rect expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent( | |
| 701 WmWindow::Get(window.get())); | |
| 702 gfx::Rect window_restore_bounds = window_state->GetRestoreBoundsInScreen(); | |
| 703 EXPECT_NE(expected_bounds.ToString(), window->bounds().ToString()); | |
| 704 EXPECT_FALSE(window_state->IsSnapped()); | |
| 705 EXPECT_FALSE(window_state->IsNormalOrSnapped()); | |
| 706 EXPECT_TRUE(window_state->IsDocked()); | |
| 707 window_state->Restore(); | |
| 708 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | |
| 709 EXPECT_TRUE(window_state->IsDocked()); | |
| 710 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | |
| 711 EXPECT_FALSE(window_state->IsDocked()); | |
| 712 EXPECT_EQ(window_restore_bounds.ToString(), | |
| 713 window_restore_bounds2.ToString()); | |
| 714 EXPECT_EQ(window_restore_bounds.ToString(), window->bounds().ToString()); | |
| 715 } | |
| 716 | |
| 717 TEST_F(EnabledDockedWindowsAcceleratorControllerTest, CenterWindowAccelerator) { | |
| 718 std::unique_ptr<aura::Window> window( | |
| 719 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
| 720 wm::WindowState* window_state = wm::GetWindowState(window.get()); | |
| 721 window_state->Activate(); | |
| 722 | |
| 723 // Center the window using accelerator. | |
| 724 GetController()->PerformActionIfEnabled(WINDOW_POSITION_CENTER); | |
| 725 gfx::Rect work_area = display::Screen::GetScreen() | |
| 726 ->GetDisplayNearestWindow(window.get()) | |
| 727 .work_area(); | |
| 728 gfx::Rect bounds = window->GetBoundsInScreen(); | |
| 729 EXPECT_NEAR(bounds.x() - work_area.x(), work_area.right() - bounds.right(), | |
| 730 1); | |
| 731 EXPECT_NEAR(bounds.y() - work_area.y(), work_area.bottom() - bounds.bottom(), | |
| 732 1); | |
| 733 | |
| 734 // Add the window to docked container and try to center it. | |
| 735 window->SetBounds(gfx::Rect(0, 0, 20, 20)); | |
| 736 const wm::WMEvent event(wm::WM_EVENT_DOCK); | |
| 737 wm::GetWindowState(window.get())->OnWMEvent(&event); | |
| 738 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); | |
| 739 | |
| 740 gfx::Rect docked_bounds = window->GetBoundsInScreen(); | |
| 741 GetController()->PerformActionIfEnabled(WINDOW_POSITION_CENTER); | |
| 742 // It should not get centered and should remain docked. | |
| 743 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); | |
| 744 EXPECT_EQ(docked_bounds.ToString(), window->GetBoundsInScreen().ToString()); | |
| 745 } | |
| 746 | |
| 747 TEST_F(AcceleratorControllerTest, AutoRepeat) { | 543 TEST_F(AcceleratorControllerTest, AutoRepeat) { |
| 748 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_CONTROL_DOWN); | 544 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_CONTROL_DOWN); |
| 749 TestTarget target_a; | 545 TestTarget target_a; |
| 750 GetController()->Register({accelerator_a}, &target_a); | 546 GetController()->Register({accelerator_a}, &target_a); |
| 751 ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_CONTROL_DOWN); | 547 ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_CONTROL_DOWN); |
| 752 TestTarget target_b; | 548 TestTarget target_b; |
| 753 GetController()->Register({accelerator_b}, &target_b); | 549 GetController()->Register({accelerator_b}, &target_b); |
| 754 | 550 |
| 755 ui::test::EventGenerator& generator = GetEventGenerator(); | 551 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 756 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); | 552 generator.PressKey(ui::VKEY_A, ui::EF_CONTROL_DOWN); |
| (...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1565 // Expect no notifications from the new accelerators. | 1361 // Expect no notifications from the new accelerators. |
| 1566 EXPECT_TRUE(IsMessageCenterEmpty()); | 1362 EXPECT_TRUE(IsMessageCenterEmpty()); |
| 1567 | 1363 |
| 1568 // If the action is LOCK_SCREEN, we must reset the state by unlocking the | 1364 // If the action is LOCK_SCREEN, we must reset the state by unlocking the |
| 1569 // screen before we proceed testing the rest of accelerators. | 1365 // screen before we proceed testing the rest of accelerators. |
| 1570 ResetStateIfNeeded(); | 1366 ResetStateIfNeeded(); |
| 1571 } | 1367 } |
| 1572 } | 1368 } |
| 1573 | 1369 |
| 1574 } // namespace ash | 1370 } // namespace ash |
| OLD | NEW |