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 partly tests child_main.*. | 5 // Note: This file also partly tests child_main.*. |
6 | 6 |
7 #include "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 "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "mojo/message_pump/message_pump_mojo.h" | 13 #include "mojo/message_pump/message_pump_mojo.h" |
14 #include "mojo/public/c/system/types.h" | 14 #include "mojo/public/c/system/types.h" |
15 #include "mojo/public/cpp/system/message_pipe.h" | 15 #include "mojo/public/cpp/system/message_pipe.h" |
| 16 #include "shell/application_manager/native_application_options.h" |
16 #include "shell/context.h" | 17 #include "shell/context.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 | 19 |
19 namespace shell { | 20 namespace shell { |
20 namespace { | 21 namespace { |
21 | 22 |
22 // Subclass just so we can observe |DidStart()|. | 23 // Subclass just so we can observe |DidStart()|. |
23 class TestChildProcessHost : public ChildProcessHost { | 24 class TestChildProcessHost : public ChildProcessHost { |
24 public: | 25 public: |
25 explicit TestChildProcessHost(Context* context) : ChildProcessHost(context) {} | 26 explicit TestChildProcessHost(Context* context) : ChildProcessHost(context) {} |
(...skipping 16 matching lines...) Expand all Loading... |
42 #define MAYBE_StartJoin StartJoin | 43 #define MAYBE_StartJoin StartJoin |
43 #endif // defined(OS_ANDROID) | 44 #endif // defined(OS_ANDROID) |
44 // Just tests starting the child process and joining it (without starting an | 45 // Just tests starting the child process and joining it (without starting an |
45 // app). | 46 // app). |
46 TEST(ChildProcessHostTest, MAYBE_StartJoin) { | 47 TEST(ChildProcessHostTest, MAYBE_StartJoin) { |
47 Context context; | 48 Context context; |
48 base::MessageLoop message_loop( | 49 base::MessageLoop message_loop( |
49 scoped_ptr<base::MessagePump>(new mojo::common::MessagePumpMojo())); | 50 scoped_ptr<base::MessagePump>(new mojo::common::MessagePumpMojo())); |
50 context.Init(); | 51 context.Init(); |
51 TestChildProcessHost child_process_host(&context); | 52 TestChildProcessHost child_process_host(&context); |
52 child_process_host.Start(false /* require_32_bit */); | 53 child_process_host.Start(NativeApplicationOptions()); |
53 message_loop.Run(); // This should run until |DidStart()|. | 54 message_loop.Run(); // This should run until |DidStart()|. |
54 child_process_host.ExitNow(123); | 55 child_process_host.ExitNow(123); |
55 int exit_code = child_process_host.Join(); | 56 int exit_code = child_process_host.Join(); |
56 VLOG(2) << "Joined child: exit_code = " << exit_code; | 57 VLOG(2) << "Joined child: exit_code = " << exit_code; |
57 EXPECT_EQ(123, exit_code); | 58 EXPECT_EQ(123, exit_code); |
58 | 59 |
59 context.Shutdown(); | 60 context.Shutdown(); |
60 } | 61 } |
61 | 62 |
62 #if defined(OS_ANDROID) | 63 #if defined(OS_ANDROID) |
63 // TODO(qsr): Multiprocess shell tests are not supported on android. | 64 // TODO(qsr): Multiprocess shell tests are not supported on android. |
64 #define MAYBE_ConnectionError DISABLED_ConnectionError | 65 #define MAYBE_ConnectionError DISABLED_ConnectionError |
65 #else | 66 #else |
66 #define MAYBE_ConnectionError ConnectionError | 67 #define MAYBE_ConnectionError ConnectionError |
67 #endif // defined(OS_ANDROID) | 68 #endif // defined(OS_ANDROID) |
68 // Tests that even on connection error, the callback to |StartApp()| will get | 69 // Tests that even on connection error, the callback to |StartApp()| will get |
69 // called. | 70 // called. |
70 TEST(ChildProcessHostTest, MAYBE_ConnectionError) { | 71 TEST(ChildProcessHostTest, MAYBE_ConnectionError) { |
71 Context context; | 72 Context context; |
72 base::MessageLoop message_loop( | 73 base::MessageLoop message_loop( |
73 scoped_ptr<base::MessagePump>(new mojo::common::MessagePumpMojo())); | 74 scoped_ptr<base::MessagePump>(new mojo::common::MessagePumpMojo())); |
74 context.Init(); | 75 context.Init(); |
75 TestChildProcessHost child_process_host(&context); | 76 TestChildProcessHost child_process_host(&context); |
76 child_process_host.Start(false /* require_32_bit */); | 77 child_process_host.Start(NativeApplicationOptions()); |
77 message_loop.Run(); // This should run until |DidStart()|. | 78 message_loop.Run(); // This should run until |DidStart()|. |
78 // Send |ExitNow()| first, so that the |StartApp()| below won't actually be | 79 // Send |ExitNow()| first, so that the |StartApp()| below won't actually be |
79 // processed, and we'll just get a connection error. | 80 // processed, and we'll just get a connection error. |
80 child_process_host.ExitNow(123); | 81 child_process_host.ExitNow(123); |
81 mojo::MessagePipe mp; | 82 mojo::MessagePipe mp; |
82 mojo::InterfaceRequest<mojo::Application> application_request; | 83 mojo::InterfaceRequest<mojo::Application> application_request; |
83 application_request.Bind(mp.handle0.Pass()); | 84 application_request.Bind(mp.handle0.Pass()); |
84 // This won't actually be called, but the callback should be run. | 85 // This won't actually be called, but the callback should be run. |
85 MojoResult result = MOJO_RESULT_INTERNAL; | 86 MojoResult result = MOJO_RESULT_INTERNAL; |
86 child_process_host.StartApp("/does_not_exist/cbvgyuio", | 87 child_process_host.StartApp("/does_not_exist/cbvgyuio", |
87 application_request.Pass(), [&result](int32_t r) { | 88 application_request.Pass(), [&result](int32_t r) { |
88 result = r; | 89 result = r; |
89 base::MessageLoop::current()->QuitWhenIdle(); | 90 base::MessageLoop::current()->QuitWhenIdle(); |
90 }); | 91 }); |
91 message_loop.Run(); | 92 message_loop.Run(); |
92 EXPECT_EQ(MOJO_RESULT_UNKNOWN, result); | 93 EXPECT_EQ(MOJO_RESULT_UNKNOWN, result); |
93 int exit_code = child_process_host.Join(); | 94 int exit_code = child_process_host.Join(); |
94 VLOG(2) << "Joined child: exit_code = " << exit_code; | 95 VLOG(2) << "Joined child: exit_code = " << exit_code; |
95 EXPECT_EQ(123, exit_code); | 96 EXPECT_EQ(123, exit_code); |
96 | 97 |
97 context.Shutdown(); | 98 context.Shutdown(); |
98 } | 99 } |
99 | 100 |
100 } // namespace | 101 } // namespace |
101 } // namespace shell | 102 } // namespace shell |
OLD | NEW |