Chromium Code Reviews| 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/shell.h" | 5 #include "ash/shell.h" |
| 6 #include "ash/shell_window_ids.h" | 6 #include "ash/shell_window_ids.h" |
| 7 #include "ash/test/ash_test_base.h" | 7 #include "ash/test/ash_test_base.h" |
| 8 #include "ash/test/shell_test_api.h" | 8 #include "ash/test/shell_test_api.h" |
| 9 #include "ash/test/test_activation_delegate.h" | 9 #include "ash/test/test_activation_delegate.h" |
| 10 #include "ash/wm/activation_controller.h" | 10 #include "ash/wm/activation_controller.h" |
| (...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 639 env_filter->RemoveHandler(f2.get()); | 639 env_filter->RemoveHandler(f2.get()); |
| 640 } | 640 } |
| 641 | 641 |
| 642 // We should show and hide the cursor in response to mouse and touch events as | 642 // We should show and hide the cursor in response to mouse and touch events as |
| 643 // requested. | 643 // requested. |
| 644 TEST_F(WindowManagerTest, UpdateCursorVisibility) { | 644 TEST_F(WindowManagerTest, UpdateCursorVisibility) { |
| 645 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); | 645 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); |
| 646 root_window->SetBounds(gfx::Rect(0, 0, 500, 500)); | 646 root_window->SetBounds(gfx::Rect(0, 0, 500, 500)); |
| 647 scoped_ptr<aura::Window> window(CreateTestWindowInShell( | 647 scoped_ptr<aura::Window> window(CreateTestWindowInShell( |
| 648 SK_ColorWHITE, -1, gfx::Rect(0, 0, 500, 500))); | 648 SK_ColorWHITE, -1, gfx::Rect(0, 0, 500, 500))); |
| 649 | 649 aura::test::EventGenerator generator(root_window, window.get()); |
|
oshima
2013/01/18 21:59:56
You should be able to use AshTestBase::GetEventGen
mazda
2013/01/18 22:44:39
Done.
| |
| 650 ash::CursorManager* cursor_manager = | 650 ash::CursorManager* cursor_manager = |
| 651 ash::Shell::GetInstance()->cursor_manager(); | 651 ash::Shell::GetInstance()->cursor_manager(); |
| 652 | 652 |
| 653 ui::MouseEvent mouse_moved( | 653 generator.MoveMouseTo(gfx::Point(0, 0)); |
| 654 ui::ET_MOUSE_MOVED, gfx::Point(0, 0), gfx::Point(0, 0), 0x0); | |
| 655 ui::TouchEvent touch_pressed1( | |
| 656 ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 0, getTime()); | |
| 657 ui::TouchEvent touch_pressed2( | |
| 658 ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1, getTime()); | |
| 659 ui::TouchEvent touch_released1( | |
| 660 ui::ET_TOUCH_RELEASED, gfx::Point(0, 0), 0, getTime()); | |
| 661 ui::TouchEvent touch_released2( | |
| 662 ui::ET_TOUCH_RELEASED, gfx::Point(0, 0), 1, getTime()); | |
| 663 | |
| 664 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); | |
| 665 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | 654 EXPECT_TRUE(cursor_manager->IsCursorVisible()); |
| 666 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_pressed1); | 655 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); |
| 656 generator.PressTouch(); | |
| 667 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | 657 EXPECT_FALSE(cursor_manager->IsCursorVisible()); |
| 668 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); | 658 EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); |
| 659 generator.MoveMouseTo(gfx::Point(0, 0)); | |
| 669 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | 660 EXPECT_TRUE(cursor_manager->IsCursorVisible()); |
| 670 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_released1); | 661 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); |
| 662 generator.ReleaseTouch(); | |
| 671 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | 663 EXPECT_TRUE(cursor_manager->IsCursorVisible()); |
| 664 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 672 | 665 |
| 673 // If someone else made cursor invisible keep it invisible even after it | 666 // If someone else made cursor invisible keep it invisible even after it |
| 674 // received mouse events. | 667 // received mouse events. |
| 675 cursor_manager->DisableMouseEvents(); | 668 cursor_manager->EnableMouseEvents(); |
| 676 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); | 669 cursor_manager->HideCursor(); |
| 670 generator.MoveMouseTo(gfx::Point(0, 0)); | |
| 677 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | 671 EXPECT_FALSE(cursor_manager->IsCursorVisible()); |
| 678 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_pressed2); | 672 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); |
| 673 generator.PressTouch(); | |
| 679 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | 674 EXPECT_FALSE(cursor_manager->IsCursorVisible()); |
| 680 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); | 675 EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); |
| 676 generator.MoveMouseTo(gfx::Point(0, 0)); | |
| 681 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | 677 EXPECT_FALSE(cursor_manager->IsCursorVisible()); |
| 682 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_released2); | 678 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); |
| 679 generator.ReleaseTouch(); | |
| 683 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | 680 EXPECT_FALSE(cursor_manager->IsCursorVisible()); |
| 681 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 684 | 682 |
| 685 // Back to normal. | 683 // Back to normal. |
| 686 cursor_manager->EnableMouseEvents(); | 684 cursor_manager->EnableMouseEvents(); |
| 687 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); | 685 cursor_manager->ShowCursor(); |
| 686 generator.MoveMouseTo(gfx::Point(0, 0)); | |
| 688 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | 687 EXPECT_TRUE(cursor_manager->IsCursorVisible()); |
| 689 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_pressed2); | 688 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); |
| 689 generator.PressTouch(); | |
| 690 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | 690 EXPECT_FALSE(cursor_manager->IsCursorVisible()); |
| 691 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); | 691 EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); |
| 692 generator.MoveMouseTo(gfx::Point(0, 0)); | |
| 692 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | 693 EXPECT_TRUE(cursor_manager->IsCursorVisible()); |
| 693 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_released2); | 694 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); |
| 695 generator.ReleaseTouch(); | |
| 694 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | 696 EXPECT_TRUE(cursor_manager->IsCursorVisible()); |
| 697 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 698 } | |
| 699 | |
| 700 TEST_F(WindowManagerTest, UpdateCursorVisibilityOnKeyEvent) { | |
| 701 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); | |
| 702 root_window->SetBounds(gfx::Rect(0, 0, 500, 500)); | |
| 703 scoped_ptr<aura::Window> window(CreateTestWindowInShell( | |
| 704 SK_ColorWHITE, -1, gfx::Rect(0, 0, 500, 500))); | |
| 705 aura::test::EventGenerator generator(root_window, window.get()); | |
|
oshima
2013/01/18 21:59:56
ditto
mazda
2013/01/18 22:44:39
Done.
| |
| 706 ash::CursorManager* cursor_manager = | |
| 707 ash::Shell::GetInstance()->cursor_manager(); | |
| 708 | |
| 709 // Pressing a key hides the cursor but does not disable mouse events. | |
| 710 generator.PressKey(ui::VKEY_A, ui::EF_NONE); | |
| 711 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | |
| 712 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 713 // Moving mouse shows the cursor. | |
| 714 generator.MoveMouseTo(gfx::Point(0, 0)); | |
| 715 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | |
| 716 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 717 // Releasing a key also hides the cursor but does not disable mouse events. | |
| 718 generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE); | |
| 719 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | |
| 720 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 721 // Moving mouse shows the cursor again. | |
| 722 generator.MoveMouseTo(gfx::Point(0, 0)); | |
| 723 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | |
| 724 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 695 } | 725 } |
| 696 | 726 |
| 697 } // namespace ash | 727 } // namespace ash |
| OLD | NEW |