diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-20 20:40:39 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-20 20:40:39 +0000 |
commit | f2c24eb2781f252e6311b61bd1d0c8a1cb671389 (patch) | |
tree | d68a93045df76ab88da06134fd6655236e60d5a0 | |
parent | 62e1926b8b77d7335c14096028102e269cb77937 (diff) | |
download | chromium_src-f2c24eb2781f252e6311b61bd1d0c8a1cb671389.zip chromium_src-f2c24eb2781f252e6311b61bd1d0c8a1cb671389.tar.gz chromium_src-f2c24eb2781f252e6311b61bd1d0c8a1cb671389.tar.bz2 |
Port ImporterTest to posix.
Changes:
- only compile IE stuff on Win
- delete unused vars, mismatched signage
- don't create the profile directory explicitly. CopyDirectory with recursive=true will move the directory *into* the target dir, rather than merging its contents with those of the target dir. The easiest workaround is to make the target dir non-existant, which changes the behavior to what we want.
- get rid of CRLF in the firefox2 history example, which was making the history import fail.
- relax NSSDecryptor::Decrypt.
BUG=none
TEST=ImporterTest runs/passes on all trybots
Review URL: http://codereview.chromium.org/2811036
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53089 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/importer/importer_unittest.cc | 149 | ||||
-rw-r--r-- | chrome/browser/importer/nss_decryptor.cc | 2 | ||||
-rw-r--r-- | chrome/browser/importer/nss_decryptor_system_nss.cc | 56 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 1 | ||||
-rw-r--r-- | chrome/test/data/firefox2_profile/history.dat | 32 |
5 files changed, 152 insertions, 88 deletions
diff --git a/chrome/browser/importer/importer_unittest.cc b/chrome/browser/importer/importer_unittest.cc index 7c3a45c..1dce41e9 100644 --- a/chrome/browser/importer/importer_unittest.cc +++ b/chrome/browser/importer/importer_unittest.cc @@ -4,42 +4,59 @@ #include "testing/gtest/include/gtest/gtest.h" +#include "build/build_config.h" + +#if defined(OS_WIN) #include <windows.h> #include <unknwn.h> #include <intshcut.h> #include <pstore.h> #include <urlhist.h> #include <shlguid.h> +#endif + #include <vector> -#include "app/win_util.h" #include "base/file_util.h" #include "base/message_loop.h" #include "base/path_service.h" -#include "base/scoped_comptr_win.h" #include "base/stl_util-inl.h" +#include "base/utf_string_conversions.h" #include "chrome/browser/chrome_thread.h" #include "chrome/browser/history/history_types.h" -#include "chrome/browser/importer/ie_importer.h" #include "chrome/browser/importer/importer.h" #include "chrome/browser/importer/importer_bridge.h" #include "chrome/browser/importer/importer_data_types.h" -#include "chrome/browser/password_manager/ie7_password.h" #include "chrome/browser/profile.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/common/chrome_paths.h" #include "webkit/glue/password_form.h" +#if defined(OS_WIN) +#include "base/scoped_comptr_win.h" +#include "app/win_util.h" +#include "chrome/browser/importer/ie_importer.h" +#include "chrome/browser/password_manager/ie7_password.h" +#endif + using importer::FAVORITES; using importer::FIREFOX2; using importer::FIREFOX3; using importer::HISTORY; using importer::ImportItem; +#if defined(OS_WIN) using importer::MS_IE; +#endif using importer::PASSWORDS; using importer::SEARCH_ENGINES; using webkit_glue::PasswordForm; +// TODO(estade): some of these are disabled on mac. http://crbug.com/48007 +#if defined(OS_MACOSX) +#define MAYBE(x) DISABLED_##x +#else +#define MAYBE(x) x +#endif class ImporterTest : public testing::Test { public: @@ -53,11 +70,8 @@ class ImporterTest : public testing::Test { test_path_ = test_path_.AppendASCII("ImporterTest"); file_util::Delete(test_path_, true); file_util::CreateDirectory(test_path_); - profile_path_ = test_path_; - profile_path_ = profile_path_.AppendASCII("profile"); - file_util::CreateDirectory(profile_path_); - app_path_ = test_path_; - app_path_ = app_path_.AppendASCII("app"); + profile_path_ = test_path_.AppendASCII("profile"); + app_path_ = test_path_.AppendASCII("app"); file_util::CreateDirectory(app_path_); } @@ -73,7 +87,7 @@ class ImporterTest : public testing::Test { bool import_search_plugins) { FilePath data_path; ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); - data_path = data_path.AppendASCII(profile_dir).AppendASCII("*"); + data_path = data_path.AppendASCII(profile_dir); ASSERT_TRUE(file_util::CopyDirectory(data_path, profile_path_, true)); ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); data_path = data_path.AppendASCII("firefox3_nss"); @@ -139,6 +153,29 @@ typedef struct { bool blacklisted; } PasswordList; +// Returns true if the |entry| is in the |list|. +bool FindBookmarkEntry(const ProfileWriter::BookmarkEntry& entry, + const BookmarkList* list, int list_size) { + for (int i = 0; i < list_size; ++i) { + if (list[i].in_toolbar == entry.in_toolbar && + list[i].path_size == entry.path.size() && + list[i].url == entry.url.spec() && + list[i].title == entry.title) { + bool equal = true; + for (size_t k = 0; k < list[i].path_size; ++k) + if (list[i].path[k] != entry.path[k]) { + equal = false; + break; + } + + if (equal) + return true; + } + } + return false; +} + +#if defined(OS_WIN) static const BookmarkList kIEBookmarks[] = { {true, 0, {}, L"TheLink", @@ -175,27 +212,6 @@ bool IsWindowsVista() { return (info.dwMajorVersion >=6); } -// Returns true if the |entry| is in the |list|. -bool FindBookmarkEntry(const ProfileWriter::BookmarkEntry& entry, - const BookmarkList* list, int list_size) { - for (int i = 0; i < list_size; ++i) - if (list[i].in_toolbar == entry.in_toolbar && - list[i].path_size == entry.path.size() && - list[i].url == entry.url.spec() && - list[i].title == entry.title) { - bool equal = true; - for (size_t k = 0; k < list[i].path_size; ++k) - if (list[i].path[k] != entry.path[k]) { - equal = false; - break; - } - - if (equal) - return true; - } - return false; -} - class TestObserver : public ProfileWriter, public ImporterHost::Observer { public: @@ -271,9 +287,9 @@ class TestObserver : public ProfileWriter, private: ~TestObserver() {} - int bookmark_count_; - int history_count_; - int password_count_; + size_t bookmark_count_; + size_t history_count_; + size_t password_count_; }; bool CreateUrlFile(std::wstring file, std::wstring url) { @@ -471,6 +487,7 @@ TEST_F(ImporterTest, IE7Importer) { EXPECT_EQ(L"abcdefghi", username); EXPECT_EQ(L"abcdefg", password); } +#endif // defined(OS_WIN) static const BookmarkList kFirefox2Bookmarks[] = { {true, 1, {L"Folder"}, @@ -560,7 +577,7 @@ class FirefoxObserver : public ProfileWriter, virtual void ImportEnded() { MessageLoop::current()->Quit(); EXPECT_EQ(arraysize(kFirefox2Bookmarks), bookmark_count_); - EXPECT_EQ(1, history_count_); + EXPECT_EQ(1U, history_count_); EXPECT_EQ(arraysize(kFirefox2Passwords), password_count_); EXPECT_EQ(arraysize(kFirefox2Keywords), keyword_count_); EXPECT_EQ(kFirefox2Keywords[kDefaultFirefox2KeywordIndex].keyword, @@ -583,18 +600,18 @@ class FirefoxObserver : public ProfileWriter, EXPECT_EQ(p.origin, form.origin.spec()); EXPECT_EQ(p.realm, form.signon_realm); EXPECT_EQ(p.action, form.action.spec()); - EXPECT_EQ(p.username_element, form.username_element); - EXPECT_EQ(p.username, form.username_value); - EXPECT_EQ(p.password_element, form.password_element); - EXPECT_EQ(p.password, form.password_value); + EXPECT_EQ(WideToUTF16(p.username_element), form.username_element); + EXPECT_EQ(WideToUTF16(p.username), form.username_value); + EXPECT_EQ(WideToUTF16(p.password_element), form.password_element); + EXPECT_EQ(WideToUTF16(p.password), form.password_value); EXPECT_EQ(p.blacklisted, form.blacklisted_by_user); ++password_count_; } virtual void AddHistoryPage(const std::vector<history::URLRow>& page) { - EXPECT_EQ(1, page.size()); + ASSERT_EQ(1U, page.size()); EXPECT_EQ("http://en-us.www.mozilla.com/", page[0].url().spec()); - EXPECT_EQ(L"Firefox Updated", page[0].title()); + EXPECT_EQ(ASCIIToUTF16("Firefox Updated"), page[0].title()); ++history_count_; } @@ -616,9 +633,7 @@ class FirefoxObserver : public ProfileWriter, // that template URL. bool found = false; std::wstring keyword = template_urls[i]->keyword(); - for (int j = 0; j < arraysize(kFirefox2Keywords); ++j) { - const wchar_t* comp_keyword = kFirefox2Keywords[j].keyword; - bool equal = (keyword == comp_keyword); + for (size_t j = 0; j < arraysize(kFirefox2Keywords); ++j) { if (template_urls[i]->keyword() == kFirefox2Keywords[j].keyword) { EXPECT_EQ(kFirefox2Keywords[j].url, template_urls[i]->url()->url()); found = true; @@ -645,18 +660,18 @@ class FirefoxObserver : public ProfileWriter, private: ~FirefoxObserver() {} - int bookmark_count_; - int history_count_; - int password_count_; - int keyword_count_; + size_t bookmark_count_; + size_t history_count_; + size_t password_count_; + size_t keyword_count_; std::wstring default_keyword_; std::string default_keyword_url_; }; -TEST_F(ImporterTest, Firefox2Importer) { +TEST_F(ImporterTest, MAYBE(Firefox2Importer)) { FilePath data_path; ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); - data_path = data_path.AppendASCII("firefox2_profile").AppendASCII("*"); + data_path = data_path.AppendASCII("firefox2_profile"); ASSERT_TRUE(file_util::CopyDirectory(data_path, profile_path_, true)); ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); data_path = data_path.AppendASCII("firefox2_nss"); @@ -756,7 +771,7 @@ class Firefox3Observer : public ProfileWriter, virtual void ImportEnded() { MessageLoop::current()->Quit(); EXPECT_EQ(arraysize(kFirefox3Bookmarks), bookmark_count_); - EXPECT_EQ(1, history_count_); + EXPECT_EQ(1U, history_count_); EXPECT_EQ(arraysize(kFirefox3Passwords), password_count_); if (import_search_engines_) { EXPECT_EQ(arraysize(kFirefox3Keywords), keyword_count_); @@ -781,23 +796,23 @@ class Firefox3Observer : public ProfileWriter, EXPECT_EQ(p.origin, form.origin.spec()); EXPECT_EQ(p.realm, form.signon_realm); EXPECT_EQ(p.action, form.action.spec()); - EXPECT_EQ(p.username_element, form.username_element); - EXPECT_EQ(p.username, form.username_value); - EXPECT_EQ(p.password_element, form.password_element); - EXPECT_EQ(p.password, form.password_value); + EXPECT_EQ(WideToUTF16(p.username_element), form.username_element); + EXPECT_EQ(WideToUTF16(p.username), form.username_value); + EXPECT_EQ(WideToUTF16(p.password_element), form.password_element); + EXPECT_EQ(WideToUTF16(p.password), form.password_value); EXPECT_EQ(p.blacklisted, form.blacklisted_by_user); ++password_count_; } virtual void AddHistoryPage(const std::vector<history::URLRow>& page) { - ASSERT_EQ(3, page.size()); + ASSERT_EQ(3U, page.size()); EXPECT_EQ("http://www.google.com/", page[0].url().spec()); - EXPECT_EQ(L"Google", page[0].title()); + EXPECT_EQ(ASCIIToUTF16("Google"), page[0].title()); EXPECT_EQ("http://www.google.com/", page[1].url().spec()); - EXPECT_EQ(L"Google", page[1].title()); + EXPECT_EQ(ASCIIToUTF16("Google"), page[1].title()); EXPECT_EQ("http://www.cs.unc.edu/~jbs/resources/perl/perl-cgi/programs/form1-POST.html", page[2].url().spec()); - EXPECT_EQ(L"example form (POST)", page[2].title()); + EXPECT_EQ(ASCIIToUTF16("example form (POST)"), page[2].title()); ++history_count_; } @@ -819,9 +834,7 @@ class Firefox3Observer : public ProfileWriter, // that template URL. bool found = false; std::wstring keyword = template_urls[i]->keyword(); - for (int j = 0; j < arraysize(kFirefox3Keywords); ++j) { - const wchar_t* comp_keyword = kFirefox3Keywords[j].keyword; - bool equal = (keyword == comp_keyword); + for (size_t j = 0; j < arraysize(kFirefox3Keywords); ++j) { if (template_urls[i]->keyword() == kFirefox3Keywords[j].keyword) { EXPECT_EQ(kFirefox3Keywords[j].url, template_urls[i]->url()->url()); found = true; @@ -848,22 +861,22 @@ class Firefox3Observer : public ProfileWriter, private: ~Firefox3Observer() {} - int bookmark_count_; - int history_count_; - int password_count_; - int keyword_count_; + size_t bookmark_count_; + size_t history_count_; + size_t password_count_; + size_t keyword_count_; bool import_search_engines_; std::wstring default_keyword_; std::string default_keyword_url_; }; -TEST_F(ImporterTest, Firefox30Importer) { +TEST_F(ImporterTest, MAYBE(Firefox30Importer)) { scoped_refptr<Firefox3Observer> observer = new Firefox3Observer(); Firefox3xImporterTest("firefox3_profile", observer.get(), observer.get(), true); } -TEST_F(ImporterTest, Firefox35Importer) { +TEST_F(ImporterTest, MAYBE(Firefox35Importer)) { bool import_search_engines = false; scoped_refptr<Firefox3Observer> observer = new Firefox3Observer(import_search_engines); diff --git a/chrome/browser/importer/nss_decryptor.cc b/chrome/browser/importer/nss_decryptor.cc index 8cbc154..91149e2 100644 --- a/chrome/browser/importer/nss_decryptor.cc +++ b/chrome/browser/importer/nss_decryptor.cc @@ -106,7 +106,7 @@ string16 NSSDecryptor::Decrypt(const std::string& crypt) const { return UTF8ToUTF16(plain); } -// There are three versions of password filess. They store saved user +// There are three versions of password files. They store saved user // names and passwords. // References: // http://kb.mozillazine.org/Signons.txt diff --git a/chrome/browser/importer/nss_decryptor_system_nss.cc b/chrome/browser/importer/nss_decryptor_system_nss.cc index c15f8a6..06be5da 100644 --- a/chrome/browser/importer/nss_decryptor_system_nss.cc +++ b/chrome/browser/importer/nss_decryptor_system_nss.cc @@ -35,7 +35,7 @@ bool NSSDecryptor::Init(const std::wstring& /* dll_path */, } // This method is based on some NSS code in -// security/nss/lib/pk11wrap/pk11sdr.c +// security/nss/lib/pk11wrap/pk11sdr.c, CVS revision 1.22 // This code is copied because the implementation assumes the use of the // internal key slot for decryption, but we need to use another slot. // The license block is: @@ -182,7 +182,7 @@ SECStatus NSSDecryptor::PK11SDR_DecryptWithSlot( CK_MECHANISM_TYPE type; SDRResult sdrResult; SECItem *params = 0; - SECItem possibleResult = { static_cast<SECItemType>(0), NULL, 0 }; + SECItem possibleResult = { siBuffer, NULL, 0 }; PLArenaPool *arena = 0; arena = PORT_NewArena(SEC_ASN1_DEFAULT_ARENA_SIZE); @@ -207,6 +207,58 @@ SECStatus NSSDecryptor::PK11SDR_DecryptWithSlot( &sdrResult.data, result); } + /* + * if the pad value was too small (1 or 2), then it's statistically + * 'likely' that (1 in 256) that we may not have the correct key. + * Check the other keys for a better match. If we find none, use + * this result. + */ + if (rv == SECWouldBlock) + possibleResult = *result; + + /* + * handle the case where your key indicies may have been broken + */ + if (rv != SECSuccess) { + PK11SymKey *keyList = PK11_ListFixedKeysInSlot(slot, NULL, cx); + PK11SymKey *testKey = NULL; + PK11SymKey *nextKey = NULL; + + for (testKey = keyList; testKey; + testKey = PK11_GetNextSymKey(testKey)) { + rv = pk11Decrypt(slot, arena, type, testKey, params, + &sdrResult.data, result); + if (rv == SECSuccess) + break; + + /* found a close match. If it's our first remember it */ + if (rv == SECWouldBlock) { + if (possibleResult.data) { + /* this is unlikely but possible. If we hit this condition, + * we have no way of knowing which possibility to prefer. + * in this case we just match the key the application + * thought was the right one */ + SECITEM_ZfreeItem(result, PR_FALSE); + } else { + possibleResult = *result; + } + } + } + + /* free the list */ + for (testKey = keyList; testKey; testKey = nextKey) { + nextKey = PK11_GetNextSymKey(testKey); + PK11_FreeSymKey(testKey); + } + } + + /* we didn't find a better key, use the one with a small pad value */ + if ((rv != SECSuccess) && (possibleResult.data)) { + *result = possibleResult; + possibleResult.data = NULL; + rv = SECSuccess; + } + loser: if (arena) PORT_FreeArena(arena, PR_TRUE); if (key) PK11_FreeSymKey(key); diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index bb60bc2..aef4727 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1409,7 +1409,6 @@ 'browser/browser_accessibility_win_unittest.cc', 'browser/chrome_plugin_unittest.cc', 'browser/extensions/extension_process_manager_unittest.cc', - 'browser/importer/importer_unittest.cc', 'browser/login_prompt_unittest.cc', 'browser/rlz/rlz_unittest.cc', 'browser/search_engines/template_url_scraper_unittest.cc', diff --git a/chrome/test/data/firefox2_profile/history.dat b/chrome/test/data/firefox2_profile/history.dat index b2f6a83..c25030c 100644 --- a/chrome/test/data/firefox2_profile/history.dat +++ b/chrome/test/data/firefox2_profile/history.dat @@ -1,16 +1,16 @@ -// <!-- <mdb:mork:z v="1.4"/> -->
-< <(a=c)> // (f=iso-8859-1)
- (8A=Typed)(8B=LastPageVisited)(8C=ByteOrder)
- (80=ns:history:db:row:scope:history:all)
- (81=ns:history:db:table:kind:history)(82=URL)(83=Referrer)
- (84=LastVisitDate)(85=FirstVisitDate)(86=VisitCount)(87=Name)
- (88=Hostname)(89=Hidden)>
-
-<(80=LE)(81=http://en-us.www.mozilla.com/)
- (82=1205364946314923)(83=en-us.www.mozilla.com)(84
- =F$00i$00r$00e$00f$00o$00x$00 $00U$00p$00d$00a$00t$00e$00d$00)>
-{1:^80 {(k^81:c)(s=9)[1(^8C=LE)]}
- [2(^82^81)(^84^82)(^85^82)(^88^83)(^87^84)]}
-
-@$${2{@
-@$$}2}@
\ No newline at end of file +// <!-- <mdb:mork:z v="1.4"/> --> +< <(a=c)> // (f=iso-8859-1) + (8A=Typed)(8B=LastPageVisited)(8C=ByteOrder) + (80=ns:history:db:row:scope:history:all) + (81=ns:history:db:table:kind:history)(82=URL)(83=Referrer) + (84=LastVisitDate)(85=FirstVisitDate)(86=VisitCount)(87=Name) + (88=Hostname)(89=Hidden)> + +<(80=LE)(81=http://en-us.www.mozilla.com/) + (82=1205364946314923)(83=en-us.www.mozilla.com)(84 + =F$00i$00r$00e$00f$00o$00x$00 $00U$00p$00d$00a$00t$00e$00d$00)> +{1:^80 {(k^81:c)(s=9)[1(^8C=LE)]} + [2(^82^81)(^84^82)(^85^82)(^88^83)(^87^84)]} + +@$${2{@ +@$$}2}@ |