| 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 // Note: This file also tests child_process.*. | 5 // Note: This file also tests child_process.*. |
| 6 | 6 |
| 7 #include "mojo/shell/child_process_host.h" | 7 #include "shell/child_process_host.h" |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "mojo/common/message_pump_mojo.h" | 12 #include "mojo/common/message_pump_mojo.h" |
| 13 #include "mojo/shell/context.h" | 13 #include "shell/context.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace mojo { | 16 namespace mojo { |
| 17 namespace shell { | 17 namespace shell { |
| 18 namespace test { | 18 namespace test { |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 class TestChildProcessHostDelegate : public ChildProcessHost::Delegate { | 21 class TestChildProcessHostDelegate : public ChildProcessHost::Delegate { |
| 22 public: | 22 public: |
| 23 TestChildProcessHostDelegate() {} | 23 TestChildProcessHostDelegate() {} |
| 24 ~TestChildProcessHostDelegate() {} | 24 ~TestChildProcessHostDelegate() {} |
| 25 void WillStart() override { | 25 void WillStart() override { |
| 26 VLOG(2) << "TestChildProcessHostDelegate::WillStart()"; | 26 VLOG(2) << "TestChildProcessHostDelegate::WillStart()"; |
| 27 } | 27 } |
| 28 void DidStart(bool success) override { | 28 void DidStart(bool success) override { |
| 29 VLOG(2) << "TestChildProcessHostDelegate::DidStart(" << success << ")"; | 29 VLOG(2) << "TestChildProcessHostDelegate::DidStart(" << success << ")"; |
| 30 base::MessageLoop::current()->QuitWhenIdle(); | 30 base::MessageLoop::current()->QuitWhenIdle(); |
| 31 } | 31 } |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 typedef testing::Test ChildProcessHostTest; | 34 typedef testing::Test ChildProcessHostTest; |
| 35 | 35 |
| 36 TEST_F(ChildProcessHostTest, Basic) { | 36 TEST_F(ChildProcessHostTest, Basic) { |
| 37 Context context; | 37 Context context; |
| 38 base::MessageLoop message_loop( | 38 base::MessageLoop message_loop( |
| 39 scoped_ptr<base::MessagePump>(new common::MessagePumpMojo())); | 39 scoped_ptr<base::MessagePump>(new common::MessagePumpMojo())); |
| 40 context.Init(); | 40 context.Init(); |
| 41 TestChildProcessHostDelegate child_process_host_delegate; | 41 TestChildProcessHostDelegate child_process_host_delegate; |
| 42 ChildProcessHost child_process_host(&context, | 42 ChildProcessHost child_process_host(&context, &child_process_host_delegate, |
| 43 &child_process_host_delegate, | |
| 44 ChildProcess::TYPE_TEST); | 43 ChildProcess::TYPE_TEST); |
| 45 child_process_host.Start(); | 44 child_process_host.Start(); |
| 46 message_loop.Run(); | 45 message_loop.Run(); |
| 47 int exit_code = child_process_host.Join(); | 46 int exit_code = child_process_host.Join(); |
| 48 VLOG(2) << "Joined child: exit_code = " << exit_code; | 47 VLOG(2) << "Joined child: exit_code = " << exit_code; |
| 49 EXPECT_EQ(0, exit_code); | 48 EXPECT_EQ(0, exit_code); |
| 50 } | 49 } |
| 51 | 50 |
| 52 } // namespace | 51 } // namespace |
| 53 } // namespace test | 52 } // namespace test |
| 54 } // namespace shell | 53 } // namespace shell |
| 55 } // namespace mojo | 54 } // namespace mojo |
| OLD | NEW |