| 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 class used for testing docked windows. | |
| 531 class EnabledDockedWindowsAcceleratorControllerTest | |
| 532 : public AcceleratorControllerTest { | |
| 533 public: | |
| 534 EnabledDockedWindowsAcceleratorControllerTest() = default; | |
| 535 ~EnabledDockedWindowsAcceleratorControllerTest() override = default; | |
| 536 | |
| 537 void SetUp() override { | |
| 538 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 539 ash::switches::kAshEnableDockedWindows); | |
| 540 AcceleratorControllerTest::SetUp(); | |
| 541 } | |
| 542 | |
| 543 private: | |
| 544 DISALLOW_COPY_AND_ASSIGN(EnabledDockedWindowsAcceleratorControllerTest); | |
| 545 }; | |
| 546 | |
| 547 TEST_F(EnabledDockedWindowsAcceleratorControllerTest, | |
| 548 WindowSnapLeftDockLeftRestore) { | |
| 549 std::unique_ptr<aura::Window> window0( | |
| 550 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
| 551 std::unique_ptr<aura::Window> window1( | |
| 552 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
| 553 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | |
| 554 window1_state->Activate(); | |
| 555 | |
| 556 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
| 557 gfx::Rect normal_bounds = window1_state->GetRestoreBoundsInParent(); | |
| 558 gfx::Rect expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent( | |
| 559 WmWindow::Get(window1.get())); | |
| 560 EXPECT_EQ(expected_bounds.ToString(), window1->bounds().ToString()); | |
| 561 EXPECT_TRUE(window1_state->IsSnapped()); | |
| 562 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
| 563 EXPECT_FALSE(window1_state->IsNormalOrSnapped()); | |
| 564 EXPECT_TRUE(window1_state->IsDocked()); | |
| 565 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
| 566 EXPECT_FALSE(window1_state->IsDocked()); | |
| 567 EXPECT_EQ(normal_bounds.ToString(), window1->bounds().ToString()); | |
| 568 } | |
| 569 | |
| 570 TEST_F(EnabledDockedWindowsAcceleratorControllerTest, | |
| 571 WindowSnapRightDockRightRestore) { | |
| 572 std::unique_ptr<aura::Window> window0( | |
| 573 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
| 574 std::unique_ptr<aura::Window> window1( | |
| 575 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
| 576 | |
| 577 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | |
| 578 window1_state->Activate(); | |
| 579 | |
| 580 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | |
| 581 gfx::Rect normal_bounds = window1_state->GetRestoreBoundsInParent(); | |
| 582 gfx::Rect expected_bounds = wm::GetDefaultRightSnappedWindowBoundsInParent( | |
| 583 WmWindow::Get(window1.get())); | |
| 584 EXPECT_EQ(expected_bounds.ToString(), window1->bounds().ToString()); | |
| 585 EXPECT_TRUE(window1_state->IsSnapped()); | |
| 586 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | |
| 587 EXPECT_FALSE(window1_state->IsNormalOrSnapped()); | |
| 588 EXPECT_TRUE(window1_state->IsDocked()); | |
| 589 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | |
| 590 EXPECT_FALSE(window1_state->IsDocked()); | |
| 591 EXPECT_EQ(normal_bounds.ToString(), window1->bounds().ToString()); | |
| 592 } | |
| 593 | |
| 594 TEST_F(EnabledDockedWindowsAcceleratorControllerTest, | |
| 595 WindowSnapLeftDockLeftSnapRight) { | |
| 596 std::unique_ptr<aura::Window> window0( | |
| 597 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
| 598 std::unique_ptr<aura::Window> window1( | |
| 599 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
| 600 | |
| 601 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | |
| 602 window1_state->Activate(); | |
| 603 | |
| 604 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
| 605 gfx::Rect expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent( | |
| 606 WmWindow::Get(window1.get())); | |
| 607 gfx::Rect expected_bounds2 = wm::GetDefaultRightSnappedWindowBoundsInParent( | |
| 608 WmWindow::Get(window1.get())); | |
| 609 EXPECT_EQ(expected_bounds.ToString(), window1->bounds().ToString()); | |
| 610 EXPECT_TRUE(window1_state->IsSnapped()); | |
| 611 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
| 612 EXPECT_FALSE(window1_state->IsNormalOrSnapped()); | |
| 613 EXPECT_TRUE(window1_state->IsDocked()); | |
| 614 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | |
| 615 EXPECT_FALSE(window1_state->IsDocked()); | |
| 616 EXPECT_TRUE(window1_state->IsSnapped()); | |
| 617 EXPECT_EQ(expected_bounds2.ToString(), window1->bounds().ToString()); | |
| 618 } | |
| 619 | |
| 620 TEST_F(EnabledDockedWindowsAcceleratorControllerTest, | |
| 621 WindowDockLeftMinimizeWindowWithRestore) { | |
| 622 std::unique_ptr<aura::Window> window0( | |
| 623 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
| 624 std::unique_ptr<aura::Window> window1( | |
| 625 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
| 626 | |
| 627 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | |
| 628 window1_state->Activate(); | |
| 629 | |
| 630 std::unique_ptr<aura::Window> window2( | |
| 631 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
| 632 | |
| 633 wm::WindowState* window2_state = wm::GetWindowState(window2.get()); | |
| 634 | |
| 635 std::unique_ptr<aura::Window> window3( | |
| 636 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
| 637 | |
| 638 wm::WindowState* window3_state = wm::GetWindowState(window3.get()); | |
| 639 window3_state->Activate(); | |
| 640 | |
| 641 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
| 642 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
| 643 gfx::Rect window3_docked_bounds = window3->bounds(); | |
| 644 | |
| 645 window2_state->Activate(); | |
| 646 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
| 647 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
| 648 window1_state->Activate(); | |
| 649 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
| 650 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
| 651 | |
| 652 EXPECT_TRUE(window3_state->IsDocked()); | |
| 653 EXPECT_TRUE(window2_state->IsDocked()); | |
| 654 EXPECT_TRUE(window1_state->IsDocked()); | |
| 655 EXPECT_TRUE(window3_state->IsMinimized()); | |
| 656 | |
| 657 window1_state->Activate(); | |
| 658 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
| 659 window2_state->Activate(); | |
| 660 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
| 661 window3_state->Unminimize(); | |
| 662 EXPECT_FALSE(window1_state->IsDocked()); | |
| 663 EXPECT_FALSE(window2_state->IsDocked()); | |
| 664 EXPECT_TRUE(window3_state->IsDocked()); | |
| 665 EXPECT_EQ(window3_docked_bounds.ToString(), window3->bounds().ToString()); | |
| 666 } | |
| 667 | |
| 668 TEST_F(EnabledDockedWindowsAcceleratorControllerTest, | |
| 669 WindowPanelDockLeftDockRightRestore) { | |
| 670 // TODO: http://crbug.com/632209. | |
| 671 if (WmShell::Get()->IsRunningInMash()) | |
| 672 return; | |
| 673 std::unique_ptr<aura::Window> window0( | |
| 674 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
| 675 | |
| 676 std::unique_ptr<aura::Window> window(CreatePanel()); | |
| 677 wm::WindowState* window_state = wm::GetWindowState(window.get()); | |
| 678 window_state->Activate(); | |
| 679 | |
| 680 gfx::Rect window_restore_bounds2 = window->bounds(); | |
| 681 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | |
| 682 gfx::Rect expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent( | |
| 683 WmWindow::Get(window.get())); | |
| 684 gfx::Rect window_restore_bounds = window_state->GetRestoreBoundsInScreen(); | |
| 685 EXPECT_NE(expected_bounds.ToString(), window->bounds().ToString()); | |
| 686 EXPECT_FALSE(window_state->IsSnapped()); | |
| 687 EXPECT_FALSE(window_state->IsNormalOrSnapped()); | |
| 688 EXPECT_TRUE(window_state->IsDocked()); | |
| 689 window_state->Restore(); | |
| 690 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | |
| 691 EXPECT_TRUE(window_state->IsDocked()); | |
| 692 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | |
| 693 EXPECT_FALSE(window_state->IsDocked()); | |
| 694 EXPECT_EQ(window_restore_bounds.ToString(), | |
| 695 window_restore_bounds2.ToString()); | |
| 696 EXPECT_EQ(window_restore_bounds.ToString(), window->bounds().ToString()); | |
| 697 } | |
| 698 | |
| 699 TEST_F(EnabledDockedWindowsAcceleratorControllerTest, CenterWindowAccelerator) { | |
| 700 std::unique_ptr<aura::Window> window( | |
| 701 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | |
| 702 wm::WindowState* window_state = wm::GetWindowState(window.get()); | |
| 703 window_state->Activate(); | |
| 704 | |
| 705 // Center the window using accelerator. | |
| 706 GetController()->PerformActionIfEnabled(WINDOW_POSITION_CENTER); | |
| 707 gfx::Rect work_area = display::Screen::GetScreen() | |
| 708 ->GetDisplayNearestWindow(window.get()) | |
| 709 .work_area(); | |
| 710 gfx::Rect bounds = window->GetBoundsInScreen(); | |
| 711 EXPECT_NEAR(bounds.x() - work_area.x(), work_area.right() - bounds.right(), | |
| 712 1); | |
| 713 EXPECT_NEAR(bounds.y() - work_area.y(), work_area.bottom() - bounds.bottom(), | |
| 714 1); | |
| 715 | |
| 716 // Add the window to docked container and try to center it. | |
| 717 window->SetBounds(gfx::Rect(0, 0, 20, 20)); | |
| 718 const wm::WMEvent event(wm::WM_EVENT_DOCK); | |
| 719 wm::GetWindowState(window.get())->OnWMEvent(&event); | |
| 720 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); | |
| 721 | |
| 722 gfx::Rect docked_bounds = window->GetBoundsInScreen(); | |
| 723 GetController()->PerformActionIfEnabled(WINDOW_POSITION_CENTER); | |
| 724 // It should not get centered and should remain docked. | |
| 725 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); | |
| 726 EXPECT_EQ(docked_bounds.ToString(), window->GetBoundsInScreen().ToString()); | |
| 727 } | |
| 728 | |
| 729 TEST_F(AcceleratorControllerTest, AutoRepeat) { | 525 TEST_F(AcceleratorControllerTest, AutoRepeat) { |
| 730 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_CONTROL_DOWN); | 526 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_CONTROL_DOWN); |
| 731 accelerator_a.set_type(ui::ET_KEY_PRESSED); | 527 accelerator_a.set_type(ui::ET_KEY_PRESSED); |
| 732 TestTarget target_a; | 528 TestTarget target_a; |
| 733 GetController()->Register({accelerator_a}, &target_a); | 529 GetController()->Register({accelerator_a}, &target_a); |
| 734 ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_CONTROL_DOWN); | 530 ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_CONTROL_DOWN); |
| 735 accelerator_b.set_type(ui::ET_KEY_PRESSED); | 531 accelerator_b.set_type(ui::ET_KEY_PRESSED); |
| 736 TestTarget target_b; | 532 TestTarget target_b; |
| 737 GetController()->Register({accelerator_b}, &target_b); | 533 GetController()->Register({accelerator_b}, &target_b); |
| 738 | 534 |
| (...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1547 // Expect no notifications from the new accelerators. | 1343 // Expect no notifications from the new accelerators. |
| 1548 EXPECT_TRUE(IsMessageCenterEmpty()); | 1344 EXPECT_TRUE(IsMessageCenterEmpty()); |
| 1549 | 1345 |
| 1550 // If the action is LOCK_SCREEN, we must reset the state by unlocking the | 1346 // If the action is LOCK_SCREEN, we must reset the state by unlocking the |
| 1551 // screen before we proceed testing the rest of accelerators. | 1347 // screen before we proceed testing the rest of accelerators. |
| 1552 ResetStateIfNeeded(); | 1348 ResetStateIfNeeded(); |
| 1553 } | 1349 } |
| 1554 } | 1350 } |
| 1555 | 1351 |
| 1556 } // namespace ash | 1352 } // namespace ash |
| OLD | NEW |