| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/importer/firefox_importer_unittest_utils.h" | 5 #include "chrome/browser/importer/firefox_importer_unittest_utils.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" |
| 10 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 11 #include "base/test/test_timeouts.h" | 12 #include "base/test/test_timeouts.h" |
| 12 #include "chrome/browser/importer/firefox_importer_utils.h" | 13 #include "chrome/browser/importer/firefox_importer_utils.h" |
| 13 #include "ipc/ipc_channel.h" | 14 #include "ipc/ipc_channel.h" |
| 14 #include "ipc/ipc_descriptors.h" | 15 #include "ipc/ipc_descriptors.h" |
| 15 #include "ipc/ipc_message.h" | 16 #include "ipc/ipc_message.h" |
| 16 #include "ipc/ipc_switches.h" | 17 #include "ipc/ipc_switches.h" |
| 17 #include "testing/multiprocess_func_list.h" | 18 #include "testing/multiprocess_func_list.h" |
| 18 | 19 |
| 19 #define IPC_MESSAGE_IMPL | 20 #define IPC_MESSAGE_IMPL |
| 20 #include "chrome/browser/importer/firefox_importer_unittest_messages_internal.h" | 21 #include "chrome/browser/importer/firefox_importer_unittest_messages_internal.h" |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 // Name of IPC Channel to use for Server<-> Child Communications. | 25 // Name of IPC Channel to use for Server<-> Child Communications. |
| 25 const char kTestChannelID[] = "T1"; | 26 const char kTestChannelID[] = "T1"; |
| 26 | 27 |
| 27 // Launch the child process: | 28 // Launch the child process: |
| 28 // |nss_path| - path to the NSS directory holding the decryption libraries. | 29 // |nss_path| - path to the NSS directory holding the decryption libraries. |
| 29 // |channel| - IPC Channel to use for communication. | 30 // |channel| - IPC Channel to use for communication. |
| 30 // |handle| - On return, the process handle to use to communicate with the | 31 // |handle| - On return, the process handle to use to communicate with the |
| 31 // child. | 32 // child. |
| 32 bool LaunchNSSDecrypterChildProcess(const FilePath& nss_path, | 33 bool LaunchNSSDecrypterChildProcess(const FilePath& nss_path, |
| 33 const IPC::Channel& channel, base::ProcessHandle* handle) { | 34 IPC::Channel* channel, base::ProcessHandle* handle) { |
| 34 CommandLine cl(*CommandLine::ForCurrentProcess()); | 35 CommandLine cl(*CommandLine::ForCurrentProcess()); |
| 35 cl.AppendSwitchASCII(switches::kTestChildProcess, "NSSDecrypterChildProcess"); | 36 cl.AppendSwitchASCII(switches::kTestChildProcess, "NSSDecrypterChildProcess"); |
| 36 | 37 |
| 37 // Set env variable needed for FF encryption libs to load. | 38 // Set env variable needed for FF encryption libs to load. |
| 38 // See "chrome/browser/importer/nss_decryptor_mac.mm" for an explanation of | 39 // See "chrome/browser/importer/nss_decryptor_mac.mm" for an explanation of |
| 39 // why we need this. | 40 // why we need this. |
| 40 base::environment_vector env; | 41 base::environment_vector env; |
| 41 std::pair<std::string, std::string> dyld_override; | 42 std::pair<std::string, std::string> dyld_override; |
| 42 dyld_override.first = "DYLD_FALLBACK_LIBRARY_PATH"; | 43 dyld_override.first = "DYLD_FALLBACK_LIBRARY_PATH"; |
| 43 dyld_override.second = nss_path.value(); | 44 dyld_override.second = nss_path.value(); |
| 44 env.push_back(dyld_override); | 45 env.push_back(dyld_override); |
| 45 | 46 |
| 47 int ipcfd = channel->TakeClientFileDescriptor(); |
| 48 if (ipcfd == -1) |
| 49 return false; |
| 50 |
| 51 file_util::ScopedFD client_file_descriptor_closer(&ipcfd); |
| 46 base::file_handle_mapping_vector fds_to_map; | 52 base::file_handle_mapping_vector fds_to_map; |
| 47 const int ipcfd = channel.GetClientFileDescriptor(); | 53 fds_to_map.push_back(std::pair<int,int>(ipcfd, kPrimaryIPCChannel + 3)); |
| 48 if (ipcfd > -1) { | |
| 49 fds_to_map.push_back(std::pair<int,int>(ipcfd, kPrimaryIPCChannel + 3)); | |
| 50 } else { | |
| 51 return false; | |
| 52 } | |
| 53 | 54 |
| 54 bool debug_on_start = CommandLine::ForCurrentProcess()->HasSwitch( | 55 bool debug_on_start = CommandLine::ForCurrentProcess()->HasSwitch( |
| 55 switches::kDebugChildren); | 56 switches::kDebugChildren); |
| 56 base::LaunchOptions options; | 57 base::LaunchOptions options; |
| 57 options.environ = &env; | 58 options.environ = &env; |
| 58 options.fds_to_remap = &fds_to_map; | 59 options.fds_to_remap = &fds_to_map; |
| 59 options.wait = debug_on_start; | 60 options.wait = debug_on_start; |
| 60 return base::LaunchProcess(cl.argv(), options, handle); | 61 return base::LaunchProcess(cl.argv(), options, handle); |
| 61 } | 62 } |
| 62 | 63 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 | 133 |
| 133 listener_.reset(new FFDecryptorServerChannelListener()); | 134 listener_.reset(new FFDecryptorServerChannelListener()); |
| 134 channel_.reset(new IPC::Channel(kTestChannelID, | 135 channel_.reset(new IPC::Channel(kTestChannelID, |
| 135 IPC::Channel::MODE_SERVER, | 136 IPC::Channel::MODE_SERVER, |
| 136 listener_.get())); | 137 listener_.get())); |
| 137 CHECK(channel_->Connect()); | 138 CHECK(channel_->Connect()); |
| 138 listener_->SetSender(channel_.get()); | 139 listener_->SetSender(channel_.get()); |
| 139 | 140 |
| 140 // Spawn child and set up sync IPC connection. | 141 // Spawn child and set up sync IPC connection. |
| 141 bool ret = LaunchNSSDecrypterChildProcess(nss_path, | 142 bool ret = LaunchNSSDecrypterChildProcess(nss_path, |
| 142 *(channel_.get()), | 143 channel_.get(), |
| 143 &child_process_); | 144 &child_process_); |
| 144 return ret && (child_process_ != 0); | 145 return ret && (child_process_ != 0); |
| 145 } | 146 } |
| 146 | 147 |
| 147 FFUnitTestDecryptorProxy::~FFUnitTestDecryptorProxy() { | 148 FFUnitTestDecryptorProxy::~FFUnitTestDecryptorProxy() { |
| 148 listener_->QuitClient(); | 149 listener_->QuitClient(); |
| 149 channel_->Close(); | 150 channel_->Close(); |
| 150 | 151 |
| 151 if (child_process_) { | 152 if (child_process_) { |
| 152 base::WaitForSingleProcess(child_process_, 5000); | 153 base::WaitForSingleProcess(child_process_, 5000); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 264 |
| 264 IPC::Channel channel(kTestChannelID, IPC::Channel::MODE_CLIENT, &listener); | 265 IPC::Channel channel(kTestChannelID, IPC::Channel::MODE_CLIENT, &listener); |
| 265 CHECK(channel.Connect()); | 266 CHECK(channel.Connect()); |
| 266 listener.SetSender(&channel); | 267 listener.SetSender(&channel); |
| 267 | 268 |
| 268 // run message loop | 269 // run message loop |
| 269 MessageLoop::current()->Run(); | 270 MessageLoop::current()->Run(); |
| 270 | 271 |
| 271 return 0; | 272 return 0; |
| 272 } | 273 } |
| OLD | NEW |