| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 const ServerWindow* FirstRoot(WindowTree* tree) { | 147 const ServerWindow* FirstRoot(WindowTree* tree) { |
| 148 return tree->roots().size() == 1u ? *(tree->roots().begin()) : nullptr; | 148 return tree->roots().size() == 1u ? *(tree->roots().begin()) : nullptr; |
| 149 } | 149 } |
| 150 | 150 |
| 151 ClientWindowId FirstRootId(WindowTree* tree) { | 151 ClientWindowId FirstRootId(WindowTree* tree) { |
| 152 return tree->roots().size() == 1u | 152 return tree->roots().size() == 1u |
| 153 ? ClientWindowIdForWindow(tree, *(tree->roots().begin())) | 153 ? ClientWindowIdForWindow(tree, *(tree->roots().begin())) |
| 154 : ClientWindowId(); | 154 : ClientWindowId(); |
| 155 } | 155 } |
| 156 | 156 |
| 157 ServerWindow* GetCaptureWindow(Display* display) { |
| 158 return display->GetActiveWindowManagerState()->capture_window(); |
| 159 } |
| 160 |
| 157 } // namespace | 161 } // namespace |
| 158 | 162 |
| 159 // ----------------------------------------------------------------------------- | 163 // ----------------------------------------------------------------------------- |
| 160 | 164 |
| 161 class WindowTreeTest : public testing::Test { | 165 class WindowTreeTest : public testing::Test { |
| 162 public: | 166 public: |
| 163 WindowTreeTest() | 167 WindowTreeTest() |
| 164 : wm_client_(nullptr), | 168 : wm_client_(nullptr), |
| 165 cursor_id_(0), | 169 cursor_id_(0), |
| 166 platform_display_factory_(&cursor_id_) {} | 170 platform_display_factory_(&cursor_id_) {} |
| (...skipping 22 matching lines...) Expand all Loading... |
| 189 void DispatchEventWithoutAck(const ui::Event& event) { | 193 void DispatchEventWithoutAck(const ui::Event& event) { |
| 190 DisplayTestApi(display_).OnEvent(event); | 194 DisplayTestApi(display_).OnEvent(event); |
| 191 } | 195 } |
| 192 | 196 |
| 193 void set_window_manager_internal(WindowTree* tree, | 197 void set_window_manager_internal(WindowTree* tree, |
| 194 mojom::WindowManager* wm_internal) { | 198 mojom::WindowManager* wm_internal) { |
| 195 WindowTreeTestApi(tree).set_window_manager_internal(wm_internal); | 199 WindowTreeTestApi(tree).set_window_manager_internal(wm_internal); |
| 196 } | 200 } |
| 197 | 201 |
| 198 void AckPreviousEvent() { | 202 void AckPreviousEvent() { |
| 199 DisplayTestApi test_api(display_); | 203 WindowManagerStateTestApi test_api(display_->GetActiveWindowManagerState()); |
| 200 while (test_api.tree_awaiting_input_ack()) | 204 while (test_api.tree_awaiting_input_ack()) |
| 201 test_api.tree_awaiting_input_ack()->OnWindowInputEventAck(0); | 205 test_api.tree_awaiting_input_ack()->OnWindowInputEventAck(0); |
| 202 } | 206 } |
| 203 | 207 |
| 204 void DispatchEventAndAckImmediately(const ui::Event& event) { | 208 void DispatchEventAndAckImmediately(const ui::Event& event) { |
| 205 DispatchEventWithoutAck(event); | 209 DispatchEventWithoutAck(event); |
| 206 AckPreviousEvent(); | 210 AckPreviousEvent(); |
| 207 } | 211 } |
| 208 | 212 |
| 209 // Creates a new window from wm_tree() and embeds a new connection in | 213 // Creates a new window from wm_tree() and embeds a new connection in |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 const ServerWindow* root_window = *tree->roots().begin(); | 632 const ServerWindow* root_window = *tree->roots().begin(); |
| 629 tree->AddWindow(FirstRootId(tree), ClientWindowIdForWindow(tree, window)); | 633 tree->AddWindow(FirstRootId(tree), ClientWindowIdForWindow(tree, window)); |
| 630 window->SetBounds(gfx::Rect(0, 0, 100, 100)); | 634 window->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 631 ASSERT_TRUE(tree->GetDisplay(window)); | 635 ASSERT_TRUE(tree->GetDisplay(window)); |
| 632 | 636 |
| 633 // Setting capture should fail when there are no active events | 637 // Setting capture should fail when there are no active events |
| 634 mojom::WindowTree* mojom_window_tree = static_cast<mojom::WindowTree*>(tree); | 638 mojom::WindowTree* mojom_window_tree = static_cast<mojom::WindowTree*>(tree); |
| 635 uint32_t change_id = 42; | 639 uint32_t change_id = 42; |
| 636 mojom_window_tree->SetCapture(change_id, WindowIdToTransportId(window->id())); | 640 mojom_window_tree->SetCapture(change_id, WindowIdToTransportId(window->id())); |
| 637 Display* display = tree->GetDisplay(window); | 641 Display* display = tree->GetDisplay(window); |
| 638 EXPECT_NE(window, display->GetCaptureWindow()); | 642 EXPECT_NE(window, GetCaptureWindow(display)); |
| 639 | 643 |
| 640 // Setting capture after the event is acknowledged should fail | 644 // Setting capture after the event is acknowledged should fail |
| 641 DispatchEventAndAckImmediately(CreatePointerDownEvent(10, 10)); | 645 DispatchEventAndAckImmediately(CreatePointerDownEvent(10, 10)); |
| 642 mojom_window_tree->SetCapture(++change_id, | 646 mojom_window_tree->SetCapture(++change_id, |
| 643 WindowIdToTransportId(window->id())); | 647 WindowIdToTransportId(window->id())); |
| 644 EXPECT_NE(window, display->GetCaptureWindow()); | 648 EXPECT_NE(window, GetCaptureWindow(display)); |
| 645 | 649 |
| 646 // Settings while the event is being process should pass | 650 // Settings while the event is being process should pass |
| 647 DispatchEventWithoutAck(CreatePointerDownEvent(10, 10)); | 651 DispatchEventWithoutAck(CreatePointerDownEvent(10, 10)); |
| 648 mojom_window_tree->SetCapture(++change_id, | 652 mojom_window_tree->SetCapture(++change_id, |
| 649 WindowIdToTransportId(window->id())); | 653 WindowIdToTransportId(window->id())); |
| 650 EXPECT_EQ(window, display->GetCaptureWindow()); | 654 EXPECT_EQ(window, GetCaptureWindow(display)); |
| 651 AckPreviousEvent(); | 655 AckPreviousEvent(); |
| 652 | 656 |
| 653 // Only the capture window should be able to release capture | 657 // Only the capture window should be able to release capture |
| 654 mojom_window_tree->ReleaseCapture(++change_id, | 658 mojom_window_tree->ReleaseCapture(++change_id, |
| 655 WindowIdToTransportId(root_window->id())); | 659 WindowIdToTransportId(root_window->id())); |
| 656 EXPECT_EQ(window, display->GetCaptureWindow()); | 660 EXPECT_EQ(window, GetCaptureWindow(display)); |
| 657 mojom_window_tree->ReleaseCapture(++change_id, | 661 mojom_window_tree->ReleaseCapture(++change_id, |
| 658 WindowIdToTransportId(window->id())); | 662 WindowIdToTransportId(window->id())); |
| 659 EXPECT_EQ(nullptr, display->GetCaptureWindow()); | 663 EXPECT_EQ(nullptr, GetCaptureWindow(display)); |
| 660 } | 664 } |
| 661 | 665 |
| 662 } // namespace test | 666 } // namespace test |
| 663 } // namespace ws | 667 } // namespace ws |
| 664 } // namespace mus | 668 } // namespace mus |
| OLD | NEW |