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/base_paths.h" | 5 #include "base/base_paths.h" |
6 #include "base/base_switches.h" | 6 #include "base/base_switches.h" |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/process/process.h" | 11 #include "base/process/process.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "mojo/edk/embedder/embedder.h" | 13 #include "mojo/edk/embedder/embedder.h" |
14 #include "mojo/edk/embedder/platform_channel_pair.h" | 14 #include "mojo/edk/embedder/platform_channel_pair.h" |
15 #include "mojo/edk/embedder/scoped_platform_handle.h" | 15 #include "mojo/edk/embedder/scoped_platform_handle.h" |
16 #include "mojo/shell/public/cpp/shell_test.h" | 16 #include "mojo/shell/public/cpp/shell_test.h" |
17 #include "mojo/shell/public/interfaces/application_manager.mojom.h" | 17 #include "mojo/shell/public/interfaces/shell.mojom.h" |
18 #include "mojo/shell/runner/common/switches.h" | 18 #include "mojo/shell/runner/common/switches.h" |
19 #include "mojo/shell/tests/lifecycle/lifecycle_unittest.mojom.h" | 19 #include "mojo/shell/tests/lifecycle/lifecycle_unittest.mojom.h" |
20 | 20 |
21 namespace mojo { | 21 namespace mojo { |
22 namespace shell { | 22 namespace shell { |
23 namespace { | 23 namespace { |
24 | 24 |
25 const char kTestAppName[] = "mojo:lifecycle_unittest_app"; | 25 const char kTestAppName[] = "mojo:lifecycle_unittest_app"; |
26 const char kTestExeName[] = "exe:lifecycle_unittest_exe"; | 26 const char kTestExeName[] = "exe:lifecycle_unittest_exe"; |
27 const char kTestPackageName[] = "mojo:lifecycle_unittest_package"; | 27 const char kTestPackageName[] = "mojo:lifecycle_unittest_package"; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 // Allocate the pipe locally. | 203 // Allocate the pipe locally. |
204 mojo::ScopedMessagePipeHandle pipe = | 204 mojo::ScopedMessagePipeHandle pipe = |
205 mojo::edk::CreateParentMessagePipe(primordial_pipe_token); | 205 mojo::edk::CreateParentMessagePipe(primordial_pipe_token); |
206 | 206 |
207 mojo::shell::mojom::CapabilityFilterPtr filter( | 207 mojo::shell::mojom::CapabilityFilterPtr filter( |
208 mojo::shell::mojom::CapabilityFilter::New()); | 208 mojo::shell::mojom::CapabilityFilter::New()); |
209 mojo::Array<mojo::String> test_interfaces; | 209 mojo::Array<mojo::String> test_interfaces; |
210 test_interfaces.push_back("*"); | 210 test_interfaces.push_back("*"); |
211 filter->filter.insert("*", std::move(test_interfaces)); | 211 filter->filter.insert("*", std::move(test_interfaces)); |
212 | 212 |
213 mojo::shell::mojom::ApplicationManagerPtr application_manager; | 213 mojo::shell::mojom::ShellPtr shell; |
214 connector()->ConnectToInterface("mojo:shell", &application_manager); | 214 connector()->ConnectToInterface("mojo:shell", &shell); |
215 | 215 |
216 mojo::shell::mojom::ShellClientFactoryPtr factory; | 216 mojo::shell::mojom::ShellClientFactoryPtr factory; |
217 factory.Bind(mojo::InterfacePtrInfo<mojo::shell::mojom::ShellClientFactory>( | 217 factory.Bind(mojo::InterfacePtrInfo<mojo::shell::mojom::ShellClientFactory>( |
218 std::move(pipe), 0u)); | 218 std::move(pipe), 0u)); |
219 | 219 |
220 application_manager->CreateInstanceForFactory( | 220 shell->CreateInstanceForFactory(std::move(factory), kTestExeName, |
221 std::move(factory), kTestExeName, mojom::Connector::kUserInherit, | 221 mojom::Connector::kUserInherit, |
222 std::move(filter), std::move(request)); | 222 std::move(filter), std::move(request)); |
223 | 223 |
224 base::LaunchOptions options; | 224 base::LaunchOptions options; |
225 #if defined(OS_WIN) | 225 #if defined(OS_WIN) |
226 options.handles_to_inherit = &handle_passing_info; | 226 options.handles_to_inherit = &handle_passing_info; |
227 #elif defined(OS_POSIX) | 227 #elif defined(OS_POSIX) |
228 options.fds_to_remap = &handle_passing_info; | 228 options.fds_to_remap = &handle_passing_info; |
229 #endif | 229 #endif |
230 base::Process process = base::LaunchProcess(child_command_line, options); | 230 base::Process process = base::LaunchProcess(child_command_line, options); |
231 DCHECK(process.IsValid()); | 231 DCHECK(process.IsValid()); |
232 receiver->SetPID(process.Pid()); | 232 receiver->SetPID(process.Pid()); |
(...skipping 11 matching lines...) Expand all Loading... |
244 InstanceState* instances() { return instances_.get(); } | 244 InstanceState* instances() { return instances_.get(); } |
245 | 245 |
246 void WaitForInstanceDestruction() { | 246 void WaitForInstanceDestruction() { |
247 base::RunLoop loop; | 247 base::RunLoop loop; |
248 instances()->WaitForInstanceDestruction(&loop); | 248 instances()->WaitForInstanceDestruction(&loop); |
249 loop.Run(); | 249 loop.Run(); |
250 } | 250 } |
251 | 251 |
252 private: | 252 private: |
253 scoped_ptr<InstanceState> TrackInstances() { | 253 scoped_ptr<InstanceState> TrackInstances() { |
254 mojom::ApplicationManagerPtr am; | 254 mojom::ShellPtr shell; |
255 connector()->ConnectToInterface("mojo:shell", &am); | 255 connector()->ConnectToInterface("mojo:shell", &shell); |
256 mojom::InstanceListenerPtr listener; | 256 mojom::InstanceListenerPtr listener; |
257 base::RunLoop loop; | 257 base::RunLoop loop; |
258 InstanceState* state = new InstanceState(GetProxy(&listener), &loop); | 258 InstanceState* state = new InstanceState(GetProxy(&listener), &loop); |
259 am->AddInstanceListener(std::move(listener)); | 259 shell->AddInstanceListener(std::move(listener)); |
260 loop.Run(); | 260 loop.Run(); |
261 return make_scoped_ptr(state); | 261 return make_scoped_ptr(state); |
262 } | 262 } |
263 | 263 |
264 scoped_ptr<InstanceState> instances_; | 264 scoped_ptr<InstanceState> instances_; |
265 | 265 |
266 DISALLOW_COPY_AND_ASSIGN(LifecycleTest); | 266 DISALLOW_COPY_AND_ASSIGN(LifecycleTest); |
267 }; | 267 }; |
268 | 268 |
269 TEST_F(LifecycleTest, Standalone_GracefulQuit) { | 269 TEST_F(LifecycleTest, Standalone_GracefulQuit) { |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 loop.Run(); | 498 loop.Run(); |
499 | 499 |
500 WaitForInstanceDestruction(); | 500 WaitForInstanceDestruction(); |
501 EXPECT_FALSE(instances()->HasInstanceForName(kTestExeName)); | 501 EXPECT_FALSE(instances()->HasInstanceForName(kTestExeName)); |
502 EXPECT_EQ(0u, instances()->GetNewInstanceCount()); | 502 EXPECT_EQ(0u, instances()->GetNewInstanceCount()); |
503 } | 503 } |
504 | 504 |
505 | 505 |
506 } // namespace shell | 506 } // namespace shell |
507 } // namespace mojo | 507 } // namespace mojo |
OLD | NEW |