| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "chrome/browser/importer/firefox2_importer.h" | 10 #include "chrome/browser/importer/firefox2_importer.h" |
| 11 #include "chrome/browser/importer/firefox_importer_unittest_utils.h" |
| 11 #include "chrome/browser/importer/firefox_importer_utils.h" | 12 #include "chrome/browser/importer/firefox_importer_utils.h" |
| 12 #include "chrome/browser/importer/nss_decryptor.h" | 13 #include "chrome/browser/importer/nss_decryptor.h" |
| 13 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
| 14 | 15 |
| 15 using base::Time; | 16 using base::Time; |
| 16 | 17 |
| 17 // TODO(jeremy): Port NSSDecryptor to OSX and enable these tests. | 18 // The following 2 tests require the use of the NSSDecryptor, on OSX this needs |
| 18 #if !defined(OS_MACOSX) | 19 // to run in a separate process, so we use a proxy object so we can share the |
| 20 // same test between platforms. |
| 19 TEST(FirefoxImporterTest, Firefox2NSS3Decryptor) { | 21 TEST(FirefoxImporterTest, Firefox2NSS3Decryptor) { |
| 20 std::wstring nss_path; | 22 std::wstring nss_path; |
| 21 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &nss_path)); | 23 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &nss_path)); |
| 24 #ifdef OS_MACOSX |
| 25 file_util::AppendToPath(&nss_path, L"firefox2_nss_mac"); |
| 26 #else |
| 22 file_util::AppendToPath(&nss_path, L"firefox2_nss"); | 27 file_util::AppendToPath(&nss_path, L"firefox2_nss"); |
| 28 #endif // !OS_MACOSX |
| 23 std::wstring db_path; | 29 std::wstring db_path; |
| 24 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &db_path)); | 30 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &db_path)); |
| 25 file_util::AppendToPath(&db_path, L"firefox2_profile"); | 31 file_util::AppendToPath(&db_path, L"firefox2_profile"); |
| 26 NSSDecryptor decryptor; | 32 |
| 27 EXPECT_TRUE(decryptor.Init(nss_path, db_path)); | 33 bool success; |
| 28 EXPECT_EQ(L"hello", decryptor.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAE" | 34 FFUnitTestDecryptorProxy decryptor_proxy(nss_path, &success); |
| 35 ASSERT_TRUE(success); |
| 36 |
| 37 EXPECT_TRUE(decryptor_proxy.Init(nss_path, db_path)); |
| 38 EXPECT_EQ(L"hello", decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAE" |
| 29 "wFAYIKoZIhvcNAwcECBJM63MpT9rtBAjMCm7qo/EhlA==")); | 39 "wFAYIKoZIhvcNAwcECBJM63MpT9rtBAjMCm7qo/EhlA==")); |
| 30 // Test UTF-16 encoding. | 40 // Test UTF-16 encoding. |
| 31 EXPECT_EQ(L"\x4E2D", decryptor.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAE" | 41 EXPECT_EQ(L"\x4E2D", decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAE" |
| 32 "wFAYIKoZIhvcNAwcECN9OQ5ZFmhb8BAiFo1Z+fUvaIQ==")); | 42 "wFAYIKoZIhvcNAwcECN9OQ5ZFmhb8BAiFo1Z+fUvaIQ==")); |
| 33 } | 43 } |
| 34 | 44 |
| 35 TEST(FirefoxImporterTest, Firefox3NSS3Decryptor) { | 45 TEST(FirefoxImporterTest, Firefox3NSS3Decryptor) { |
| 36 std::wstring nss_path; | 46 std::wstring nss_path; |
| 37 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &nss_path)); | 47 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &nss_path)); |
| 48 #ifdef OS_MACOSX |
| 49 file_util::AppendToPath(&nss_path, L"firefox3_nss_mac"); |
| 50 #else |
| 38 file_util::AppendToPath(&nss_path, L"firefox3_nss"); | 51 file_util::AppendToPath(&nss_path, L"firefox3_nss"); |
| 52 #endif // !OS_MACOSX |
| 39 std::wstring db_path; | 53 std::wstring db_path; |
| 40 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &db_path)); | 54 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &db_path)); |
| 41 file_util::AppendToPath(&db_path, L"firefox3_profile"); | 55 file_util::AppendToPath(&db_path, L"firefox3_profile"); |
| 42 NSSDecryptor decryptor; | 56 |
| 43 EXPECT_TRUE(decryptor.Init(nss_path, db_path)); | 57 bool success; |
| 44 EXPECT_EQ(L"hello", decryptor.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAE" | 58 FFUnitTestDecryptorProxy decryptor_proxy(nss_path, &success); |
| 59 ASSERT_TRUE(success); |
| 60 |
| 61 EXPECT_TRUE(decryptor_proxy.Init(nss_path, db_path)); |
| 62 EXPECT_EQ(L"hello", decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAE" |
| 45 "wFAYIKoZIhvcNAwcECKajtRg4qFSHBAhv9luFkXgDJA==")); | 63 "wFAYIKoZIhvcNAwcECKajtRg4qFSHBAhv9luFkXgDJA==")); |
| 46 // Test UTF-16 encoding. | 64 // Test UTF-16 encoding. |
| 47 EXPECT_EQ(L"\x4E2D", decryptor.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAE" | 65 EXPECT_EQ(L"\x4E2D", decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAE" |
| 48 "wFAYIKoZIhvcNAwcECLWqqiccfQHWBAie74hxnULxlw==")); | 66 "wFAYIKoZIhvcNAwcECLWqqiccfQHWBAie74hxnULxlw==")); |
| 49 } | 67 } |
| 50 #endif // !OS_MACOSX | |
| 51 | 68 |
| 52 TEST(FirefoxImporterTest, Firefox2BookmarkParse) { | 69 TEST(FirefoxImporterTest, Firefox2BookmarkParse) { |
| 53 bool result; | 70 bool result; |
| 54 | 71 |
| 55 // Tests charset. | 72 // Tests charset. |
| 56 std::string charset; | 73 std::string charset; |
| 57 result = Firefox2Importer::ParseCharsetFromLine( | 74 result = Firefox2Importer::ParseCharsetFromLine( |
| 58 "<META HTTP-EQUIV=\"Content-Type\" " | 75 "<META HTTP-EQUIV=\"Content-Type\" " |
| 59 "CONTENT=\"text/html; charset=UTF-8\">", | 76 "CONTENT=\"text/html; charset=UTF-8\">", |
| 60 &charset); | 77 &charset); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 result = Firefox2Importer::ParseBookmarkFromLine( | 164 result = Firefox2Importer::ParseBookmarkFromLine( |
| 148 "<DT><A HREF=\"http://domain.com/?q=%22", | 165 "<DT><A HREF=\"http://domain.com/?q=%22", |
| 149 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); | 166 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); |
| 150 EXPECT_FALSE(result); | 167 EXPECT_FALSE(result); |
| 151 EXPECT_EQ(L"", title); | 168 EXPECT_EQ(L"", title); |
| 152 EXPECT_EQ("", url.spec()); | 169 EXPECT_EQ("", url.spec()); |
| 153 EXPECT_EQ(L"", shortcut); | 170 EXPECT_EQ(L"", shortcut); |
| 154 EXPECT_EQ(L"", post_data); | 171 EXPECT_EQ(L"", post_data); |
| 155 EXPECT_TRUE(Time() == add_date); | 172 EXPECT_TRUE(Time() == add_date); |
| 156 } | 173 } |
| OLD | NEW |