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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/process/process.h" | 8 #include "base/process/process.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "mojo/shell/public/cpp/identity.h" | 10 #include "mojo/shell/public/cpp/identity.h" |
11 #include "mojo/shell/public/cpp/shell_test.h" | 11 #include "mojo/shell/public/cpp/shell_test.h" |
12 #include "mojo/shell/public/interfaces/shell.mojom.h" | 12 #include "mojo/shell/public/interfaces/shell.mojom.h" |
13 #include "mojo/shell/tests/lifecycle/lifecycle_unittest.mojom.h" | 13 #include "mojo/shell/tests/lifecycle/lifecycle_unittest.mojom.h" |
14 #include "mojo/shell/tests/util.h" | 14 #include "mojo/shell/tests/util.h" |
15 | 15 |
16 namespace mojo { | 16 namespace mojo { |
17 namespace shell { | 17 namespace shell { |
18 namespace { | 18 namespace { |
19 | 19 |
20 const char kTestAppName[] = "mojo:lifecycle_unittest_app"; | 20 const char kTestAppName[] = "mojo:lifecycle_unittest_app"; |
| 21 const char kTestParentName[] = "mojo:lifecycle_unittest_parent"; |
21 const char kTestExeName[] = "exe:lifecycle_unittest_exe"; | 22 const char kTestExeName[] = "exe:lifecycle_unittest_exe"; |
22 const char kTestPackageName[] = "mojo:lifecycle_unittest_package"; | 23 const char kTestPackageName[] = "mojo:lifecycle_unittest_package"; |
23 const char kTestPackageAppNameA[] = "mojo:lifecycle_unittest_package_app_a"; | 24 const char kTestPackageAppNameA[] = "mojo:lifecycle_unittest_package_app_a"; |
24 const char kTestPackageAppNameB[] = "mojo:lifecycle_unittest_package_app_b"; | 25 const char kTestPackageAppNameB[] = "mojo:lifecycle_unittest_package_app_b"; |
25 const char kTestName[] = "mojo:lifecycle_unittest"; | 26 const char kTestName[] = "mojo:lifecycle_unittest"; |
26 | 27 |
27 void QuitLoop(base::RunLoop* loop) { | 28 void QuitLoop(base::RunLoop* loop) { |
28 loop->Quit(); | 29 loop->Quit(); |
29 } | 30 } |
30 | 31 |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 base::RunLoop loop; | 432 base::RunLoop loop; |
432 lifecycle.set_connection_error_handler(base::Bind(&QuitLoop, &loop)); | 433 lifecycle.set_connection_error_handler(base::Bind(&QuitLoop, &loop)); |
433 process.Terminate(9, true); | 434 process.Terminate(9, true); |
434 loop.Run(); | 435 loop.Run(); |
435 | 436 |
436 WaitForInstanceDestruction(); | 437 WaitForInstanceDestruction(); |
437 EXPECT_FALSE(instances()->HasInstanceForName(kTestExeName)); | 438 EXPECT_FALSE(instances()->HasInstanceForName(kTestExeName)); |
438 EXPECT_EQ(0u, instances()->GetNewInstanceCount()); | 439 EXPECT_EQ(0u, instances()->GetNewInstanceCount()); |
439 } | 440 } |
440 | 441 |
| 442 TEST_F(LifecycleTest, ShutdownTree) { |
| 443 // Verifies that Instances are destroyed when their creator is. |
| 444 scoped_ptr<Connection> parent_connection = |
| 445 connector()->Connect(kTestParentName); |
| 446 test::mojom::ParentPtr parent; |
| 447 parent_connection->GetInterface(&parent); |
| 448 |
| 449 // This asks kTestParentName to open a connection to kTestAppName and blocks |
| 450 // on a response from a Ping(). |
| 451 { |
| 452 base::RunLoop loop; |
| 453 parent->ConnectToChild(base::Bind(&QuitLoop, &loop)); |
| 454 loop.Run(); |
| 455 } |
| 456 |
| 457 // Should now have two new instances (parent and child). |
| 458 EXPECT_EQ(2u, instances()->GetNewInstanceCount()); |
| 459 EXPECT_TRUE(instances()->HasInstanceForName(kTestParentName)); |
| 460 EXPECT_TRUE(instances()->HasInstanceForName(kTestAppName)); |
| 461 |
| 462 parent->Quit(); |
| 463 |
| 464 // Quitting the parent should cascade-quit the child. |
| 465 WaitForInstanceDestruction(); |
| 466 EXPECT_EQ(0u, instances()->GetNewInstanceCount()); |
| 467 EXPECT_FALSE(instances()->HasInstanceForName(kTestParentName)); |
| 468 EXPECT_FALSE(instances()->HasInstanceForName(kTestAppName)); |
| 469 } |
441 | 470 |
442 } // namespace shell | 471 } // namespace shell |
443 } // namespace mojo | 472 } // namespace mojo |
OLD | NEW |