| 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> |
| 11 #include <set> |
| 11 #include <vector> | 12 #include <vector> |
| 12 | 13 |
| 13 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 14 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "services/ui/display/platform_screen.h" |
| 17 #include "services/ui/display/viewport_metrics.h" |
| 15 #include "services/ui/public/interfaces/display_manager.mojom.h" | 18 #include "services/ui/public/interfaces/display_manager.mojom.h" |
| 16 #include "services/ui/public/interfaces/window_tree.mojom.h" | 19 #include "services/ui/public/interfaces/window_tree.mojom.h" |
| 17 #include "services/ui/ws/display.h" | 20 #include "services/ui/ws/display.h" |
| 18 #include "services/ui/ws/display_binding.h" | 21 #include "services/ui/ws/display_binding.h" |
| 19 #include "services/ui/ws/drag_controller.h" | 22 #include "services/ui/ws/drag_controller.h" |
| 20 #include "services/ui/ws/event_dispatcher.h" | 23 #include "services/ui/ws/event_dispatcher.h" |
| 21 #include "services/ui/ws/frame_generator_delegate.h" | 24 #include "services/ui/ws/frame_generator_delegate.h" |
| 22 #include "services/ui/ws/platform_display.h" | 25 #include "services/ui/ws/platform_display.h" |
| 23 #include "services/ui/ws/platform_display_factory.h" | 26 #include "services/ui/ws/platform_display_factory.h" |
| 24 #include "services/ui/ws/test_change_tracker.h" | 27 #include "services/ui/ws/test_change_tracker.h" |
| 25 #include "services/ui/ws/user_activity_monitor.h" | 28 #include "services/ui/ws/user_activity_monitor.h" |
| 26 #include "services/ui/ws/user_display_manager.h" | 29 #include "services/ui/ws/user_display_manager.h" |
| 27 #include "services/ui/ws/user_id.h" | 30 #include "services/ui/ws/user_id.h" |
| 28 #include "services/ui/ws/window_manager_state.h" | 31 #include "services/ui/ws/window_manager_state.h" |
| 29 #include "services/ui/ws/window_manager_window_tree_factory_set.h" | 32 #include "services/ui/ws/window_manager_window_tree_factory_set.h" |
| 30 #include "services/ui/ws/window_server_delegate.h" | 33 #include "services/ui/ws/window_server_delegate.h" |
| 31 #include "services/ui/ws/window_tree.h" | 34 #include "services/ui/ws/window_tree.h" |
| 32 #include "services/ui/ws/window_tree_binding.h" | 35 #include "services/ui/ws/window_tree_binding.h" |
| 36 #include "ui/display/display.h" |
| 33 | 37 |
| 34 namespace ui { | 38 namespace ui { |
| 35 namespace ws { | 39 namespace ws { |
| 36 namespace test { | 40 namespace test { |
| 37 | 41 |
| 38 // Collection of utilities useful in creating mus tests. | 42 // Collection of utilities useful in creating mus tests. |
| 39 | 43 |
| 44 // Test PlatformDisplay instance that allows adding/modifying/removing displays. |
| 45 // Tracks display ids to perform some basic verification that no duplicates are |
| 46 // added and displays was added before being modified or removed. |
| 47 class TestPlatformScreen : public display::PlatformScreen { |
| 48 public: |
| 49 TestPlatformScreen(); |
| 50 ~TestPlatformScreen() override; |
| 51 |
| 52 // Adds a new display with default metrics, generates a unique display id and |
| 53 // returns it. Calls OnDisplayAdded() on delegate. |
| 54 int64_t AddDisplay(); |
| 55 |
| 56 // Adds a new display with provided |metrics|, generates a unique display id |
| 57 // and returns it. Calls OnDisplayAdded() on delegate. |
| 58 int64_t AddDisplay(const display::ViewportMetrics& metrics); |
| 59 |
| 60 // Calls OnDisplayModified() on delegate. |
| 61 void ModifyDisplay(int64_t id, const display::ViewportMetrics& metrics); |
| 62 |
| 63 // Calls OnDisplayRemoved() on delegate. |
| 64 void RemoveDisplay(int64_t id); |
| 65 |
| 66 // display::PlatformScreen: |
| 67 void AddInterfaces(service_manager::InterfaceRegistry* registry) override {} |
| 68 void Init(display::PlatformScreenDelegate* delegate) override; |
| 69 void RequestCloseDisplay(int64_t display_id) override {} |
| 70 int64_t GetPrimaryDisplayId() const override; |
| 71 |
| 72 private: |
| 73 display::PlatformScreenDelegate* delegate_; |
| 74 int64_t primary_display_id_ = display::Display::kInvalidDisplayID; |
| 75 std::set<int64_t> display_ids_; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(TestPlatformScreen); |
| 78 }; |
| 79 |
| 80 // ----------------------------------------------------------------------------- |
| 81 |
| 40 class UserDisplayManagerTestApi { | 82 class UserDisplayManagerTestApi { |
| 41 public: | 83 public: |
| 42 explicit UserDisplayManagerTestApi(UserDisplayManager* udm) : udm_(udm) {} | 84 explicit UserDisplayManagerTestApi(UserDisplayManager* udm) : udm_(udm) {} |
| 43 ~UserDisplayManagerTestApi() {} | 85 ~UserDisplayManagerTestApi() {} |
| 44 | 86 |
| 45 void SetTestObserver(mojom::DisplayManagerObserver* observer) { | 87 void SetTestObserver(mojom::DisplayManagerObserver* observer) { |
| 46 udm_->test_observer_ = observer; | 88 udm_->test_observer_ = observer; |
| 47 if (observer) | 89 if (observer) |
| 48 udm_->OnObserverAdded(observer); | 90 udm_->OnObserverAdded(observer); |
| 49 } | 91 } |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 WindowServer* window_server_; | 278 WindowServer* window_server_; |
| 237 | 279 |
| 238 DISALLOW_COPY_AND_ASSIGN(TestDisplayBinding); | 280 DISALLOW_COPY_AND_ASSIGN(TestDisplayBinding); |
| 239 }; | 281 }; |
| 240 | 282 |
| 241 // ----------------------------------------------------------------------------- | 283 // ----------------------------------------------------------------------------- |
| 242 | 284 |
| 243 // Factory that dispenses TestPlatformDisplays. | 285 // Factory that dispenses TestPlatformDisplays. |
| 244 class TestPlatformDisplayFactory : public PlatformDisplayFactory { | 286 class TestPlatformDisplayFactory : public PlatformDisplayFactory { |
| 245 public: | 287 public: |
| 246 static const int64_t kFirstDisplayId; | |
| 247 | |
| 248 explicit TestPlatformDisplayFactory(mojom::Cursor* cursor_storage); | 288 explicit TestPlatformDisplayFactory(mojom::Cursor* cursor_storage); |
| 249 ~TestPlatformDisplayFactory(); | 289 ~TestPlatformDisplayFactory(); |
| 250 | 290 |
| 251 // PlatformDisplayFactory: | 291 // PlatformDisplayFactory: |
| 252 std::unique_ptr<PlatformDisplay> CreatePlatformDisplay() override; | 292 std::unique_ptr<PlatformDisplay> CreatePlatformDisplay( |
| 293 const PlatformDisplayInitParams& init_params) override; |
| 253 | 294 |
| 254 private: | 295 private: |
| 255 mojom::Cursor* cursor_storage_; | 296 mojom::Cursor* cursor_storage_; |
| 256 int64_t next_display_id_; | |
| 257 | 297 |
| 258 DISALLOW_COPY_AND_ASSIGN(TestPlatformDisplayFactory); | 298 DISALLOW_COPY_AND_ASSIGN(TestPlatformDisplayFactory); |
| 259 }; | 299 }; |
| 260 | 300 |
| 261 // ----------------------------------------------------------------------------- | 301 // ----------------------------------------------------------------------------- |
| 262 | 302 |
| 263 // A stub implementation of FrameGeneratorDelegate. | 303 // A stub implementation of FrameGeneratorDelegate. |
| 264 class TestFrameGeneratorDelegate : public FrameGeneratorDelegate { | 304 class TestFrameGeneratorDelegate : public FrameGeneratorDelegate { |
| 265 public: | 305 public: |
| 266 TestFrameGeneratorDelegate(); | 306 TestFrameGeneratorDelegate(); |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 return last_binding() ? last_binding()->client() : nullptr; | 550 return last_binding() ? last_binding()->client() : nullptr; |
| 511 } | 551 } |
| 512 TestWindowTreeBinding* last_binding() { | 552 TestWindowTreeBinding* last_binding() { |
| 513 return bindings_.empty() ? nullptr : bindings_.back(); | 553 return bindings_.empty() ? nullptr : bindings_.back(); |
| 514 } | 554 } |
| 515 | 555 |
| 516 std::vector<TestWindowTreeBinding*>* bindings() { return &bindings_; } | 556 std::vector<TestWindowTreeBinding*>* bindings() { return &bindings_; } |
| 517 | 557 |
| 518 bool got_on_no_more_displays() const { return got_on_no_more_displays_; } | 558 bool got_on_no_more_displays() const { return got_on_no_more_displays_; } |
| 519 | 559 |
| 520 // Creates |num_displays| displays. | |
| 521 void CreateDisplays(int num_displays); | |
| 522 | |
| 523 Display* AddDisplay(); | |
| 524 | |
| 525 // WindowServerDelegate: | 560 // WindowServerDelegate: |
| 526 void StartDisplayInit() override; | 561 void StartDisplayInit() override; |
| 527 void OnNoMoreDisplays() override; | 562 void OnNoMoreDisplays() override; |
| 528 std::unique_ptr<WindowTreeBinding> CreateWindowTreeBinding( | 563 std::unique_ptr<WindowTreeBinding> CreateWindowTreeBinding( |
| 529 BindingType type, | 564 BindingType type, |
| 530 ws::WindowServer* window_server, | 565 ws::WindowServer* window_server, |
| 531 ws::WindowTree* tree, | 566 ws::WindowTree* tree, |
| 532 mojom::WindowTreeRequest* tree_request, | 567 mojom::WindowTreeRequest* tree_request, |
| 533 mojom::WindowTreeClientPtr* client) override; | 568 mojom::WindowTreeClientPtr* client) override; |
| 534 bool IsTestConfig() const override; | 569 bool IsTestConfig() const override; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 | 655 |
| 621 DISALLOW_COPY_AND_ASSIGN(WindowEventTargetingHelper); | 656 DISALLOW_COPY_AND_ASSIGN(WindowEventTargetingHelper); |
| 622 }; | 657 }; |
| 623 | 658 |
| 624 // ----------------------------------------------------------------------------- | 659 // ----------------------------------------------------------------------------- |
| 625 | 660 |
| 626 // Adds a new WM to |window_server| for |user_id|. Creates | 661 // Adds a new WM to |window_server| for |user_id|. Creates |
| 627 // WindowManagerWindowTreeFactory and associated WindowTree for the WM. | 662 // WindowManagerWindowTreeFactory and associated WindowTree for the WM. |
| 628 void AddWindowManager(WindowServer* window_server, const UserId& user_id); | 663 void AddWindowManager(WindowServer* window_server, const UserId& user_id); |
| 629 | 664 |
| 665 // Create a new ViewportMetrics object with specified bounds, size and |
| 666 // scale factor. Bounds origin, |origin_x| and |origin_y|, are in DIP and bounds |
| 667 // size is computed. |
| 668 display::ViewportMetrics MakeViewportMetrics(int origin_x, |
| 669 int origin_y, |
| 670 int width_pixels, |
| 671 int height_pixels, |
| 672 float scale_factor); |
| 673 |
| 630 // Returns the first and only root of |tree|. If |tree| has zero or more than | 674 // Returns the first and only root of |tree|. If |tree| has zero or more than |
| 631 // one root returns null. | 675 // one root returns null. |
| 632 ServerWindow* FirstRoot(WindowTree* tree); | 676 ServerWindow* FirstRoot(WindowTree* tree); |
| 633 | 677 |
| 634 // Returns the ClientWindowId of the first root of |tree|, or an empty | 678 // Returns the ClientWindowId of the first root of |tree|, or an empty |
| 635 // ClientWindowId if |tree| has zero or more than one root. | 679 // ClientWindowId if |tree| has zero or more than one root. |
| 636 ClientWindowId FirstRootId(WindowTree* tree); | 680 ClientWindowId FirstRootId(WindowTree* tree); |
| 637 | 681 |
| 638 // Returns |tree|s ClientWindowId for |window|. | 682 // Returns |tree|s ClientWindowId for |window|. |
| 639 ClientWindowId ClientWindowIdForWindow(WindowTree* tree, | 683 ClientWindowId ClientWindowIdForWindow(WindowTree* tree, |
| 640 const ServerWindow* window); | 684 const ServerWindow* window); |
| 641 | 685 |
| 642 // Creates a new visible window as a child of the single root of |tree|. | 686 // Creates a new visible window as a child of the single root of |tree|. |
| 643 // |client_id| is set to the ClientWindowId of the new window. | 687 // |client_id| is set to the ClientWindowId of the new window. |
| 644 ServerWindow* NewWindowInTree(WindowTree* tree, ClientWindowId* client_id); | 688 ServerWindow* NewWindowInTree(WindowTree* tree, ClientWindowId* client_id); |
| 645 ServerWindow* NewWindowInTreeWithParent(WindowTree* tree, | 689 ServerWindow* NewWindowInTreeWithParent(WindowTree* tree, |
| 646 ServerWindow* parent, | 690 ServerWindow* parent, |
| 647 ClientWindowId* client_id); | 691 ClientWindowId* client_id); |
| 648 | 692 |
| 649 } // namespace test | 693 } // namespace test |
| 650 } // namespace ws | 694 } // namespace ws |
| 651 } // namespace ui | 695 } // namespace ui |
| 652 | 696 |
| 653 #endif // SERVICES_UI_WS_TEST_UTILS_H_ | 697 #endif // SERVICES_UI_WS_TEST_UTILS_H_ |
| OLD | NEW |