| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 } | 93 } |
| 93 | 94 |
| 94 void DestroyWindowTree() { | 95 void DestroyWindowTree() { |
| 95 window_event_targeting_helper_.window_server()->DestroyTree(window_tree_); | 96 window_event_targeting_helper_.window_server()->DestroyTree(window_tree_); |
| 96 window_tree_ = nullptr; | 97 window_tree_ = nullptr; |
| 97 } | 98 } |
| 98 | 99 |
| 99 // testing::Test: | 100 // testing::Test: |
| 100 void SetUp() override; | 101 void SetUp() override; |
| 101 | 102 |
| 103 protected: |
| 104 // Handles WindowStateManager ack timeouts. |
| 105 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
| 106 |
| 102 private: | 107 private: |
| 103 WindowEventTargetingHelper window_event_targeting_helper_; | 108 WindowEventTargetingHelper window_event_targeting_helper_; |
| 104 | 109 |
| 105 WindowManagerState* window_manager_state_; | 110 WindowManagerState* window_manager_state_; |
| 106 | 111 |
| 107 // Handles WindowStateManager ack timeouts. | |
| 108 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | |
| 109 TestWindowManager window_manager_; | 112 TestWindowManager window_manager_; |
| 110 ServerWindow* window_ = nullptr; | 113 ServerWindow* window_ = nullptr; |
| 111 WindowTree* window_tree_ = nullptr; | 114 WindowTree* window_tree_ = nullptr; |
| 112 TestWindowTreeClient* window_tree_client_ = nullptr; | 115 TestWindowTreeClient* window_tree_client_ = nullptr; |
| 113 | 116 |
| 114 DISALLOW_COPY_AND_ASSIGN(WindowManagerStateTest); | 117 DISALLOW_COPY_AND_ASSIGN(WindowManagerStateTest); |
| 115 }; | 118 }; |
| 116 | 119 |
| 117 WindowManagerStateTest::WindowManagerStateTest() | 120 WindowManagerStateTest::WindowManagerStateTest() |
| 118 : task_runner_(new base::TestSimpleTaskRunner) {} | 121 : task_runner_(new base::TestSimpleTaskRunner) {} |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 window_tree_client_->tracker()->changes()->clear(); | 171 window_tree_client_->tracker()->changes()->clear(); |
| 169 } | 172 } |
| 170 | 173 |
| 171 void SetCanFocusUp(ServerWindow* window) { | 174 void SetCanFocusUp(ServerWindow* window) { |
| 172 while (window) { | 175 while (window) { |
| 173 window->set_can_focus(true); | 176 window->set_can_focus(true); |
| 174 window = window->parent(); | 177 window = window->parent(); |
| 175 } | 178 } |
| 176 } | 179 } |
| 177 | 180 |
| 181 class WindowManagerStateTestAsync : public WindowManagerStateTest { |
| 182 public: |
| 183 WindowManagerStateTestAsync() {} |
| 184 ~WindowManagerStateTestAsync() override {} |
| 185 |
| 186 // WindowManagerStateTest: |
| 187 void SetUp() override { |
| 188 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 189 "enable-async-event-targeting"); |
| 190 WindowManagerStateTest::SetUp(); |
| 191 } |
| 192 |
| 193 private: |
| 194 DISALLOW_COPY_AND_ASSIGN(WindowManagerStateTestAsync); |
| 195 }; |
| 196 |
| 178 // Tests that when an event is dispatched with no accelerator, that post target | 197 // Tests that when an event is dispatched with no accelerator, that post target |
| 179 // accelerator is not triggered. | 198 // accelerator is not triggered. |
| 180 TEST_F(WindowManagerStateTest, NullAccelerator) { | 199 TEST_F(WindowManagerStateTest, NullAccelerator) { |
| 181 WindowManagerState* state = window_manager_state(); | 200 WindowManagerState* state = window_manager_state(); |
| 182 EXPECT_TRUE(state); | 201 EXPECT_TRUE(state); |
| 183 | 202 |
| 184 ServerWindow* target = window(); | 203 ServerWindow* target = window(); |
| 185 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); | 204 ui::KeyEvent key(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); |
| 186 DispatchInputEventToWindow(target, key, nullptr); | 205 DispatchInputEventToWindow(target, key, nullptr); |
| 187 WindowTree* target_tree = window_tree(); | 206 WindowTree* target_tree = window_tree(); |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 ui::PointerEvent move( | 677 ui::PointerEvent move( |
| 659 ui::ET_POINTER_MOVED, gfx::Point(25, 25), gfx::Point(25, 25), 0, 0, | 678 ui::ET_POINTER_MOVED, gfx::Point(25, 25), gfx::Point(25, 25), 0, 0, |
| 660 ui::PointerDetails(EventPointerType::POINTER_TYPE_MOUSE, 0), | 679 ui::PointerDetails(EventPointerType::POINTER_TYPE_MOUSE, 0), |
| 661 base::TimeTicks()); | 680 base::TimeTicks()); |
| 662 window_manager_state()->ProcessEvent(move, 0); | 681 window_manager_state()->ProcessEvent(move, 0); |
| 663 // The event isn't over a valid target, which should trigger resetting the | 682 // The event isn't over a valid target, which should trigger resetting the |
| 664 // cursor to POINTER. | 683 // cursor to POINTER. |
| 665 EXPECT_EQ(ui::CursorType::kPointer, cursor_type()); | 684 EXPECT_EQ(ui::CursorType::kPointer, cursor_type()); |
| 666 } | 685 } |
| 667 | 686 |
| 687 TEST_F(WindowManagerStateTestAsync, CursorResetOverNoTargetAsync) { |
| 688 ASSERT_EQ(1u, window_server()->display_manager()->displays().size()); |
| 689 const ClientWindowId child_window_id(11); |
| 690 window_tree()->NewWindow(child_window_id, ServerWindow::Properties()); |
| 691 ServerWindow* child_window = |
| 692 window_tree()->GetWindowByClientId(child_window_id); |
| 693 window_tree()->AddWindow(FirstRootId(window_tree()), child_window_id); |
| 694 // Setup steps already do hit-test for mouse cursor update so this should go |
| 695 // to the queue in EventDispatcher. |
| 696 EXPECT_TRUE(window_manager_state()->event_dispatcher()->IsHitTestInFlight()); |
| 697 child_window->SetVisible(true); |
| 698 child_window->SetBounds(gfx::Rect(0, 0, 20, 20)); |
| 699 child_window->parent()->SetCursor(ui::CursorData(ui::CursorType::kCopy)); |
| 700 // Move the mouse outside the bounds of the child, so that the mouse is not |
| 701 // over any valid windows. Cursor should change to POINTER. |
| 702 ui::PointerEvent move( |
| 703 ui::ET_POINTER_MOVED, gfx::Point(25, 25), gfx::Point(25, 25), 0, 0, |
| 704 ui::PointerDetails(EventPointerType::POINTER_TYPE_MOUSE, 0), |
| 705 base::TimeTicks()); |
| 706 WindowManagerStateTestApi test_api(window_manager_state()); |
| 707 EXPECT_TRUE(test_api.event_queue_empty()); |
| 708 window_manager_state()->ProcessEvent(move, 0); |
| 709 // There's no event dispatching in flight but there's hit-test in flight in |
| 710 // EventDispatcher so we still put event processing request into the queue |
| 711 // in WindowManagerState. |
| 712 EXPECT_FALSE(test_api.tree_awaiting_input_ack()); |
| 713 EXPECT_TRUE(window_manager_state()->event_dispatcher()->IsHitTestInFlight()); |
| 714 EXPECT_FALSE(test_api.event_queue_empty()); |
| 715 task_runner_->RunUntilIdle(); |
| 716 EXPECT_TRUE(test_api.event_queue_empty()); |
| 717 // The event isn't over a valid target, which should trigger resetting the |
| 718 // cursor to POINTER. |
| 719 EXPECT_EQ(ui::CursorType::kPointer, cursor_type()); |
| 720 } |
| 721 |
| 668 } // namespace test | 722 } // namespace test |
| 669 } // namespace ws | 723 } // namespace ws |
| 670 } // namespace ui | 724 } // namespace ui |
| OLD | NEW |