| 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 "mojo/public/cpp/application/application_delegate.h" | 8 #include "mojo/public/cpp/application/application_delegate.h" |
| 9 #include "mojo/public/cpp/application/application_impl.h" | 9 #include "mojo/public/cpp/application/application_impl.h" |
| 10 #include "mojo/public/cpp/application/application_test_base.h" | 10 #include "mojo/public/cpp/application/application_test_base.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 // block until call completes and return the result. | 73 // block until call completes and return the result. |
| 74 bool CreateView(ViewManagerService* vm, Id view_id) { | 74 bool CreateView(ViewManagerService* vm, Id view_id) { |
| 75 ErrorCode result = ERROR_CODE_NONE; | 75 ErrorCode result = ERROR_CODE_NONE; |
| 76 base::RunLoop run_loop; | 76 base::RunLoop run_loop; |
| 77 vm->CreateView(view_id, | 77 vm->CreateView(view_id, |
| 78 base::Bind(&ErrorCodeResultCallback, &run_loop, &result)); | 78 base::Bind(&ErrorCodeResultCallback, &run_loop, &result)); |
| 79 run_loop.Run(); | 79 run_loop.Run(); |
| 80 return result == ERROR_CODE_NONE; | 80 return result == ERROR_CODE_NONE; |
| 81 } | 81 } |
| 82 | 82 |
| 83 bool EmbedUrl(ViewManagerService* vm, Id root_id) { | 83 bool EmbedUrl(ViewManagerService* vm, const String& url, Id root_id) { |
| 84 bool result = false; | 84 bool result = false; |
| 85 base::RunLoop run_loop; | 85 base::RunLoop run_loop; |
| 86 { | 86 { |
| 87 vm->EmbedUrl("mojo:view_manager_service_apptests", root_id, nullptr, | 87 vm->EmbedUrl(url, root_id, nullptr, nullptr, |
| 88 nullptr, base::Bind(&BoolResultCallback, &run_loop, &result)); | 88 base::Bind(&BoolResultCallback, &run_loop, &result)); |
| 89 } | 89 } |
| 90 run_loop.Run(); | 90 run_loop.Run(); |
| 91 return result; | 91 return result; |
| 92 } | 92 } |
| 93 | 93 |
| 94 bool Embed(ViewManagerService* vm, | 94 bool Embed(ViewManagerService* vm, |
| 95 Id root_id, | 95 Id root_id, |
| 96 mojo::ViewManagerClientPtr client) { | 96 mojo::ViewManagerClientPtr client) { |
| 97 bool result = false; | 97 bool result = false; |
| 98 base::RunLoop run_loop; | 98 base::RunLoop run_loop; |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 ASSERT_TRUE(vm_client3_.get() == nullptr); | 435 ASSERT_TRUE(vm_client3_.get() == nullptr); |
| 436 vm_client3_ = EstablishConnectionViaEmbed(owner, root_id); | 436 vm_client3_ = EstablishConnectionViaEmbed(owner, root_id); |
| 437 ASSERT_TRUE(vm_client3_.get() != nullptr); | 437 ASSERT_TRUE(vm_client3_.get() != nullptr); |
| 438 } | 438 } |
| 439 | 439 |
| 440 // Establishes a new connection by way of Embed() on the specified | 440 // Establishes a new connection by way of Embed() on the specified |
| 441 // ViewManagerService. | 441 // ViewManagerService. |
| 442 scoped_ptr<ViewManagerClientImpl> EstablishConnectionViaEmbed( | 442 scoped_ptr<ViewManagerClientImpl> EstablishConnectionViaEmbed( |
| 443 ViewManagerService* owner, | 443 ViewManagerService* owner, |
| 444 Id root_id) { | 444 Id root_id) { |
| 445 if (!EmbedUrl(owner, root_id)) { | 445 if (!EmbedUrl(owner, application_impl()->url(), root_id)) { |
| 446 ADD_FAILURE() << "Embed() failed"; | 446 ADD_FAILURE() << "Embed() failed"; |
| 447 return nullptr; | 447 return nullptr; |
| 448 } | 448 } |
| 449 scoped_ptr<ViewManagerClientImpl> client = | 449 scoped_ptr<ViewManagerClientImpl> client = |
| 450 client_factory_.WaitForInstance(); | 450 client_factory_.WaitForInstance(); |
| 451 if (!client.get()) { | 451 if (!client.get()) { |
| 452 ADD_FAILURE() << "WaitForInstance failed"; | 452 ADD_FAILURE() << "WaitForInstance failed"; |
| 453 return nullptr; | 453 return nullptr; |
| 454 } | 454 } |
| 455 client->WaitForOnEmbed(); | 455 client->WaitForOnEmbed(); |
| 456 | 456 |
| 457 const std::string expected_creator = | 457 const std::string expected_creator = |
| 458 owner == vm1() ? "mojo:window_manager" | 458 owner == vm1() ? "mojo:window_manager" : application_impl()->url(); |
| 459 : "mojo:view_manager_service_apptests"; | |
| 460 EXPECT_EQ("OnEmbed creator=" + expected_creator, | 459 EXPECT_EQ("OnEmbed creator=" + expected_creator, |
| 461 SingleChangeToDescription(*client->tracker()->changes())); | 460 SingleChangeToDescription(*client->tracker()->changes())); |
| 462 return client.Pass(); | 461 return client.Pass(); |
| 463 } | 462 } |
| 464 | 463 |
| 465 // ApplicationTestBase: | 464 // ApplicationTestBase: |
| 466 ApplicationDelegate* GetApplicationDelegate() override { return this; } | 465 ApplicationDelegate* GetApplicationDelegate() override { return this; } |
| 467 void SetUp() override { | 466 void SetUp() override { |
| 468 ApplicationTestBase::SetUp(); | 467 ApplicationTestBase::SetUp(); |
| 469 ApplicationConnection* vm_connection = | 468 ApplicationConnection* vm_connection = |
| (...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1490 // TODO(sky): need to better track changes to initial connection. For example, | 1489 // TODO(sky): need to better track changes to initial connection. For example, |
| 1491 // that SetBounsdViews/AddView and the like don't result in messages to the | 1490 // that SetBounsdViews/AddView and the like don't result in messages to the |
| 1492 // originating connection. | 1491 // originating connection. |
| 1493 | 1492 |
| 1494 // TODO(sky): make sure coverage of what was | 1493 // TODO(sky): make sure coverage of what was |
| 1495 // ViewManagerTest.SecondEmbedRoot_InitService and | 1494 // ViewManagerTest.SecondEmbedRoot_InitService and |
| 1496 // ViewManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window manager | 1495 // ViewManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window manager |
| 1497 // tests. | 1496 // tests. |
| 1498 | 1497 |
| 1499 } // namespace view_manager | 1498 } // namespace view_manager |
| OLD | NEW |