| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Note: This file also tests app_child_process.*. | |
| 6 | |
| 7 #include "shell/app_child_process_host.h" | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/macros.h" | |
| 11 #include "base/message_loop/message_loop.h" | |
| 12 #include "mojo/common/message_pump_mojo.h" | |
| 13 #include "mojo/public/c/system/types.h" | |
| 14 #include "mojo/public/cpp/system/message_pipe.h" | |
| 15 #include "shell/context.h" | |
| 16 #include "testing/gtest/include/gtest/gtest.h" | |
| 17 | |
| 18 namespace mojo { | |
| 19 namespace shell { | |
| 20 namespace { | |
| 21 | |
| 22 // Subclass just so we can observe |DidStart()|. | |
| 23 class TestAppChildProcessHost : public AppChildProcessHost { | |
| 24 public: | |
| 25 explicit TestAppChildProcessHost(Context* context) | |
| 26 : AppChildProcessHost(context) {} | |
| 27 ~TestAppChildProcessHost() override {} | |
| 28 | |
| 29 void DidStart(bool success) override { | |
| 30 EXPECT_TRUE(success); | |
| 31 AppChildProcessHost::DidStart(success); | |
| 32 base::MessageLoop::current()->QuitWhenIdle(); | |
| 33 } | |
| 34 | |
| 35 private: | |
| 36 DISALLOW_COPY_AND_ASSIGN(TestAppChildProcessHost); | |
| 37 }; | |
| 38 | |
| 39 #if defined(OS_ANDROID) | |
| 40 // TODO(qsr): Multiprocess shell tests are not supported on android. | |
| 41 #define MAYBE_StartJoin DISABLED_StartJoin | |
| 42 #else | |
| 43 #define MAYBE_StartJoin StartJoin | |
| 44 #endif // defined(OS_ANDROID) | |
| 45 // Just tests starting the child process and joining it (without starting an | |
| 46 // app). | |
| 47 TEST(AppChildProcessHostTest, MAYBE_StartJoin) { | |
| 48 Context context; | |
| 49 base::MessageLoop message_loop( | |
| 50 scoped_ptr<base::MessagePump>(new common::MessagePumpMojo())); | |
| 51 context.Init(); | |
| 52 TestAppChildProcessHost app_child_process_host(&context); | |
| 53 app_child_process_host.Start(); | |
| 54 message_loop.Run(); // This should run until |DidStart()|. | |
| 55 app_child_process_host.ExitNow(123); | |
| 56 int exit_code = app_child_process_host.Join(); | |
| 57 VLOG(2) << "Joined child: exit_code = " << exit_code; | |
| 58 EXPECT_EQ(123, exit_code); | |
| 59 | |
| 60 context.Shutdown(); | |
| 61 } | |
| 62 | |
| 63 #if defined(OS_ANDROID) | |
| 64 // TODO(qsr): Multiprocess shell tests are not supported on android. | |
| 65 #define MAYBE_ConnectionError DISABLED_ConnectionError | |
| 66 #else | |
| 67 #define MAYBE_ConnectionError ConnectionError | |
| 68 #endif // defined(OS_ANDROID) | |
| 69 // Tests that even on connection error, the callback to |StartApp()| will get | |
| 70 // called. | |
| 71 TEST(AppChildProcessHostTest, MAYBE_ConnectionError) { | |
| 72 Context context; | |
| 73 base::MessageLoop message_loop( | |
| 74 scoped_ptr<base::MessagePump>(new common::MessagePumpMojo())); | |
| 75 context.Init(); | |
| 76 TestAppChildProcessHost app_child_process_host(&context); | |
| 77 app_child_process_host.Start(); | |
| 78 message_loop.Run(); // This should run until |DidStart()|. | |
| 79 // Send |ExitNow()| first, so that the |StartApp()| below won't actually be | |
| 80 // processed, and we'll just get a connection error. | |
| 81 app_child_process_host.ExitNow(123); | |
| 82 MessagePipe mp; | |
| 83 InterfaceRequest<Application> application_request; | |
| 84 application_request.Bind(mp.handle0.Pass()); | |
| 85 // This won't actually be called, but the callback should be run. | |
| 86 MojoResult result = MOJO_RESULT_INTERNAL; | |
| 87 app_child_process_host.StartApp( | |
| 88 "/does_not_exist/cbvgyuio", false, application_request.Pass(), | |
| 89 [&result](int32_t r) { | |
| 90 result = r; | |
| 91 base::MessageLoop::current()->QuitWhenIdle(); | |
| 92 }); | |
| 93 message_loop.Run(); | |
| 94 EXPECT_EQ(MOJO_RESULT_UNKNOWN, result); | |
| 95 int exit_code = app_child_process_host.Join(); | |
| 96 VLOG(2) << "Joined child: exit_code = " << exit_code; | |
| 97 EXPECT_EQ(123, exit_code); | |
| 98 | |
| 99 context.Shutdown(); | |
| 100 } | |
| 101 | |
| 102 } // namespace | |
| 103 } // namespace shell | |
| 104 } // namespace mojo | |
| OLD | NEW |