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 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 656 ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 0, getTime()); | 656 ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 0, getTime()); |
| 657 ui::TouchEvent touch_pressed2( | 657 ui::TouchEvent touch_pressed2( |
| 658 ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1, getTime()); | 658 ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1, getTime()); |
| 659 ui::TouchEvent touch_released1( | 659 ui::TouchEvent touch_released1( |
| 660 ui::ET_TOUCH_RELEASED, gfx::Point(0, 0), 0, getTime()); | 660 ui::ET_TOUCH_RELEASED, gfx::Point(0, 0), 0, getTime()); |
| 661 ui::TouchEvent touch_released2( | 661 ui::TouchEvent touch_released2( |
| 662 ui::ET_TOUCH_RELEASED, gfx::Point(0, 0), 1, getTime()); | 662 ui::ET_TOUCH_RELEASED, gfx::Point(0, 0), 1, getTime()); |
| 663 | 663 |
| 664 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); | 664 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); |
| 665 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | 665 EXPECT_TRUE(cursor_manager->IsCursorVisible()); |
| 666 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 666 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_pressed1); | 667 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_pressed1); |
| 667 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | 668 EXPECT_FALSE(cursor_manager->IsCursorVisible()); |
| 669 EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); | |
| 668 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); | 670 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); |
| 669 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | 671 EXPECT_TRUE(cursor_manager->IsCursorVisible()); |
| 672 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 670 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_released1); | 673 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_released1); |
| 671 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | 674 EXPECT_TRUE(cursor_manager->IsCursorVisible()); |
| 675 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 672 | 676 |
| 673 // If someone else made cursor invisible keep it invisible even after it | 677 // If someone else made cursor invisible keep it invisible even after it |
| 674 // received mouse events. | 678 // received mouse events. |
| 675 cursor_manager->DisableMouseEvents(); | 679 cursor_manager->EnableMouseEvents(); |
| 680 cursor_manager->HideCursor(); | |
| 676 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); | 681 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); |
| 677 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | 682 EXPECT_FALSE(cursor_manager->IsCursorVisible()); |
| 683 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 678 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_pressed2); | 684 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_pressed2); |
| 679 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | 685 EXPECT_FALSE(cursor_manager->IsCursorVisible()); |
| 686 EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); | |
| 680 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); | 687 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); |
| 681 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | 688 EXPECT_FALSE(cursor_manager->IsCursorVisible()); |
| 689 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 682 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_released2); | 690 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_released2); |
| 683 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | 691 EXPECT_FALSE(cursor_manager->IsCursorVisible()); |
| 692 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 684 | 693 |
| 685 // Back to normal. | 694 // Back to normal. |
| 686 cursor_manager->EnableMouseEvents(); | 695 cursor_manager->EnableMouseEvents(); |
| 696 cursor_manager->ShowCursor(); | |
| 687 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); | 697 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); |
| 688 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | 698 EXPECT_TRUE(cursor_manager->IsCursorVisible()); |
| 699 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 689 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_pressed2); | 700 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_pressed2); |
| 690 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | 701 EXPECT_FALSE(cursor_manager->IsCursorVisible()); |
| 702 EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); | |
| 691 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); | 703 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); |
| 692 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | 704 EXPECT_TRUE(cursor_manager->IsCursorVisible()); |
| 705 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 693 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_released2); | 706 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touch_released2); |
| 694 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | 707 EXPECT_TRUE(cursor_manager->IsCursorVisible()); |
| 708 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 709 } | |
| 710 | |
| 711 TEST_F(WindowManagerTest, UpdateCursorVisibilityOnKeyEvent) { | |
| 712 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); | |
| 713 root_window->SetBounds(gfx::Rect(0, 0, 500, 500)); | |
| 714 scoped_ptr<aura::Window> window(CreateTestWindowInShell( | |
| 715 SK_ColorWHITE, -1, gfx::Rect(0, 0, 500, 500))); | |
| 716 | |
| 717 ash::CursorManager* cursor_manager = | |
| 718 ash::Shell::GetInstance()->cursor_manager(); | |
| 719 | |
| 720 ui::MouseEvent mouse_moved( | |
| 721 ui::ET_MOUSE_MOVED, gfx::Point(0, 0), gfx::Point(0, 0), 0x0); | |
| 722 ui::KeyEvent key_pressed(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE, false); | |
| 723 ui::KeyEvent key_released(ui::ET_KEY_RELEASED, ui::VKEY_A, ui::EF_NONE, | |
| 724 false); | |
|
oshima
2013/01/17 18:57:02
can you use event generator?
mazda
2013/01/18 20:34:54
Rewrote tests using EventGenerator. Thanks.
| |
| 725 // Pressing a key hides the cursor but does not disable mouse events. | |
| 726 root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&key_pressed); | |
| 727 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | |
| 728 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 729 // Moving mouse shows the cursor. | |
| 730 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); | |
| 731 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | |
| 732 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 733 // Releasing a key also hides the cursor but does not disable mouse events. | |
| 734 root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&key_pressed); | |
| 735 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | |
| 736 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 737 // Moving mouse shows the cursor again. | |
| 738 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_moved); | |
| 739 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | |
| 740 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 695 } | 741 } |
| 696 | 742 |
| 697 } // namespace ash | 743 } // namespace ash |
| OLD | NEW |