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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "components/view_manager/ids.h" | 8 #include "components/view_manager/ids.h" |
9 #include "components/view_manager/public/interfaces/view_manager.mojom.h" | 9 #include "components/view_manager/public/interfaces/view_manager.mojom.h" |
10 #include "components/view_manager/public/interfaces/view_manager_root.mojom.h" | 10 #include "components/view_manager/public/interfaces/view_manager_root.mojom.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 void ViewTreeResultCallback(base::RunLoop* run_loop, | 62 void ViewTreeResultCallback(base::RunLoop* run_loop, |
63 std::vector<TestView>* views, | 63 std::vector<TestView>* views, |
64 Array<ViewDataPtr> results) { | 64 Array<ViewDataPtr> results) { |
65 ViewDatasToTestViews(results, views); | 65 ViewDatasToTestViews(results, views); |
66 run_loop->Quit(); | 66 run_loop->Quit(); |
67 } | 67 } |
68 | 68 |
69 // ----------------------------------------------------------------------------- | 69 // ----------------------------------------------------------------------------- |
70 | 70 |
71 // The following functions call through to the supplied ViewManagerService. They | 71 // The following functions call through to the supplied ViewManagerService. They |
72 // block until call completes and return the result. | 72 // block until the call completes and return the result. |
73 bool CreateView(ViewManagerService* vm, Id view_id) { | 73 bool CreateView(ViewManagerService* vm, Id view_id) { |
74 ErrorCode result = ERROR_CODE_NONE; | 74 ErrorCode result = ERROR_CODE_NONE; |
75 base::RunLoop run_loop; | 75 base::RunLoop run_loop; |
76 vm->CreateView(view_id, | 76 vm->CreateView(view_id, |
77 base::Bind(&ErrorCodeResultCallback, &run_loop, &result)); | 77 base::Bind(&ErrorCodeResultCallback, &run_loop, &result)); |
78 run_loop.Run(); | 78 run_loop.Run(); |
79 return result == ERROR_CODE_NONE; | 79 return result == ERROR_CODE_NONE; |
80 } | 80 } |
81 | 81 |
82 bool EmbedUrl(ViewManagerService* vm, const String& url, Id root_id) { | 82 bool EmbedUrl(mojo::ApplicationImpl* app, |
| 83 ViewManagerService* vm, |
| 84 const String& url, |
| 85 Id root_id) { |
83 bool result = false; | 86 bool result = false; |
84 base::RunLoop run_loop; | 87 base::RunLoop run_loop; |
85 { | 88 { |
86 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 89 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
87 request->url = mojo::String::From(url); | 90 request->url = mojo::String::From(url); |
88 vm->EmbedRequest(request.Pass(), root_id, nullptr, nullptr, | 91 ApplicationConnection* connection = |
89 base::Bind(&BoolResultCallback, &run_loop, &result)); | 92 app->ConnectToApplication(request.Pass()); |
| 93 mojo::ViewManagerClientPtr client; |
| 94 connection->ConnectToService(&client); |
| 95 vm->Embed(root_id, client.Pass(), |
| 96 base::Bind(&BoolResultCallback, &run_loop, &result)); |
90 } | 97 } |
91 run_loop.Run(); | 98 run_loop.Run(); |
92 return result; | 99 return result; |
| 100 } |
| 101 |
| 102 bool EmbedAllowingReembed(mojo::ApplicationImpl* app, |
| 103 ViewManagerService* vm, |
| 104 const String& url, |
| 105 Id root_id) { |
| 106 bool result = false; |
| 107 base::RunLoop run_loop; |
| 108 { |
| 109 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
| 110 request->url = mojo::String::From(url); |
| 111 vm->EmbedAllowingReembed( |
| 112 root_id, request.Pass(), |
| 113 base::Bind(&BoolResultCallback, &run_loop, &result)); |
| 114 } |
| 115 run_loop.Run(); |
| 116 return result; |
93 } | 117 } |
94 | 118 |
95 bool Embed(ViewManagerService* vm, | 119 bool Embed(ViewManagerService* vm, |
96 Id root_id, | 120 Id root_id, |
97 mojo::ViewManagerClientPtr client) { | 121 mojo::ViewManagerClientPtr client) { |
98 bool result = false; | 122 bool result = false; |
99 base::RunLoop run_loop; | 123 base::RunLoop run_loop; |
100 { | 124 { |
101 vm->Embed(root_id, client.Pass(), | 125 vm->Embed(root_id, client.Pass(), |
102 base::Bind(&BoolResultCallback, &run_loop, &result)); | 126 base::Bind(&BoolResultCallback, &run_loop, &result)); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 return true; | 248 return true; |
225 return false; | 249 return false; |
226 } | 250 } |
227 | 251 |
228 // ----------------------------------------------------------------------------- | 252 // ----------------------------------------------------------------------------- |
229 | 253 |
230 // A ViewManagerClient implementation that logs all changes to a tracker. | 254 // A ViewManagerClient implementation that logs all changes to a tracker. |
231 class ViewManagerClientImpl : public mojo::ViewManagerClient, | 255 class ViewManagerClientImpl : public mojo::ViewManagerClient, |
232 public TestChangeTracker::Delegate { | 256 public TestChangeTracker::Delegate { |
233 public: | 257 public: |
234 ViewManagerClientImpl() : binding_(this) { tracker_.set_delegate(this); } | 258 explicit ViewManagerClientImpl(mojo::ApplicationImpl* app) |
| 259 : binding_(this), app_(app) { |
| 260 tracker_.set_delegate(this); |
| 261 } |
235 | 262 |
236 void Bind(mojo::InterfaceRequest<mojo::ViewManagerClient> request) { | 263 void Bind(mojo::InterfaceRequest<mojo::ViewManagerClient> request) { |
237 binding_.Bind(request.Pass()); | 264 binding_.Bind(request.Pass()); |
238 } | 265 } |
239 | 266 |
240 mojo::ViewManagerService* service() { return service_.get(); } | 267 mojo::ViewManagerService* service() { return service_.get(); } |
241 TestChangeTracker* tracker() { return &tracker_; } | 268 TestChangeTracker* tracker() { return &tracker_; } |
242 | 269 |
243 // Runs a nested MessageLoop until |count| changes (calls to | 270 // Runs a nested MessageLoop until |count| changes (calls to |
244 // ViewManagerClient functions) have been received. | 271 // ViewManagerClient functions) have been received. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 // TestChangeTracker::Delegate: | 306 // TestChangeTracker::Delegate: |
280 void OnChangeAdded() override { | 307 void OnChangeAdded() override { |
281 if (wait_state_.get() && | 308 if (wait_state_.get() && |
282 wait_state_->change_count == tracker_.changes()->size()) { | 309 wait_state_->change_count == tracker_.changes()->size()) { |
283 wait_state_->run_loop.Quit(); | 310 wait_state_->run_loop.Quit(); |
284 } | 311 } |
285 } | 312 } |
286 | 313 |
287 // ViewManagerClient: | 314 // ViewManagerClient: |
288 void OnEmbed(ConnectionSpecificId connection_id, | 315 void OnEmbed(ConnectionSpecificId connection_id, |
289 const String& creator_url, | |
290 ViewDataPtr root, | 316 ViewDataPtr root, |
291 mojo::ViewManagerServicePtr view_manager_service, | 317 mojo::ViewManagerServicePtr view_manager_service, |
292 InterfaceRequest<ServiceProvider> services, | |
293 ServiceProviderPtr exposed_services, | |
294 mojo::Id focused_view_id) override { | 318 mojo::Id focused_view_id) override { |
295 // TODO(sky): add coverage of |focused_view_id|. | 319 // TODO(sky): add coverage of |focused_view_id|. |
296 service_ = view_manager_service.Pass(); | 320 service_ = view_manager_service.Pass(); |
297 tracker()->OnEmbed(connection_id, creator_url, root.Pass()); | 321 tracker()->OnEmbed(connection_id, root.Pass()); |
298 if (embed_run_loop_) | 322 if (embed_run_loop_) |
299 embed_run_loop_->Quit(); | 323 embed_run_loop_->Quit(); |
300 } | 324 } |
301 void OnWillEmbed(uint32_t view, | 325 void OnEmbedForDescendant( |
302 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 326 uint32_t view, |
303 mojo::ServiceProviderPtr exposed_services, | 327 mojo::URLRequestPtr request, |
304 const OnWillEmbedCallback& callback) override { | 328 const OnEmbedForDescendantCallback& callback) override { |
305 tracker()->OnWillEmbed(view); | 329 tracker()->OnEmbedForDescendant(view); |
306 callback.Run(true, services.Pass(), exposed_services.Pass()); | 330 mojo::ViewManagerClientPtr client; |
| 331 ApplicationConnection* connection = |
| 332 app_->ConnectToApplication(request.Pass()); |
| 333 connection->ConnectToService(&client); |
| 334 callback.Run(client.Pass()); |
307 } | 335 } |
308 void OnEmbeddedAppDisconnected(Id view_id) override { | 336 void OnEmbeddedAppDisconnected(Id view_id) override { |
309 tracker()->OnEmbeddedAppDisconnected(view_id); | 337 tracker()->OnEmbeddedAppDisconnected(view_id); |
310 } | 338 } |
311 void OnViewBoundsChanged(Id view_id, | 339 void OnViewBoundsChanged(Id view_id, |
312 RectPtr old_bounds, | 340 RectPtr old_bounds, |
313 RectPtr new_bounds) override { | 341 RectPtr new_bounds) override { |
314 tracker()->OnViewBoundsChanged(view_id, old_bounds.Pass(), | 342 tracker()->OnViewBoundsChanged(view_id, old_bounds.Pass(), |
315 new_bounds.Pass()); | 343 new_bounds.Pass()); |
316 } | 344 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 mojo::ViewManagerServicePtr service_; | 385 mojo::ViewManagerServicePtr service_; |
358 | 386 |
359 // If non-null we're waiting for OnEmbed() using this RunLoop. | 387 // If non-null we're waiting for OnEmbed() using this RunLoop. |
360 scoped_ptr<base::RunLoop> embed_run_loop_; | 388 scoped_ptr<base::RunLoop> embed_run_loop_; |
361 | 389 |
362 // If non-null we're waiting for a certain number of change notifications to | 390 // If non-null we're waiting for a certain number of change notifications to |
363 // be encountered. | 391 // be encountered. |
364 scoped_ptr<WaitState> wait_state_; | 392 scoped_ptr<WaitState> wait_state_; |
365 | 393 |
366 mojo::Binding<ViewManagerClient> binding_; | 394 mojo::Binding<ViewManagerClient> binding_; |
| 395 mojo::ApplicationImpl* app_; |
| 396 |
367 DISALLOW_COPY_AND_ASSIGN(ViewManagerClientImpl); | 397 DISALLOW_COPY_AND_ASSIGN(ViewManagerClientImpl); |
368 }; | 398 }; |
369 | 399 |
370 // ----------------------------------------------------------------------------- | 400 // ----------------------------------------------------------------------------- |
371 | 401 |
372 // InterfaceFactory for vending ViewManagerClientImpls. | 402 // InterfaceFactory for vending ViewManagerClientImpls. |
373 class ViewManagerClientFactory | 403 class ViewManagerClientFactory |
374 : public mojo::InterfaceFactory<ViewManagerClient> { | 404 : public mojo::InterfaceFactory<ViewManagerClient> { |
375 public: | 405 public: |
376 ViewManagerClientFactory() {} | 406 explicit ViewManagerClientFactory(mojo::ApplicationImpl* app) : app_(app) {} |
377 ~ViewManagerClientFactory() override {} | 407 ~ViewManagerClientFactory() override {} |
378 | 408 |
379 // Runs a nested MessageLoop until a new instance has been created. | 409 // Runs a nested MessageLoop until a new instance has been created. |
380 scoped_ptr<ViewManagerClientImpl> WaitForInstance() { | 410 scoped_ptr<ViewManagerClientImpl> WaitForInstance() { |
381 if (!client_impl_.get()) { | 411 if (!client_impl_.get()) { |
382 DCHECK(!run_loop_.get()); | 412 DCHECK(!run_loop_.get()); |
383 run_loop_.reset(new base::RunLoop); | 413 run_loop_.reset(new base::RunLoop); |
384 run_loop_->Run(); | 414 run_loop_->Run(); |
385 run_loop_.reset(); | 415 run_loop_.reset(); |
386 } | 416 } |
387 return client_impl_.Pass(); | 417 return client_impl_.Pass(); |
388 } | 418 } |
389 | 419 |
390 private: | 420 private: |
391 // InterfaceFactory<ViewManagerClient>: | 421 // InterfaceFactory<ViewManagerClient>: |
392 void Create(ApplicationConnection* connection, | 422 void Create(ApplicationConnection* connection, |
393 InterfaceRequest<ViewManagerClient> request) override { | 423 InterfaceRequest<ViewManagerClient> request) override { |
394 client_impl_.reset(new ViewManagerClientImpl); | 424 client_impl_.reset(new ViewManagerClientImpl(app_)); |
395 client_impl_->Bind(request.Pass()); | 425 client_impl_->Bind(request.Pass()); |
396 if (run_loop_.get()) | 426 if (run_loop_.get()) |
397 run_loop_->Quit(); | 427 run_loop_->Quit(); |
398 } | 428 } |
399 | 429 |
| 430 mojo::ApplicationImpl* app_; |
400 scoped_ptr<ViewManagerClientImpl> client_impl_; | 431 scoped_ptr<ViewManagerClientImpl> client_impl_; |
401 scoped_ptr<base::RunLoop> run_loop_; | 432 scoped_ptr<base::RunLoop> run_loop_; |
402 | 433 |
403 DISALLOW_COPY_AND_ASSIGN(ViewManagerClientFactory); | 434 DISALLOW_COPY_AND_ASSIGN(ViewManagerClientFactory); |
404 }; | 435 }; |
405 | 436 |
406 class ViewManagerServiceAppTest : public mojo::test::ApplicationTestBase, | 437 class ViewManagerServiceAppTest : public mojo::test::ApplicationTestBase, |
407 public ApplicationDelegate { | 438 public ApplicationDelegate { |
408 public: | 439 public: |
409 ViewManagerServiceAppTest() {} | 440 ViewManagerServiceAppTest() {} |
410 ~ViewManagerServiceAppTest() override {} | 441 ~ViewManagerServiceAppTest() override {} |
411 | 442 |
412 protected: | 443 protected: |
| 444 enum class EmbedType { |
| 445 ALLOW_REEMBED, |
| 446 NO_REEMBED, |
| 447 }; |
| 448 |
413 // Returns the changes from the various connections. | 449 // Returns the changes from the various connections. |
414 std::vector<Change>* changes1() { return vm_client1_->tracker()->changes(); } | 450 std::vector<Change>* changes1() { return vm_client1_->tracker()->changes(); } |
415 std::vector<Change>* changes2() { return vm_client2_->tracker()->changes(); } | 451 std::vector<Change>* changes2() { return vm_client2_->tracker()->changes(); } |
416 std::vector<Change>* changes3() { return vm_client3_->tracker()->changes(); } | 452 std::vector<Change>* changes3() { return vm_client3_->tracker()->changes(); } |
417 | 453 |
418 // Various connections. |vm1()|, being the first connection, has special | 454 // Various connections. |vm1()|, being the first connection, has special |
419 // permissions (it's treated as the window manager). | 455 // permissions (it's treated as the window manager). |
420 ViewManagerService* vm1() { return vm1_.get(); } | 456 ViewManagerService* vm1() { return vm1_.get(); } |
421 ViewManagerService* vm2() { return vm_client2_->service(); } | 457 ViewManagerService* vm2() { return vm_client2_->service(); } |
422 ViewManagerService* vm3() { return vm_client3_->service(); } | 458 ViewManagerService* vm3() { return vm_client3_->service(); } |
423 | 459 |
424 void EstablishSecondConnectionWithRoot(Id root_id) { | 460 void EstablishSecondConnectionWithRoot(Id root_id) { |
425 ASSERT_TRUE(vm_client2_.get() == nullptr); | 461 ASSERT_TRUE(vm_client2_.get() == nullptr); |
426 vm_client2_ = EstablishConnectionViaEmbed(vm1(), root_id); | 462 vm_client2_ = |
| 463 EstablishConnectionViaEmbed(vm1(), root_id, EmbedType::NO_REEMBED); |
427 ASSERT_TRUE(vm_client2_.get() != nullptr); | 464 ASSERT_TRUE(vm_client2_.get() != nullptr); |
428 } | 465 } |
429 | 466 |
430 void EstablishSecondConnection(bool create_initial_view) { | 467 void EstablishSecondConnection(bool create_initial_view) { |
431 if (create_initial_view) | 468 if (create_initial_view) |
432 ASSERT_TRUE(CreateView(vm1_.get(), BuildViewId(1, 1))); | 469 ASSERT_TRUE(CreateView(vm1_.get(), BuildViewId(1, 1))); |
433 ASSERT_NO_FATAL_FAILURE( | 470 ASSERT_NO_FATAL_FAILURE( |
434 EstablishSecondConnectionWithRoot(BuildViewId(1, 1))); | 471 EstablishSecondConnectionWithRoot(BuildViewId(1, 1))); |
435 | 472 |
436 if (create_initial_view) | 473 if (create_initial_view) |
437 EXPECT_EQ("[view=1,1 parent=null]", ChangeViewDescription(*changes2())); | 474 EXPECT_EQ("[view=1,1 parent=null]", ChangeViewDescription(*changes2())); |
438 } | 475 } |
439 | 476 |
440 void EstablishThirdConnection(ViewManagerService* owner, Id root_id) { | 477 void EstablishThirdConnection(ViewManagerService* owner, Id root_id) { |
441 ASSERT_TRUE(vm_client3_.get() == nullptr); | 478 ASSERT_TRUE(vm_client3_.get() == nullptr); |
442 vm_client3_ = EstablishConnectionViaEmbed(owner, root_id); | 479 vm_client3_ = |
| 480 EstablishConnectionViaEmbed(owner, root_id, EmbedType::NO_REEMBED); |
443 ASSERT_TRUE(vm_client3_.get() != nullptr); | 481 ASSERT_TRUE(vm_client3_.get() != nullptr); |
444 } | 482 } |
445 | 483 |
446 // Establishes a new connection by way of Embed() on the specified | 484 // Establishes a new connection by way of Embed() on the specified |
447 // ViewManagerService. | 485 // ViewManagerService. |
448 scoped_ptr<ViewManagerClientImpl> EstablishConnectionViaEmbed( | 486 scoped_ptr<ViewManagerClientImpl> EstablishConnectionViaEmbed( |
449 ViewManagerService* owner, | 487 ViewManagerService* owner, |
450 Id root_id) { | 488 Id root_id, |
451 if (!EmbedUrl(owner, application_impl()->url(), root_id)) { | 489 EmbedType embed_type) { |
| 490 if (embed_type == EmbedType::NO_REEMBED && |
| 491 !EmbedUrl(application_impl(), owner, application_impl()->url(), |
| 492 root_id)) { |
| 493 ADD_FAILURE() << "Embed() failed"; |
| 494 return nullptr; |
| 495 } else if (embed_type == EmbedType::ALLOW_REEMBED && |
| 496 !EmbedAllowingReembed(application_impl(), owner, |
| 497 application_impl()->url(), root_id)) { |
452 ADD_FAILURE() << "Embed() failed"; | 498 ADD_FAILURE() << "Embed() failed"; |
453 return nullptr; | 499 return nullptr; |
454 } | 500 } |
455 scoped_ptr<ViewManagerClientImpl> client = | 501 scoped_ptr<ViewManagerClientImpl> client = |
456 client_factory_.WaitForInstance(); | 502 client_factory_->WaitForInstance(); |
457 if (!client.get()) { | 503 if (!client.get()) { |
458 ADD_FAILURE() << "WaitForInstance failed"; | 504 ADD_FAILURE() << "WaitForInstance failed"; |
459 return nullptr; | 505 return nullptr; |
460 } | 506 } |
461 client->WaitForOnEmbed(); | 507 client->WaitForOnEmbed(); |
462 | 508 |
463 EXPECT_EQ("OnEmbed creator=" + application_impl()->url(), | 509 EXPECT_EQ("OnEmbed", |
464 SingleChangeToDescription(*client->tracker()->changes())); | 510 SingleChangeToDescription(*client->tracker()->changes())); |
465 return client.Pass(); | 511 return client.Pass(); |
466 } | 512 } |
467 | 513 |
468 // ApplicationTestBase: | 514 // ApplicationTestBase: |
469 ApplicationDelegate* GetApplicationDelegate() override { return this; } | 515 ApplicationDelegate* GetApplicationDelegate() override { return this; } |
470 void SetUp() override { | 516 void SetUp() override { |
471 ApplicationTestBase::SetUp(); | 517 ApplicationTestBase::SetUp(); |
| 518 client_factory_.reset(new ViewManagerClientFactory(application_impl())); |
472 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 519 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
473 request->url = mojo::String::From("mojo:view_manager"); | 520 request->url = mojo::String::From("mojo:view_manager"); |
474 ApplicationConnection* vm_connection = | 521 ApplicationConnection* vm_connection = |
475 application_impl()->ConnectToApplication(request.Pass()); | 522 application_impl()->ConnectToApplication(request.Pass()); |
476 vm_connection->ConnectToService(&vm1_); | 523 vm_connection->ConnectToService(&vm1_); |
477 vm_connection->ConnectToService(&view_manager_root_); | 524 vm_connection->ConnectToService(&view_manager_root_); |
478 vm_connection->AddService(&client_factory_); | 525 vm_connection->AddService(client_factory_.get()); |
479 vm_client1_ = client_factory_.WaitForInstance(); | 526 vm_client1_ = client_factory_->WaitForInstance(); |
480 ASSERT_TRUE(vm_client1_); | 527 ASSERT_TRUE(vm_client1_); |
481 // Next we should get an embed call on the "window manager" client. | 528 // Next we should get an embed call on the "window manager" client. |
482 vm_client1_->WaitForIncomingMethodCall(); | 529 vm_client1_->WaitForIncomingMethodCall(); |
483 ASSERT_EQ(1u, changes1()->size()); | 530 ASSERT_EQ(1u, changes1()->size()); |
484 EXPECT_EQ(CHANGE_TYPE_EMBED, (*changes1())[0].type); | 531 EXPECT_EQ(CHANGE_TYPE_EMBED, (*changes1())[0].type); |
485 // All these tests assume 1 for the client id. The only real assertion here | 532 // All these tests assume 1 for the client id. The only real assertion here |
486 // is the client id is not zero, but adding this as rest of code here | 533 // is the client id is not zero, but adding this as rest of code here |
487 // assumes 1. | 534 // assumes 1. |
488 ASSERT_EQ(1, (*changes1())[0].connection_id); | 535 ASSERT_EQ(1, (*changes1())[0].connection_id); |
489 changes1()->clear(); | 536 changes1()->clear(); |
490 } | 537 } |
491 | 538 |
492 // ApplicationDelegate implementation. | 539 // ApplicationDelegate implementation. |
493 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { | 540 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { |
494 connection->AddService(&client_factory_); | 541 connection->AddService(client_factory_.get()); |
495 return true; | 542 return true; |
496 } | 543 } |
497 | 544 |
498 scoped_ptr<ViewManagerClientImpl> vm_client1_; | 545 scoped_ptr<ViewManagerClientImpl> vm_client1_; |
499 scoped_ptr<ViewManagerClientImpl> vm_client2_; | 546 scoped_ptr<ViewManagerClientImpl> vm_client2_; |
500 scoped_ptr<ViewManagerClientImpl> vm_client3_; | 547 scoped_ptr<ViewManagerClientImpl> vm_client3_; |
501 | 548 |
502 mojo::ViewManagerRootPtr view_manager_root_; | 549 mojo::ViewManagerRootPtr view_manager_root_; |
503 | 550 |
504 private: | 551 private: |
505 mojo::ViewManagerServicePtr vm1_; | 552 mojo::ViewManagerServicePtr vm1_; |
506 ViewManagerClientFactory client_factory_; | 553 scoped_ptr<ViewManagerClientFactory> client_factory_; |
507 | 554 |
508 MOJO_DISALLOW_COPY_AND_ASSIGN(ViewManagerServiceAppTest); | 555 MOJO_DISALLOW_COPY_AND_ASSIGN(ViewManagerServiceAppTest); |
509 }; | 556 }; |
510 | 557 |
511 // Verifies two clients/connections get different ids. | 558 // Verifies two clients/connections get different ids. |
512 TEST_F(ViewManagerServiceAppTest, TwoClientsGetDifferentConnectionIds) { | 559 TEST_F(ViewManagerServiceAppTest, TwoClientsGetDifferentConnectionIds) { |
513 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 560 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
514 | 561 |
515 // It isn't strictly necessary that the second connection gets 2, but these | 562 // It isn't strictly necessary that the second connection gets 2, but these |
516 // tests are written assuming that is the case. The key thing is the | 563 // tests are written assuming that is the case. The key thing is the |
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1196 vm_client1_->WaitForChangeCount(1); | 1243 vm_client1_->WaitForChangeCount(1); |
1197 EXPECT_EQ("HierarchyChanged view=3,1 new_parent=1,1 old_parent=null", | 1244 EXPECT_EQ("HierarchyChanged view=3,1 new_parent=1,1 old_parent=null", |
1198 SingleChangeToDescription(*changes1())); | 1245 SingleChangeToDescription(*changes1())); |
1199 } | 1246 } |
1200 | 1247 |
1201 // Embed 1,1 again. | 1248 // Embed 1,1 again. |
1202 { | 1249 { |
1203 changes3()->clear(); | 1250 changes3()->clear(); |
1204 | 1251 |
1205 // We should get a new connection for the new embedding. | 1252 // We should get a new connection for the new embedding. |
1206 scoped_ptr<ViewManagerClientImpl> connection4( | 1253 scoped_ptr<ViewManagerClientImpl> connection4(EstablishConnectionViaEmbed( |
1207 EstablishConnectionViaEmbed(vm1(), BuildViewId(1, 1))); | 1254 vm1(), BuildViewId(1, 1), EmbedType::NO_REEMBED)); |
1208 ASSERT_TRUE(connection4.get()); | 1255 ASSERT_TRUE(connection4.get()); |
1209 EXPECT_EQ("[view=1,1 parent=null]", | 1256 EXPECT_EQ("[view=1,1 parent=null]", |
1210 ChangeViewDescription(*connection4->tracker()->changes())); | 1257 ChangeViewDescription(*connection4->tracker()->changes())); |
1211 | 1258 |
1212 // And 3 should get a delete. | 1259 // And 3 should get a delete. |
1213 vm_client3_->WaitForChangeCount(1); | 1260 vm_client3_->WaitForChangeCount(1); |
1214 EXPECT_EQ("ViewDeleted view=1,1", SingleChangeToDescription(*changes3())); | 1261 EXPECT_EQ("ViewDeleted view=1,1", SingleChangeToDescription(*changes3())); |
1215 } | 1262 } |
1216 | 1263 |
1217 // vm3() has no root. Verify it can't see view 1,1 anymore. | 1264 // vm3() has no root. Verify it can't see view 1,1 anymore. |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1550 views.clear(); | 1597 views.clear(); |
1551 | 1598 |
1552 GetViewTree(vm2(), BuildViewId(1, 1), &views); | 1599 GetViewTree(vm2(), BuildViewId(1, 1), &views); |
1553 EXPECT_FALSE(HasClonedView(views)); | 1600 EXPECT_FALSE(HasClonedView(views)); |
1554 } | 1601 } |
1555 | 1602 |
1556 // Verifies Embed() works when supplying a ViewManagerClient. | 1603 // Verifies Embed() works when supplying a ViewManagerClient. |
1557 TEST_F(ViewManagerServiceAppTest, EmbedSupplyingViewManagerClient) { | 1604 TEST_F(ViewManagerServiceAppTest, EmbedSupplyingViewManagerClient) { |
1558 ASSERT_TRUE(CreateView(vm1(), BuildViewId(1, 1))); | 1605 ASSERT_TRUE(CreateView(vm1(), BuildViewId(1, 1))); |
1559 | 1606 |
1560 ViewManagerClientImpl client2; | 1607 ViewManagerClientImpl client2(application_impl()); |
1561 mojo::ViewManagerClientPtr client2_ptr; | 1608 mojo::ViewManagerClientPtr client2_ptr; |
1562 mojo::Binding<ViewManagerClient> client2_binding(&client2, &client2_ptr); | 1609 mojo::Binding<ViewManagerClient> client2_binding(&client2, &client2_ptr); |
1563 ASSERT_TRUE(Embed(vm1(), BuildViewId(1, 1), client2_ptr.Pass())); | 1610 ASSERT_TRUE(Embed(vm1(), BuildViewId(1, 1), client2_ptr.Pass())); |
1564 client2.WaitForOnEmbed(); | 1611 client2.WaitForOnEmbed(); |
1565 EXPECT_EQ("OnEmbed creator=" + application_impl()->url(), | 1612 EXPECT_EQ("OnEmbed", |
1566 SingleChangeToDescription(*client2.tracker()->changes())); | 1613 SingleChangeToDescription(*client2.tracker()->changes())); |
1567 } | 1614 } |
1568 | 1615 |
1569 // TODO(msw|sky): Fails on Android; see http://crbug.com/497920 | 1616 // TODO(msw|sky): Fails on Android; see http://crbug.com/497920 |
1570 #if defined(OS_ANDROID) | 1617 #if defined(OS_ANDROID) |
1571 #define MAYBE_OnWillEmbed DISABLED_OnWillEmbed | 1618 #define MAYBE_OnWillEmbed DISABLED_OnWillEmbed |
1572 #else | 1619 #else |
1573 #define MAYBE_OnWillEmbed OnWillEmbed | 1620 #define MAYBE_OnWillEmbed OnWillEmbed |
1574 #endif | 1621 #endif |
1575 TEST_F(ViewManagerServiceAppTest, MAYBE_OnWillEmbed) { | 1622 TEST_F(ViewManagerServiceAppTest, MAYBE_OnWillEmbed) { |
1576 // Create connections 2 and 3, marking 2 as an embed root. | 1623 // Create connections 2 and 3, marking 2 as an embed root. |
1577 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 1624 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
1578 ASSERT_TRUE(AddView(vm1(), BuildViewId(0, 1), BuildViewId(1, 1))); | 1625 ASSERT_TRUE(AddView(vm1(), BuildViewId(0, 1), BuildViewId(1, 1))); |
1579 ASSERT_TRUE(CreateView(vm2(), BuildViewId(2, 2))); | 1626 ASSERT_TRUE(CreateView(vm2(), BuildViewId(2, 2))); |
1580 ASSERT_TRUE(AddView(vm2(), BuildViewId(1, 1), BuildViewId(2, 2))); | 1627 ASSERT_TRUE(AddView(vm2(), BuildViewId(1, 1), BuildViewId(2, 2))); |
1581 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(vm2(), BuildViewId(2, 2))); | 1628 ASSERT_NO_FATAL_FAILURE(EstablishThirdConnection(vm2(), BuildViewId(2, 2))); |
1582 ASSERT_TRUE(CreateView(vm3(), BuildViewId(3, 3))); | 1629 ASSERT_TRUE(CreateView(vm3(), BuildViewId(3, 3))); |
1583 ASSERT_TRUE(AddView(vm3(), BuildViewId(2, 2), BuildViewId(3, 3))); | 1630 ASSERT_TRUE(AddView(vm3(), BuildViewId(2, 2), BuildViewId(3, 3))); |
1584 vm2()->SetEmbedRoot(); | 1631 vm2()->SetEmbedRoot(); |
1585 // Make sure the viewmanager processed the SetEmbedRoot() call. | 1632 // Make sure the viewmanager processed the SetEmbedRoot() call. |
1586 ASSERT_TRUE(WaitForAllMessages(vm2())); | 1633 ASSERT_TRUE(WaitForAllMessages(vm2())); |
1587 changes2()->clear(); | 1634 changes2()->clear(); |
1588 | 1635 |
1589 // Embed 4 into 3, connection 2 should get the OnWillEmbed. | 1636 // Embed 4 into 3, connection 2 should get the OnWillEmbed. |
1590 scoped_ptr<ViewManagerClientImpl> connection4( | 1637 scoped_ptr<ViewManagerClientImpl> connection4(EstablishConnectionViaEmbed( |
1591 EstablishConnectionViaEmbed(vm3(), BuildViewId(3, 3))); | 1638 vm3(), BuildViewId(3, 3), EmbedType::ALLOW_REEMBED)); |
1592 ASSERT_TRUE(connection4.get()); | 1639 ASSERT_TRUE(connection4.get()); |
1593 EXPECT_EQ("OnWillEmbed view=3,3", SingleChangeToDescription(*changes2())); | 1640 EXPECT_EQ("OnEmbedForDescendant view=3,3", |
| 1641 SingleChangeToDescription(*changes2())); |
1594 | 1642 |
1595 // Mark 3 as an embed root. | 1643 // Mark 3 as an embed root. |
1596 vm3()->SetEmbedRoot(); | 1644 vm3()->SetEmbedRoot(); |
1597 // Make sure the viewmanager processed the SetEmbedRoot() call. | 1645 // Make sure the viewmanager processed the SetEmbedRoot() call. |
1598 ASSERT_TRUE(WaitForAllMessages(vm3())); | 1646 ASSERT_TRUE(WaitForAllMessages(vm3())); |
1599 changes2()->clear(); | 1647 changes2()->clear(); |
1600 changes3()->clear(); | 1648 changes3()->clear(); |
1601 | 1649 |
1602 // Embed 5 into 4. Only 3 should get the will embed. | 1650 // Embed 5 into 4. Only 3 should get the will embed. |
1603 ASSERT_TRUE(CreateView(connection4->service(), BuildViewId(4, 4))); | 1651 ASSERT_TRUE(CreateView(connection4->service(), BuildViewId(4, 4))); |
1604 ASSERT_TRUE( | 1652 ASSERT_TRUE( |
1605 AddView(connection4->service(), BuildViewId(3, 3), BuildViewId(4, 4))); | 1653 AddView(connection4->service(), BuildViewId(3, 3), BuildViewId(4, 4))); |
1606 scoped_ptr<ViewManagerClientImpl> connection5( | 1654 scoped_ptr<ViewManagerClientImpl> connection5(EstablishConnectionViaEmbed( |
1607 EstablishConnectionViaEmbed(connection4->service(), BuildViewId(4, 4))); | 1655 connection4->service(), BuildViewId(4, 4), EmbedType::ALLOW_REEMBED)); |
1608 ASSERT_TRUE(connection5.get()); | 1656 ASSERT_TRUE(connection5.get()); |
1609 EXPECT_EQ("OnWillEmbed view=4,4", SingleChangeToDescription(*changes3())); | 1657 EXPECT_EQ("OnEmbedForDescendant view=4,4", |
| 1658 SingleChangeToDescription(*changes3())); |
1610 ASSERT_TRUE(changes2()->empty()); | 1659 ASSERT_TRUE(changes2()->empty()); |
1611 } | 1660 } |
1612 | 1661 |
1613 // TODO(sky): need to better track changes to initial connection. For example, | 1662 // TODO(sky): need to better track changes to initial connection. For example, |
1614 // that SetBounsdViews/AddView and the like don't result in messages to the | 1663 // that SetBounsdViews/AddView and the like don't result in messages to the |
1615 // originating connection. | 1664 // originating connection. |
1616 | 1665 |
1617 // TODO(sky): make sure coverage of what was | 1666 // TODO(sky): make sure coverage of what was |
1618 // ViewManagerTest.SecondEmbedRoot_InitService and | 1667 // ViewManagerTest.SecondEmbedRoot_InitService and |
1619 // ViewManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window manager | 1668 // ViewManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window manager |
1620 // tests. | 1669 // tests. |
1621 | 1670 |
1622 } // namespace view_manager | 1671 } // namespace view_manager |
OLD | NEW |