Index: chrome/browser/importer/firefox_importer_unittest_utils.h |
diff --git a/chrome/browser/importer/firefox_importer_unittest_utils.h b/chrome/browser/importer/firefox_importer_unittest_utils.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5a94879d3404f066a70de985304867e3a7a01d23 |
--- /dev/null |
+++ b/chrome/browser/importer/firefox_importer_unittest_utils.h |
@@ -0,0 +1,73 @@ |
+// Copyright (c) 2009 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_IMPORTER_UNITTEST_UTILS_H_ |
John Grabowski
2009/08/21 01:13:18
CHROME_BROWSER_IMPORTER_UNITTEST_UTILS_H_ -->
CHRO
|
+#define CHROME_BROWSER_IMPORTER_UNITTEST_UTILS_H_ |
+ |
+#include "base/basictypes.h" |
+#include "base/process_util.h" |
+#include "base/scoped_ptr.h" |
+#include "chrome/browser/importer/nss_decryptor.h" |
+ |
+class FFDecryptorServerChannelListener; |
+namespace IPC { |
+ class Channel; |
+} // namespace IPC |
+class MessageLoopForIO; |
+ |
+// On OS X NSSDecryptor needs to run in a separate process, to allow us to use |
John Grabowski
2009/08/21 01:13:18
More comments would be nice. E.g. brief example o
|
+// the same uni test on all platforms we use a proxy class which spawns a |
John Grabowski
2009/08/21 01:13:18
uni test --> unit test (and run on sentence)
|
+// child process to do decryption on OS X, and calls through directly |
+// to NSSDecryptor on other platforms. |
+class FFUnitTestDecryptorProxy { |
+ public: |
+ // Initialize a decryptor, on return |success| is true if the object was |
+ // constructed successfully. |
+ FFUnitTestDecryptorProxy(std::wstring &nss_path, bool* success); |
John Grabowski
2009/08/21 01:13:18
We don't use C++ exceptions so constructors in gen
|
+ virtual ~FFUnitTestDecryptorProxy(); |
+ |
+ // This match the parallel functions in NSSDecryptor. |
+ bool Init(const std::wstring& dll_path, const std::wstring& db_path); |
+ std::wstring Decrypt(const std::string& crypt); |
+ |
+ private: |
+#if defined(OS_MACOSX) |
+ // Blocks until either a timeout is reached, or until the client process |
+ // responds to an IPC message. |
+ // Returns true if a reply was recieved successfully and false if the |
+ // the operation timed out. |
+ bool WaitForClientResponse(); |
+ |
+ base::ProcessHandle child_process_; |
+ scoped_ptr<IPC::Channel> channel_; |
+ scoped_ptr<FFDecryptorServerChannelListener> listener_; |
+ scoped_ptr<MessageLoopForIO> message_loop_; |
+#else |
+ NSSDecrypter decryptor_; |
+#endif // !OS_MACOSX |
+ DISALLOW_COPY_AND_ASSIGN(FFUnitTestDecryptorProxy); |
+}; |
+ |
+// On Non-OSX platforms FFUnitTestDecryptorProxy simply calls through to |
+// NSSDecryptor. |
+#if !defined(OS_MACOSX) |
+FFUnitTestDecryptorProxy::FFUnitTestDecryptorProxy(std::wstring& /* nss_path */, |
+ bool* success) { |
+ *success = true; |
+} |
+ |
+FFUnitTestDecryptorProxy::~FFUnitTestDecryptorProxy() { |
+} |
+ |
+bool FFUnitTestDecryptorProxy::Init(const std::wstring& dll_path, |
+ const std::wstring& db_path) { |
+ return decryptor_.Init(dll_path, db_path); |
+} |
+ |
+std::wstring FFUnitTestDecryptorProxy::Decrypt(const std::string& crypt) { |
+ return decryptor_.Decrypt(crypt); |
+} |
+#endif // !OS_MACOSX |
+ |
+#endif // CHROME_BROWSER_IMPORTER_UNITTEST_UTILS_H_ |