OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "services/ui/ws/window_manager_state.h" | 5 #include "services/ui/ws/window_manager_state.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
| 9 #include "base/command_line.h" |
9 #include "base/macros.h" | 10 #include "base/macros.h" |
10 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
12 #include "base/test/test_simple_task_runner.h" | 13 #include "base/test/test_simple_task_runner.h" |
13 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
14 #include "services/service_manager/public/interfaces/connector.mojom.h" | 15 #include "services/service_manager/public/interfaces/connector.mojom.h" |
15 #include "services/ui/common/accelerator_util.h" | 16 #include "services/ui/common/accelerator_util.h" |
16 #include "services/ui/ws/accelerator.h" | 17 #include "services/ui/ws/accelerator.h" |
17 #include "services/ui/ws/display.h" | 18 #include "services/ui/ws/display.h" |
18 #include "services/ui/ws/display_manager.h" | 19 #include "services/ui/ws/display_manager.h" |
(...skipping 21 matching lines...) Expand all Loading... |
40 | 41 |
41 std::unique_ptr<Accelerator> CreateAccelerator(); | 42 std::unique_ptr<Accelerator> CreateAccelerator(); |
42 | 43 |
43 // Creates a child |server_window| with associataed |window_tree| and | 44 // Creates a child |server_window| with associataed |window_tree| and |
44 // |test_client|. The window is setup for processing input. | 45 // |test_client|. The window is setup for processing input. |
45 void CreateSecondaryTree(TestWindowTreeClient** test_client, | 46 void CreateSecondaryTree(TestWindowTreeClient** test_client, |
46 WindowTree** window_tree, | 47 WindowTree** window_tree, |
47 ServerWindow** server_window); | 48 ServerWindow** server_window); |
48 | 49 |
49 void DispatchInputEventToWindow(ServerWindow* target, | 50 void DispatchInputEventToWindow(ServerWindow* target, |
50 const int64_t display_id, | 51 int64_t display_id, |
51 const ui::Event& event, | 52 const ui::Event& event, |
52 Accelerator* accelerator); | 53 Accelerator* accelerator); |
53 void OnEventAckTimeout(ClientSpecificId client_id); | 54 void OnEventAckTimeout(ClientSpecificId client_id); |
54 | 55 |
55 // This is the tree associated with the WindowManagerState. That is, this is | 56 // This is the tree associated with the WindowManagerState. That is, this is |
56 // the WindowTree of the WindowManager. | 57 // the WindowTree of the WindowManager. |
57 WindowTree* tree() { | 58 WindowTree* tree() { |
58 return window_event_targeting_helper_.window_server()->GetTreeWithId(1); | 59 return window_event_targeting_helper_.window_server()->GetTreeWithId(1); |
59 } | 60 } |
60 // This is *not* the tree associated with the WindowManagerState, use tree() | 61 // This is *not* the tree associated with the WindowManagerState, use tree() |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 } | 94 } |
94 | 95 |
95 void DestroyWindowTree() { | 96 void DestroyWindowTree() { |
96 window_event_targeting_helper_.window_server()->DestroyTree(window_tree_); | 97 window_event_targeting_helper_.window_server()->DestroyTree(window_tree_); |
97 window_tree_ = nullptr; | 98 window_tree_ = nullptr; |
98 } | 99 } |
99 | 100 |
100 // testing::Test: | 101 // testing::Test: |
101 void SetUp() override; | 102 void SetUp() override; |
102 | 103 |
| 104 protected: |
| 105 // Handles WindowStateManager ack timeouts. |
| 106 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
| 107 |
103 private: | 108 private: |
104 WindowEventTargetingHelper window_event_targeting_helper_; | 109 WindowEventTargetingHelper window_event_targeting_helper_; |
105 | 110 |
106 WindowManagerState* window_manager_state_; | 111 WindowManagerState* window_manager_state_; |
107 | 112 |
108 // Handles WindowStateManager ack timeouts. | |
109 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | |
110 TestWindowManager window_manager_; | 113 TestWindowManager window_manager_; |
111 ServerWindow* window_ = nullptr; | 114 ServerWindow* window_ = nullptr; |
112 WindowTree* window_tree_ = nullptr; | 115 WindowTree* window_tree_ = nullptr; |
113 TestWindowTreeClient* window_tree_client_ = nullptr; | 116 TestWindowTreeClient* window_tree_client_ = nullptr; |
114 | 117 |
115 DISALLOW_COPY_AND_ASSIGN(WindowManagerStateTest); | 118 DISALLOW_COPY_AND_ASSIGN(WindowManagerStateTest); |
116 }; | 119 }; |
117 | 120 |
118 WindowManagerStateTest::WindowManagerStateTest() | 121 WindowManagerStateTest::WindowManagerStateTest() |
119 : task_runner_(new base::TestSimpleTaskRunner) {} | 122 : task_runner_(new base::TestSimpleTaskRunner) {} |
(...skipping 12 matching lines...) Expand all Loading... |
132 TestWindowTreeClient** test_client, | 135 TestWindowTreeClient** test_client, |
133 WindowTree** window_tree, | 136 WindowTree** window_tree, |
134 ServerWindow** server_window) { | 137 ServerWindow** server_window) { |
135 window_event_targeting_helper_.CreateSecondaryTree( | 138 window_event_targeting_helper_.CreateSecondaryTree( |
136 window_, gfx::Rect(20, 20, 20, 20), test_client, window_tree, | 139 window_, gfx::Rect(20, 20, 20, 20), test_client, window_tree, |
137 server_window); | 140 server_window); |
138 } | 141 } |
139 | 142 |
140 void WindowManagerStateTest::DispatchInputEventToWindow( | 143 void WindowManagerStateTest::DispatchInputEventToWindow( |
141 ServerWindow* target, | 144 ServerWindow* target, |
142 const int64_t display_id, | 145 int64_t display_id, |
143 const ui::Event& event, | 146 const ui::Event& event, |
144 Accelerator* accelerator) { | 147 Accelerator* accelerator) { |
145 WindowManagerStateTestApi test_api(window_manager_state_); | 148 WindowManagerStateTestApi test_api(window_manager_state_); |
146 ClientSpecificId client_id = test_api.GetEventTargetClientId(target, false); | 149 ClientSpecificId client_id = test_api.GetEventTargetClientId(target, false); |
147 test_api.DispatchInputEventToWindow(target, client_id, display_id, event, | 150 test_api.DispatchInputEventToWindow(target, client_id, display_id, event, |
148 accelerator); | 151 accelerator); |
149 } | 152 } |
150 | 153 |
151 void WindowManagerStateTest::OnEventAckTimeout( | 154 void WindowManagerStateTest::OnEventAckTimeout( |
152 ClientSpecificId client_id) { | 155 ClientSpecificId client_id) { |
(...skipping 18 matching lines...) Expand all Loading... |
171 window_tree_client_->tracker()->changes()->clear(); | 174 window_tree_client_->tracker()->changes()->clear(); |
172 } | 175 } |
173 | 176 |
174 void SetCanFocusUp(ServerWindow* window) { | 177 void SetCanFocusUp(ServerWindow* window) { |
175 while (window) { | 178 while (window) { |
176 window->set_can_focus(true); | 179 window->set_can_focus(true); |
177 window = window->parent(); | 180 window = window->parent(); |
178 } | 181 } |
179 } | 182 } |
180 | 183 |
| 184 class WindowManagerStateTestAsync : public WindowManagerStateTest { |
| 185 public: |
| 186 WindowManagerStateTestAsync() {} |
| 187 ~WindowManagerStateTestAsync() override {} |
| 188 |
| 189 // WindowManagerStateTest: |
| 190 void SetUp() override { |
| 191 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 192 "enable-async-event-targeting"); |
| 193 WindowManagerStateTest::SetUp(); |
| 194 } |
| 195 |
| 196 private: |
| 197 DISALLOW_COPY_AND_ASSIGN(WindowManagerStateTestAsync); |
| 198 }; |
| 199 |
181 // Tests that when an event is dispatched with no accelerator, that post target | 200 // Tests that when an event is dispatched with no accelerator, that post target |
182 // accelerator is not triggered. | 201 // accelerator is not triggered. |
183 TEST_F(WindowManagerStateTest, NullAccelerator) { | 202 TEST_F(WindowManagerStateTest, NullAccelerator) { |
184 WindowManagerState* state = window_manager_state(); | 203 WindowManagerState* state = window_manager_state(); |
185 EXPECT_TRUE(state); | 204 EXPECT_TRUE(state); |
186 | 205 |
187 ServerWindow* target = window(); | 206 ServerWindow* target = window(); |
188 const Display* display = window_tree()->GetDisplay(target); | 207 const Display* display = window_tree()->GetDisplay(target); |
189 DCHECK(display); | 208 DCHECK(display); |
190 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); | 209 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 ui::PointerEvent move( | 711 ui::PointerEvent move( |
693 ui::ET_POINTER_MOVED, gfx::Point(25, 25), gfx::Point(25, 25), 0, 0, | 712 ui::ET_POINTER_MOVED, gfx::Point(25, 25), gfx::Point(25, 25), 0, 0, |
694 ui::PointerDetails(EventPointerType::POINTER_TYPE_MOUSE, 0), | 713 ui::PointerDetails(EventPointerType::POINTER_TYPE_MOUSE, 0), |
695 base::TimeTicks()); | 714 base::TimeTicks()); |
696 window_manager_state()->ProcessEvent(move, 0); | 715 window_manager_state()->ProcessEvent(move, 0); |
697 // The event isn't over a valid target, which should trigger resetting the | 716 // The event isn't over a valid target, which should trigger resetting the |
698 // cursor to POINTER. | 717 // cursor to POINTER. |
699 EXPECT_EQ(ui::CursorType::kPointer, cursor_type()); | 718 EXPECT_EQ(ui::CursorType::kPointer, cursor_type()); |
700 } | 719 } |
701 | 720 |
| 721 TEST_F(WindowManagerStateTestAsync, CursorResetOverNoTargetAsync) { |
| 722 ASSERT_EQ(1u, window_server()->display_manager()->displays().size()); |
| 723 const ClientWindowId child_window_id(11); |
| 724 window_tree()->NewWindow(child_window_id, ServerWindow::Properties()); |
| 725 ServerWindow* child_window = |
| 726 window_tree()->GetWindowByClientId(child_window_id); |
| 727 window_tree()->AddWindow(FirstRootId(window_tree()), child_window_id); |
| 728 // Setup steps already do hit-test for mouse cursor update so this should go |
| 729 // to the queue in EventDispatcher. |
| 730 EXPECT_TRUE(window_manager_state() |
| 731 ->event_dispatcher() |
| 732 ->event_targeter() |
| 733 ->IsHitTestInFlight()); |
| 734 child_window->SetVisible(true); |
| 735 child_window->SetBounds(gfx::Rect(0, 0, 20, 20)); |
| 736 child_window->parent()->SetCursor(ui::CursorData(ui::CursorType::kCopy)); |
| 737 // Move the mouse outside the bounds of the child, so that the mouse is not |
| 738 // over any valid windows. Cursor should change to POINTER. |
| 739 ui::PointerEvent move( |
| 740 ui::ET_POINTER_MOVED, gfx::Point(25, 25), gfx::Point(25, 25), 0, 0, |
| 741 ui::PointerDetails(EventPointerType::POINTER_TYPE_MOUSE, 0), |
| 742 base::TimeTicks()); |
| 743 WindowManagerStateTestApi test_api(window_manager_state()); |
| 744 EXPECT_TRUE(test_api.event_queue_empty()); |
| 745 window_manager_state()->ProcessEvent(move, 0); |
| 746 // There's no event dispatching in flight but there's hit-test in flight in |
| 747 // EventDispatcher so we still put event processing request into the queue |
| 748 // in WindowManagerState. |
| 749 EXPECT_FALSE(test_api.tree_awaiting_input_ack()); |
| 750 EXPECT_TRUE(window_manager_state() |
| 751 ->event_dispatcher() |
| 752 ->event_targeter() |
| 753 ->IsHitTestInFlight()); |
| 754 EXPECT_FALSE(test_api.event_queue_empty()); |
| 755 task_runner_->RunUntilIdle(); |
| 756 EXPECT_TRUE(test_api.event_queue_empty()); |
| 757 // The event isn't over a valid target, which should trigger resetting the |
| 758 // cursor to POINTER. |
| 759 EXPECT_EQ(ui::CursorType::kPointer, cursor_type()); |
| 760 } |
| 761 |
702 } // namespace test | 762 } // namespace test |
703 } // namespace ws | 763 } // namespace ws |
704 } // namespace ui | 764 } // namespace ui |
OLD | NEW |