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