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_unittest_utils.h" |
12 #include "chrome/browser/importer/firefox_importer_utils.h" | 12 #include "chrome/browser/importer/firefox_importer_utils.h" |
13 #include "chrome/browser/importer/nss_decryptor.h" | 13 #include "chrome/browser/importer/nss_decryptor.h" |
14 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
15 | 15 |
16 using base::Time; | 16 using base::Time; |
17 | 17 |
18 // The following 2 tests require the use of the NSSDecryptor, on OSX this needs | 18 // The following 2 tests require the use of the NSSDecryptor, on OSX this needs |
19 // to run in a separate process, so we use a proxy object so we can share the | 19 // to run in a separate process, so we use a proxy object so we can share the |
20 // same test between platforms. | 20 // same test between platforms. |
21 TEST(FirefoxImporterTest, Firefox2NSS3Decryptor) { | 21 TEST(FirefoxImporterTest, Firefox2NSS3Decryptor) { |
22 std::wstring nss_path; | 22 FilePath nss_path; |
23 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 | 24 #ifdef OS_MACOSX |
25 file_util::AppendToPath(&nss_path, L"firefox2_nss_mac"); | 25 nss_path = nss_path.AppendASCII("firefox2_nss_mac"); |
26 #else | 26 #else |
27 file_util::AppendToPath(&nss_path, L"firefox2_nss"); | 27 nss_path = nss_path.AppendASCII("firefox2_nss"); |
28 #endif // !OS_MACOSX | 28 #endif // !OS_MACOSX |
29 std::wstring db_path; | 29 FilePath db_path; |
30 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &db_path)); | 30 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &db_path)); |
31 file_util::AppendToPath(&db_path, L"firefox2_profile"); | 31 db_path = db_path.AppendASCII("firefox2_profile"); |
32 | 32 |
33 FFUnitTestDecryptorProxy decryptor_proxy; | 33 FFUnitTestDecryptorProxy decryptor_proxy; |
34 ASSERT_TRUE(decryptor_proxy.Setup(nss_path)); | 34 ASSERT_TRUE(decryptor_proxy.Setup(nss_path.ToWStringHack())); |
35 | 35 |
36 EXPECT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path)); | 36 EXPECT_TRUE(decryptor_proxy.DecryptorInit(nss_path.ToWStringHack(), |
| 37 db_path.ToWStringHack())); |
37 EXPECT_EQ(L"hello", decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAE" | 38 EXPECT_EQ(L"hello", decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAE" |
38 "wFAYIKoZIhvcNAwcECBJM63MpT9rtBAjMCm7qo/EhlA==")); | 39 "wFAYIKoZIhvcNAwcECBJM63MpT9rtBAjMCm7qo/EhlA==")); |
39 // Test UTF-16 encoding. | 40 // Test UTF-16 encoding. |
40 EXPECT_EQ(L"\x4E2D", decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAE" | 41 EXPECT_EQ(L"\x4E2D", decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAE" |
41 "wFAYIKoZIhvcNAwcECN9OQ5ZFmhb8BAiFo1Z+fUvaIQ==")); | 42 "wFAYIKoZIhvcNAwcECN9OQ5ZFmhb8BAiFo1Z+fUvaIQ==")); |
42 } | 43 } |
43 | 44 |
44 TEST(FirefoxImporterTest, Firefox3NSS3Decryptor) { | 45 TEST(FirefoxImporterTest, Firefox3NSS3Decryptor) { |
45 std::wstring nss_path; | 46 FilePath nss_path; |
46 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &nss_path)); | 47 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &nss_path)); |
47 #ifdef OS_MACOSX | 48 #ifdef OS_MACOSX |
48 file_util::AppendToPath(&nss_path, L"firefox3_nss_mac"); | 49 nss_path = nss_path.AppendASCII("firefox3_nss_mac"); |
49 #else | 50 #else |
50 file_util::AppendToPath(&nss_path, L"firefox3_nss"); | 51 nss_path = nss_path.AppendASCII("firefox3_nss"); |
51 #endif // !OS_MACOSX | 52 #endif // !OS_MACOSX |
52 std::wstring db_path; | 53 FilePath db_path; |
53 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &db_path)); | 54 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &db_path)); |
54 file_util::AppendToPath(&db_path, L"firefox3_profile"); | 55 db_path = db_path.AppendASCII("firefox3_profile"); |
55 | 56 |
56 FFUnitTestDecryptorProxy decryptor_proxy; | 57 FFUnitTestDecryptorProxy decryptor_proxy; |
57 ASSERT_TRUE(decryptor_proxy.Setup(nss_path)); | 58 ASSERT_TRUE(decryptor_proxy.Setup(nss_path.ToWStringHack())); |
58 | 59 |
59 EXPECT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path)); | 60 EXPECT_TRUE(decryptor_proxy.DecryptorInit(nss_path.ToWStringHack(), |
| 61 db_path.ToWStringHack())); |
60 EXPECT_EQ(L"hello", decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAE" | 62 EXPECT_EQ(L"hello", decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAE" |
61 "wFAYIKoZIhvcNAwcECKajtRg4qFSHBAhv9luFkXgDJA==")); | 63 "wFAYIKoZIhvcNAwcECKajtRg4qFSHBAhv9luFkXgDJA==")); |
62 // Test UTF-16 encoding. | 64 // Test UTF-16 encoding. |
63 EXPECT_EQ(L"\x4E2D", decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAE" | 65 EXPECT_EQ(L"\x4E2D", decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAE" |
64 "wFAYIKoZIhvcNAwcECLWqqiccfQHWBAie74hxnULxlw==")); | 66 "wFAYIKoZIhvcNAwcECLWqqiccfQHWBAie74hxnULxlw==")); |
65 } | 67 } |
66 | 68 |
67 TEST(FirefoxImporterTest, Firefox2BookmarkParse) { | 69 TEST(FirefoxImporterTest, Firefox2BookmarkParse) { |
68 bool result; | 70 bool result; |
69 | 71 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 result = Firefox2Importer::ParseBookmarkFromLine( | 164 result = Firefox2Importer::ParseBookmarkFromLine( |
163 "<DT><A HREF=\"http://domain.com/?q=%22", | 165 "<DT><A HREF=\"http://domain.com/?q=%22", |
164 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); | 166 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); |
165 EXPECT_FALSE(result); | 167 EXPECT_FALSE(result); |
166 EXPECT_EQ(L"", title); | 168 EXPECT_EQ(L"", title); |
167 EXPECT_EQ("", url.spec()); | 169 EXPECT_EQ("", url.spec()); |
168 EXPECT_EQ(L"", shortcut); | 170 EXPECT_EQ(L"", shortcut); |
169 EXPECT_EQ(L"", post_data); | 171 EXPECT_EQ(L"", post_data); |
170 EXPECT_TRUE(Time() == add_date); | 172 EXPECT_TRUE(Time() == add_date); |
171 } | 173 } |
OLD | NEW |