| 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" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "cc/output/copy_output_request.h" | |
| 14 #include "components/mus/common/types.h" | 13 #include "components/mus/common/types.h" |
| 15 #include "components/mus/common/util.h" | 14 #include "components/mus/common/util.h" |
| 16 #include "components/mus/public/interfaces/window_tree.mojom.h" | 15 #include "components/mus/public/interfaces/window_tree.mojom.h" |
| 17 #include "components/mus/surfaces/surfaces_state.h" | 16 #include "components/mus/surfaces/surfaces_state.h" |
| 18 #include "components/mus/ws/client_connection.h" | 17 #include "components/mus/ws/client_connection.h" |
| 19 #include "components/mus/ws/connection_manager.h" | 18 #include "components/mus/ws/connection_manager.h" |
| 20 #include "components/mus/ws/connection_manager_delegate.h" | 19 #include "components/mus/ws/connection_manager_delegate.h" |
| 21 #include "components/mus/ws/display_manager.h" | 20 #include "components/mus/ws/display_manager.h" |
| 22 #include "components/mus/ws/display_manager_factory.h" | 21 #include "components/mus/ws/display_manager_factory.h" |
| 23 #include "components/mus/ws/ids.h" | 22 #include "components/mus/ws/ids.h" |
| 24 #include "components/mus/ws/server_window.h" | 23 #include "components/mus/ws/server_window.h" |
| 25 #include "components/mus/ws/server_window_surface_manager_test_api.h" | 24 #include "components/mus/ws/server_window_surface_manager_test_api.h" |
| 26 #include "components/mus/ws/test_change_tracker.h" | 25 #include "components/mus/ws/test_change_tracker.h" |
| 26 #include "components/mus/ws/test_utils.h" |
| 27 #include "components/mus/ws/window_tree_host_connection.h" | 27 #include "components/mus/ws/window_tree_host_connection.h" |
| 28 #include "components/mus/ws/window_tree_impl.h" | 28 #include "components/mus/ws/window_tree_impl.h" |
| 29 #include "mojo/converters/geometry/geometry_type_converters.h" | 29 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 30 #include "mojo/services/network/public/interfaces/url_loader.mojom.h" | 30 #include "mojo/services/network/public/interfaces/url_loader.mojom.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 32 #include "ui/events/event.h" | 32 #include "ui/events/event.h" |
| 33 #include "ui/events/event_utils.h" | 33 #include "ui/events/event_utils.h" |
| 34 #include "ui/gfx/geometry/rect.h" | 34 #include "ui/gfx/geometry/rect.h" |
| 35 | 35 |
| 36 using mojo::Array; | |
| 37 using mojo::InterfaceRequest; | |
| 38 using mojo::String; | |
| 39 using mus::mojom::Event; | |
| 40 using mus::mojom::EventPtr; | |
| 41 using mus::mojom::LocationData; | |
| 42 using mus::mojom::PointerData; | |
| 43 using mus::mojom::WindowDataPtr; | |
| 44 | |
| 45 namespace mus { | 36 namespace mus { |
| 46 namespace ws { | 37 namespace ws { |
| 38 namespace test { |
| 47 namespace { | 39 namespace { |
| 48 | 40 |
| 49 std::string WindowIdToString(const WindowId& id) { | 41 std::string WindowIdToString(const WindowId& id) { |
| 50 return base::StringPrintf("%d,%d", id.connection_id, id.window_id); | 42 return base::StringPrintf("%d,%d", id.connection_id, id.window_id); |
| 51 } | 43 } |
| 52 | 44 |
| 53 ClientWindowId BuildClientWindowId(WindowTreeImpl* tree, | 45 ClientWindowId BuildClientWindowId(WindowTreeImpl* tree, |
| 54 ConnectionSpecificId window_id) { | 46 ConnectionSpecificId window_id) { |
| 55 return ClientWindowId(WindowIdToTransportId(WindowId(tree->id(), window_id))); | 47 return ClientWindowId(WindowIdToTransportId(WindowId(tree->id(), window_id))); |
| 56 } | 48 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 void OnAccelerator(uint32_t id, mojom::EventPtr event) override {} | 87 void OnAccelerator(uint32_t id, mojom::EventPtr event) override {} |
| 96 | 88 |
| 97 bool got_create_top_level_window_; | 89 bool got_create_top_level_window_; |
| 98 uint32_t change_id_; | 90 uint32_t change_id_; |
| 99 | 91 |
| 100 DISALLOW_COPY_AND_ASSIGN(TestWindowManager); | 92 DISALLOW_COPY_AND_ASSIGN(TestWindowManager); |
| 101 }; | 93 }; |
| 102 | 94 |
| 103 // ----------------------------------------------------------------------------- | 95 // ----------------------------------------------------------------------------- |
| 104 | 96 |
| 105 // WindowTreeClient implementation that logs all calls to a TestChangeTracker. | |
| 106 // TODO(sky): refactor so both this and WindowTreeAppTest share code. | |
| 107 class TestWindowTreeClient : public mus::mojom::WindowTreeClient { | |
| 108 public: | |
| 109 TestWindowTreeClient() : binding_(this), record_on_change_completed_(false) {} | |
| 110 ~TestWindowTreeClient() override {} | |
| 111 | |
| 112 TestChangeTracker* tracker() { return &tracker_; } | |
| 113 | |
| 114 void Bind(mojo::InterfaceRequest<mojom::WindowTreeClient> request) { | |
| 115 binding_.Bind(std::move(request)); | |
| 116 } | |
| 117 | |
| 118 void set_record_on_change_completed(bool value) { | |
| 119 record_on_change_completed_ = value; | |
| 120 } | |
| 121 | |
| 122 private: | |
| 123 // WindowTreeClient: | |
| 124 void OnEmbed(uint16_t connection_id, | |
| 125 WindowDataPtr root, | |
| 126 mus::mojom::WindowTreePtr tree, | |
| 127 Id focused_window_id, | |
| 128 uint32_t access_policy) override { | |
| 129 // TODO(sky): add test coverage of |focused_window_id|. | |
| 130 tracker_.OnEmbed(connection_id, std::move(root)); | |
| 131 } | |
| 132 void OnEmbeddedAppDisconnected(uint32_t window) override { | |
| 133 tracker_.OnEmbeddedAppDisconnected(window); | |
| 134 } | |
| 135 void OnUnembed(Id window_id) override { tracker_.OnUnembed(window_id); } | |
| 136 void OnLostCapture(Id window_id) override {} | |
| 137 void OnTopLevelCreated(uint32_t change_id, | |
| 138 mojom::WindowDataPtr data) override { | |
| 139 tracker_.OnTopLevelCreated(change_id, std::move(data)); | |
| 140 } | |
| 141 void OnWindowBoundsChanged(uint32_t window, | |
| 142 mojo::RectPtr old_bounds, | |
| 143 mojo::RectPtr new_bounds) override { | |
| 144 tracker_.OnWindowBoundsChanged(window, std::move(old_bounds), | |
| 145 std::move(new_bounds)); | |
| 146 } | |
| 147 void OnClientAreaChanged( | |
| 148 uint32_t window_id, | |
| 149 mojo::InsetsPtr new_client_area, | |
| 150 mojo::Array<mojo::RectPtr> new_additional_client_areas) override {} | |
| 151 void OnTransientWindowAdded(uint32_t window_id, | |
| 152 uint32_t transient_window_id) override {} | |
| 153 void OnTransientWindowRemoved(uint32_t window_id, | |
| 154 uint32_t transient_window_id) override {} | |
| 155 void OnWindowViewportMetricsChanged( | |
| 156 mojo::Array<uint32_t> window_ids, | |
| 157 mojom::ViewportMetricsPtr old_metrics, | |
| 158 mojom::ViewportMetricsPtr new_metrics) override { | |
| 159 tracker_.OnWindowViewportMetricsChanged(std::move(old_metrics), | |
| 160 std::move(new_metrics)); | |
| 161 } | |
| 162 void OnWindowHierarchyChanged(uint32_t window, | |
| 163 uint32_t new_parent, | |
| 164 uint32_t old_parent, | |
| 165 Array<WindowDataPtr> windows) override { | |
| 166 tracker_.OnWindowHierarchyChanged(window, new_parent, old_parent, | |
| 167 std::move(windows)); | |
| 168 } | |
| 169 void OnWindowReordered(uint32_t window_id, | |
| 170 uint32_t relative_window_id, | |
| 171 mojom::OrderDirection direction) override { | |
| 172 tracker_.OnWindowReordered(window_id, relative_window_id, direction); | |
| 173 } | |
| 174 void OnWindowDeleted(uint32_t window) override { | |
| 175 tracker_.OnWindowDeleted(window); | |
| 176 } | |
| 177 void OnWindowVisibilityChanged(uint32_t window, bool visible) override { | |
| 178 tracker_.OnWindowVisibilityChanged(window, visible); | |
| 179 } | |
| 180 void OnWindowDrawnStateChanged(uint32_t window, bool drawn) override { | |
| 181 tracker_.OnWindowDrawnStateChanged(window, drawn); | |
| 182 } | |
| 183 void OnWindowSharedPropertyChanged(uint32_t window, | |
| 184 const String& name, | |
| 185 Array<uint8_t> new_data) override { | |
| 186 tracker_.OnWindowSharedPropertyChanged(window, name, std::move(new_data)); | |
| 187 } | |
| 188 void OnWindowInputEvent(uint32_t event_id, | |
| 189 uint32_t window, | |
| 190 EventPtr event) override { | |
| 191 tracker_.OnWindowInputEvent(window, std::move(event)); | |
| 192 } | |
| 193 void OnWindowFocused(uint32_t focused_window_id) override { | |
| 194 tracker_.OnWindowFocused(focused_window_id); | |
| 195 } | |
| 196 void OnWindowPredefinedCursorChanged(uint32_t window_id, | |
| 197 mojom::Cursor cursor_id) override { | |
| 198 tracker_.OnWindowPredefinedCursorChanged(window_id, cursor_id); | |
| 199 } | |
| 200 void OnChangeCompleted(uint32_t change_id, bool success) override { | |
| 201 if (record_on_change_completed_) | |
| 202 tracker_.OnChangeCompleted(change_id, success); | |
| 203 } | |
| 204 void RequestClose(uint32_t window_id) override {} | |
| 205 void GetWindowManager(mojo::AssociatedInterfaceRequest<mojom::WindowManager> | |
| 206 internal) override {} | |
| 207 | |
| 208 TestChangeTracker tracker_; | |
| 209 | |
| 210 mojo::Binding<mojom::WindowTreeClient> binding_; | |
| 211 bool record_on_change_completed_; | |
| 212 | |
| 213 DISALLOW_COPY_AND_ASSIGN(TestWindowTreeClient); | |
| 214 }; | |
| 215 | |
| 216 // ----------------------------------------------------------------------------- | |
| 217 | |
| 218 // ClientConnection implementation that vends TestWindowTreeClient. | |
| 219 class TestClientConnection : public ClientConnection { | |
| 220 public: | |
| 221 TestClientConnection() : ClientConnection(&client_), is_paused_(false) {} | |
| 222 ~TestClientConnection() override {} | |
| 223 | |
| 224 TestWindowTreeClient* client() { return &client_; } | |
| 225 | |
| 226 bool is_paused() const { return is_paused_; } | |
| 227 | |
| 228 // ClientConnection: | |
| 229 mojom::WindowManager* GetWindowManager() override { | |
| 230 NOTREACHED(); | |
| 231 return nullptr; | |
| 232 } | |
| 233 void SetIncomingMethodCallProcessingPaused(bool paused) override { | |
| 234 is_paused_ = paused; | |
| 235 } | |
| 236 | |
| 237 private: | |
| 238 TestWindowTreeClient client_; | |
| 239 bool is_paused_; | |
| 240 | |
| 241 DISALLOW_COPY_AND_ASSIGN(TestClientConnection); | |
| 242 }; | |
| 243 | |
| 244 // ----------------------------------------------------------------------------- | |
| 245 | |
| 246 // Empty implementation of ConnectionManagerDelegate. | |
| 247 class TestConnectionManagerDelegate : public ConnectionManagerDelegate { | |
| 248 public: | |
| 249 TestConnectionManagerDelegate() : last_connection_(nullptr) {} | |
| 250 ~TestConnectionManagerDelegate() override {} | |
| 251 | |
| 252 TestWindowTreeClient* last_client() { | |
| 253 return last_connection_ ? last_connection_->client() : nullptr; | |
| 254 } | |
| 255 | |
| 256 TestClientConnection* last_connection() { return last_connection_; } | |
| 257 | |
| 258 private: | |
| 259 // ConnectionManagerDelegate: | |
| 260 void OnNoMoreRootConnections() override {} | |
| 261 scoped_ptr<ClientConnection> CreateClientConnectionForEmbedAtWindow( | |
| 262 ws::ConnectionManager* connection_manager, | |
| 263 ws::WindowTreeImpl* tree, | |
| 264 mojom::WindowTreeRequest tree_request, | |
| 265 mojom::WindowTreeClientPtr client) override { | |
| 266 scoped_ptr<TestClientConnection> connection(new TestClientConnection); | |
| 267 last_connection_ = connection.get(); | |
| 268 return std::move(connection); | |
| 269 } | |
| 270 void CreateDefaultWindowTreeHosts() override { NOTREACHED(); } | |
| 271 | |
| 272 TestClientConnection* last_connection_; | |
| 273 WindowTreeHostImpl* window_tree_host_; | |
| 274 | |
| 275 DISALLOW_COPY_AND_ASSIGN(TestConnectionManagerDelegate); | |
| 276 }; | |
| 277 | |
| 278 // ----------------------------------------------------------------------------- | |
| 279 | |
| 280 class TestWindowTreeHostConnection : public WindowTreeHostConnection { | 97 class TestWindowTreeHostConnection : public WindowTreeHostConnection { |
| 281 public: | 98 public: |
| 282 TestWindowTreeHostConnection(WindowTreeHostImpl* host_impl, | 99 TestWindowTreeHostConnection(WindowTreeHostImpl* host_impl, |
| 283 ConnectionManager* manager) | 100 ConnectionManager* manager) |
| 284 : host_(host_impl), connection_manager_(manager) {} | 101 : host_(host_impl), connection_manager_(manager) {} |
| 285 ~TestWindowTreeHostConnection() override {} | 102 ~TestWindowTreeHostConnection() override {} |
| 286 | 103 |
| 287 private: | 104 private: |
| 288 // WindowTreeHostConnection: | 105 // WindowTreeHostConnection: |
| 289 WindowTreeImpl* CreateWindowTree(ServerWindow* root) override { | 106 WindowTreeImpl* CreateWindowTree(ServerWindow* root) override { |
| 290 return connection_manager_->EmbedAtWindow( | 107 return connection_manager_->EmbedAtWindow( |
| 291 root, mus::mojom::WindowTree::kAccessPolicyEmbedRoot, | 108 root, mus::mojom::WindowTree::kAccessPolicyEmbedRoot, |
| 292 mus::mojom::WindowTreeClientPtr()); | 109 mus::mojom::WindowTreeClientPtr()); |
| 293 } | 110 } |
| 294 | 111 |
| 295 WindowTreeHostImpl* host_; | 112 WindowTreeHostImpl* host_; |
| 296 ConnectionManager* connection_manager_; | 113 ConnectionManager* connection_manager_; |
| 297 | 114 |
| 298 DISALLOW_COPY_AND_ASSIGN(TestWindowTreeHostConnection); | 115 DISALLOW_COPY_AND_ASSIGN(TestWindowTreeHostConnection); |
| 299 }; | 116 }; |
| 300 | 117 |
| 301 // ----------------------------------------------------------------------------- | |
| 302 // Empty implementation of DisplayManager. | |
| 303 class TestDisplayManager : public DisplayManager { | |
| 304 public: | |
| 305 explicit TestDisplayManager(int32_t* cursor_id_storage) | |
| 306 : cursor_id_storage_(cursor_id_storage) {} | |
| 307 ~TestDisplayManager() override {} | |
| 308 | |
| 309 // DisplayManager: | |
| 310 void Init(DisplayManagerDelegate* delegate) override { | |
| 311 // It is necessary to tell the delegate about the ViewportMetrics to make | |
| 312 // sure that the WindowTreeHostConnection is correctly initialized (and a | |
| 313 // root-window is created). | |
| 314 mojom::ViewportMetrics metrics; | |
| 315 metrics.size_in_pixels = mojo::Size::From(gfx::Size(400, 300)); | |
| 316 metrics.device_pixel_ratio = 1.f; | |
| 317 delegate->OnViewportMetricsChanged(mojom::ViewportMetrics(), metrics); | |
| 318 } | |
| 319 void SchedulePaint(const ServerWindow* window, | |
| 320 const gfx::Rect& bounds) override {} | |
| 321 void SetViewportSize(const gfx::Size& size) override {} | |
| 322 void SetTitle(const base::string16& title) override {} | |
| 323 void SetCapture() override {} | |
| 324 void ReleaseCapture() override {} | |
| 325 void SetCursorById(int32_t cursor) override { *cursor_id_storage_ = cursor; } | |
| 326 mojom::Rotation GetRotation() override { return mojom::Rotation::VALUE_0; } | |
| 327 const mojom::ViewportMetrics& GetViewportMetrics() override { | |
| 328 return display_metrices_; | |
| 329 } | |
| 330 void UpdateTextInputState(const ui::TextInputState& state) override {} | |
| 331 void SetImeVisibility(bool visible) override {} | |
| 332 bool IsFramePending() const override { return false; } | |
| 333 void RequestCopyOfOutput( | |
| 334 scoped_ptr<cc::CopyOutputRequest> output_request) override {} | |
| 335 | |
| 336 private: | |
| 337 mojom::ViewportMetrics display_metrices_; | |
| 338 | |
| 339 int32_t* cursor_id_storage_; | |
| 340 | |
| 341 DISALLOW_COPY_AND_ASSIGN(TestDisplayManager); | |
| 342 }; | |
| 343 | |
| 344 // Factory that dispenses TestDisplayManagers. | |
| 345 class TestDisplayManagerFactory : public DisplayManagerFactory { | |
| 346 public: | |
| 347 explicit TestDisplayManagerFactory(int32_t* cursor_id_storage) | |
| 348 : cursor_id_storage_(cursor_id_storage) {} | |
| 349 ~TestDisplayManagerFactory() {} | |
| 350 DisplayManager* CreateDisplayManager( | |
| 351 mojo::Connector* connector, | |
| 352 const scoped_refptr<GpuState>& gpu_state, | |
| 353 const scoped_refptr<mus::SurfacesState>& surfaces_state) override { | |
| 354 return new TestDisplayManager(cursor_id_storage_); | |
| 355 } | |
| 356 | |
| 357 private: | |
| 358 int32_t* cursor_id_storage_; | |
| 359 | |
| 360 DISALLOW_COPY_AND_ASSIGN(TestDisplayManagerFactory); | |
| 361 }; | |
| 362 | |
| 363 ui::PointerEvent CreatePointerDownEvent(int x, int y) { | 118 ui::PointerEvent CreatePointerDownEvent(int x, int y) { |
| 364 return ui::PointerEvent(ui::TouchEvent(ui::ET_TOUCH_PRESSED, gfx::Point(x, y), | 119 return ui::PointerEvent(ui::TouchEvent(ui::ET_TOUCH_PRESSED, gfx::Point(x, y), |
| 365 1, ui::EventTimeForNow())); | 120 1, ui::EventTimeForNow())); |
| 366 } | 121 } |
| 367 | 122 |
| 368 ui::PointerEvent CreatePointerUpEvent(int x, int y) { | 123 ui::PointerEvent CreatePointerUpEvent(int x, int y) { |
| 369 return ui::PointerEvent(ui::TouchEvent( | 124 return ui::PointerEvent(ui::TouchEvent( |
| 370 ui::ET_TOUCH_RELEASED, gfx::Point(x, y), 1, ui::EventTimeForNow())); | 125 ui::ET_TOUCH_RELEASED, gfx::Point(x, y), 1, ui::EventTimeForNow())); |
| 371 } | 126 } |
| 372 | 127 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 } | 189 } |
| 435 | 190 |
| 436 TestWindowTreeClient* wm_client() { return wm_client_; } | 191 TestWindowTreeClient* wm_client() { return wm_client_; } |
| 437 mus::mojom::Cursor cursor_id() { | 192 mus::mojom::Cursor cursor_id() { |
| 438 return static_cast<mus::mojom::Cursor>(cursor_id_); | 193 return static_cast<mus::mojom::Cursor>(cursor_id_); |
| 439 } | 194 } |
| 440 | 195 |
| 441 TestWindowTreeHostConnection* host_connection() { return host_connection_; } | 196 TestWindowTreeHostConnection* host_connection() { return host_connection_; } |
| 442 | 197 |
| 443 void DispatchEventWithoutAck(const ui::Event& event) { | 198 void DispatchEventWithoutAck(const ui::Event& event) { |
| 444 window_tree_host_->OnEvent(event); | 199 WindowTreeHostTestApi(window_tree_host_).OnEvent(event); |
| 445 } | 200 } |
| 446 | 201 |
| 447 void set_window_manager_internal(WindowTreeImpl* connection, | 202 void set_window_manager_internal(WindowTreeImpl* connection, |
| 448 mojom::WindowManager* wm_internal) { | 203 mojom::WindowManager* wm_internal) { |
| 449 connection->window_manager_internal_ = wm_internal; | 204 WindowTreeTestApi(connection).set_window_manager_internal(wm_internal); |
| 450 } | 205 } |
| 451 | 206 |
| 452 void AckPreviousEvent() { | 207 void AckPreviousEvent() { |
| 453 while (window_tree_host_->tree_awaiting_input_ack_) | 208 WindowTreeHostTestApi test_api(window_tree_host_); |
| 454 window_tree_host_->tree_awaiting_input_ack_->OnWindowInputEventAck(0); | 209 while (test_api.tree_awaiting_input_ack()) |
| 210 test_api.tree_awaiting_input_ack()->OnWindowInputEventAck(0); |
| 455 } | 211 } |
| 456 | 212 |
| 457 void DispatchEventAndAckImmediately(const ui::Event& event) { | 213 void DispatchEventAndAckImmediately(const ui::Event& event) { |
| 458 DispatchEventWithoutAck(event); | 214 DispatchEventWithoutAck(event); |
| 459 AckPreviousEvent(); | 215 AckPreviousEvent(); |
| 460 } | 216 } |
| 461 | 217 |
| 462 // Creates a new window from wm_connection() and embeds a new connection in | 218 // Creates a new window from wm_connection() and embeds a new connection in |
| 463 // it. | 219 // it. |
| 464 void SetupEventTargeting(TestWindowTreeClient** out_client, | 220 void SetupEventTargeting(TestWindowTreeClient** out_client, |
| 465 WindowTreeImpl** window_tree_connection, | 221 WindowTreeImpl** window_tree_connection, |
| 466 ServerWindow** window); | 222 ServerWindow** window); |
| 467 | 223 |
| 468 protected: | 224 protected: |
| 469 // testing::Test: | 225 // testing::Test: |
| 470 void SetUp() override { | 226 void SetUp() override { |
| 471 DisplayManager::set_factory_for_testing(&display_manager_factory_); | 227 DisplayManager::set_factory_for_testing(&display_manager_factory_); |
| 472 // TODO(fsamuel): This is probably broken. We need a root. | |
| 473 connection_manager_.reset( | 228 connection_manager_.reset( |
| 474 new ConnectionManager(&delegate_, scoped_refptr<SurfacesState>())); | 229 new ConnectionManager(&delegate_, scoped_refptr<SurfacesState>())); |
| 475 window_tree_host_ = new WindowTreeHostImpl( | 230 window_tree_host_ = new WindowTreeHostImpl( |
| 476 connection_manager_.get(), nullptr, scoped_refptr<GpuState>(), | 231 connection_manager_.get(), nullptr, scoped_refptr<GpuState>(), |
| 477 scoped_refptr<mus::SurfacesState>()); | 232 scoped_refptr<mus::SurfacesState>()); |
| 478 // TODO(fsamuel): This is way too magical. We need to find a better way to | |
| 479 // manage lifetime. | |
| 480 host_connection_ = new TestWindowTreeHostConnection( | 233 host_connection_ = new TestWindowTreeHostConnection( |
| 481 window_tree_host_, connection_manager_.get()); | 234 window_tree_host_, connection_manager_.get()); |
| 482 window_tree_host_->Init(make_scoped_ptr(host_connection_)); | 235 window_tree_host_->Init(make_scoped_ptr(host_connection_)); |
| 483 wm_client_ = delegate_.last_client(); | 236 wm_client_ = delegate_.last_client(); |
| 484 } | 237 } |
| 485 | 238 |
| 486 protected: | 239 protected: |
| 487 // TestWindowTreeClient that is used for the WM connection. | 240 // TestWindowTreeClient that is used for the WM connection. |
| 488 TestWindowTreeClient* wm_client_; | 241 TestWindowTreeClient* wm_client_; |
| 489 int32_t cursor_id_; | 242 int32_t cursor_id_; |
| 490 TestDisplayManagerFactory display_manager_factory_; | 243 TestDisplayManagerFactory display_manager_factory_; |
| 491 TestConnectionManagerDelegate delegate_; | 244 TestConnectionManagerDelegate delegate_; |
| 245 // Owned by ConnectionManager. |
| 492 TestWindowTreeHostConnection* host_connection_; | 246 TestWindowTreeHostConnection* host_connection_; |
| 493 WindowTreeHostImpl* window_tree_host_ = nullptr; | 247 WindowTreeHostImpl* window_tree_host_ = nullptr; |
| 494 scoped_ptr<ConnectionManager> connection_manager_; | 248 scoped_ptr<ConnectionManager> connection_manager_; |
| 495 base::MessageLoop message_loop_; | 249 base::MessageLoop message_loop_; |
| 496 | 250 |
| 497 DISALLOW_COPY_AND_ASSIGN(WindowTreeTest); | 251 DISALLOW_COPY_AND_ASSIGN(WindowTreeTest); |
| 498 }; | 252 }; |
| 499 | 253 |
| 500 // Creates a new window in wm_connection(), adds it to the root, embeds a | 254 // Creates a new window in wm_connection(), adds it to the root, embeds a |
| 501 // new client in the window and creates a child of said window. |window| is | 255 // new client in the window and creates a child of said window. |window| is |
| 502 // set to the child of |window_tree_connection| that is created. | 256 // set to the child of |window_tree_connection| that is created. |
| 503 void WindowTreeTest::SetupEventTargeting( | 257 void WindowTreeTest::SetupEventTargeting( |
| 504 TestWindowTreeClient** out_client, | 258 TestWindowTreeClient** out_client, |
| 505 WindowTreeImpl** window_tree_connection, | 259 WindowTreeImpl** window_tree_connection, |
| 506 ServerWindow** window) { | 260 ServerWindow** window) { |
| 507 const ClientWindowId embed_window_id = | 261 const ClientWindowId embed_window_id = |
| 508 BuildClientWindowId(wm_connection(), 1); | 262 BuildClientWindowId(wm_connection(), 1); |
| 509 EXPECT_TRUE( | 263 EXPECT_TRUE( |
| 510 wm_connection()->NewWindow(embed_window_id, ServerWindow::Properties())); | 264 wm_connection()->NewWindow(embed_window_id, ServerWindow::Properties())); |
| 511 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true)); | 265 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true)); |
| 512 EXPECT_TRUE(wm_connection()->AddWindow(FirstRootId(wm_connection()), | 266 EXPECT_TRUE(wm_connection()->AddWindow(FirstRootId(wm_connection()), |
| 513 embed_window_id)); | 267 embed_window_id)); |
| 514 window_tree_host_->root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 268 window_tree_host_->root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 515 mojom::WindowTreeClientPtr client; | 269 mojom::WindowTreeClientPtr client; |
| 516 mojo::InterfaceRequest<mojom::WindowTreeClient> client_request = | 270 mojom::WindowTreeClientRequest client_request = GetProxy(&client); |
| 517 GetProxy(&client); | |
| 518 wm_client()->Bind(std::move(client_request)); | 271 wm_client()->Bind(std::move(client_request)); |
| 519 ConnectionSpecificId connection_id = 0; | 272 ConnectionSpecificId connection_id = 0; |
| 520 wm_connection()->Embed(embed_window_id, std::move(client), | 273 wm_connection()->Embed(embed_window_id, std::move(client), |
| 521 mojom::WindowTree::kAccessPolicyDefault, | 274 mojom::WindowTree::kAccessPolicyDefault, |
| 522 &connection_id); | 275 &connection_id); |
| 523 ServerWindow* embed_window = | 276 ServerWindow* embed_window = |
| 524 wm_connection()->GetWindowByClientId(embed_window_id); | 277 wm_connection()->GetWindowByClientId(embed_window_id); |
| 525 WindowTreeImpl* connection1 = | 278 WindowTreeImpl* connection1 = |
| 526 connection_manager()->GetConnectionWithRoot(embed_window); | 279 connection_manager()->GetConnectionWithRoot(embed_window); |
| 527 ASSERT_TRUE(connection1 != nullptr); | 280 ASSERT_TRUE(connection1 != nullptr); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 558 wm_connection()->NewWindow(embed_window_id, ServerWindow::Properties())); | 311 wm_connection()->NewWindow(embed_window_id, ServerWindow::Properties())); |
| 559 ServerWindow* embed_window = | 312 ServerWindow* embed_window = |
| 560 wm_connection()->GetWindowByClientId(embed_window_id); | 313 wm_connection()->GetWindowByClientId(embed_window_id); |
| 561 ASSERT_TRUE(embed_window); | 314 ASSERT_TRUE(embed_window); |
| 562 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true)); | 315 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true)); |
| 563 ASSERT_TRUE(FirstRoot(wm_connection())); | 316 ASSERT_TRUE(FirstRoot(wm_connection())); |
| 564 const ClientWindowId wm_root_id = FirstRootId(wm_connection()); | 317 const ClientWindowId wm_root_id = FirstRootId(wm_connection()); |
| 565 EXPECT_TRUE(wm_connection()->AddWindow(wm_root_id, embed_window_id)); | 318 EXPECT_TRUE(wm_connection()->AddWindow(wm_root_id, embed_window_id)); |
| 566 window_tree_host_->root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 319 window_tree_host_->root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 567 mojom::WindowTreeClientPtr client; | 320 mojom::WindowTreeClientPtr client; |
| 568 mojo::InterfaceRequest<mojom::WindowTreeClient> client_request = | 321 mojom::WindowTreeClientRequest client_request = GetProxy(&client); |
| 569 GetProxy(&client); | |
| 570 wm_client()->Bind(std::move(client_request)); | 322 wm_client()->Bind(std::move(client_request)); |
| 571 ConnectionSpecificId connection_id = 0; | 323 ConnectionSpecificId connection_id = 0; |
| 572 wm_connection()->Embed(embed_window_id, std::move(client), | 324 wm_connection()->Embed(embed_window_id, std::move(client), |
| 573 mojom::WindowTree::kAccessPolicyDefault, | 325 mojom::WindowTree::kAccessPolicyDefault, |
| 574 &connection_id); | 326 &connection_id); |
| 575 WindowTreeImpl* connection1 = | 327 WindowTreeImpl* connection1 = |
| 576 connection_manager()->GetConnectionWithRoot(embed_window); | 328 connection_manager()->GetConnectionWithRoot(embed_window); |
| 577 ASSERT_TRUE(connection1 != nullptr); | 329 ASSERT_TRUE(connection1 != nullptr); |
| 578 ASSERT_NE(connection1, wm_connection()); | 330 ASSERT_NE(connection1, wm_connection()); |
| 579 | 331 |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 932 | 684 |
| 933 // Only the capture window should be able to release capture | 685 // Only the capture window should be able to release capture |
| 934 mojom_window_tree->ReleaseCapture(++change_id, | 686 mojom_window_tree->ReleaseCapture(++change_id, |
| 935 WindowIdToTransportId(root_window->id())); | 687 WindowIdToTransportId(root_window->id())); |
| 936 EXPECT_EQ(window, host->GetCaptureWindow()); | 688 EXPECT_EQ(window, host->GetCaptureWindow()); |
| 937 mojom_window_tree->ReleaseCapture(++change_id, | 689 mojom_window_tree->ReleaseCapture(++change_id, |
| 938 WindowIdToTransportId(window->id())); | 690 WindowIdToTransportId(window->id())); |
| 939 EXPECT_EQ(nullptr, host->GetCaptureWindow()); | 691 EXPECT_EQ(nullptr, host->GetCaptureWindow()); |
| 940 } | 692 } |
| 941 | 693 |
| 694 } // namespace test |
| 942 } // namespace ws | 695 } // namespace ws |
| 943 } // namespace mus | 696 } // namespace mus |
| OLD | NEW |