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
3 // found in the LICENSE file.
5 #ifndef CHROME_UTILITY_IMPORTER_FIREFOX_IMPORTER_UNITTEST_UTILS_H_
6 #define CHROME_UTILITY_IMPORTER_FIREFOX_IMPORTER_UNITTEST_UTILS_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/process/process_handle.h"
11 #include "chrome/utility/importer/nss_decryptor.h"
13 class FFDecryptorServerChannelListener
;
16 class MessageLoopForIO
;
23 // On OS X NSSDecryptor needs to run in a separate process. To allow us to use
24 // the same unit test on all platforms we use a proxy class which spawns a
25 // child process to do decryption on OS X, and calls through directly
26 // to NSSDecryptor on other platforms.
28 // 2 IPC messages are sent for every method of NSSDecryptor, one containing the
29 // input arguments sent from Server->Child and one coming back containing
30 // the return argument e.g.
32 // -> Msg_Decryptor_Init(dll_path, db_path)
33 // <- Msg_Decryptor_InitReturnCode(bool)
34 class FFUnitTestDecryptorProxy
{
36 FFUnitTestDecryptorProxy();
37 virtual ~FFUnitTestDecryptorProxy();
39 // Initialize a decryptor, returns true if the object was
40 // constructed successfully.
41 bool Setup(const base::FilePath
& nss_path
);
43 // This match the parallel functions in NSSDecryptor.
44 bool DecryptorInit(const base::FilePath
& dll_path
,
45 const base::FilePath
& db_path
);
46 base::string16
Decrypt(const std::string
& crypt
);
49 #if defined(OS_MACOSX)
50 // Blocks until either a timeout is reached, or until the client process
51 // responds to an IPC message.
52 // Returns true if a reply was received successfully and false if the
53 // the operation timed out.
54 bool WaitForClientResponse();
56 base::ProcessHandle child_process_
;
57 scoped_ptr
<IPC::Channel
> channel_
;
58 scoped_ptr
<FFDecryptorServerChannelListener
> listener_
;
59 scoped_ptr
<base::MessageLoopForIO
> message_loop_
;
61 NSSDecryptor decryptor_
;
63 DISALLOW_COPY_AND_ASSIGN(FFUnitTestDecryptorProxy
);
66 // On Non-OSX platforms FFUnitTestDecryptorProxy simply calls through to
68 #if !defined(OS_MACOSX)
69 FFUnitTestDecryptorProxy::FFUnitTestDecryptorProxy() {
72 FFUnitTestDecryptorProxy::~FFUnitTestDecryptorProxy() {
75 bool FFUnitTestDecryptorProxy::Setup(const base::FilePath
& nss_path
) {
79 bool FFUnitTestDecryptorProxy::DecryptorInit(const base::FilePath
& dll_path
,
80 const base::FilePath
& db_path
) {
81 return decryptor_
.Init(dll_path
, db_path
);
84 base::string16
FFUnitTestDecryptorProxy::Decrypt(const std::string
& crypt
) {
85 return decryptor_
.Decrypt(crypt
);
89 #endif // CHROME_UTILITY_IMPORTER_FIREFOX_IMPORTER_UNITTEST_UTILS_H_