| 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/shell_window_ids.h" | 5 #include "ash/common/shell_window_ids.h" |
| 6 #include "ash/shell.h" | 6 #include "ash/shell.h" |
| 7 #include "ash/test/ash_test_base.h" | 7 #include "ash/test/ash_test_base.h" |
| 8 #include "ash/test/test_activation_delegate.h" | 8 #include "ash/test/test_activation_delegate.h" |
| 9 #include "ash/wm/window_util.h" | 9 #include "ash/wm/window_util.h" |
| 10 #include "ui/aura/client/cursor_client_observer.h" | 10 #include "ui/aura/client/cursor_client_observer.h" |
| 11 #include "ui/aura/client/focus_client.h" | 11 #include "ui/aura/client/focus_client.h" |
| 12 #include "ui/aura/env.h" | 12 #include "ui/aura/env.h" |
| 13 #include "ui/aura/test/aura_test_base.h" | 13 #include "ui/aura/test/aura_test_base.h" |
| 14 #include "ui/aura/test/test_window_delegate.h" | 14 #include "ui/aura/test/test_window_delegate.h" |
| 15 #include "ui/aura/test/test_windows.h" | 15 #include "ui/aura/test/test_windows.h" |
| 16 #include "ui/base/cursor/cursor.h" | 16 #include "ui/base/cursor/cursor.h" |
| 17 #include "ui/base/hit_test.h" | 17 #include "ui/base/hit_test.h" |
| 18 #include "ui/display/screen.h" | 18 #include "ui/display/screen.h" |
| 19 #include "ui/events/event.h" | 19 #include "ui/events/event.h" |
| 20 #include "ui/events/event_processor.h" | 20 #include "ui/events/event_processor.h" |
| 21 #include "ui/events/event_utils.h" | 21 #include "ui/events/event_utils.h" |
| 22 #include "ui/events/test/event_generator.h" | 22 #include "ui/events/test/event_generator.h" |
| 23 #include "ui/events/test/test_event_handler.h" | 23 #include "ui/events/test/test_event_handler.h" |
| 24 #include "ui/wm/core/compound_event_filter.h" | 24 #include "ui/wm/core/compound_event_filter.h" |
| 25 #include "ui/wm/public/activation_client.h" | 25 #include "ui/wm/public/activation_client.h" |
| 26 #include "ui/wm/public/activation_delegate.h" | 26 #include "ui/wm/public/activation_delegate.h" |
| 27 #include "ui/wm/test/testing_cursor_client_observer.h" |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 class TestingCursorClientObserver : public aura::client::CursorClientObserver { | |
| 31 public: | |
| 32 TestingCursorClientObserver() | |
| 33 : cursor_visibility_(false), did_visibility_change_(false) {} | |
| 34 void reset() { cursor_visibility_ = did_visibility_change_ = false; } | |
| 35 bool is_cursor_visible() const { return cursor_visibility_; } | |
| 36 bool did_visibility_change() const { return did_visibility_change_; } | |
| 37 | |
| 38 // Overridden from aura::client::CursorClientObserver: | |
| 39 void OnCursorVisibilityChanged(bool is_visible) override { | |
| 40 cursor_visibility_ = is_visible; | |
| 41 did_visibility_change_ = true; | |
| 42 } | |
| 43 | |
| 44 private: | |
| 45 bool cursor_visibility_; | |
| 46 bool did_visibility_change_; | |
| 47 | |
| 48 DISALLOW_COPY_AND_ASSIGN(TestingCursorClientObserver); | |
| 49 }; | |
| 50 | |
| 51 base::TimeTicks getTime() { | 31 base::TimeTicks getTime() { |
| 52 return ui::EventTimeForNow(); | 32 return ui::EventTimeForNow(); |
| 53 } | 33 } |
| 54 | 34 |
| 55 // A slightly changed TestEventHandler which can be configured to return a | 35 // A slightly changed TestEventHandler which can be configured to return a |
| 56 // specified value for key/mouse event handling. | 36 // specified value for key/mouse event handling. |
| 57 class CustomEventHandler : public ui::test::TestEventHandler { | 37 class CustomEventHandler : public ui::test::TestEventHandler { |
| 58 public: | 38 public: |
| 59 CustomEventHandler() | 39 CustomEventHandler() |
| 60 : key_result_(ui::ER_UNHANDLED), mouse_result_(ui::ER_UNHANDLED) {} | 40 : key_result_(ui::ER_UNHANDLED), mouse_result_(ui::ER_UNHANDLED) {} |
| (...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 ui::test::EventGenerator& generator = GetEventGenerator(); | 770 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 791 ::wm::CursorManager* cursor_manager = | 771 ::wm::CursorManager* cursor_manager = |
| 792 ash::Shell::GetInstance()->cursor_manager(); | 772 ash::Shell::GetInstance()->cursor_manager(); |
| 793 | 773 |
| 794 std::unique_ptr<aura::Window> w1( | 774 std::unique_ptr<aura::Window> w1( |
| 795 CreateTestWindowInShell(SK_ColorWHITE, -1, gfx::Rect(0, 0, 100, 100))); | 775 CreateTestWindowInShell(SK_ColorWHITE, -1, gfx::Rect(0, 0, 100, 100))); |
| 796 wm::ActivateWindow(w1.get()); | 776 wm::ActivateWindow(w1.get()); |
| 797 | 777 |
| 798 // Add two observers. Both should have OnCursorVisibilityChanged() | 778 // Add two observers. Both should have OnCursorVisibilityChanged() |
| 799 // invoked when an event changes the visibility of the cursor. | 779 // invoked when an event changes the visibility of the cursor. |
| 800 TestingCursorClientObserver observer_a; | 780 ::wm::TestingCursorClientObserver observer_a; |
| 801 TestingCursorClientObserver observer_b; | 781 ::wm::TestingCursorClientObserver observer_b; |
| 802 cursor_manager->AddObserver(&observer_a); | 782 cursor_manager->AddObserver(&observer_a); |
| 803 cursor_manager->AddObserver(&observer_b); | 783 cursor_manager->AddObserver(&observer_b); |
| 804 | 784 |
| 805 // Initial state before any events have been sent. | 785 // Initial state before any events have been sent. |
| 806 observer_a.reset(); | 786 observer_a.reset(); |
| 807 observer_b.reset(); | 787 observer_b.reset(); |
| 808 EXPECT_FALSE(observer_a.did_visibility_change()); | 788 EXPECT_FALSE(observer_a.did_visibility_change()); |
| 809 EXPECT_FALSE(observer_b.did_visibility_change()); | 789 EXPECT_FALSE(observer_b.did_visibility_change()); |
| 810 EXPECT_FALSE(observer_a.is_cursor_visible()); | 790 EXPECT_FALSE(observer_a.is_cursor_visible()); |
| 811 EXPECT_FALSE(observer_b.is_cursor_visible()); | 791 EXPECT_FALSE(observer_b.is_cursor_visible()); |
| 792 EXPECT_FALSE(observer_a.did_cursor_set_change()); |
| 793 EXPECT_FALSE(observer_b.did_cursor_set_change()); |
| 812 | 794 |
| 813 // Keypress should hide the cursor. | 795 // Keypress should hide the cursor. |
| 814 generator.PressKey(ui::VKEY_A, ui::EF_NONE); | 796 generator.PressKey(ui::VKEY_A, ui::EF_NONE); |
| 815 EXPECT_TRUE(observer_a.did_visibility_change()); | 797 EXPECT_TRUE(observer_a.did_visibility_change()); |
| 816 EXPECT_TRUE(observer_b.did_visibility_change()); | 798 EXPECT_TRUE(observer_b.did_visibility_change()); |
| 817 EXPECT_FALSE(observer_a.is_cursor_visible()); | 799 EXPECT_FALSE(observer_a.is_cursor_visible()); |
| 818 EXPECT_FALSE(observer_b.is_cursor_visible()); | 800 EXPECT_FALSE(observer_b.is_cursor_visible()); |
| 819 | 801 |
| 802 // Set cursor set. |
| 803 cursor_manager->SetCursorSet(ui::CURSOR_SET_LARGE); |
| 804 EXPECT_TRUE(observer_a.did_cursor_set_change()); |
| 805 EXPECT_EQ(ui::CURSOR_SET_LARGE, observer_a.cursor_set()); |
| 806 EXPECT_TRUE(observer_b.did_cursor_set_change()); |
| 807 EXPECT_EQ(ui::CURSOR_SET_LARGE, observer_b.cursor_set()); |
| 808 |
| 820 // Mouse move should show the cursor. | 809 // Mouse move should show the cursor. |
| 821 observer_a.reset(); | 810 observer_a.reset(); |
| 822 observer_b.reset(); | 811 observer_b.reset(); |
| 823 generator.MoveMouseTo(50, 50); | 812 generator.MoveMouseTo(50, 50); |
| 824 EXPECT_TRUE(observer_a.did_visibility_change()); | 813 EXPECT_TRUE(observer_a.did_visibility_change()); |
| 825 EXPECT_TRUE(observer_b.did_visibility_change()); | 814 EXPECT_TRUE(observer_b.did_visibility_change()); |
| 826 EXPECT_TRUE(observer_a.is_cursor_visible()); | 815 EXPECT_TRUE(observer_a.is_cursor_visible()); |
| 827 EXPECT_TRUE(observer_b.is_cursor_visible()); | 816 EXPECT_TRUE(observer_b.is_cursor_visible()); |
| 828 | 817 |
| 829 // Remove observer_b. Its OnCursorVisibilityChanged() should | 818 // Remove observer_b. Its OnCursorVisibilityChanged() should |
| 830 // not be invoked past this point. | 819 // not be invoked past this point. |
| 831 cursor_manager->RemoveObserver(&observer_b); | 820 cursor_manager->RemoveObserver(&observer_b); |
| 832 | 821 |
| 833 // Gesture tap should hide the cursor. | 822 // Gesture tap should hide the cursor. |
| 834 observer_a.reset(); | 823 observer_a.reset(); |
| 835 observer_b.reset(); | 824 observer_b.reset(); |
| 836 generator.GestureTapAt(gfx::Point(25, 25)); | 825 generator.GestureTapAt(gfx::Point(25, 25)); |
| 837 EXPECT_TRUE(observer_a.did_visibility_change()); | 826 EXPECT_TRUE(observer_a.did_visibility_change()); |
| 838 EXPECT_FALSE(observer_b.did_visibility_change()); | 827 EXPECT_FALSE(observer_b.did_visibility_change()); |
| 839 EXPECT_FALSE(observer_a.is_cursor_visible()); | 828 EXPECT_FALSE(observer_a.is_cursor_visible()); |
| 840 | 829 |
| 830 // Set back cursor set to normal. |
| 831 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL); |
| 832 EXPECT_TRUE(observer_a.did_cursor_set_change()); |
| 833 EXPECT_EQ(ui::CURSOR_SET_NORMAL, observer_a.cursor_set()); |
| 834 EXPECT_FALSE(observer_b.did_cursor_set_change()); |
| 835 |
| 841 // Mouse move should show the cursor. | 836 // Mouse move should show the cursor. |
| 842 observer_a.reset(); | 837 observer_a.reset(); |
| 843 observer_b.reset(); | 838 observer_b.reset(); |
| 844 generator.MoveMouseTo(50, 50); | 839 generator.MoveMouseTo(50, 50); |
| 845 EXPECT_TRUE(observer_a.did_visibility_change()); | 840 EXPECT_TRUE(observer_a.did_visibility_change()); |
| 846 EXPECT_FALSE(observer_b.did_visibility_change()); | 841 EXPECT_FALSE(observer_b.did_visibility_change()); |
| 847 EXPECT_TRUE(observer_a.is_cursor_visible()); | 842 EXPECT_TRUE(observer_a.is_cursor_visible()); |
| 848 | 843 |
| 849 cursor_manager->RemoveObserver(&observer_a); | 844 cursor_manager->RemoveObserver(&observer_a); |
| 850 } | 845 } |
| 851 #endif // defined(OS_CHROMEOS) | 846 #endif // defined(OS_CHROMEOS) |
| 852 | 847 |
| 853 } // namespace ash | 848 } // namespace ash |
| OLD | NEW |