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 "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "components/mus/ids.h" | 9 #include "components/mus/ids.h" |
10 #include "components/mus/public/interfaces/view_tree.mojom.h" | 10 #include "components/mus/public/interfaces/view_tree.mojom.h" |
11 #include "components/mus/public/interfaces/view_tree_host.mojom.h" | 11 #include "components/mus/public/interfaces/view_tree_host.mojom.h" |
12 #include "components/mus/test_change_tracker.h" | 12 #include "components/mus/test_change_tracker.h" |
13 #include "mojo/application/public/cpp/application_delegate.h" | 13 #include "mojo/application/public/cpp/application_delegate.h" |
14 #include "mojo/application/public/cpp/application_impl.h" | 14 #include "mojo/application/public/cpp/application_impl.h" |
15 #include "mojo/application/public/cpp/application_test_base.h" | 15 #include "mojo/application/public/cpp/application_test_base.h" |
16 | 16 |
17 using mojo::ApplicationConnection; | 17 using mojo::ApplicationConnection; |
18 using mojo::ApplicationDelegate; | 18 using mojo::ApplicationDelegate; |
19 using mojo::Array; | 19 using mojo::Array; |
20 using mojo::Callback; | 20 using mojo::Callback; |
21 using mojo::ConnectionSpecificId; | |
22 using mojo::ERROR_CODE_NONE; | 21 using mojo::ERROR_CODE_NONE; |
23 using mojo::ErrorCode; | 22 using mojo::ErrorCode; |
24 using mojo::EventPtr; | 23 using mojo::EventPtr; |
25 using mojo::Id; | |
26 using mojo::InterfaceRequest; | 24 using mojo::InterfaceRequest; |
27 using mojo::ORDER_DIRECTION_ABOVE; | 25 using mojo::ORDER_DIRECTION_ABOVE; |
28 using mojo::ORDER_DIRECTION_BELOW; | 26 using mojo::ORDER_DIRECTION_BELOW; |
29 using mojo::OrderDirection; | 27 using mojo::OrderDirection; |
30 using mojo::RectPtr; | 28 using mojo::RectPtr; |
31 using mojo::ServiceProvider; | 29 using mojo::ServiceProvider; |
32 using mojo::ServiceProviderPtr; | 30 using mojo::ServiceProviderPtr; |
33 using mojo::String; | 31 using mojo::String; |
34 using mojo::ViewDataPtr; | 32 using mojo::ViewDataPtr; |
35 using mojo::ViewTree; | 33 using mojo::ViewTree; |
36 using mojo::ViewTreeClient; | 34 using mojo::ViewTreeClient; |
37 using mojo::ViewportMetricsPtr; | 35 using mojo::ViewportMetricsPtr; |
38 | 36 |
39 namespace view_manager { | 37 namespace mus { |
| 38 |
| 39 namespace { |
40 | 40 |
41 // Creates an id used for transport from the specified parameters. | 41 // Creates an id used for transport from the specified parameters. |
42 Id BuildViewId(ConnectionSpecificId connection_id, | 42 Id BuildViewId(ConnectionSpecificId connection_id, |
43 ConnectionSpecificId view_id) { | 43 ConnectionSpecificId view_id) { |
44 return (connection_id << 16) | view_id; | 44 return (connection_id << 16) | view_id; |
45 } | 45 } |
46 | 46 |
47 // Callback function from ViewTree functions. ---------------------------------- | 47 // Callback function from ViewTree functions. ---------------------------------- |
48 | 48 |
49 void BoolResultCallback(base::RunLoop* run_loop, | 49 void BoolResultCallback(base::RunLoop* run_loop, |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 ErrorCode result = ERROR_CODE_NONE; | 209 ErrorCode result = ERROR_CODE_NONE; |
210 base::RunLoop run_loop; | 210 base::RunLoop run_loop; |
211 vm->CreateView(ViewIdToTransportId(InvalidViewId()), | 211 vm->CreateView(ViewIdToTransportId(InvalidViewId()), |
212 base::Bind(&ErrorCodeResultCallback, &run_loop, &result)); | 212 base::Bind(&ErrorCodeResultCallback, &run_loop, &result)); |
213 run_loop.Run(); | 213 run_loop.Run(); |
214 return result != ERROR_CODE_NONE; | 214 return result != ERROR_CODE_NONE; |
215 } | 215 } |
216 | 216 |
217 const Id kNullParentId = 0; | 217 const Id kNullParentId = 0; |
218 std::string IdToString(Id id) { | 218 std::string IdToString(Id id) { |
219 return (id == kNullParentId) | 219 return (id == kNullParentId) ? "null" : base::StringPrintf( |
220 ? "null" | 220 "%d,%d", HiWord(id), LoWord(id)); |
221 : base::StringPrintf("%d,%d", mojo::HiWord(id), mojo::LoWord(id)); | |
222 } | 221 } |
223 | 222 |
224 std::string ViewParentToString(Id view, Id parent) { | 223 std::string ViewParentToString(Id view, Id parent) { |
225 return base::StringPrintf("view=%s parent=%s", IdToString(view).c_str(), | 224 return base::StringPrintf("view=%s parent=%s", IdToString(view).c_str(), |
226 IdToString(parent).c_str()); | 225 IdToString(parent).c_str()); |
227 } | 226 } |
228 | 227 |
229 // ----------------------------------------------------------------------------- | 228 // ----------------------------------------------------------------------------- |
230 | 229 |
231 // A ViewTreeClient implementation that logs all changes to a tracker. | 230 // A ViewTreeClient implementation that logs all changes to a tracker. |
232 class ViewTreeClientImpl : public mojo::ViewTreeClient, | 231 class TestViewTreeClientImpl : public mojo::ViewTreeClient, |
233 public TestChangeTracker::Delegate { | 232 public TestChangeTracker::Delegate { |
234 public: | 233 public: |
235 explicit ViewTreeClientImpl(mojo::ApplicationImpl* app) | 234 explicit TestViewTreeClientImpl(mojo::ApplicationImpl* app) |
236 : binding_(this), app_(app), connection_id_(0), root_view_id_(0) { | 235 : binding_(this), app_(app), connection_id_(0), root_view_id_(0) { |
237 tracker_.set_delegate(this); | 236 tracker_.set_delegate(this); |
238 } | 237 } |
239 | 238 |
240 void Bind(mojo::InterfaceRequest<mojo::ViewTreeClient> request) { | 239 void Bind(mojo::InterfaceRequest<mojo::ViewTreeClient> request) { |
241 binding_.Bind(request.Pass()); | 240 binding_.Bind(request.Pass()); |
242 } | 241 } |
243 | 242 |
244 mojo::ViewTree* tree() { return tree_.get(); } | 243 mojo::ViewTree* tree() { return tree_.get(); } |
245 TestChangeTracker* tracker() { return &tracker_; } | 244 TestChangeTracker* tracker() { return &tracker_; } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 if (wait_state_.get() && | 296 if (wait_state_.get() && |
298 wait_state_->change_count == tracker_.changes()->size()) { | 297 wait_state_->change_count == tracker_.changes()->size()) { |
299 wait_state_->run_loop.Quit(); | 298 wait_state_->run_loop.Quit(); |
300 } | 299 } |
301 } | 300 } |
302 | 301 |
303 // ViewTreeClient: | 302 // ViewTreeClient: |
304 void OnEmbed(ConnectionSpecificId connection_id, | 303 void OnEmbed(ConnectionSpecificId connection_id, |
305 ViewDataPtr root, | 304 ViewDataPtr root, |
306 mojo::ViewTreePtr tree, | 305 mojo::ViewTreePtr tree, |
307 mojo::Id focused_view_id, | 306 Id focused_view_id, |
308 uint32_t access_policy) override { | 307 uint32_t access_policy) override { |
309 // TODO(sky): add coverage of |focused_view_id|. | 308 // TODO(sky): add coverage of |focused_view_id|. |
310 tree_ = tree.Pass(); | 309 tree_ = tree.Pass(); |
311 connection_id_ = connection_id; | 310 connection_id_ = connection_id; |
312 tracker()->OnEmbed(connection_id, root.Pass()); | 311 tracker()->OnEmbed(connection_id, root.Pass()); |
313 if (embed_run_loop_) | 312 if (embed_run_loop_) |
314 embed_run_loop_->Quit(); | 313 embed_run_loop_->Quit(); |
315 } | 314 } |
316 void OnEmbeddedAppDisconnected(Id view_id) override { | 315 void OnEmbeddedAppDisconnected(Id view_id) override { |
317 tracker()->OnEmbeddedAppDisconnected(view_id); | 316 tracker()->OnEmbeddedAppDisconnected(view_id); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 | 374 |
376 // If non-null we're waiting for a certain number of change notifications to | 375 // If non-null we're waiting for a certain number of change notifications to |
377 // be encountered. | 376 // be encountered. |
378 scoped_ptr<WaitState> wait_state_; | 377 scoped_ptr<WaitState> wait_state_; |
379 | 378 |
380 mojo::Binding<ViewTreeClient> binding_; | 379 mojo::Binding<ViewTreeClient> binding_; |
381 mojo::ApplicationImpl* app_; | 380 mojo::ApplicationImpl* app_; |
382 Id connection_id_; | 381 Id connection_id_; |
383 Id root_view_id_; | 382 Id root_view_id_; |
384 | 383 |
385 DISALLOW_COPY_AND_ASSIGN(ViewTreeClientImpl); | 384 DISALLOW_COPY_AND_ASSIGN(TestViewTreeClientImpl); |
386 }; | 385 }; |
387 | 386 |
388 // ----------------------------------------------------------------------------- | 387 // ----------------------------------------------------------------------------- |
389 | 388 |
390 // InterfaceFactory for vending ViewTreeClientImpls. | 389 // InterfaceFactory for vending TestViewTreeClientImpls. |
391 class ViewTreeClientFactory : public mojo::InterfaceFactory<ViewTreeClient> { | 390 class ViewTreeClientFactory : public mojo::InterfaceFactory<ViewTreeClient> { |
392 public: | 391 public: |
393 explicit ViewTreeClientFactory(mojo::ApplicationImpl* app) : app_(app) {} | 392 explicit ViewTreeClientFactory(mojo::ApplicationImpl* app) : app_(app) {} |
394 ~ViewTreeClientFactory() override {} | 393 ~ViewTreeClientFactory() override {} |
395 | 394 |
396 // Runs a nested MessageLoop until a new instance has been created. | 395 // Runs a nested MessageLoop until a new instance has been created. |
397 scoped_ptr<ViewTreeClientImpl> WaitForInstance() { | 396 scoped_ptr<TestViewTreeClientImpl> WaitForInstance() { |
398 if (!client_impl_.get()) { | 397 if (!client_impl_.get()) { |
399 DCHECK(!run_loop_.get()); | 398 DCHECK(!run_loop_.get()); |
400 run_loop_.reset(new base::RunLoop); | 399 run_loop_.reset(new base::RunLoop); |
401 run_loop_->Run(); | 400 run_loop_->Run(); |
402 run_loop_.reset(); | 401 run_loop_.reset(); |
403 } | 402 } |
404 return client_impl_.Pass(); | 403 return client_impl_.Pass(); |
405 } | 404 } |
406 | 405 |
407 private: | 406 private: |
408 // InterfaceFactory<ViewTreeClient>: | 407 // InterfaceFactory<ViewTreeClient>: |
409 void Create(ApplicationConnection* connection, | 408 void Create(ApplicationConnection* connection, |
410 InterfaceRequest<ViewTreeClient> request) override { | 409 InterfaceRequest<ViewTreeClient> request) override { |
411 client_impl_.reset(new ViewTreeClientImpl(app_)); | 410 client_impl_.reset(new TestViewTreeClientImpl(app_)); |
412 client_impl_->Bind(request.Pass()); | 411 client_impl_->Bind(request.Pass()); |
413 if (run_loop_.get()) | 412 if (run_loop_.get()) |
414 run_loop_->Quit(); | 413 run_loop_->Quit(); |
415 } | 414 } |
416 | 415 |
417 mojo::ApplicationImpl* app_; | 416 mojo::ApplicationImpl* app_; |
418 scoped_ptr<ViewTreeClientImpl> client_impl_; | 417 scoped_ptr<TestViewTreeClientImpl> client_impl_; |
419 scoped_ptr<base::RunLoop> run_loop_; | 418 scoped_ptr<base::RunLoop> run_loop_; |
420 | 419 |
421 DISALLOW_COPY_AND_ASSIGN(ViewTreeClientFactory); | 420 DISALLOW_COPY_AND_ASSIGN(ViewTreeClientFactory); |
422 }; | 421 }; |
423 | 422 |
| 423 } // namespace |
| 424 |
424 class ViewTreeAppTest : public mojo::test::ApplicationTestBase, | 425 class ViewTreeAppTest : public mojo::test::ApplicationTestBase, |
425 public ApplicationDelegate { | 426 public ApplicationDelegate { |
426 public: | 427 public: |
427 ViewTreeAppTest() | 428 ViewTreeAppTest() |
428 : connection_id_1_(0), connection_id_2_(0), root_view_id_(0) {} | 429 : connection_id_1_(0), connection_id_2_(0), root_view_id_(0) {} |
429 ~ViewTreeAppTest() override {} | 430 ~ViewTreeAppTest() override {} |
430 | 431 |
431 protected: | 432 protected: |
432 // Returns the changes from the various connections. | 433 // Returns the changes from the various connections. |
433 std::vector<Change>* changes1() { return vm_client1_->tracker()->changes(); } | 434 std::vector<Change>* changes1() { return vm_client1_->tracker()->changes(); } |
434 std::vector<Change>* changes2() { return vm_client2_->tracker()->changes(); } | 435 std::vector<Change>* changes2() { return vm_client2_->tracker()->changes(); } |
435 std::vector<Change>* changes3() { return vm_client3_->tracker()->changes(); } | 436 std::vector<Change>* changes3() { return vm_client3_->tracker()->changes(); } |
436 | 437 |
437 // Various connections. |vm1()|, being the first connection, has special | 438 // Various connections. |vm1()|, being the first connection, has special |
438 // permissions (it's treated as the window manager). | 439 // permissions (it's treated as the window manager). |
439 ViewTree* vm1() { return vm_client1_->tree(); } | 440 ViewTree* vm1() { return vm_client1_->tree(); } |
440 ViewTree* vm2() { return vm_client2_->tree(); } | 441 ViewTree* vm2() { return vm_client2_->tree(); } |
441 ViewTree* vm3() { return vm_client3_->tree(); } | 442 ViewTree* vm3() { return vm_client3_->tree(); } |
442 | 443 |
443 ViewTreeClientImpl* vm_client1() { return vm_client1_.get(); } | 444 TestViewTreeClientImpl* vm_client1() { return vm_client1_.get(); } |
444 ViewTreeClientImpl* vm_client2() { return vm_client2_.get(); } | 445 TestViewTreeClientImpl* vm_client2() { return vm_client2_.get(); } |
445 ViewTreeClientImpl* vm_client3() { return vm_client3_.get(); } | 446 TestViewTreeClientImpl* vm_client3() { return vm_client3_.get(); } |
446 | 447 |
447 Id root_view_id() const { return root_view_id_; } | 448 Id root_view_id() const { return root_view_id_; } |
448 | 449 |
449 int connection_id_1() const { return connection_id_1_; } | 450 int connection_id_1() const { return connection_id_1_; } |
450 int connection_id_2() const { return connection_id_2_; } | 451 int connection_id_2() const { return connection_id_2_; } |
451 | 452 |
452 void EstablishSecondConnectionWithRoot(Id root_id) { | 453 void EstablishSecondConnectionWithRoot(Id root_id) { |
453 ASSERT_TRUE(vm_client2_.get() == nullptr); | 454 ASSERT_TRUE(vm_client2_.get() == nullptr); |
454 vm_client2_ = | 455 vm_client2_ = |
455 EstablishConnectionViaEmbed(vm1(), root_id, &connection_id_2_); | 456 EstablishConnectionViaEmbed(vm1(), root_id, &connection_id_2_); |
(...skipping 17 matching lines...) Expand all Loading... |
473 } | 474 } |
474 } | 475 } |
475 | 476 |
476 void EstablishThirdConnection(ViewTree* owner, Id root_id) { | 477 void EstablishThirdConnection(ViewTree* owner, Id root_id) { |
477 ASSERT_TRUE(vm_client3_.get() == nullptr); | 478 ASSERT_TRUE(vm_client3_.get() == nullptr); |
478 vm_client3_ = EstablishConnectionViaEmbed(owner, root_id, nullptr); | 479 vm_client3_ = EstablishConnectionViaEmbed(owner, root_id, nullptr); |
479 ASSERT_TRUE(vm_client3_.get() != nullptr); | 480 ASSERT_TRUE(vm_client3_.get() != nullptr); |
480 vm_client3_->set_root_view(root_view_id_); | 481 vm_client3_->set_root_view(root_view_id_); |
481 } | 482 } |
482 | 483 |
483 scoped_ptr<ViewTreeClientImpl> WaitForViewTreeClient() { | 484 scoped_ptr<TestViewTreeClientImpl> WaitForViewTreeClient() { |
484 return client_factory_->WaitForInstance(); | 485 return client_factory_->WaitForInstance(); |
485 } | 486 } |
486 | 487 |
487 // Establishes a new connection by way of Embed() on the specified | 488 // Establishes a new connection by way of Embed() on the specified |
488 // ViewTree. | 489 // ViewTree. |
489 scoped_ptr<ViewTreeClientImpl> | 490 scoped_ptr<TestViewTreeClientImpl> |
490 EstablishConnectionViaEmbed(ViewTree* owner, Id root_id, int* connection_id) { | 491 EstablishConnectionViaEmbed(ViewTree* owner, Id root_id, int* connection_id) { |
491 return EstablishConnectionViaEmbedWithPolicyBitmask( | 492 return EstablishConnectionViaEmbedWithPolicyBitmask( |
492 owner, root_id, mojo::ViewTree::ACCESS_POLICY_DEFAULT, connection_id); | 493 owner, root_id, mojo::ViewTree::ACCESS_POLICY_DEFAULT, connection_id); |
493 } | 494 } |
494 | 495 |
495 scoped_ptr<ViewTreeClientImpl> EstablishConnectionViaEmbedWithPolicyBitmask( | 496 scoped_ptr<TestViewTreeClientImpl> |
496 ViewTree* owner, | 497 EstablishConnectionViaEmbedWithPolicyBitmask(ViewTree* owner, |
497 Id root_id, | 498 Id root_id, |
498 uint32_t policy_bitmask, | 499 uint32_t policy_bitmask, |
499 int* connection_id) { | 500 int* connection_id) { |
500 if (!EmbedUrl(application_impl(), owner, application_impl()->url(), | 501 if (!EmbedUrl(application_impl(), owner, application_impl()->url(), |
501 root_id)) { | 502 root_id)) { |
502 ADD_FAILURE() << "Embed() failed"; | 503 ADD_FAILURE() << "Embed() failed"; |
503 return nullptr; | 504 return nullptr; |
504 } | 505 } |
505 scoped_ptr<ViewTreeClientImpl> client = client_factory_->WaitForInstance(); | 506 scoped_ptr<TestViewTreeClientImpl> client = |
| 507 client_factory_->WaitForInstance(); |
506 if (!client.get()) { | 508 if (!client.get()) { |
507 ADD_FAILURE() << "WaitForInstance failed"; | 509 ADD_FAILURE() << "WaitForInstance failed"; |
508 return nullptr; | 510 return nullptr; |
509 } | 511 } |
510 client->WaitForOnEmbed(); | 512 client->WaitForOnEmbed(); |
511 | 513 |
512 EXPECT_EQ("OnEmbed", | 514 EXPECT_EQ("OnEmbed", |
513 SingleChangeToDescription(*client->tracker()->changes())); | 515 SingleChangeToDescription(*client->tracker()->changes())); |
514 if (connection_id) | 516 if (connection_id) |
515 *connection_id = (*client->tracker()->changes())[0].connection_id; | 517 *connection_id = (*client->tracker()->changes())[0].connection_id; |
516 return client.Pass(); | 518 return client.Pass(); |
517 } | 519 } |
518 | 520 |
519 // ApplicationTestBase: | 521 // ApplicationTestBase: |
520 ApplicationDelegate* GetApplicationDelegate() override { return this; } | 522 ApplicationDelegate* GetApplicationDelegate() override { return this; } |
521 void SetUp() override { | 523 void SetUp() override { |
522 ApplicationTestBase::SetUp(); | 524 ApplicationTestBase::SetUp(); |
523 client_factory_.reset(new ViewTreeClientFactory(application_impl())); | 525 client_factory_.reset(new ViewTreeClientFactory(application_impl())); |
524 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 526 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
525 request->url = mojo::String::From("mojo:mus"); | 527 request->url = mojo::String::From("mojo:mus"); |
526 | 528 |
527 mojo::ViewTreeHostFactoryPtr factory; | 529 mojo::ViewTreeHostFactoryPtr factory; |
528 application_impl()->ConnectToService(request.Pass(), &factory); | 530 application_impl()->ConnectToService(request.Pass(), &factory); |
529 | 531 |
530 mojo::ViewTreeClientPtr tree_client_ptr; | 532 mojo::ViewTreeClientPtr tree_client_ptr; |
531 vm_client1_.reset(new ViewTreeClientImpl(application_impl())); | 533 vm_client1_.reset(new TestViewTreeClientImpl(application_impl())); |
532 vm_client1_->Bind(GetProxy(&tree_client_ptr)); | 534 vm_client1_->Bind(GetProxy(&tree_client_ptr)); |
533 | 535 |
534 factory->CreateViewTreeHost(GetProxy(&host_), mojo::ViewTreeHostClientPtr(), | 536 factory->CreateViewTreeHost(GetProxy(&host_), mojo::ViewTreeHostClientPtr(), |
535 tree_client_ptr.Pass()); | 537 tree_client_ptr.Pass()); |
536 | 538 |
537 // Next we should get an embed call on the "window manager" client. | 539 // Next we should get an embed call on the "window manager" client. |
538 vm_client1_->WaitForIncomingMethodCall(); | 540 vm_client1_->WaitForIncomingMethodCall(); |
539 | 541 |
540 ASSERT_EQ(1u, changes1()->size()); | 542 ASSERT_EQ(1u, changes1()->size()); |
541 EXPECT_EQ(CHANGE_TYPE_EMBED, (*changes1())[0].type); | 543 EXPECT_EQ(CHANGE_TYPE_EMBED, (*changes1())[0].type); |
542 // All these tests assume 1 for the client id. The only real assertion here | 544 // All these tests assume 1 for the client id. The only real assertion here |
543 // is the client id is not zero, but adding this as rest of code here | 545 // is the client id is not zero, but adding this as rest of code here |
544 // assumes 1. | 546 // assumes 1. |
545 ASSERT_GT((*changes1())[0].connection_id, 0); | 547 ASSERT_GT((*changes1())[0].connection_id, 0); |
546 connection_id_1_ = (*changes1())[0].connection_id; | 548 connection_id_1_ = (*changes1())[0].connection_id; |
547 ASSERT_FALSE((*changes1())[0].views.empty()); | 549 ASSERT_FALSE((*changes1())[0].views.empty()); |
548 root_view_id_ = (*changes1())[0].views[0].view_id; | 550 root_view_id_ = (*changes1())[0].views[0].view_id; |
549 vm_client1_->set_root_view(root_view_id_); | 551 vm_client1_->set_root_view(root_view_id_); |
550 changes1()->clear(); | 552 changes1()->clear(); |
551 } | 553 } |
552 | 554 |
553 // ApplicationDelegate implementation. | 555 // ApplicationDelegate implementation. |
554 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { | 556 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { |
555 connection->AddService(client_factory_.get()); | 557 connection->AddService(client_factory_.get()); |
556 return true; | 558 return true; |
557 } | 559 } |
558 | 560 |
559 scoped_ptr<ViewTreeClientImpl> vm_client1_; | 561 scoped_ptr<TestViewTreeClientImpl> vm_client1_; |
560 scoped_ptr<ViewTreeClientImpl> vm_client2_; | 562 scoped_ptr<TestViewTreeClientImpl> vm_client2_; |
561 scoped_ptr<ViewTreeClientImpl> vm_client3_; | 563 scoped_ptr<TestViewTreeClientImpl> vm_client3_; |
562 | 564 |
563 mojo::ViewTreeHostPtr host_; | 565 mojo::ViewTreeHostPtr host_; |
564 | 566 |
565 private: | 567 private: |
566 scoped_ptr<ViewTreeClientFactory> client_factory_; | 568 scoped_ptr<ViewTreeClientFactory> client_factory_; |
567 int connection_id_1_; | 569 int connection_id_1_; |
568 int connection_id_2_; | 570 int connection_id_2_; |
569 Id root_view_id_; | 571 Id root_view_id_; |
570 | 572 |
571 MOJO_DISALLOW_COPY_AND_ASSIGN(ViewTreeAppTest); | 573 MOJO_DISALLOW_COPY_AND_ASSIGN(ViewTreeAppTest); |
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1258 EXPECT_EQ("HierarchyChanged view=" + IdToString(view_3_1) + " new_parent=" + | 1260 EXPECT_EQ("HierarchyChanged view=" + IdToString(view_3_1) + " new_parent=" + |
1259 IdToString(view_1_1) + " old_parent=null", | 1261 IdToString(view_1_1) + " old_parent=null", |
1260 SingleChangeToDescription(*changes1())); | 1262 SingleChangeToDescription(*changes1())); |
1261 } | 1263 } |
1262 | 1264 |
1263 // Embed 1,1 again. | 1265 // Embed 1,1 again. |
1264 { | 1266 { |
1265 changes3()->clear(); | 1267 changes3()->clear(); |
1266 | 1268 |
1267 // We should get a new connection for the new embedding. | 1269 // We should get a new connection for the new embedding. |
1268 scoped_ptr<ViewTreeClientImpl> connection4( | 1270 scoped_ptr<TestViewTreeClientImpl> connection4( |
1269 EstablishConnectionViaEmbed(vm1(), view_1_1, nullptr)); | 1271 EstablishConnectionViaEmbed(vm1(), view_1_1, nullptr)); |
1270 ASSERT_TRUE(connection4.get()); | 1272 ASSERT_TRUE(connection4.get()); |
1271 EXPECT_EQ("[" + ViewParentToString(view_1_1, kNullParentId) + "]", | 1273 EXPECT_EQ("[" + ViewParentToString(view_1_1, kNullParentId) + "]", |
1272 ChangeViewDescription(*connection4->tracker()->changes())); | 1274 ChangeViewDescription(*connection4->tracker()->changes())); |
1273 | 1275 |
1274 // And 3 should get an unembed and delete. | 1276 // And 3 should get an unembed and delete. |
1275 vm_client3_->WaitForChangeCount(2); | 1277 vm_client3_->WaitForChangeCount(2); |
1276 EXPECT_EQ("OnUnembed", ChangesToDescription1(*changes3())[0]); | 1278 EXPECT_EQ("OnUnembed", ChangesToDescription1(*changes3())[0]); |
1277 EXPECT_EQ("ViewDeleted view=" + IdToString(view_1_1), | 1279 EXPECT_EQ("ViewDeleted view=" + IdToString(view_1_1), |
1278 ChangesToDescription1(*changes3())[1]); | 1280 ChangesToDescription1(*changes3())[1]); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1579 SingleChangeToDescription(*changes1())); | 1581 SingleChangeToDescription(*changes1())); |
1580 std::vector<TestView> views; | 1582 std::vector<TestView> views; |
1581 GetViewTree(vm1(), view_1_1, &views); | 1583 GetViewTree(vm1(), view_1_1, &views); |
1582 EXPECT_FALSE(views.empty()); | 1584 EXPECT_FALSE(views.empty()); |
1583 } | 1585 } |
1584 | 1586 |
1585 // Verifies Embed() works when supplying a ViewTreeClient. | 1587 // Verifies Embed() works when supplying a ViewTreeClient. |
1586 TEST_F(ViewTreeAppTest, EmbedSupplyingViewTreeClient) { | 1588 TEST_F(ViewTreeAppTest, EmbedSupplyingViewTreeClient) { |
1587 ASSERT_TRUE(vm_client1()->CreateView(1)); | 1589 ASSERT_TRUE(vm_client1()->CreateView(1)); |
1588 | 1590 |
1589 ViewTreeClientImpl client2(application_impl()); | 1591 TestViewTreeClientImpl client2(application_impl()); |
1590 mojo::ViewTreeClientPtr client2_ptr; | 1592 mojo::ViewTreeClientPtr client2_ptr; |
1591 mojo::Binding<ViewTreeClient> client2_binding(&client2, &client2_ptr); | 1593 mojo::Binding<ViewTreeClient> client2_binding(&client2, &client2_ptr); |
1592 ASSERT_TRUE( | 1594 ASSERT_TRUE( |
1593 Embed(vm1(), BuildViewId(connection_id_1(), 1), client2_ptr.Pass())); | 1595 Embed(vm1(), BuildViewId(connection_id_1(), 1), client2_ptr.Pass())); |
1594 client2.WaitForOnEmbed(); | 1596 client2.WaitForOnEmbed(); |
1595 EXPECT_EQ("OnEmbed", | 1597 EXPECT_EQ("OnEmbed", |
1596 SingleChangeToDescription(*client2.tracker()->changes())); | 1598 SingleChangeToDescription(*client2.tracker()->changes())); |
1597 } | 1599 } |
1598 | 1600 |
1599 TEST_F(ViewTreeAppTest, EmbedFailsFromOtherConnection) { | 1601 TEST_F(ViewTreeAppTest, EmbedFailsFromOtherConnection) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1667 | 1669 |
1668 // TODO(sky): need to better track changes to initial connection. For example, | 1670 // TODO(sky): need to better track changes to initial connection. For example, |
1669 // that SetBounsdViews/AddView and the like don't result in messages to the | 1671 // that SetBounsdViews/AddView and the like don't result in messages to the |
1670 // originating connection. | 1672 // originating connection. |
1671 | 1673 |
1672 // TODO(sky): make sure coverage of what was | 1674 // TODO(sky): make sure coverage of what was |
1673 // ViewManagerTest.SecondEmbedRoot_InitService and | 1675 // ViewManagerTest.SecondEmbedRoot_InitService and |
1674 // ViewManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window manager | 1676 // ViewManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window manager |
1675 // tests. | 1677 // tests. |
1676 | 1678 |
1677 } // namespace view_manager | 1679 } // namespace mus |
OLD | NEW |