Skip to content

Commit

Permalink
Recommit "Bring up Firefox Password Import Unittest on OS X."
Browse files Browse the repository at this point in the history
This recommits r23971

Review URL: http://codereview.chromium.org/174259

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24024 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jeremy@chromium.org committed Aug 21, 2009
1 parent c451714 commit 1db97ce
Show file tree
Hide file tree
Showing 29 changed files with 520 additions and 30 deletions.
2 changes: 1 addition & 1 deletion chrome/browser/importer/firefox3_importer.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Firefox3Importer : public Importer {
std::wstring source_path_;
std::wstring app_path_;

DISALLOW_EVIL_CONSTRUCTORS(Firefox3Importer);
DISALLOW_COPY_AND_ASSIGN(Firefox3Importer);
};

#endif // CHROME_BROWSER_IMPORTER_FIREFOX3_IMPORTER_H_
37 changes: 26 additions & 11 deletions chrome/browser/importer/firefox_importer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,61 @@
#include "base/file_util.h"
#include "base/path_service.h"
#include "chrome/browser/importer/firefox2_importer.h"
#include "chrome/browser/importer/firefox_importer_unittest_utils.h"
#include "chrome/browser/importer/firefox_importer_utils.h"
#include "chrome/browser/importer/nss_decryptor.h"
#include "chrome/common/chrome_paths.h"

using base::Time;

// TODO(jeremy): Port NSSDecryptor to OSX and enable these tests.
#if !defined(OS_MACOSX)
// The following 2 tests require the use of the NSSDecryptor, on OSX this needs
// to run in a separate process, so we use a proxy object so we can share the
// same test between platforms.
TEST(FirefoxImporterTest, Firefox2NSS3Decryptor) {
std::wstring nss_path;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &nss_path));
#ifdef OS_MACOSX
file_util::AppendToPath(&nss_path, L"firefox2_nss_mac");
#else
file_util::AppendToPath(&nss_path, L"firefox2_nss");
#endif // !OS_MACOSX
std::wstring db_path;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &db_path));
file_util::AppendToPath(&db_path, L"firefox2_profile");
NSSDecryptor decryptor;
EXPECT_TRUE(decryptor.Init(nss_path, db_path));
EXPECT_EQ(L"hello", decryptor.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAE"

FFUnitTestDecryptorProxy decryptor_proxy;
ASSERT_TRUE(decryptor_proxy.Setup(nss_path));

EXPECT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path));
EXPECT_EQ(L"hello", decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAE"
"wFAYIKoZIhvcNAwcECBJM63MpT9rtBAjMCm7qo/EhlA=="));
// Test UTF-16 encoding.
EXPECT_EQ(L"\x4E2D", decryptor.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAE"
EXPECT_EQ(L"\x4E2D", decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAE"
"wFAYIKoZIhvcNAwcECN9OQ5ZFmhb8BAiFo1Z+fUvaIQ=="));
}

TEST(FirefoxImporterTest, Firefox3NSS3Decryptor) {
std::wstring nss_path;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &nss_path));
#ifdef OS_MACOSX
file_util::AppendToPath(&nss_path, L"firefox3_nss_mac");
#else
file_util::AppendToPath(&nss_path, L"firefox3_nss");
#endif // !OS_MACOSX
std::wstring db_path;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &db_path));
file_util::AppendToPath(&db_path, L"firefox3_profile");
NSSDecryptor decryptor;
EXPECT_TRUE(decryptor.Init(nss_path, db_path));
EXPECT_EQ(L"hello", decryptor.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAE"

FFUnitTestDecryptorProxy decryptor_proxy;
ASSERT_TRUE(decryptor_proxy.Setup(nss_path));

EXPECT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path));
EXPECT_EQ(L"hello", decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAE"
"wFAYIKoZIhvcNAwcECKajtRg4qFSHBAhv9luFkXgDJA=="));
// Test UTF-16 encoding.
EXPECT_EQ(L"\x4E2D", decryptor.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAE"
EXPECT_EQ(L"\x4E2D", decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAE"
"wFAYIKoZIhvcNAwcECLWqqiccfQHWBAie74hxnULxlw=="));
}
#endif // !OS_MACOSX

TEST(FirefoxImporterTest, Firefox2BookmarkParse) {
bool result;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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.

// This header is meant to be included in multiple passes, hence no traditional
// header guard.
// See ipc_message_macros.h for explanation of the macros and passes.

#include "ipc/ipc_message_macros.h"

// Messages definitions for messages sent between the unit test binary and
// a child process by FFUnitTestDecryptorProxy.
IPC_BEGIN_MESSAGES(Test)

// Server->Child: Initialize the decrytor with the following paramters.
IPC_MESSAGE_CONTROL2(Msg_Decryptor_Init,
std::wstring /* dll_path */,
std::wstring /* db_path */)
// Child->Server: Return paramter from init call.
IPC_MESSAGE_CONTROL1(Msg_Decryptor_InitReturnCode,
bool /* ret */)

// Server->Child: Decrypt a given string.
IPC_MESSAGE_CONTROL1(Msg_Decrypt,
std::string /* crypt */)
// Child->Server: Decrypted String.
IPC_MESSAGE_CONTROL1(Msg_Decryptor_Response,
std::wstring /* unencrypted_str */)

// Server->Child: Die.
IPC_MESSAGE_CONTROL0(Msg_Decryptor_Quit)

IPC_END_MESSAGES(Test)
84 changes: 84 additions & 0 deletions chrome/browser/importer/firefox_importer_unittest_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// 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_FIREFOX_IMPORTER_UNITTEST_UTILS_H_
#define CHROME_BROWSER_IMPORTER_FIREFOX_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
// the same unit test on all platforms we use a proxy class which spawns a
// child process to do decryption on OS X, and calls through directly
// to NSSDecryptor on other platforms.
// On OS X:
// 2 IPC messages are sent for every method of NSSDecryptor, one containing the
// input arguments sent from Server->Child and one coming back containing
// the return argument e.g.
//
// -> Msg_Decryptor_Init(dll_path, db_path)
// <- Msg_Decryptor_InitReturnCode(bool)
class FFUnitTestDecryptorProxy {
public:
FFUnitTestDecryptorProxy();
virtual ~FFUnitTestDecryptorProxy();

// Initialize a decryptor, returns true if the object was
// constructed successfully.
bool Setup(std::wstring& nss_path);

// This match the parallel functions in NSSDecryptor.
bool DecryptorInit(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
NSSDecryptor 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() {
}

FFUnitTestDecryptorProxy::~FFUnitTestDecryptorProxy() {
}

bool FFUnitTestDecryptorProxy::Setup(std::wstring& /* nss_path */) {
return true;
}

bool FFUnitTestDecryptorProxy::DecryptorInit(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_FIREFOX_IMPORTER_UNITTEST_UTILS_H_
Loading

0 comments on commit 1db97ce

Please sign in to comment.