OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 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 #ifndef CHROME_BROWSER_IMPORTER_FIREFOX_IMPORTER_UNITTEST_UTILS_H_ |
| 6 #define CHROME_BROWSER_IMPORTER_FIREFOX_IMPORTER_UNITTEST_UTILS_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "base/process_util.h" |
| 10 #include "base/scoped_ptr.h" |
| 11 #include "chrome/browser/importer/nss_decryptor.h" |
| 12 |
| 13 class FFDecryptorServerChannelListener; |
| 14 namespace IPC { |
| 15 class Channel; |
| 16 } // namespace IPC |
| 17 class MessageLoopForIO; |
| 18 |
| 19 // On OS X NSSDecryptor needs to run in a separate process. To allow us to use |
| 20 // the same unit test on all platforms we use a proxy class which spawns a |
| 21 // child process to do decryption on OS X, and calls through directly |
| 22 // to NSSDecryptor on other platforms. |
| 23 // On OS X: |
| 24 // 2 IPC messages are sent for every method of NSSDecryptor, one containing the |
| 25 // input arguments sent from Server->Child and one coming back containing |
| 26 // the return argument e.g. |
| 27 // |
| 28 // -> Msg_Decryptor_Init(dll_path, db_path) |
| 29 // <- Msg_Decryptor_InitReturnCode(bool) |
| 30 class FFUnitTestDecryptorProxy { |
| 31 public: |
| 32 FFUnitTestDecryptorProxy(); |
| 33 virtual ~FFUnitTestDecryptorProxy(); |
| 34 |
| 35 // Initialize a decryptor, returns true if the object was |
| 36 // constructed successfully. |
| 37 bool Setup(std::wstring& nss_path); |
| 38 |
| 39 // This match the parallel functions in NSSDecryptor. |
| 40 bool DecryptorInit(const std::wstring& dll_path, const std::wstring& db_path); |
| 41 std::wstring Decrypt(const std::string& crypt); |
| 42 |
| 43 private: |
| 44 #if defined(OS_MACOSX) |
| 45 // Blocks until either a timeout is reached, or until the client process |
| 46 // responds to an IPC message. |
| 47 // Returns true if a reply was recieved successfully and false if the |
| 48 // the operation timed out. |
| 49 bool WaitForClientResponse(); |
| 50 |
| 51 base::ProcessHandle child_process_; |
| 52 scoped_ptr<IPC::Channel> channel_; |
| 53 scoped_ptr<FFDecryptorServerChannelListener> listener_; |
| 54 scoped_ptr<MessageLoopForIO> message_loop_; |
| 55 #else |
| 56 NSSDecryptor decryptor_; |
| 57 #endif // !OS_MACOSX |
| 58 DISALLOW_COPY_AND_ASSIGN(FFUnitTestDecryptorProxy); |
| 59 }; |
| 60 |
| 61 // On Non-OSX platforms FFUnitTestDecryptorProxy simply calls through to |
| 62 // NSSDecryptor. |
| 63 #if !defined(OS_MACOSX) |
| 64 FFUnitTestDecryptorProxy::FFUnitTestDecryptorProxy() { |
| 65 } |
| 66 |
| 67 FFUnitTestDecryptorProxy::~FFUnitTestDecryptorProxy() { |
| 68 } |
| 69 |
| 70 bool FFUnitTestDecryptorProxy::Setup(std::wstring& /* nss_path */) { |
| 71 return true; |
| 72 } |
| 73 |
| 74 bool FFUnitTestDecryptorProxy::DecryptorInit(const std::wstring& dll_path, |
| 75 const std::wstring& db_path) { |
| 76 return decryptor_.Init(dll_path, db_path); |
| 77 } |
| 78 |
| 79 std::wstring FFUnitTestDecryptorProxy::Decrypt(const std::string& crypt) { |
| 80 return decryptor_.Decrypt(crypt); |
| 81 } |
| 82 #endif // !OS_MACOSX |
| 83 |
| 84 #endif // CHROME_BROWSER_IMPORTER_FIREFOX_IMPORTER_UNITTEST_UTILS_H_ |
OLD | NEW |