| 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 #ifndef SERVICES_UI_WS_TEST_UTILS_H_ | 5 #ifndef SERVICES_UI_WS_TEST_UTILS_H_ |
| 6 #define SERVICES_UI_WS_TEST_UTILS_H_ | 6 #define SERVICES_UI_WS_TEST_UTILS_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 void AckLastAccelerator( | 120 void AckLastAccelerator( |
| 121 mojom::EventResult result, | 121 mojom::EventResult result, |
| 122 const std::unordered_map<std::string, std::vector<uint8_t>>& properties = | 122 const std::unordered_map<std::string, std::vector<uint8_t>>& properties = |
| 123 std::unordered_map<std::string, std::vector<uint8_t>>()) { | 123 std::unordered_map<std::string, std::vector<uint8_t>>()) { |
| 124 tree_->OnAcceleratorAck(tree_->event_ack_id_, result, properties); | 124 tree_->OnAcceleratorAck(tree_->event_ack_id_, result, properties); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void StartPointerWatcher(bool want_moves); | 127 void StartPointerWatcher(bool want_moves); |
| 128 void StopPointerWatcher(); | 128 void StopPointerWatcher(); |
| 129 | 129 |
| 130 bool ProcessSetDisplayRoot(int64_t display_id, |
| 131 const ClientWindowId& client_window_id) { |
| 132 return tree_->ProcessSetDisplayRoot(display_id, client_window_id); |
| 133 } |
| 134 |
| 130 private: | 135 private: |
| 131 WindowTree* tree_; | 136 WindowTree* tree_; |
| 132 | 137 |
| 133 DISALLOW_COPY_AND_ASSIGN(WindowTreeTestApi); | 138 DISALLOW_COPY_AND_ASSIGN(WindowTreeTestApi); |
| 134 }; | 139 }; |
| 135 | 140 |
| 136 // ----------------------------------------------------------------------------- | 141 // ----------------------------------------------------------------------------- |
| 137 | 142 |
| 138 class DisplayTestApi { | 143 class DisplayTestApi { |
| 139 public: | 144 public: |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 ClientSpecificId GetEventTargetClientId(const ServerWindow* window, | 225 ClientSpecificId GetEventTargetClientId(const ServerWindow* window, |
| 221 bool in_nonclient_area) { | 226 bool in_nonclient_area) { |
| 222 return wms_->GetEventTargetClientId(window, in_nonclient_area); | 227 return wms_->GetEventTargetClientId(window, in_nonclient_area); |
| 223 } | 228 } |
| 224 | 229 |
| 225 WindowTree* tree_awaiting_input_ack() { | 230 WindowTree* tree_awaiting_input_ack() { |
| 226 return wms_->in_flight_event_details_ ? wms_->in_flight_event_details_->tree | 231 return wms_->in_flight_event_details_ ? wms_->in_flight_event_details_->tree |
| 227 : nullptr; | 232 : nullptr; |
| 228 } | 233 } |
| 229 | 234 |
| 235 const std::vector<std::unique_ptr<WindowManagerDisplayRoot>>& |
| 236 window_manager_display_roots() const { |
| 237 return wms_->window_manager_display_roots_; |
| 238 } |
| 239 |
| 230 private: | 240 private: |
| 231 WindowManagerState* wms_; | 241 WindowManagerState* wms_; |
| 232 | 242 |
| 233 DISALLOW_COPY_AND_ASSIGN(WindowManagerStateTestApi); | 243 DISALLOW_COPY_AND_ASSIGN(WindowManagerStateTestApi); |
| 234 }; | 244 }; |
| 235 | 245 |
| 236 // ----------------------------------------------------------------------------- | 246 // ----------------------------------------------------------------------------- |
| 237 | 247 |
| 238 class DragControllerTestApi { | 248 class DragControllerTestApi { |
| 239 public: | 249 public: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 250 DragController* op_; | 260 DragController* op_; |
| 251 | 261 |
| 252 DISALLOW_COPY_AND_ASSIGN(DragControllerTestApi); | 262 DISALLOW_COPY_AND_ASSIGN(DragControllerTestApi); |
| 253 }; | 263 }; |
| 254 | 264 |
| 255 // ----------------------------------------------------------------------------- | 265 // ----------------------------------------------------------------------------- |
| 256 | 266 |
| 257 // Factory that always embeds the new WindowTree as the root user id. | 267 // Factory that always embeds the new WindowTree as the root user id. |
| 258 class TestDisplayBinding : public DisplayBinding { | 268 class TestDisplayBinding : public DisplayBinding { |
| 259 public: | 269 public: |
| 260 explicit TestDisplayBinding(WindowServer* window_server) | 270 explicit TestDisplayBinding(WindowServer* window_server, |
| 261 : window_server_(window_server) {} | 271 bool automatically_create_display_roots = true) |
| 272 : window_server_(window_server), |
| 273 automatically_create_display_roots_( |
| 274 automatically_create_display_roots) {} |
| 262 ~TestDisplayBinding() override {} | 275 ~TestDisplayBinding() override {} |
| 263 | 276 |
| 264 private: | 277 private: |
| 265 // DisplayBinding: | 278 // DisplayBinding: |
| 266 WindowTree* CreateWindowTree(ServerWindow* root) override; | 279 WindowTree* CreateWindowTree(ServerWindow* root) override; |
| 267 | 280 |
| 268 WindowServer* window_server_; | 281 WindowServer* window_server_; |
| 282 const bool automatically_create_display_roots_; |
| 269 | 283 |
| 270 DISALLOW_COPY_AND_ASSIGN(TestDisplayBinding); | 284 DISALLOW_COPY_AND_ASSIGN(TestDisplayBinding); |
| 271 }; | 285 }; |
| 272 | 286 |
| 273 // ----------------------------------------------------------------------------- | 287 // ----------------------------------------------------------------------------- |
| 274 | 288 |
| 275 // Factory that dispenses TestPlatformDisplays. | 289 // Factory that dispenses TestPlatformDisplays. |
| 276 class TestPlatformDisplayFactory : public PlatformDisplayFactory { | 290 class TestPlatformDisplayFactory : public PlatformDisplayFactory { |
| 277 public: | 291 public: |
| 278 explicit TestPlatformDisplayFactory(mojom::CursorType* cursor_storage); | 292 explicit TestPlatformDisplayFactory(mojom::CursorType* cursor_storage); |
| 279 ~TestPlatformDisplayFactory(); | 293 ~TestPlatformDisplayFactory(); |
| 280 | 294 |
| 281 // PlatformDisplayFactory: | 295 // PlatformDisplayFactory: |
| 282 std::unique_ptr<PlatformDisplay> CreatePlatformDisplay( | 296 std::unique_ptr<PlatformDisplay> CreatePlatformDisplay( |
| 283 ServerWindow* root_window, | 297 ServerWindow* root_window, |
| 284 const display::ViewportMetrics& metrics) override; | 298 const display::ViewportMetrics& metrics) override; |
| 285 | 299 |
| 286 private: | 300 private: |
| 287 mojom::CursorType* cursor_storage_; | 301 mojom::CursorType* cursor_storage_; |
| 288 | 302 |
| 289 DISALLOW_COPY_AND_ASSIGN(TestPlatformDisplayFactory); | 303 DISALLOW_COPY_AND_ASSIGN(TestPlatformDisplayFactory); |
| 290 }; | 304 }; |
| 291 | 305 |
| 292 // ----------------------------------------------------------------------------- | 306 // ----------------------------------------------------------------------------- |
| 293 | 307 |
| 294 class TestWindowManager : public mojom::WindowManager { | 308 class TestWindowManager : public mojom::WindowManager { |
| 295 public: | 309 public: |
| 296 TestWindowManager() | 310 TestWindowManager(); |
| 297 : got_create_top_level_window_(false), | 311 ~TestWindowManager() override; |
| 298 change_id_(0u), | |
| 299 on_accelerator_called_(false), | |
| 300 on_accelerator_id_(0u) {} | |
| 301 ~TestWindowManager() override {} | |
| 302 | 312 |
| 303 bool did_call_create_top_level_window(uint32_t* change_id) { | 313 bool did_call_create_top_level_window(uint32_t* change_id) { |
| 304 if (!got_create_top_level_window_) | 314 if (!got_create_top_level_window_) |
| 305 return false; | 315 return false; |
| 306 | 316 |
| 307 got_create_top_level_window_ = false; | 317 got_create_top_level_window_ = false; |
| 308 *change_id = change_id_; | 318 *change_id = change_id_; |
| 309 return true; | 319 return true; |
| 310 } | 320 } |
| 311 | 321 |
| 312 void ClearAcceleratorCalled() { | 322 void ClearAcceleratorCalled() { |
| 313 on_accelerator_id_ = 0u; | 323 on_accelerator_id_ = 0u; |
| 314 on_accelerator_called_ = false; | 324 on_accelerator_called_ = false; |
| 315 } | 325 } |
| 316 | 326 |
| 317 bool on_perform_move_loop_called() { return on_perform_move_loop_called_; } | 327 bool on_perform_move_loop_called() { return on_perform_move_loop_called_; } |
| 318 bool on_accelerator_called() { return on_accelerator_called_; } | 328 bool on_accelerator_called() { return on_accelerator_called_; } |
| 319 uint32_t on_accelerator_id() { return on_accelerator_id_; } | 329 uint32_t on_accelerator_id() { return on_accelerator_id_; } |
| 320 bool got_display_removed() const { return got_display_removed_; } | 330 bool got_display_removed() const { return got_display_removed_; } |
| 321 int64_t display_removed_id() const { return display_removed_id_; } | 331 int64_t display_removed_id() const { return display_removed_id_; } |
| 322 bool on_set_modal_type_called() { return on_set_modal_type_called_; } | 332 bool on_set_modal_type_called() { return on_set_modal_type_called_; } |
| 333 int connect_count() const { return connect_count_; } |
| 334 int display_added_count() const { return display_added_count_; } |
| 323 | 335 |
| 324 private: | 336 private: |
| 325 // WindowManager: | 337 // WindowManager: |
| 326 void OnConnect(uint16_t client_id) override {} | 338 void OnConnect(uint16_t client_id) override; |
| 327 void WmNewDisplayAdded( | 339 void WmNewDisplayAdded( |
| 328 const display::Display& display, | 340 const display::Display& display, |
| 329 ui::mojom::WindowDataPtr root, | 341 ui::mojom::WindowDataPtr root, |
| 330 bool drawn, | 342 bool drawn, |
| 331 const cc::FrameSinkId& frame_sink_id, | 343 const cc::FrameSinkId& frame_sink_id, |
| 332 const base::Optional<cc::LocalSurfaceId>& local_surface_id) override {} | 344 const base::Optional<cc::LocalSurfaceId>& local_surface_id) override; |
| 333 void WmDisplayRemoved(int64_t display_id) override; | 345 void WmDisplayRemoved(int64_t display_id) override; |
| 334 void WmDisplayModified(const display::Display& display) override {} | 346 void WmDisplayModified(const display::Display& display) override {} |
| 335 void WmSetBounds(uint32_t change_id, | 347 void WmSetBounds(uint32_t change_id, |
| 336 uint32_t window_id, | 348 uint32_t window_id, |
| 337 const gfx::Rect& bounds) override {} | 349 const gfx::Rect& bounds) override {} |
| 338 void WmSetProperty( | 350 void WmSetProperty( |
| 339 uint32_t change_id, | 351 uint32_t change_id, |
| 340 uint32_t window_id, | 352 uint32_t window_id, |
| 341 const std::string& name, | 353 const std::string& name, |
| 342 const base::Optional<std::vector<uint8_t>>& value) override {} | 354 const base::Optional<std::vector<uint8_t>>& value) override {} |
| (...skipping 22 matching lines...) Expand all Loading... |
| 365 void WmStackAbove(uint32_t change_id, uint32_t above_id, | 377 void WmStackAbove(uint32_t change_id, uint32_t above_id, |
| 366 uint32_t below_id) override; | 378 uint32_t below_id) override; |
| 367 void WmStackAtTop(uint32_t change_id, uint32_t window_id) override; | 379 void WmStackAtTop(uint32_t change_id, uint32_t window_id) override; |
| 368 void OnAccelerator(uint32_t ack_id, | 380 void OnAccelerator(uint32_t ack_id, |
| 369 uint32_t accelerator_id, | 381 uint32_t accelerator_id, |
| 370 std::unique_ptr<ui::Event> event) override; | 382 std::unique_ptr<ui::Event> event) override; |
| 371 | 383 |
| 372 bool on_perform_move_loop_called_ = false; | 384 bool on_perform_move_loop_called_ = false; |
| 373 bool on_set_modal_type_called_ = false; | 385 bool on_set_modal_type_called_ = false; |
| 374 | 386 |
| 375 bool got_create_top_level_window_; | 387 bool got_create_top_level_window_ = false; |
| 376 uint32_t change_id_; | 388 uint32_t change_id_ = 0u; |
| 377 | 389 |
| 378 bool on_accelerator_called_; | 390 bool on_accelerator_called_ = false; |
| 379 uint32_t on_accelerator_id_; | 391 uint32_t on_accelerator_id_ = 0u; |
| 380 | 392 |
| 381 bool got_display_removed_ = false; | 393 bool got_display_removed_ = false; |
| 382 int64_t display_removed_id_ = 0; | 394 int64_t display_removed_id_ = 0; |
| 383 | 395 |
| 396 int connect_count_ = 0; |
| 397 int display_added_count_ = 0; |
| 398 |
| 384 DISALLOW_COPY_AND_ASSIGN(TestWindowManager); | 399 DISALLOW_COPY_AND_ASSIGN(TestWindowManager); |
| 385 }; | 400 }; |
| 386 | 401 |
| 387 // ----------------------------------------------------------------------------- | 402 // ----------------------------------------------------------------------------- |
| 388 | 403 |
| 389 // WindowTreeClient implementation that logs all calls to a TestChangeTracker. | 404 // WindowTreeClient implementation that logs all calls to a TestChangeTracker. |
| 390 class TestWindowTreeClient : public ui::mojom::WindowTreeClient { | 405 class TestWindowTreeClient : public ui::mojom::WindowTreeClient { |
| 391 public: | 406 public: |
| 392 TestWindowTreeClient(); | 407 TestWindowTreeClient(); |
| 393 ~TestWindowTreeClient() override; | 408 ~TestWindowTreeClient() override; |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 | 626 |
| 612 DISALLOW_COPY_AND_ASSIGN(WindowServerTestHelper); | 627 DISALLOW_COPY_AND_ASSIGN(WindowServerTestHelper); |
| 613 }; | 628 }; |
| 614 | 629 |
| 615 // ----------------------------------------------------------------------------- | 630 // ----------------------------------------------------------------------------- |
| 616 | 631 |
| 617 // Helper class which owns all of the necessary objects to test event targeting | 632 // Helper class which owns all of the necessary objects to test event targeting |
| 618 // of ServerWindow objects. | 633 // of ServerWindow objects. |
| 619 class WindowEventTargetingHelper { | 634 class WindowEventTargetingHelper { |
| 620 public: | 635 public: |
| 621 WindowEventTargetingHelper(); | 636 explicit WindowEventTargetingHelper( |
| 637 bool automatically_create_display_roots = true); |
| 622 ~WindowEventTargetingHelper(); | 638 ~WindowEventTargetingHelper(); |
| 623 | 639 |
| 624 // Creates |window| as an embeded window of the primary tree. This window is a | 640 // Creates |window| as an embeded window of the primary tree. This window is a |
| 625 // root window of its own tree, with bounds |window_bounds|. The bounds of the | 641 // root window of its own tree, with bounds |window_bounds|. The bounds of the |
| 626 // root window of |display_| are defined by |root_window_bounds|. | 642 // root window of |display_| are defined by |root_window_bounds|. |
| 627 ServerWindow* CreatePrimaryTree(const gfx::Rect& root_window_bounds, | 643 ServerWindow* CreatePrimaryTree(const gfx::Rect& root_window_bounds, |
| 628 const gfx::Rect& window_bounds); | 644 const gfx::Rect& window_bounds); |
| 629 // Creates a secondary tree, embedded as a child of |embed_window|. The | 645 // Creates a secondary tree, embedded as a child of |embed_window|. The |
| 630 // resulting |window| is setup for event targeting, with bounds | 646 // resulting |window| is setup for event targeting, with bounds |
| 631 // |window_bounds|. | 647 // |window_bounds|. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 660 Display* display_ = nullptr; | 676 Display* display_ = nullptr; |
| 661 ClientSpecificId next_primary_tree_window_id_ = 1; | 677 ClientSpecificId next_primary_tree_window_id_ = 1; |
| 662 | 678 |
| 663 DISALLOW_COPY_AND_ASSIGN(WindowEventTargetingHelper); | 679 DISALLOW_COPY_AND_ASSIGN(WindowEventTargetingHelper); |
| 664 }; | 680 }; |
| 665 | 681 |
| 666 // ----------------------------------------------------------------------------- | 682 // ----------------------------------------------------------------------------- |
| 667 | 683 |
| 668 // Adds a new WM to |window_server| for |user_id|. Creates | 684 // Adds a new WM to |window_server| for |user_id|. Creates |
| 669 // WindowManagerWindowTreeFactory and associated WindowTree for the WM. | 685 // WindowManagerWindowTreeFactory and associated WindowTree for the WM. |
| 670 void AddWindowManager(WindowServer* window_server, const UserId& user_id); | 686 void AddWindowManager(WindowServer* window_server, |
| 687 const UserId& user_id, |
| 688 bool automatically_create_display_roots = true); |
| 671 | 689 |
| 672 // Create a new Display object with specified origin, pixel size and device | 690 // Create a new Display object with specified origin, pixel size and device |
| 673 // scale factor. The bounds size is computed based on the pixel size and device | 691 // scale factor. The bounds size is computed based on the pixel size and device |
| 674 // scale factor. | 692 // scale factor. |
| 675 display::Display MakeDisplay(int origin_x, | 693 display::Display MakeDisplay(int origin_x, |
| 676 int origin_y, | 694 int origin_y, |
| 677 int width_pixels, | 695 int width_pixels, |
| 678 int height_pixels, | 696 int height_pixels, |
| 679 float scale_factor); | 697 float scale_factor); |
| 680 | 698 |
| 681 // Returns the first and only root of |tree|. If |tree| has zero or more than | 699 // Returns the first and only root of |tree|. If |tree| has zero or more than |
| 682 // one root returns null. | 700 // one root returns null. |
| 683 ServerWindow* FirstRoot(WindowTree* tree); | 701 ServerWindow* FirstRoot(WindowTree* tree); |
| 684 | 702 |
| 685 // Returns the ClientWindowId of the first root of |tree|, or an empty | 703 // Returns the ClientWindowId of the first root of |tree|, or an empty |
| 686 // ClientWindowId if |tree| has zero or more than one root. | 704 // ClientWindowId if |tree| has zero or more than one root. |
| 687 ClientWindowId FirstRootId(WindowTree* tree); | 705 ClientWindowId FirstRootId(WindowTree* tree); |
| 688 | 706 |
| 689 // Returns |tree|s ClientWindowId for |window|. | 707 // Returns |tree|s ClientWindowId for |window|. |
| 690 ClientWindowId ClientWindowIdForWindow(WindowTree* tree, | 708 ClientWindowId ClientWindowIdForWindow(WindowTree* tree, |
| 691 const ServerWindow* window); | 709 const ServerWindow* window); |
| 692 | 710 |
| 693 // Creates a new visible window as a child of the single root of |tree|. | 711 // Creates a new visible window as a child of the single root of |tree|. |
| 694 // |client_id| is set to the ClientWindowId of the new window. | 712 // |client_id| is set to the ClientWindowId of the new window. |
| 695 ServerWindow* NewWindowInTree(WindowTree* tree, ClientWindowId* client_id); | 713 ServerWindow* NewWindowInTree(WindowTree* tree, |
| 714 ClientWindowId* client_id = nullptr); |
| 696 ServerWindow* NewWindowInTreeWithParent(WindowTree* tree, | 715 ServerWindow* NewWindowInTreeWithParent(WindowTree* tree, |
| 697 ServerWindow* parent, | 716 ServerWindow* parent, |
| 698 ClientWindowId* client_id = nullptr); | 717 ClientWindowId* client_id = nullptr); |
| 699 | 718 |
| 700 } // namespace test | 719 } // namespace test |
| 701 } // namespace ws | 720 } // namespace ws |
| 702 } // namespace ui | 721 } // namespace ui |
| 703 | 722 |
| 704 #endif // SERVICES_UI_WS_TEST_UTILS_H_ | 723 #endif // SERVICES_UI_WS_TEST_UTILS_H_ |
| OLD | NEW |