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