Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / utility / importer / firefox_importer_unittest_utils.h
blob293634d90f6ff9d5e602cd0bed5cd339baefc87f
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/files/file_util.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/process/process.h"
12 #include "chrome/utility/importer/nss_decryptor.h"
13 #include "components/autofill/core/common/password_form.h"
15 class FFDecryptorServerChannelListener;
17 namespace base {
18 class MessageLoopForIO;
21 namespace IPC {
22 class Channel;
23 } // namespace IPC
25 // On OS X NSSDecryptor needs to run in a separate process. To allow us to use
26 // the same unit test on all platforms we use a proxy class which spawns a
27 // child process to do decryption on OS X, and calls through directly
28 // to NSSDecryptor on other platforms.
29 // On OS X:
30 // 2 IPC messages are sent for every method of NSSDecryptor, one containing the
31 // input arguments sent from Server->Child and one coming back containing
32 // the return argument e.g.
34 // -> Msg_Decryptor_Init(dll_path, db_path)
35 // <- Msg_Decryptor_InitReturnCode(bool)
36 class FFUnitTestDecryptorProxy {
37 public:
38 FFUnitTestDecryptorProxy();
39 virtual ~FFUnitTestDecryptorProxy();
41 // Initialize a decryptor, returns true if the object was
42 // constructed successfully.
43 bool Setup(const base::FilePath& nss_path);
45 // This match the parallel functions in NSSDecryptor.
46 bool DecryptorInit(const base::FilePath& dll_path,
47 const base::FilePath& db_path);
48 base::string16 Decrypt(const std::string& crypt);
49 std::vector<autofill::PasswordForm> ParseSignons(
50 const base::FilePath& signons_path);
52 private:
53 #if defined(OS_MACOSX)
54 // Blocks until either a timeout is reached, or until the client process
55 // responds to an IPC message.
56 // Returns true if a reply was received successfully and false if the
57 // the operation timed out.
58 bool WaitForClientResponse();
60 base::Process child_process_;
61 scoped_ptr<IPC::Channel> channel_;
62 scoped_ptr<FFDecryptorServerChannelListener> listener_;
63 scoped_ptr<base::MessageLoopForIO> message_loop_;
64 #else
65 NSSDecryptor decryptor_;
66 #endif // !OS_MACOSX
67 DISALLOW_COPY_AND_ASSIGN(FFUnitTestDecryptorProxy);
70 // On Non-OSX platforms FFUnitTestDecryptorProxy simply calls through to
71 // NSSDecryptor.
72 #if !defined(OS_MACOSX)
73 FFUnitTestDecryptorProxy::FFUnitTestDecryptorProxy() {
76 FFUnitTestDecryptorProxy::~FFUnitTestDecryptorProxy() {
79 bool FFUnitTestDecryptorProxy::Setup(const base::FilePath& nss_path) {
80 return true;
83 bool FFUnitTestDecryptorProxy::DecryptorInit(const base::FilePath& dll_path,
84 const base::FilePath& db_path) {
85 return decryptor_.Init(dll_path, db_path);
88 base::string16 FFUnitTestDecryptorProxy::Decrypt(const std::string& crypt) {
89 return decryptor_.Decrypt(crypt);
92 std::vector<autofill::PasswordForm> FFUnitTestDecryptorProxy::ParseSignons(
93 const base::FilePath& signons_path) {
94 std::vector<autofill::PasswordForm> signons;
95 if (decryptor_.ReadAndParseSignons(signons_path, &signons))
96 return signons;
98 return std::vector<autofill::PasswordForm>();
101 #endif // !OS_MACOSX
103 #endif // CHROME_UTILITY_IMPORTER_FIREFOX_IMPORTER_UNITTEST_UTILS_H_