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/view_manager/client_connection.h" | 9 #include "components/view_manager/client_connection.h" |
10 #include "components/view_manager/connection_manager.h" | 10 #include "components/view_manager/connection_manager.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 class TestViewManagerClient : public mojo::ViewManagerClient { | 40 class TestViewManagerClient : public mojo::ViewManagerClient { |
41 public: | 41 public: |
42 TestViewManagerClient() {} | 42 TestViewManagerClient() {} |
43 ~TestViewManagerClient() override {} | 43 ~TestViewManagerClient() override {} |
44 | 44 |
45 TestChangeTracker* tracker() { return &tracker_; } | 45 TestChangeTracker* tracker() { return &tracker_; } |
46 | 46 |
47 private: | 47 private: |
48 // ViewManagerClient: | 48 // ViewManagerClient: |
49 void OnEmbed(uint16_t connection_id, | 49 void OnEmbed(uint16_t connection_id, |
50 const String& embedder_url, | |
51 ViewDataPtr root, | 50 ViewDataPtr root, |
52 mojo::ViewManagerServicePtr view_manager_service, | 51 mojo::ViewManagerServicePtr view_manager_service, |
53 InterfaceRequest<ServiceProvider> services, | |
54 ServiceProviderPtr exposed_services, | |
55 mojo::Id focused_view_id) override { | 52 mojo::Id focused_view_id) override { |
56 // TODO(sky): add test coverage of |focused_view_id|. | 53 // TODO(sky): add test coverage of |focused_view_id|. |
57 tracker_.OnEmbed(connection_id, embedder_url, root.Pass()); | 54 tracker_.OnEmbed(connection_id, root.Pass()); |
58 } | 55 } |
59 void OnWillEmbed(uint32_t view, | 56 void OnEmbedForDescendant( |
60 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 57 uint32_t view, |
61 mojo::ServiceProviderPtr exposed_services, | 58 mojo::URLRequestPtr request, |
62 const OnWillEmbedCallback& callback) override {} | 59 const OnEmbedForDescendantCallback& callback) override {} |
63 void OnEmbeddedAppDisconnected(uint32_t view) override { | 60 void OnEmbeddedAppDisconnected(uint32_t view) override { |
64 tracker_.OnEmbeddedAppDisconnected(view); | 61 tracker_.OnEmbeddedAppDisconnected(view); |
65 } | 62 } |
66 void OnViewBoundsChanged(uint32_t view, | 63 void OnViewBoundsChanged(uint32_t view, |
67 mojo::RectPtr old_bounds, | 64 mojo::RectPtr old_bounds, |
68 mojo::RectPtr new_bounds) override { | 65 mojo::RectPtr new_bounds) override { |
69 tracker_.OnViewBoundsChanged(view, old_bounds.Pass(), new_bounds.Pass()); | 66 tracker_.OnViewBoundsChanged(view, old_bounds.Pass(), new_bounds.Pass()); |
70 } | 67 } |
71 void OnViewViewportMetricsChanged( | 68 void OnViewViewportMetricsChanged( |
72 mojo::ViewportMetricsPtr old_metrics, | 69 mojo::ViewportMetricsPtr old_metrics, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 TestClientConnection* last_connection() { return last_connection_; } | 140 TestClientConnection* last_connection() { return last_connection_; } |
144 | 141 |
145 private: | 142 private: |
146 // ConnectionManagerDelegate: | 143 // ConnectionManagerDelegate: |
147 void OnLostConnectionToWindowManager() override {} | 144 void OnLostConnectionToWindowManager() override {} |
148 | 145 |
149 ClientConnection* CreateClientConnectionForEmbedAtView( | 146 ClientConnection* CreateClientConnectionForEmbedAtView( |
150 ConnectionManager* connection_manager, | 147 ConnectionManager* connection_manager, |
151 mojo::InterfaceRequest<mojo::ViewManagerService> service_request, | 148 mojo::InterfaceRequest<mojo::ViewManagerService> service_request, |
152 mojo::ConnectionSpecificId creator_id, | 149 mojo::ConnectionSpecificId creator_id, |
153 const std::string& creator_url, | |
154 mojo::URLRequestPtr request, | 150 mojo::URLRequestPtr request, |
155 const ViewId& root_id) override { | 151 const ViewId& root_id) override { |
156 scoped_ptr<ViewManagerServiceImpl> service(new ViewManagerServiceImpl( | 152 scoped_ptr<ViewManagerServiceImpl> service( |
157 connection_manager, creator_id, creator_url, request->url, root_id)); | 153 new ViewManagerServiceImpl(connection_manager, creator_id, root_id)); |
158 last_connection_ = new TestClientConnection(service.Pass()); | 154 last_connection_ = new TestClientConnection(service.Pass()); |
159 return last_connection_; | 155 return last_connection_; |
160 } | 156 } |
161 ClientConnection* CreateClientConnectionForEmbedAtView( | 157 ClientConnection* CreateClientConnectionForEmbedAtView( |
162 ConnectionManager* connection_manager, | 158 ConnectionManager* connection_manager, |
163 mojo::InterfaceRequest<mojo::ViewManagerService> service_request, | 159 mojo::InterfaceRequest<mojo::ViewManagerService> service_request, |
164 mojo::ConnectionSpecificId creator_id, | 160 mojo::ConnectionSpecificId creator_id, |
165 const std::string& creator_url, | |
166 const ViewId& root_id, | 161 const ViewId& root_id, |
167 mojo::ViewManagerClientPtr client) override { | 162 mojo::ViewManagerClientPtr client) override { |
168 NOTIMPLEMENTED(); | 163 NOTIMPLEMENTED(); |
169 return nullptr; | 164 return nullptr; |
170 } | 165 } |
171 | 166 |
172 TestClientConnection* last_connection_; | 167 TestClientConnection* last_connection_; |
173 | 168 |
174 DISALLOW_COPY_AND_ASSIGN(TestConnectionManagerDelegate); | 169 DISALLOW_COPY_AND_ASSIGN(TestConnectionManagerDelegate); |
175 }; | 170 }; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 ConnectionManager* connection_manager() { return connection_manager_.get(); } | 238 ConnectionManager* connection_manager() { return connection_manager_.get(); } |
244 | 239 |
245 TestViewManagerClient* wm_client() { return wm_client_; } | 240 TestViewManagerClient* wm_client() { return wm_client_; } |
246 | 241 |
247 protected: | 242 protected: |
248 // testing::Test: | 243 // testing::Test: |
249 void SetUp() override { | 244 void SetUp() override { |
250 connection_manager_.reset(new ConnectionManager( | 245 connection_manager_.reset(new ConnectionManager( |
251 &delegate_, scoped_ptr<DisplayManager>(new TestDisplayManager))); | 246 &delegate_, scoped_ptr<DisplayManager>(new TestDisplayManager))); |
252 scoped_ptr<ViewManagerServiceImpl> service(new ViewManagerServiceImpl( | 247 scoped_ptr<ViewManagerServiceImpl> service(new ViewManagerServiceImpl( |
253 connection_manager_.get(), kInvalidConnectionId, std::string(), | 248 connection_manager_.get(), kInvalidConnectionId, RootViewId())); |
254 std::string("mojo:window_manager"), RootViewId())); | |
255 scoped_ptr<TestClientConnection> client_connection( | 249 scoped_ptr<TestClientConnection> client_connection( |
256 new TestClientConnection(service.Pass())); | 250 new TestClientConnection(service.Pass())); |
257 wm_client_ = client_connection->client(); | 251 wm_client_ = client_connection->client(); |
258 ASSERT_TRUE(wm_client_ != nullptr); | 252 ASSERT_TRUE(wm_client_ != nullptr); |
259 connection_manager_->SetWindowManagerClientConnection( | 253 connection_manager_->SetWindowManagerClientConnection( |
260 client_connection.Pass()); | 254 client_connection.Pass()); |
261 ASSERT_TRUE(wm_connection() != nullptr); | 255 ASSERT_TRUE(wm_connection() != nullptr); |
262 ASSERT_TRUE(wm_connection()->root() != nullptr); | 256 ASSERT_TRUE(wm_connection()->root() != nullptr); |
263 } | 257 } |
264 | 258 |
(...skipping 25 matching lines...) Expand all Loading... |
290 // 2,2 bounds=2,3 6x7 | 284 // 2,2 bounds=2,3 6x7 |
291 // 2,3 bounds=3,4 6x7 | 285 // 2,3 bounds=3,4 6x7 |
292 // CloneAndAnimate() is invoked for 2,2. | 286 // CloneAndAnimate() is invoked for 2,2. |
293 void SetUpAnimate1(ViewManagerServiceTest* test, ViewId* embed_view_id) { | 287 void SetUpAnimate1(ViewManagerServiceTest* test, ViewId* embed_view_id) { |
294 *embed_view_id = ViewId(test->wm_connection()->id(), 1); | 288 *embed_view_id = ViewId(test->wm_connection()->id(), 1); |
295 EXPECT_EQ(ERROR_CODE_NONE, test->wm_connection()->CreateView(*embed_view_id)); | 289 EXPECT_EQ(ERROR_CODE_NONE, test->wm_connection()->CreateView(*embed_view_id)); |
296 EXPECT_TRUE(test->wm_connection()->SetViewVisibility(*embed_view_id, true)); | 290 EXPECT_TRUE(test->wm_connection()->SetViewVisibility(*embed_view_id, true)); |
297 EXPECT_TRUE(test->wm_connection()->AddView(*(test->wm_connection()->root()), | 291 EXPECT_TRUE(test->wm_connection()->AddView(*(test->wm_connection()->root()), |
298 *embed_view_id)); | 292 *embed_view_id)); |
299 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 293 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
300 test->wm_connection()->Embed(request.Pass(), *embed_view_id, | 294 test->wm_connection()->EmbedAllowingReembed(*embed_view_id, request.Pass(), |
301 ViewManagerServiceImpl::EmbedType::NO_REEMBED, | 295 mojo::Callback<void(bool)>()); |
302 nullptr, nullptr, mojo::Callback<void(bool)>()); | |
303 ViewManagerServiceImpl* connection1 = | 296 ViewManagerServiceImpl* connection1 = |
304 test->connection_manager()->GetConnectionWithRoot(*embed_view_id); | 297 test->connection_manager()->GetConnectionWithRoot(*embed_view_id); |
305 ASSERT_TRUE(connection1 != nullptr); | 298 ASSERT_TRUE(connection1 != nullptr); |
306 ASSERT_NE(connection1, test->wm_connection()); | 299 ASSERT_NE(connection1, test->wm_connection()); |
307 | 300 |
308 const ViewId child1(connection1->id(), 1); | 301 const ViewId child1(connection1->id(), 1); |
309 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child1)); | 302 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child1)); |
310 const ViewId child2(connection1->id(), 2); | 303 const ViewId child2(connection1->id(), 2); |
311 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child2)); | 304 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child2)); |
312 const ViewId child3(connection1->id(), 3); | 305 const ViewId child3(connection1->id(), 3); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 | 422 |
430 // Clone and animate on a tree with more depth. Basically that of | 423 // Clone and animate on a tree with more depth. Basically that of |
431 // SetUpAnimate1() but cloning 2,1. | 424 // SetUpAnimate1() but cloning 2,1. |
432 TEST_F(ViewManagerServiceTest, CloneAndAnimateLargerDepth) { | 425 TEST_F(ViewManagerServiceTest, CloneAndAnimateLargerDepth) { |
433 const ViewId embed_view_id(wm_connection()->id(), 1); | 426 const ViewId embed_view_id(wm_connection()->id(), 1); |
434 EXPECT_EQ(ERROR_CODE_NONE, wm_connection()->CreateView(embed_view_id)); | 427 EXPECT_EQ(ERROR_CODE_NONE, wm_connection()->CreateView(embed_view_id)); |
435 EXPECT_TRUE(wm_connection()->SetViewVisibility(embed_view_id, true)); | 428 EXPECT_TRUE(wm_connection()->SetViewVisibility(embed_view_id, true)); |
436 EXPECT_TRUE( | 429 EXPECT_TRUE( |
437 wm_connection()->AddView(*(wm_connection()->root()), embed_view_id)); | 430 wm_connection()->AddView(*(wm_connection()->root()), embed_view_id)); |
438 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 431 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
439 wm_connection()->Embed(request.Pass(), embed_view_id, | 432 wm_connection()->EmbedAllowingReembed(embed_view_id, request.Pass(), |
440 ViewManagerServiceImpl::EmbedType::NO_REEMBED, nullptr, | 433 mojo::Callback<void(bool)>()); |
441 nullptr, mojo::Callback<void(bool)>()); | |
442 ViewManagerServiceImpl* connection1 = | 434 ViewManagerServiceImpl* connection1 = |
443 connection_manager()->GetConnectionWithRoot(embed_view_id); | 435 connection_manager()->GetConnectionWithRoot(embed_view_id); |
444 ASSERT_TRUE(connection1 != nullptr); | 436 ASSERT_TRUE(connection1 != nullptr); |
445 ASSERT_NE(connection1, wm_connection()); | 437 ASSERT_NE(connection1, wm_connection()); |
446 | 438 |
447 const ViewId child1(connection1->id(), 1); | 439 const ViewId child1(connection1->id(), 1); |
448 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child1)); | 440 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child1)); |
449 const ViewId child2(connection1->id(), 2); | 441 const ViewId child2(connection1->id(), 2); |
450 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child2)); | 442 EXPECT_EQ(ERROR_CODE_NONE, connection1->CreateView(child2)); |
451 const ViewId child3(connection1->id(), 3); | 443 const ViewId child3(connection1->id(), 3); |
(...skipping 27 matching lines...) Expand all Loading... |
479 | 471 |
480 // Verifies focus correctly changes on pointer events. | 472 // Verifies focus correctly changes on pointer events. |
481 TEST_F(ViewManagerServiceTest, FocusOnPointer) { | 473 TEST_F(ViewManagerServiceTest, FocusOnPointer) { |
482 const ViewId embed_view_id(wm_connection()->id(), 1); | 474 const ViewId embed_view_id(wm_connection()->id(), 1); |
483 EXPECT_EQ(ERROR_CODE_NONE, wm_connection()->CreateView(embed_view_id)); | 475 EXPECT_EQ(ERROR_CODE_NONE, wm_connection()->CreateView(embed_view_id)); |
484 EXPECT_TRUE(wm_connection()->SetViewVisibility(embed_view_id, true)); | 476 EXPECT_TRUE(wm_connection()->SetViewVisibility(embed_view_id, true)); |
485 EXPECT_TRUE( | 477 EXPECT_TRUE( |
486 wm_connection()->AddView(*(wm_connection()->root()), embed_view_id)); | 478 wm_connection()->AddView(*(wm_connection()->root()), embed_view_id)); |
487 connection_manager()->root()->SetBounds(gfx::Rect(0, 0, 100, 100)); | 479 connection_manager()->root()->SetBounds(gfx::Rect(0, 0, 100, 100)); |
488 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 480 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
489 wm_connection()->Embed(request.Pass(), embed_view_id, | 481 wm_connection()->EmbedAllowingReembed(embed_view_id, request.Pass(), |
490 ViewManagerServiceImpl::EmbedType::NO_REEMBED, nullptr, | 482 mojo::Callback<void(bool)>()); |
491 nullptr, mojo::Callback<void(bool)>()); | |
492 ViewManagerServiceImpl* connection1 = | 483 ViewManagerServiceImpl* connection1 = |
493 connection_manager()->GetConnectionWithRoot(embed_view_id); | 484 connection_manager()->GetConnectionWithRoot(embed_view_id); |
494 ASSERT_TRUE(connection1 != nullptr); | 485 ASSERT_TRUE(connection1 != nullptr); |
495 ASSERT_NE(connection1, wm_connection()); | 486 ASSERT_NE(connection1, wm_connection()); |
496 | 487 |
497 connection_manager() | 488 connection_manager() |
498 ->GetView(embed_view_id) | 489 ->GetView(embed_view_id) |
499 ->SetBounds(gfx::Rect(0, 0, 50, 50)); | 490 ->SetBounds(gfx::Rect(0, 0, 50, 50)); |
500 | 491 |
501 const ViewId child1(connection1->id(), 1); | 492 const ViewId child1(connection1->id(), 1); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 EXPECT_EQ(connection_manager()->root(), | 540 EXPECT_EQ(connection_manager()->root(), |
550 connection_manager()->GetFocusedView()); | 541 connection_manager()->GetFocusedView()); |
551 ASSERT_EQ(wm_client()->tracker()->changes()->size(), 1u); | 542 ASSERT_EQ(wm_client()->tracker()->changes()->size(), 1u); |
552 EXPECT_EQ("InputEvent view=0,1 event_action=4", | 543 EXPECT_EQ("InputEvent view=0,1 event_action=4", |
553 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); | 544 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); |
554 EXPECT_TRUE(connection1_client->tracker()->changes()->empty()); | 545 EXPECT_TRUE(connection1_client->tracker()->changes()->empty()); |
555 ; | 546 ; |
556 } | 547 } |
557 | 548 |
558 } // namespace view_manager | 549 } // namespace view_manager |
OLD | NEW |