| 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/window_util.h" | 10 #include "ash/wm/window_util.h" |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 // Creates a window and make it active | 658 // Creates a window and make it active |
| 659 scoped_ptr<aura::Window> w1(CreateTestWindowInShell( | 659 scoped_ptr<aura::Window> w1(CreateTestWindowInShell( |
| 660 SK_ColorWHITE, -1, gfx::Rect(0, 0, 100, 100))); | 660 SK_ColorWHITE, -1, gfx::Rect(0, 0, 100, 100))); |
| 661 wm::ActivateWindow(w1.get()); | 661 wm::ActivateWindow(w1.get()); |
| 662 | 662 |
| 663 // Creates two addition filters | 663 // Creates two addition filters |
| 664 scoped_ptr<CustomEventHandler> f1(new CustomEventHandler); | 664 scoped_ptr<CustomEventHandler> f1(new CustomEventHandler); |
| 665 scoped_ptr<CustomEventHandler> f2(new CustomEventHandler); | 665 scoped_ptr<CustomEventHandler> f2(new CustomEventHandler); |
| 666 | 666 |
| 667 // Adds them to root window event filter. | 667 // Adds them to root window event filter. |
| 668 views::corewm::CompoundEventFilter* env_filter = | 668 ::wm::CompoundEventFilter* env_filter = |
| 669 Shell::GetInstance()->env_filter(); | 669 Shell::GetInstance()->env_filter(); |
| 670 env_filter->AddHandler(f1.get()); | 670 env_filter->AddHandler(f1.get()); |
| 671 env_filter->AddHandler(f2.get()); | 671 env_filter->AddHandler(f2.get()); |
| 672 | 672 |
| 673 // Dispatches mouse and keyboard events. | 673 // Dispatches mouse and keyboard events. |
| 674 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, false); | 674 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, false); |
| 675 ui::EventProcessor* dispatcher = root_window->GetHost()->event_processor(); | 675 ui::EventProcessor* dispatcher = root_window->GetHost()->event_processor(); |
| 676 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&key_event); | 676 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&key_event); |
| 677 ASSERT_FALSE(details.dispatcher_destroyed); | 677 ASSERT_FALSE(details.dispatcher_destroyed); |
| 678 ui::MouseEvent mouse_pressed( | 678 ui::MouseEvent mouse_pressed( |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 EXPECT_EQ(1, f2->num_mouse_events()); | 726 EXPECT_EQ(1, f2->num_mouse_events()); |
| 727 | 727 |
| 728 env_filter->RemoveHandler(f2.get()); | 728 env_filter->RemoveHandler(f2.get()); |
| 729 } | 729 } |
| 730 | 730 |
| 731 #if defined(OS_CHROMEOS) | 731 #if defined(OS_CHROMEOS) |
| 732 // Touch visually hides the cursor on ChromeOS and Windows, but we only update | 732 // Touch visually hides the cursor on ChromeOS and Windows, but we only update |
| 733 // our internal tracking of the cursor state on ChromeOS (crbug.com/333952). | 733 // our internal tracking of the cursor state on ChromeOS (crbug.com/333952). |
| 734 TEST_F(WindowManagerTest, UpdateCursorVisibility) { | 734 TEST_F(WindowManagerTest, UpdateCursorVisibility) { |
| 735 aura::test::EventGenerator& generator = GetEventGenerator(); | 735 aura::test::EventGenerator& generator = GetEventGenerator(); |
| 736 views::corewm::CursorManager* cursor_manager = | 736 ::wm::CursorManager* cursor_manager = |
| 737 ash::Shell::GetInstance()->cursor_manager(); | 737 ash::Shell::GetInstance()->cursor_manager(); |
| 738 | 738 |
| 739 generator.MoveMouseTo(gfx::Point(0, 0)); | 739 generator.MoveMouseTo(gfx::Point(0, 0)); |
| 740 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | 740 EXPECT_TRUE(cursor_manager->IsCursorVisible()); |
| 741 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | 741 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); |
| 742 generator.PressTouch(); | 742 generator.PressTouch(); |
| 743 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | 743 EXPECT_FALSE(cursor_manager->IsCursorVisible()); |
| 744 EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); | 744 EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); |
| 745 generator.MoveMouseTo(gfx::Point(0, 0)); | 745 generator.MoveMouseTo(gfx::Point(0, 0)); |
| 746 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | 746 EXPECT_TRUE(cursor_manager->IsCursorVisible()); |
| 747 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | 747 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); |
| 748 generator.ReleaseTouch(); | 748 generator.ReleaseTouch(); |
| 749 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | 749 EXPECT_TRUE(cursor_manager->IsCursorVisible()); |
| 750 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | 750 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); |
| 751 } | 751 } |
| 752 | 752 |
| 753 // ChromeOS is the only platform for which the cursor is hidden on keypress | 753 // ChromeOS is the only platform for which the cursor is hidden on keypress |
| 754 // (crbug.com/304296). | 754 // (crbug.com/304296). |
| 755 TEST_F(WindowManagerTest, UpdateCursorVisibilityOnKeyEvent) { | 755 TEST_F(WindowManagerTest, UpdateCursorVisibilityOnKeyEvent) { |
| 756 aura::test::EventGenerator& generator = GetEventGenerator(); | 756 aura::test::EventGenerator& generator = GetEventGenerator(); |
| 757 views::corewm::CursorManager* cursor_manager = | 757 ::wm::CursorManager* cursor_manager = |
| 758 ash::Shell::GetInstance()->cursor_manager(); | 758 ash::Shell::GetInstance()->cursor_manager(); |
| 759 | 759 |
| 760 // Pressing a key hides the cursor but does not disable mouse events. | 760 // Pressing a key hides the cursor but does not disable mouse events. |
| 761 generator.PressKey(ui::VKEY_A, ui::EF_NONE); | 761 generator.PressKey(ui::VKEY_A, ui::EF_NONE); |
| 762 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | 762 EXPECT_FALSE(cursor_manager->IsCursorVisible()); |
| 763 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | 763 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); |
| 764 // Moving mouse shows the cursor. | 764 // Moving mouse shows the cursor. |
| 765 generator.MoveMouseTo(gfx::Point(0, 0)); | 765 generator.MoveMouseTo(gfx::Point(0, 0)); |
| 766 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | 766 EXPECT_TRUE(cursor_manager->IsCursorVisible()); |
| 767 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | 767 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); |
| 768 // Releasing a key also hides the cursor but does not disable mouse events. | 768 // Releasing a key also hides the cursor but does not disable mouse events. |
| 769 generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE); | 769 generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE); |
| 770 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | 770 EXPECT_FALSE(cursor_manager->IsCursorVisible()); |
| 771 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | 771 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); |
| 772 // Moving mouse shows the cursor again. | 772 // Moving mouse shows the cursor again. |
| 773 generator.MoveMouseTo(gfx::Point(0, 0)); | 773 generator.MoveMouseTo(gfx::Point(0, 0)); |
| 774 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | 774 EXPECT_TRUE(cursor_manager->IsCursorVisible()); |
| 775 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | 775 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); |
| 776 } | 776 } |
| 777 | 777 |
| 778 TEST_F(WindowManagerTest, TestCursorClientObserver) { | 778 TEST_F(WindowManagerTest, TestCursorClientObserver) { |
| 779 aura::test::EventGenerator& generator = GetEventGenerator(); | 779 aura::test::EventGenerator& generator = GetEventGenerator(); |
| 780 views::corewm::CursorManager* cursor_manager = | 780 ::wm::CursorManager* cursor_manager = |
| 781 ash::Shell::GetInstance()->cursor_manager(); | 781 ash::Shell::GetInstance()->cursor_manager(); |
| 782 | 782 |
| 783 scoped_ptr<aura::Window> w1(CreateTestWindowInShell( | 783 scoped_ptr<aura::Window> w1(CreateTestWindowInShell( |
| 784 SK_ColorWHITE, -1, gfx::Rect(0, 0, 100, 100))); | 784 SK_ColorWHITE, -1, gfx::Rect(0, 0, 100, 100))); |
| 785 wm::ActivateWindow(w1.get()); | 785 wm::ActivateWindow(w1.get()); |
| 786 | 786 |
| 787 // Add two observers. Both should have OnCursorVisibilityChanged() | 787 // Add two observers. Both should have OnCursorVisibilityChanged() |
| 788 // invoked when an event changes the visibility of the cursor. | 788 // invoked when an event changes the visibility of the cursor. |
| 789 TestingCursorClientObserver observer_a; | 789 TestingCursorClientObserver observer_a; |
| 790 TestingCursorClientObserver observer_b; | 790 TestingCursorClientObserver observer_b; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 observer_a.reset(); | 831 observer_a.reset(); |
| 832 observer_b.reset(); | 832 observer_b.reset(); |
| 833 generator.MoveMouseTo(50, 50); | 833 generator.MoveMouseTo(50, 50); |
| 834 EXPECT_TRUE(observer_a.did_visibility_change()); | 834 EXPECT_TRUE(observer_a.did_visibility_change()); |
| 835 EXPECT_FALSE(observer_b.did_visibility_change()); | 835 EXPECT_FALSE(observer_b.did_visibility_change()); |
| 836 EXPECT_TRUE(observer_a.is_cursor_visible()); | 836 EXPECT_TRUE(observer_a.is_cursor_visible()); |
| 837 } | 837 } |
| 838 #endif // defined(OS_CHROMEOS) | 838 #endif // defined(OS_CHROMEOS) |
| 839 | 839 |
| 840 } // namespace ash | 840 } // namespace ash |
| OLD | NEW |