| 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "components/mus/client_connection.h" | 9 #include "components/mus/client_connection.h" |
| 10 #include "components/mus/connection_manager.h" | 10 #include "components/mus/connection_manager.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "ui/gfx/geometry/rect.h" | 26 #include "ui/gfx/geometry/rect.h" |
| 27 | 27 |
| 28 using mojo::Array; | 28 using mojo::Array; |
| 29 using mojo::ERROR_CODE_NONE; | 29 using mojo::ERROR_CODE_NONE; |
| 30 using mojo::InterfaceRequest; | 30 using mojo::InterfaceRequest; |
| 31 using mojo::ServiceProvider; | 31 using mojo::ServiceProvider; |
| 32 using mojo::ServiceProviderPtr; | 32 using mojo::ServiceProviderPtr; |
| 33 using mojo::String; | 33 using mojo::String; |
| 34 using mojo::ViewDataPtr; | 34 using mojo::ViewDataPtr; |
| 35 | 35 |
| 36 namespace view_manager { | 36 namespace mus { |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 // ----------------------------------------------------------------------------- | 39 // ----------------------------------------------------------------------------- |
| 40 | 40 |
| 41 // ViewTreeClient implementation that logs all calls to a TestChangeTracker. | 41 // ViewTreeClient implementation that logs all calls to a TestChangeTracker. |
| 42 // TODO(sky): refactor so both this and ViewTreeAppTest share code. | 42 // TODO(sky): refactor so both this and ViewTreeAppTest share code. |
| 43 class TestViewTreeClient : public mojo::ViewTreeClient { | 43 class TestViewTreeClient : public mojo::ViewTreeClient { |
| 44 public: | 44 public: |
| 45 TestViewTreeClient() {} | 45 TestViewTreeClient() {} |
| 46 ~TestViewTreeClient() override {} | 46 ~TestViewTreeClient() override {} |
| 47 | 47 |
| 48 TestChangeTracker* tracker() { return &tracker_; } | 48 TestChangeTracker* tracker() { return &tracker_; } |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 // ViewTreeClient: | 51 // ViewTreeClient: |
| 52 void OnEmbed(uint16_t connection_id, | 52 void OnEmbed(uint16_t connection_id, |
| 53 ViewDataPtr root, | 53 ViewDataPtr root, |
| 54 mojo::ViewTreePtr tree, | 54 mojo::ViewTreePtr tree, |
| 55 mojo::Id focused_view_id, | 55 Id focused_view_id, |
| 56 uint32_t access_policy) override { | 56 uint32_t access_policy) override { |
| 57 // TODO(sky): add test coverage of |focused_view_id|. | 57 // TODO(sky): add test coverage of |focused_view_id|. |
| 58 tracker_.OnEmbed(connection_id, root.Pass()); | 58 tracker_.OnEmbed(connection_id, root.Pass()); |
| 59 } | 59 } |
| 60 void OnEmbeddedAppDisconnected(uint32_t view) override { | 60 void OnEmbeddedAppDisconnected(uint32_t view) override { |
| 61 tracker_.OnEmbeddedAppDisconnected(view); | 61 tracker_.OnEmbeddedAppDisconnected(view); |
| 62 } | 62 } |
| 63 void OnUnembed() override { tracker_.OnUnembed(); } | 63 void OnUnembed() override { tracker_.OnUnembed(); } |
| 64 void OnViewBoundsChanged(uint32_t view, | 64 void OnViewBoundsChanged(uint32_t view, |
| 65 mojo::RectPtr old_bounds, | 65 mojo::RectPtr old_bounds, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 | 141 |
| 142 TestClientConnection* last_connection() { return last_connection_; } | 142 TestClientConnection* last_connection() { return last_connection_; } |
| 143 | 143 |
| 144 private: | 144 private: |
| 145 // ConnectionManagerDelegate: | 145 // ConnectionManagerDelegate: |
| 146 void OnNoMoreRootConnections() override {} | 146 void OnNoMoreRootConnections() override {} |
| 147 | 147 |
| 148 ClientConnection* CreateClientConnectionForEmbedAtView( | 148 ClientConnection* CreateClientConnectionForEmbedAtView( |
| 149 ConnectionManager* connection_manager, | 149 ConnectionManager* connection_manager, |
| 150 mojo::InterfaceRequest<mojo::ViewTree> service_request, | 150 mojo::InterfaceRequest<mojo::ViewTree> service_request, |
| 151 mojo::ConnectionSpecificId creator_id, | 151 ConnectionSpecificId creator_id, |
| 152 mojo::URLRequestPtr request, | 152 mojo::URLRequestPtr request, |
| 153 const ViewId& root_id) override { | 153 const ViewId& root_id) override { |
| 154 scoped_ptr<ViewTreeImpl> service( | 154 scoped_ptr<ViewTreeImpl> service( |
| 155 new ViewTreeImpl(connection_manager, creator_id, root_id)); | 155 new ViewTreeImpl(connection_manager, creator_id, root_id)); |
| 156 last_connection_ = new TestClientConnection(service.Pass()); | 156 last_connection_ = new TestClientConnection(service.Pass()); |
| 157 return last_connection_; | 157 return last_connection_; |
| 158 } | 158 } |
| 159 ClientConnection* CreateClientConnectionForEmbedAtView( | 159 ClientConnection* CreateClientConnectionForEmbedAtView( |
| 160 ConnectionManager* connection_manager, | 160 ConnectionManager* connection_manager, |
| 161 mojo::InterfaceRequest<mojo::ViewTree> service_request, | 161 mojo::InterfaceRequest<mojo::ViewTree> service_request, |
| 162 mojo::ConnectionSpecificId creator_id, | 162 ConnectionSpecificId creator_id, |
| 163 const ViewId& root_id, | 163 const ViewId& root_id, |
| 164 mojo::ViewTreeClientPtr client) override { | 164 mojo::ViewTreeClientPtr client) override { |
| 165 // Used by ConnectionManager::AddRoot. | 165 // Used by ConnectionManager::AddRoot. |
| 166 scoped_ptr<ViewTreeImpl> service( | 166 scoped_ptr<ViewTreeImpl> service( |
| 167 new ViewTreeImpl(connection_manager, creator_id, root_id)); | 167 new ViewTreeImpl(connection_manager, creator_id, root_id)); |
| 168 last_connection_ = new TestClientConnection(service.Pass()); | 168 last_connection_ = new TestClientConnection(service.Pass()); |
| 169 return last_connection_; | 169 return last_connection_; |
| 170 } | 170 } |
| 171 | 171 |
| 172 TestClientConnection* last_connection_; | 172 TestClientConnection* last_connection_; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 }; | 228 }; |
| 229 | 229 |
| 230 // Factory that dispenses TestDisplayManagers. | 230 // Factory that dispenses TestDisplayManagers. |
| 231 class TestDisplayManagerFactory : public DisplayManagerFactory { | 231 class TestDisplayManagerFactory : public DisplayManagerFactory { |
| 232 public: | 232 public: |
| 233 TestDisplayManagerFactory() {} | 233 TestDisplayManagerFactory() {} |
| 234 ~TestDisplayManagerFactory() {} | 234 ~TestDisplayManagerFactory() {} |
| 235 DisplayManager* CreateDisplayManager( | 235 DisplayManager* CreateDisplayManager( |
| 236 bool is_headless, | 236 bool is_headless, |
| 237 mojo::ApplicationImpl* app_impl, | 237 mojo::ApplicationImpl* app_impl, |
| 238 const scoped_refptr<gles2::GpuState>& gpu_state, | 238 const scoped_refptr<GpuState>& gpu_state, |
| 239 const scoped_refptr<surfaces::SurfacesState>& surfaces_state) override { | 239 const scoped_refptr<SurfacesState>& surfaces_state) override { |
| 240 return new TestDisplayManager(); | 240 return new TestDisplayManager(); |
| 241 } | 241 } |
| 242 | 242 |
| 243 private: | 243 private: |
| 244 DISALLOW_COPY_AND_ASSIGN(TestDisplayManagerFactory); | 244 DISALLOW_COPY_AND_ASSIGN(TestDisplayManagerFactory); |
| 245 }; | 245 }; |
| 246 | 246 |
| 247 mojo::EventPtr CreatePointerDownEvent(int x, int y) { | 247 mojo::EventPtr CreatePointerDownEvent(int x, int y) { |
| 248 mojo::EventPtr event(mojo::Event::New()); | 248 mojo::EventPtr event(mojo::Event::New()); |
| 249 event->action = mojo::EVENT_TYPE_POINTER_DOWN; | 249 event->action = mojo::EVENT_TYPE_POINTER_DOWN; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 TestViewTreeHostConnection* host_connection() { return host_connection_; } | 293 TestViewTreeHostConnection* host_connection() { return host_connection_; } |
| 294 DisplayManagerDelegate* display_manager_delegate() { | 294 DisplayManagerDelegate* display_manager_delegate() { |
| 295 return host_connection()->view_tree_host(); | 295 return host_connection()->view_tree_host(); |
| 296 } | 296 } |
| 297 | 297 |
| 298 protected: | 298 protected: |
| 299 // testing::Test: | 299 // testing::Test: |
| 300 void SetUp() override { | 300 void SetUp() override { |
| 301 DisplayManager::set_factory_for_testing(&display_manager_factory_); | 301 DisplayManager::set_factory_for_testing(&display_manager_factory_); |
| 302 // TODO(fsamuel): This is probably broken. We need a root. | 302 // TODO(fsamuel): This is probably broken. We need a root. |
| 303 connection_manager_.reset(new ConnectionManager( | 303 connection_manager_.reset( |
| 304 &delegate_, scoped_refptr<surfaces::SurfacesState>())); | 304 new ConnectionManager(&delegate_, scoped_refptr<SurfacesState>())); |
| 305 ViewTreeHostImpl* host = new ViewTreeHostImpl( | 305 ViewTreeHostImpl* host = new ViewTreeHostImpl( |
| 306 mojo::ViewTreeHostClientPtr(), connection_manager_.get(), | 306 mojo::ViewTreeHostClientPtr(), connection_manager_.get(), |
| 307 true /* is_headless */, nullptr, scoped_refptr<gles2::GpuState>(), | 307 true /* is_headless */, nullptr, scoped_refptr<GpuState>(), |
| 308 scoped_refptr<surfaces::SurfacesState>()); | 308 scoped_refptr<SurfacesState>()); |
| 309 // TODO(fsamuel): This is way too magical. We need to find a better way to | 309 // TODO(fsamuel): This is way too magical. We need to find a better way to |
| 310 // manage lifetime. | 310 // manage lifetime. |
| 311 host_connection_ = new TestViewTreeHostConnection( | 311 host_connection_ = new TestViewTreeHostConnection( |
| 312 make_scoped_ptr(host), connection_manager_.get()); | 312 make_scoped_ptr(host), connection_manager_.get()); |
| 313 host->Init(host_connection_); | 313 host->Init(host_connection_); |
| 314 wm_client_ = delegate_.last_client(); | 314 wm_client_ = delegate_.last_client(); |
| 315 } | 315 } |
| 316 | 316 |
| 317 private: | 317 private: |
| 318 // TestViewTreeClient that is used for the WM connection. | 318 // TestViewTreeClient that is used for the WM connection. |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); | 438 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); |
| 439 EXPECT_EQ("Focused id=2,1", | 439 EXPECT_EQ("Focused id=2,1", |
| 440 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); | 440 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); |
| 441 ASSERT_EQ(2u, embed_connection->tracker()->changes()->size()); | 441 ASSERT_EQ(2u, embed_connection->tracker()->changes()->size()); |
| 442 EXPECT_EQ("Focused id=2,1", | 442 EXPECT_EQ("Focused id=2,1", |
| 443 ChangesToDescription1(*embed_connection->tracker()->changes())[0]); | 443 ChangesToDescription1(*embed_connection->tracker()->changes())[0]); |
| 444 EXPECT_EQ("InputEvent view=2,1 event_action=4", | 444 EXPECT_EQ("InputEvent view=2,1 event_action=4", |
| 445 ChangesToDescription1(*embed_connection->tracker()->changes())[1]); | 445 ChangesToDescription1(*embed_connection->tracker()->changes())[1]); |
| 446 } | 446 } |
| 447 | 447 |
| 448 } // namespace view_manager | 448 } // namespace mus |
| OLD | NEW |