OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/utility/importer/firefox_importer_unittest_utils.h" | 5 #include "chrome/utility/importer/firefox_importer_unittest_utils.h" |
6 | 6 |
7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
12 #include "base/files/scoped_file.h" | 12 #include "base/files/scoped_file.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/posix/global_descriptors.h" | 15 #include "base/posix/global_descriptors.h" |
16 #include "base/process/kill.h" | 16 #include "base/process/kill.h" |
17 #include "base/process/launch.h" | 17 #include "base/process/launch.h" |
18 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
19 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
| 20 #include "base/test/multiprocess_test.h" |
20 #include "base/test/test_timeouts.h" | 21 #include "base/test/test_timeouts.h" |
21 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
22 #include "chrome/common/importer/firefox_importer_utils.h" | 23 #include "chrome/common/importer/firefox_importer_utils.h" |
| 24 #include "content/public/common/content_descriptors.h" |
23 #include "content/public/common/mojo_channel_switches.h" | 25 #include "content/public/common/mojo_channel_switches.h" |
24 #include "ipc/ipc_channel.h" | 26 #include "ipc/ipc_channel.h" |
25 #include "ipc/ipc_descriptors.h" | 27 #include "ipc/ipc_descriptors.h" |
26 #include "ipc/ipc_listener.h" | 28 #include "ipc/ipc_listener.h" |
27 #include "ipc/ipc_message.h" | 29 #include "ipc/ipc_message.h" |
28 #include "ipc/ipc_multiprocess_test.h" | |
29 #include "mojo/edk/embedder/embedder.h" | 30 #include "mojo/edk/embedder/embedder.h" |
30 #include "mojo/edk/embedder/platform_channel_pair.h" | 31 #include "mojo/edk/embedder/platform_channel_pair.h" |
31 #include "mojo/edk/embedder/scoped_platform_handle.h" | 32 #include "mojo/edk/embedder/scoped_platform_handle.h" |
32 #include "testing/multiprocess_func_list.h" | 33 #include "testing/multiprocess_func_list.h" |
33 | 34 |
34 #define IPC_MESSAGE_IMPL | 35 #define IPC_MESSAGE_IMPL |
35 #include "chrome/utility/importer/firefox_importer_unittest_messages_internal.h" | 36 #include "chrome/utility/importer/firefox_importer_unittest_messages_internal.h" |
36 | 37 |
37 namespace { | 38 namespace { |
38 | 39 |
39 // Launch the child process: | 40 // Launch the child process: |
40 // |nss_path| - path to the NSS directory holding the decryption libraries. | 41 // |nss_path| - path to the NSS directory holding the decryption libraries. |
41 // |mojo_handle| - platform handle for Mojo transport. | 42 // |mojo_handle| - platform handle for Mojo transport. |
42 // |mojo_channel_token| - token for creating the IPC channel over Mojo. | 43 // |mojo_channel_token| - token for creating the IPC channel over Mojo. |
43 base::Process LaunchNSSDecrypterChildProcess( | 44 base::Process LaunchNSSDecrypterChildProcess( |
44 const base::FilePath& nss_path, | 45 const base::FilePath& nss_path, |
45 mojo::edk::ScopedPlatformHandle mojo_handle, | 46 mojo::edk::ScopedPlatformHandle mojo_handle, |
46 const std::string& mojo_channel_token) { | 47 const std::string& mojo_channel_token) { |
47 base::CommandLine cl(*base::CommandLine::ForCurrentProcess()); | 48 base::CommandLine cl(*base::CommandLine::ForCurrentProcess()); |
48 cl.AppendSwitchASCII(switches::kTestChildProcess, "NSSDecrypterChildProcess"); | 49 cl.AppendSwitchASCII(switches::kTestChildProcess, "NSSDecrypterChildProcess"); |
49 cl.AppendSwitchASCII(switches::kMojoChannelToken, mojo_channel_token); | 50 cl.AppendSwitchASCII(switches::kMojoChannelToken, mojo_channel_token); |
50 | 51 |
51 // Set env variable needed for FF encryption libs to load. | 52 // Set env variable needed for FF encryption libs to load. |
52 // See "chrome/utility/importer/nss_decryptor_mac.mm" for an explanation of | 53 // See "chrome/utility/importer/nss_decryptor_mac.mm" for an explanation of |
53 // why we need this. | 54 // why we need this. |
54 base::LaunchOptions options; | 55 base::LaunchOptions options; |
55 options.environ["DYLD_FALLBACK_LIBRARY_PATH"] = nss_path.value(); | 56 options.environ["DYLD_FALLBACK_LIBRARY_PATH"] = nss_path.value(); |
56 | 57 |
57 base::FileHandleMappingVector fds_to_map; | 58 base::FileHandleMappingVector fds_to_map; |
58 fds_to_map.push_back(std::pair<int,int>(mojo_handle.get().handle, | 59 fds_to_map.push_back(std::pair<int, int>( |
59 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); | 60 mojo_handle.get().handle, |
| 61 kMojoIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); |
60 | 62 |
61 options.fds_to_remap = &fds_to_map; | 63 options.fds_to_remap = &fds_to_map; |
62 return base::LaunchProcess(cl.argv(), options); | 64 return base::LaunchProcess(cl.argv(), options); |
63 } | 65 } |
64 | 66 |
65 } // namespace | 67 } // namespace |
66 | 68 |
67 //----------------------- Server -------------------- | 69 //----------------------- Server -------------------- |
68 | 70 |
69 // Class to communicate on the server side of the IPC Channel. | 71 // Class to communicate on the server side of the IPC Channel. |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 void OnChannelError() override { | 273 void OnChannelError() override { |
272 base::MessageLoop::current()->QuitWhenIdle(); | 274 base::MessageLoop::current()->QuitWhenIdle(); |
273 } | 275 } |
274 | 276 |
275 private: | 277 private: |
276 NSSDecryptor decryptor_; | 278 NSSDecryptor decryptor_; |
277 IPC::Sender* sender_; | 279 IPC::Sender* sender_; |
278 }; | 280 }; |
279 | 281 |
280 // Entry function in child process. | 282 // Entry function in child process. |
281 MULTIPROCESS_IPC_TEST_MAIN(NSSDecrypterChildProcess) { | 283 MULTIPROCESS_TEST_MAIN(NSSDecrypterChildProcess) { |
282 base::MessageLoopForIO main_message_loop; | 284 base::MessageLoopForIO main_message_loop; |
283 FFDecryptorClientChannelListener listener; | 285 FFDecryptorClientChannelListener listener; |
284 | 286 |
285 mojo::edk::SetParentPipeHandle( | 287 mojo::edk::SetParentPipeHandle( |
286 mojo::edk::ScopedPlatformHandle(mojo::edk::PlatformHandle( | 288 mojo::edk::ScopedPlatformHandle(mojo::edk::PlatformHandle( |
287 base::GlobalDescriptors::GetInstance()->Get(kPrimaryIPCChannel)))); | 289 kMojoIPCChannel + base::GlobalDescriptors::kBaseDescriptor))); |
288 mojo::ScopedMessagePipeHandle mojo_handle = | 290 mojo::ScopedMessagePipeHandle mojo_handle = |
289 mojo::edk::CreateChildMessagePipe( | 291 mojo::edk::CreateChildMessagePipe( |
290 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 292 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
291 switches::kMojoChannelToken)); | 293 switches::kMojoChannelToken)); |
292 | 294 |
293 std::unique_ptr<IPC::Channel> channel = | 295 std::unique_ptr<IPC::Channel> channel = |
294 IPC::Channel::CreateClient(mojo_handle.release(), &listener); | 296 IPC::Channel::CreateClient(mojo_handle.release(), &listener); |
295 CHECK(channel->Connect()); | 297 CHECK(channel->Connect()); |
296 listener.SetSender(channel.get()); | 298 listener.SetSender(channel.get()); |
297 | 299 |
298 // run message loop | 300 // run message loop |
299 base::RunLoop().Run(); | 301 base::RunLoop().Run(); |
300 | 302 |
301 return 0; | 303 return 0; |
302 } | 304 } |
OLD | NEW |