| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/process/process.h" | 11 #include "base/process/process.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "mojo/public/cpp/bindings/binding.h" | 13 #include "mojo/public/cpp/bindings/binding.h" |
| 14 #include "services/service_manager/public/cpp/identity.h" | 14 #include "services/service_manager/public/cpp/identity.h" |
| 15 #include "services/service_manager/public/cpp/service_test.h" | 15 #include "services/service_manager/public/cpp/service_test.h" |
| 16 #include "services/service_manager/public/interfaces/constants.mojom.h" | 16 #include "services/service_manager/public/interfaces/constants.mojom.h" |
| 17 #include "services/service_manager/public/interfaces/service_manager.mojom.h" | 17 #include "services/service_manager/public/interfaces/service_manager.mojom.h" |
| 18 #include "services/service_manager/tests/lifecycle/lifecycle_unittest.mojom.h" | 18 #include "services/service_manager/tests/lifecycle/lifecycle_unittest.mojom.h" |
| 19 #include "services/service_manager/tests/util.h" | 19 #include "services/service_manager/tests/util.h" |
| 20 | 20 |
| 21 namespace service_manager { | 21 namespace service_manager { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 const char kTestAppName[] = "lifecycle_unittest_app"; | 25 const char kTestAppName[] = "lifecycle_unittest_app"; |
| 26 const char kTestParentName[] = "lifecycle_unittest_parent"; | |
| 27 const char kTestExeName[] = "lifecycle_unittest_exe"; | 26 const char kTestExeName[] = "lifecycle_unittest_exe"; |
| 28 const char kTestPackageName[] = "lifecycle_unittest_package"; | 27 const char kTestPackageName[] = "lifecycle_unittest_package"; |
| 29 const char kTestPackageAppNameA[] = "lifecycle_unittest_package_app_a"; | 28 const char kTestPackageAppNameA[] = "lifecycle_unittest_package_app_a"; |
| 30 const char kTestPackageAppNameB[] = "lifecycle_unittest_package_app_b"; | 29 const char kTestPackageAppNameB[] = "lifecycle_unittest_package_app_b"; |
| 31 const char kTestName[] = "lifecycle_unittest"; | 30 const char kTestName[] = "lifecycle_unittest"; |
| 32 | 31 |
| 33 void QuitLoop(base::RunLoop* loop) { | 32 void QuitLoop(base::RunLoop* loop) { |
| 34 loop->Quit(); | 33 loop->Quit(); |
| 35 } | 34 } |
| 36 | 35 |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 base::RunLoop loop; | 418 base::RunLoop loop; |
| 420 lifecycle.set_connection_error_handler(base::Bind(&QuitLoop, &loop)); | 419 lifecycle.set_connection_error_handler(base::Bind(&QuitLoop, &loop)); |
| 421 process.Terminate(9, true); | 420 process.Terminate(9, true); |
| 422 loop.Run(); | 421 loop.Run(); |
| 423 | 422 |
| 424 WaitForInstanceDestruction(); | 423 WaitForInstanceDestruction(); |
| 425 EXPECT_FALSE(instances()->HasInstanceForName(kTestExeName)); | 424 EXPECT_FALSE(instances()->HasInstanceForName(kTestExeName)); |
| 426 EXPECT_EQ(0u, instances()->GetNewInstanceCount()); | 425 EXPECT_EQ(0u, instances()->GetNewInstanceCount()); |
| 427 } | 426 } |
| 428 | 427 |
| 429 TEST_F(LifecycleTest, ShutdownTree) { | |
| 430 // Verifies that Instances are destroyed when their creator is. | |
| 431 std::unique_ptr<Connection> parent_connection = | |
| 432 connector()->Connect(kTestParentName); | |
| 433 test::mojom::ParentPtr parent; | |
| 434 parent_connection->GetInterface(&parent); | |
| 435 | |
| 436 // This asks kTestParentName to open a connection to kTestAppName and blocks | |
| 437 // on a response from a Ping(). | |
| 438 { | |
| 439 base::RunLoop loop; | |
| 440 parent->ConnectToChild(base::Bind(&QuitLoop, &loop)); | |
| 441 loop.Run(); | |
| 442 } | |
| 443 | |
| 444 // Should now have two new instances (parent and child). | |
| 445 EXPECT_EQ(2u, instances()->GetNewInstanceCount()); | |
| 446 EXPECT_TRUE(instances()->HasInstanceForName(kTestParentName)); | |
| 447 EXPECT_TRUE(instances()->HasInstanceForName(kTestAppName)); | |
| 448 | |
| 449 parent->Quit(); | |
| 450 | |
| 451 // Quitting the parent should cascade-quit the child. | |
| 452 WaitForInstanceDestruction(); | |
| 453 EXPECT_EQ(0u, instances()->GetNewInstanceCount()); | |
| 454 EXPECT_FALSE(instances()->HasInstanceForName(kTestParentName)); | |
| 455 EXPECT_FALSE(instances()->HasInstanceForName(kTestAppName)); | |
| 456 } | |
| 457 | |
| 458 } // namespace service_manager | 428 } // namespace service_manager |
| OLD | NEW |