Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: shell/child_process_host_unittest.cc

Issue 1067173003: Remove mojo:: part of mojo::shell:: nested namespace in //shell. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/common/message_pump_mojo.h" 13 #include "mojo/common/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/context.h" 16 #include "shell/context.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 namespace mojo {
20 namespace shell { 19 namespace shell {
21 namespace { 20 namespace {
22 21
23 // Subclass just so we can observe |DidStart()|. 22 // Subclass just so we can observe |DidStart()|.
24 class TestChildProcessHost : public ChildProcessHost { 23 class TestChildProcessHost : public ChildProcessHost {
25 public: 24 public:
26 explicit TestChildProcessHost(Context* context) : ChildProcessHost(context) {} 25 explicit TestChildProcessHost(Context* context) : ChildProcessHost(context) {}
27 ~TestChildProcessHost() override {} 26 ~TestChildProcessHost() override {}
28 27
29 void DidStart(bool success) override { 28 void DidStart(bool success) override {
(...skipping 10 matching lines...) Expand all
40 // TODO(qsr): Multiprocess shell tests are not supported on android. 39 // TODO(qsr): Multiprocess shell tests are not supported on android.
41 #define MAYBE_StartJoin DISABLED_StartJoin 40 #define MAYBE_StartJoin DISABLED_StartJoin
42 #else 41 #else
43 #define MAYBE_StartJoin StartJoin 42 #define MAYBE_StartJoin StartJoin
44 #endif // defined(OS_ANDROID) 43 #endif // defined(OS_ANDROID)
45 // Just tests starting the child process and joining it (without starting an 44 // Just tests starting the child process and joining it (without starting an
46 // app). 45 // app).
47 TEST(ChildProcessHostTest, MAYBE_StartJoin) { 46 TEST(ChildProcessHostTest, MAYBE_StartJoin) {
48 Context context; 47 Context context;
49 base::MessageLoop message_loop( 48 base::MessageLoop message_loop(
50 scoped_ptr<base::MessagePump>(new common::MessagePumpMojo())); 49 scoped_ptr<base::MessagePump>(new mojo::common::MessagePumpMojo()));
51 context.Init(); 50 context.Init();
52 TestChildProcessHost child_process_host(&context); 51 TestChildProcessHost child_process_host(&context);
53 child_process_host.Start(); 52 child_process_host.Start();
54 message_loop.Run(); // This should run until |DidStart()|. 53 message_loop.Run(); // This should run until |DidStart()|.
55 child_process_host.ExitNow(123); 54 child_process_host.ExitNow(123);
56 int exit_code = child_process_host.Join(); 55 int exit_code = child_process_host.Join();
57 VLOG(2) << "Joined child: exit_code = " << exit_code; 56 VLOG(2) << "Joined child: exit_code = " << exit_code;
58 EXPECT_EQ(123, exit_code); 57 EXPECT_EQ(123, exit_code);
59 58
60 context.Shutdown(); 59 context.Shutdown();
61 } 60 }
62 61
63 #if defined(OS_ANDROID) 62 #if defined(OS_ANDROID)
64 // TODO(qsr): Multiprocess shell tests are not supported on android. 63 // TODO(qsr): Multiprocess shell tests are not supported on android.
65 #define MAYBE_ConnectionError DISABLED_ConnectionError 64 #define MAYBE_ConnectionError DISABLED_ConnectionError
66 #else 65 #else
67 #define MAYBE_ConnectionError ConnectionError 66 #define MAYBE_ConnectionError ConnectionError
68 #endif // defined(OS_ANDROID) 67 #endif // defined(OS_ANDROID)
69 // Tests that even on connection error, the callback to |StartApp()| will get 68 // Tests that even on connection error, the callback to |StartApp()| will get
70 // called. 69 // called.
71 TEST(ChildProcessHostTest, MAYBE_ConnectionError) { 70 TEST(ChildProcessHostTest, MAYBE_ConnectionError) {
72 Context context; 71 Context context;
73 base::MessageLoop message_loop( 72 base::MessageLoop message_loop(
74 scoped_ptr<base::MessagePump>(new common::MessagePumpMojo())); 73 scoped_ptr<base::MessagePump>(new mojo::common::MessagePumpMojo()));
75 context.Init(); 74 context.Init();
76 TestChildProcessHost child_process_host(&context); 75 TestChildProcessHost child_process_host(&context);
77 child_process_host.Start(); 76 child_process_host.Start();
78 message_loop.Run(); // This should run until |DidStart()|. 77 message_loop.Run(); // This should run until |DidStart()|.
79 // Send |ExitNow()| first, so that the |StartApp()| below won't actually be 78 // Send |ExitNow()| first, so that the |StartApp()| below won't actually be
80 // processed, and we'll just get a connection error. 79 // processed, and we'll just get a connection error.
81 child_process_host.ExitNow(123); 80 child_process_host.ExitNow(123);
82 MessagePipe mp; 81 mojo::MessagePipe mp;
83 InterfaceRequest<Application> application_request; 82 mojo::InterfaceRequest<mojo::Application> application_request;
84 application_request.Bind(mp.handle0.Pass()); 83 application_request.Bind(mp.handle0.Pass());
85 // This won't actually be called, but the callback should be run. 84 // This won't actually be called, but the callback should be run.
86 MojoResult result = MOJO_RESULT_INTERNAL; 85 MojoResult result = MOJO_RESULT_INTERNAL;
87 child_process_host.StartApp("/does_not_exist/cbvgyuio", false, 86 child_process_host.StartApp("/does_not_exist/cbvgyuio", false,
88 application_request.Pass(), [&result](int32_t r) { 87 application_request.Pass(), [&result](int32_t r) {
89 result = r; 88 result = r;
90 base::MessageLoop::current()->QuitWhenIdle(); 89 base::MessageLoop::current()->QuitWhenIdle();
91 }); 90 });
92 message_loop.Run(); 91 message_loop.Run();
93 EXPECT_EQ(MOJO_RESULT_UNKNOWN, result); 92 EXPECT_EQ(MOJO_RESULT_UNKNOWN, result);
94 int exit_code = child_process_host.Join(); 93 int exit_code = child_process_host.Join();
95 VLOG(2) << "Joined child: exit_code = " << exit_code; 94 VLOG(2) << "Joined child: exit_code = " << exit_code;
96 EXPECT_EQ(123, exit_code); 95 EXPECT_EQ(123, exit_code);
97 96
98 context.Shutdown(); 97 context.Shutdown();
99 } 98 }
100 99
101 } // namespace 100 } // namespace
102 } // namespace shell 101 } // namespace shell
103 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698