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