| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_MUS_WS_TEST_UTILS_H_ |
| 6 #define COMPONENTS_MUS_WS_TEST_UTILS_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include "components/mus/public/interfaces/window_tree.mojom.h" |
| 11 #include "components/mus/ws/client_connection.h" |
| 12 #include "components/mus/ws/connection_manager_delegate.h" |
| 13 #include "components/mus/ws/display_manager.h" |
| 14 #include "components/mus/ws/display_manager_factory.h" |
| 15 #include "components/mus/ws/test_change_tracker.h" |
| 16 #include "components/mus/ws/window_manager_factory_registry.h" |
| 17 #include "components/mus/ws/window_tree_host_impl.h" |
| 18 #include "components/mus/ws/window_tree_impl.h" |
| 19 |
| 20 namespace mus { |
| 21 namespace ws { |
| 22 namespace test { |
| 23 |
| 24 // Collection of utilities useful in creating mus tests. |
| 25 |
| 26 class WindowManagerFactoryRegistryTestApi { |
| 27 public: |
| 28 WindowManagerFactoryRegistryTestApi(WindowManagerFactoryRegistry* registry); |
| 29 ~WindowManagerFactoryRegistryTestApi(); |
| 30 |
| 31 void AddService(UserId user_id, mojom::WindowManagerFactory* factory); |
| 32 |
| 33 private: |
| 34 WindowManagerFactoryRegistry* registry_; |
| 35 |
| 36 DISALLOW_COPY_AND_ASSIGN(WindowManagerFactoryRegistryTestApi); |
| 37 }; |
| 38 |
| 39 // ----------------------------------------------------------------------------- |
| 40 |
| 41 class WindowTreeTestApi { |
| 42 public: |
| 43 WindowTreeTestApi(WindowTreeImpl* tree); |
| 44 ~WindowTreeTestApi(); |
| 45 |
| 46 void set_window_manager_internal(mojom::WindowManager* wm_internal) { |
| 47 tree_->window_manager_internal_ = wm_internal; |
| 48 } |
| 49 |
| 50 private: |
| 51 WindowTreeImpl* tree_; |
| 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(WindowTreeTestApi); |
| 54 }; |
| 55 |
| 56 // ----------------------------------------------------------------------------- |
| 57 |
| 58 class WindowTreeHostTestApi { |
| 59 public: |
| 60 explicit WindowTreeHostTestApi(WindowTreeHostImpl* tree_host); |
| 61 ~WindowTreeHostTestApi(); |
| 62 |
| 63 void OnEvent(const ui::Event& event) { tree_host_->OnEvent(event); } |
| 64 |
| 65 mojom::WindowTree* tree_awaiting_input_ack() { |
| 66 return tree_host_->tree_awaiting_input_ack_; |
| 67 } |
| 68 |
| 69 private: |
| 70 WindowTreeHostImpl* tree_host_; |
| 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(WindowTreeHostTestApi); |
| 73 }; |
| 74 |
| 75 // ----------------------------------------------------------------------------- |
| 76 |
| 77 // Factory that dispenses TestDisplayManagers. |
| 78 class TestDisplayManagerFactory : public DisplayManagerFactory { |
| 79 public: |
| 80 explicit TestDisplayManagerFactory(int32_t* cursor_id_storage); |
| 81 ~TestDisplayManagerFactory(); |
| 82 |
| 83 // DisplayManagerFactory: |
| 84 DisplayManager* CreateDisplayManager( |
| 85 mojo::Connector* connector, |
| 86 const scoped_refptr<GpuState>& gpu_state, |
| 87 const scoped_refptr<mus::SurfacesState>& surfaces_state) override; |
| 88 |
| 89 private: |
| 90 int32_t* cursor_id_storage_; |
| 91 |
| 92 DISALLOW_COPY_AND_ASSIGN(TestDisplayManagerFactory); |
| 93 }; |
| 94 |
| 95 // ----------------------------------------------------------------------------- |
| 96 |
| 97 // WindowTreeClient implementation that logs all calls to a TestChangeTracker. |
| 98 class TestWindowTreeClient : public mus::mojom::WindowTreeClient { |
| 99 public: |
| 100 TestWindowTreeClient(); |
| 101 ~TestWindowTreeClient() override; |
| 102 |
| 103 TestChangeTracker* tracker() { return &tracker_; } |
| 104 |
| 105 void Bind(mojo::InterfaceRequest<mojom::WindowTreeClient> request); |
| 106 |
| 107 void set_record_on_change_completed(bool value) { |
| 108 record_on_change_completed_ = value; |
| 109 } |
| 110 |
| 111 private: |
| 112 // WindowTreeClient: |
| 113 void OnEmbed(uint16_t connection_id, |
| 114 mojom::WindowDataPtr root, |
| 115 mus::mojom::WindowTreePtr tree, |
| 116 Id focused_window_id, |
| 117 uint32_t access_policy) override; |
| 118 void OnEmbeddedAppDisconnected(uint32_t window) override; |
| 119 void OnUnembed(Id window_id) override; |
| 120 void OnLostCapture(Id window_id) override; |
| 121 void OnTopLevelCreated(uint32_t change_id, |
| 122 mojom::WindowDataPtr data) override; |
| 123 void OnWindowBoundsChanged(uint32_t window, |
| 124 mojo::RectPtr old_bounds, |
| 125 mojo::RectPtr new_bounds) override; |
| 126 void OnClientAreaChanged( |
| 127 uint32_t window_id, |
| 128 mojo::InsetsPtr new_client_area, |
| 129 mojo::Array<mojo::RectPtr> new_additional_client_areas) override; |
| 130 void OnTransientWindowAdded(uint32_t window_id, |
| 131 uint32_t transient_window_id) override; |
| 132 void OnTransientWindowRemoved(uint32_t window_id, |
| 133 uint32_t transient_window_id) override; |
| 134 void OnWindowViewportMetricsChanged( |
| 135 mojo::Array<uint32_t> window_ids, |
| 136 mojom::ViewportMetricsPtr old_metrics, |
| 137 mojom::ViewportMetricsPtr new_metrics) override; |
| 138 void OnWindowHierarchyChanged( |
| 139 uint32_t window, |
| 140 uint32_t new_parent, |
| 141 uint32_t old_parent, |
| 142 mojo::Array<mojom::WindowDataPtr> windows) override; |
| 143 void OnWindowReordered(uint32_t window_id, |
| 144 uint32_t relative_window_id, |
| 145 mojom::OrderDirection direction) override; |
| 146 void OnWindowDeleted(uint32_t window) override; |
| 147 void OnWindowVisibilityChanged(uint32_t window, bool visible) override; |
| 148 void OnWindowDrawnStateChanged(uint32_t window, bool drawn) override; |
| 149 void OnWindowSharedPropertyChanged(uint32_t window, |
| 150 const mojo::String& name, |
| 151 mojo::Array<uint8_t> new_data) override; |
| 152 void OnWindowInputEvent(uint32_t event_id, |
| 153 uint32_t window, |
| 154 mojom::EventPtr event) override; |
| 155 void OnWindowFocused(uint32_t focused_window_id) override; |
| 156 void OnWindowPredefinedCursorChanged(uint32_t window_id, |
| 157 mojom::Cursor cursor_id) override; |
| 158 void OnChangeCompleted(uint32_t change_id, bool success) override; |
| 159 void RequestClose(uint32_t window_id) override; |
| 160 void GetWindowManager( |
| 161 mojo::AssociatedInterfaceRequest<mojom::WindowManager> internal) override; |
| 162 |
| 163 TestChangeTracker tracker_; |
| 164 mojo::Binding<mojom::WindowTreeClient> binding_; |
| 165 bool record_on_change_completed_ = false; |
| 166 |
| 167 DISALLOW_COPY_AND_ASSIGN(TestWindowTreeClient); |
| 168 }; |
| 169 |
| 170 // ----------------------------------------------------------------------------- |
| 171 |
| 172 // ClientConnection implementation that vends TestWindowTreeClient. |
| 173 class TestClientConnection : public ClientConnection { |
| 174 public: |
| 175 TestClientConnection(); |
| 176 ~TestClientConnection() override; |
| 177 |
| 178 TestWindowTreeClient* client() { return &client_; } |
| 179 |
| 180 bool is_paused() const { return is_paused_; } |
| 181 |
| 182 // ClientConnection: |
| 183 mojom::WindowManager* GetWindowManager() override; |
| 184 void SetIncomingMethodCallProcessingPaused(bool paused) override; |
| 185 |
| 186 private: |
| 187 TestWindowTreeClient client_; |
| 188 bool is_paused_ = false; |
| 189 |
| 190 DISALLOW_COPY_AND_ASSIGN(TestClientConnection); |
| 191 }; |
| 192 |
| 193 // ----------------------------------------------------------------------------- |
| 194 |
| 195 // ConnectionManagerDelegate that creates TestWindowTreeClients. |
| 196 class TestConnectionManagerDelegate : public ConnectionManagerDelegate { |
| 197 public: |
| 198 TestConnectionManagerDelegate(); |
| 199 ~TestConnectionManagerDelegate() override; |
| 200 |
| 201 void set_connection_manager(ConnectionManager* connection_manager) { |
| 202 connection_manager_ = connection_manager; |
| 203 } |
| 204 |
| 205 void set_num_tree_hosts_to_create(int count) { |
| 206 num_tree_hosts_to_create_ = count; |
| 207 } |
| 208 |
| 209 TestWindowTreeClient* last_client() { |
| 210 return last_connection_ ? last_connection_->client() : nullptr; |
| 211 } |
| 212 TestClientConnection* last_connection() { return last_connection_; } |
| 213 |
| 214 bool got_on_no_more_connections() const { |
| 215 return got_on_no_more_connections_; |
| 216 } |
| 217 |
| 218 // ConnectionManagerDelegate: |
| 219 void OnNoMoreRootConnections() override; |
| 220 scoped_ptr<ClientConnection> CreateClientConnectionForEmbedAtWindow( |
| 221 ws::ConnectionManager* connection_manager, |
| 222 ws::WindowTreeImpl* tree, |
| 223 mojom::WindowTreeRequest tree_request, |
| 224 mojom::WindowTreeClientPtr client) override; |
| 225 void CreateDefaultWindowTreeHosts() override; |
| 226 |
| 227 private: |
| 228 // If CreateDefaultWindowTreeHosts() this is the number of WindowTreeHosts |
| 229 // that are created. The default is 0, which results in a DCHECK. |
| 230 int num_tree_hosts_to_create_ = 0; |
| 231 TestClientConnection* last_connection_ = nullptr; |
| 232 WindowTreeHostImpl* window_tree_host_ = nullptr; |
| 233 ConnectionManager* connection_manager_ = nullptr; |
| 234 bool got_on_no_more_connections_ = false; |
| 235 |
| 236 DISALLOW_COPY_AND_ASSIGN(TestConnectionManagerDelegate); |
| 237 }; |
| 238 |
| 239 } // namespace test |
| 240 } // namespace ws |
| 241 } // namespace mus |
| 242 |
| 243 #endif // COMPONENTS_MUS_WS_TEST_UTILS_H_ |
| OLD | NEW |