OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 #include "base/files/scoped_temp_dir.h" | 6 #include "base/files/scoped_temp_dir.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "chrome/common/chrome_paths.h" | 10 #include "chrome/common/chrome_paths.h" |
| 11 #include "chrome/common/importer/imported_bookmark_entry.h" |
| 12 #include "chrome/common/importer/importer_data_types.h" |
| 13 #include "chrome/common/importer/importer_url_row.h" |
| 14 #include "chrome/common/importer/mock_importer_bridge.h" |
| 15 #include "chrome/utility/importer/firefox_importer.h" |
11 #include "chrome/utility/importer/firefox_importer_unittest_utils.h" | 16 #include "chrome/utility/importer/firefox_importer_unittest_utils.h" |
12 #include "chrome/utility/importer/nss_decryptor.h" | 17 #include "chrome/utility/importer/nss_decryptor.h" |
| 18 #include "components/favicon_base/favicon_usage_data.h" |
13 #include "sql/connection.h" | 19 #include "sql/connection.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
15 | 21 |
16 // TODO(jschuh): Disabled on Win64 build. http://crbug.com/179688 | 22 // TODO(jschuh): Disabled on Win64 build. http://crbug.com/179688 |
17 #if defined(OS_WIN) && defined(ARCH_CPU_X86_64) | 23 #if defined(OS_WIN) && defined(ARCH_CPU_X86_64) |
18 #define MAYBE_NSS(x) DISABLED_##x | 24 #define MAYBE_NSS(x) DISABLED_##x |
19 #else | 25 #else |
20 #define MAYBE_NSS(x) x | 26 #define MAYBE_NSS(x) x |
21 #endif | 27 #endif |
22 | 28 |
23 // The following test requires the use of the NSSDecryptor, on OSX this needs | 29 // The following test requires the use of the NSSDecryptor, on OSX this needs |
24 // to run in a separate process, so we use a proxy object so we can share the | 30 // to run in a separate process, so we use a proxy object so we can share the |
25 // same test between platforms. | 31 // same test between platforms. |
26 TEST(FirefoxImporterTest, MAYBE_NSS(Firefox3NSS3Decryptor)) { | 32 TEST(FirefoxImporterTest, MAYBE_NSS(Firefox3NSS3Decryptor)) { |
27 base::FilePath nss_path; | 33 base::FilePath nss_path; |
28 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &nss_path)); | 34 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &nss_path)); |
29 #if defined(OS_MACOSX) | 35 #if defined(OS_MACOSX) |
30 nss_path = nss_path.AppendASCII("firefox3_nss_mac"); | 36 nss_path = nss_path.AppendASCII("firefox3_nss_mac"); |
31 #else | 37 #else |
32 nss_path = nss_path.AppendASCII("firefox3_nss"); | 38 nss_path = nss_path.AppendASCII("firefox3_nss"); |
33 #endif // !OS_MACOSX | 39 #endif // !OS_MACOSX |
34 base::FilePath db_path; | 40 base::FilePath db_path; |
35 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &db_path)); | 41 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &db_path)); |
36 db_path = db_path.AppendASCII("firefox3_profile"); | 42 db_path = db_path.AppendASCII("firefox3_profile"); |
37 | 43 |
38 FFUnitTestDecryptorProxy decryptor_proxy; | 44 FFUnitTestDecryptorProxy decryptor_proxy; |
39 ASSERT_TRUE(decryptor_proxy.Setup(nss_path)); | 45 ASSERT_TRUE(decryptor_proxy.Setup(nss_path)); |
40 | 46 |
41 ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path)); | 47 ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path)); |
42 EXPECT_EQ(base::ASCIIToUTF16("hello"), | 48 EXPECT_EQ( |
| 49 base::ASCIIToUTF16("hello"), |
43 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECKa" | 50 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECKa" |
44 "jtRg4qFSHBAhv9luFkXgDJA==")); | 51 "jtRg4qFSHBAhv9luFkXgDJA==")); |
45 // Test UTF-16 encoding. | 52 // Test UTF-16 encoding. |
46 EXPECT_EQ(base::WideToUTF16(L"\x4E2D"), | 53 EXPECT_EQ( |
| 54 base::WideToUTF16(L"\x4E2D"), |
47 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECLW" | 55 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECLW" |
48 "qqiccfQHWBAie74hxnULxlw==")); | 56 "qqiccfQHWBAie74hxnULxlw==")); |
49 | 57 |
50 // Test empty string edge case. | 58 // Test empty string edge case. |
51 EXPECT_EQ(base::string16(), decryptor_proxy.Decrypt(std::string())); | 59 EXPECT_EQ(base::string16(), decryptor_proxy.Decrypt(std::string())); |
52 | 60 |
53 // Test invalid base64. | 61 // Test invalid base64. |
54 EXPECT_EQ(base::string16(), decryptor_proxy.Decrypt("Not! Valid! Base64!")); | 62 EXPECT_EQ(base::string16(), decryptor_proxy.Decrypt("Not! Valid! Base64!")); |
55 } | 63 } |
56 | 64 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 ASSERT_TRUE(decryptor_proxy.Setup(nss_path)); | 116 ASSERT_TRUE(decryptor_proxy.Setup(nss_path)); |
109 | 117 |
110 ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path)); | 118 ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path)); |
111 std::vector<autofill::PasswordForm> forms = | 119 std::vector<autofill::PasswordForm> forms = |
112 decryptor_proxy.ParseSignons(signons_path); | 120 decryptor_proxy.ParseSignons(signons_path); |
113 | 121 |
114 ASSERT_EQ(2u, forms.size()); | 122 ASSERT_EQ(2u, forms.size()); |
115 EXPECT_EQ(autofill::PasswordForm::SCHEME_BASIC, forms[0].scheme); | 123 EXPECT_EQ(autofill::PasswordForm::SCHEME_BASIC, forms[0].scheme); |
116 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, forms[1].scheme); | 124 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, forms[1].scheme); |
117 } | 125 } |
| 126 |
| 127 TEST(FirefoxImporterTest, ImportBookmarks) { |
| 128 using ::testing::_; |
| 129 base::FilePath places_path; |
| 130 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &places_path)); |
| 131 places_path = |
| 132 places_path.AppendASCII("import").AppendASCII("firefox").AppendASCII( |
| 133 "48.0.2"); |
| 134 scoped_refptr<FirefoxImporter> importer = new FirefoxImporter; |
| 135 importer::SourceProfile profile; |
| 136 profile.source_path = places_path; |
| 137 scoped_refptr<MockImporterBridge> bridge = new MockImporterBridge; |
| 138 std::vector<ImportedBookmarkEntry> bookmarks; |
| 139 favicon_base::FaviconUsageDataList favicons; |
| 140 EXPECT_CALL(*bridge, NotifyStarted()); |
| 141 EXPECT_CALL(*bridge, NotifyItemStarted(importer::FAVORITES)); |
| 142 EXPECT_CALL(*bridge, AddBookmarks(_, _)) |
| 143 .WillOnce(::testing::SaveArg<0>(&bookmarks)); |
| 144 EXPECT_CALL(*bridge, SetFavicons(_)) |
| 145 .WillOnce(::testing::SaveArg<0>(&favicons)); |
| 146 EXPECT_CALL(*bridge, NotifyItemEnded(importer::FAVORITES)); |
| 147 EXPECT_CALL(*bridge, NotifyEnded()); |
| 148 importer->StartImport(profile, importer::FAVORITES, bridge.get()); |
| 149 ASSERT_EQ(6u, bookmarks.size()); |
| 150 EXPECT_EQ("https://www.mozilla.org/en-US/firefox/central/", |
| 151 bookmarks[0].url.spec()); |
| 152 EXPECT_EQ("https://www.mozilla.org/en-US/firefox/help/", |
| 153 bookmarks[1].url.spec()); |
| 154 EXPECT_EQ("https://www.mozilla.org/en-US/firefox/customize/", |
| 155 bookmarks[2].url.spec()); |
| 156 EXPECT_EQ("https://www.mozilla.org/en-US/contribute/", |
| 157 bookmarks[3].url.spec()); |
| 158 EXPECT_EQ("https://www.mozilla.org/en-US/about/", bookmarks[4].url.spec()); |
| 159 EXPECT_EQ("https://www.google.com/", bookmarks[5].url.spec()); |
| 160 ASSERT_EQ(5u, favicons.size()); |
| 161 EXPECT_EQ("http://www.mozilla.org/2005/made-up-favicon/0-1473403921346", |
| 162 favicons[0].favicon_url.spec()); |
| 163 EXPECT_EQ("http://www.mozilla.org/2005/made-up-favicon/1-1473403921347", |
| 164 favicons[1].favicon_url.spec()); |
| 165 EXPECT_EQ("http://www.mozilla.org/2005/made-up-favicon/2-1473403921348", |
| 166 favicons[2].favicon_url.spec()); |
| 167 EXPECT_EQ("http://www.mozilla.org/2005/made-up-favicon/3-1473403921349", |
| 168 favicons[3].favicon_url.spec()); |
| 169 EXPECT_EQ("http://www.mozilla.org/2005/made-up-favicon/4-1473403921349", |
| 170 favicons[4].favicon_url.spec()); |
| 171 } |
| 172 |
| 173 TEST(FirefoxImporterTest, ImportHistorySchema) { |
| 174 using ::testing::_; |
| 175 base::FilePath places_path; |
| 176 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &places_path)); |
| 177 places_path = |
| 178 places_path.AppendASCII("import").AppendASCII("firefox").AppendASCII( |
| 179 "48.0.2"); |
| 180 scoped_refptr<FirefoxImporter> ff_importer = new FirefoxImporter; |
| 181 importer::SourceProfile profile; |
| 182 profile.source_path = places_path; |
| 183 scoped_refptr<MockImporterBridge> bridge = new MockImporterBridge; |
| 184 std::vector<ImporterURLRow> history; |
| 185 EXPECT_CALL(*bridge, NotifyStarted()); |
| 186 EXPECT_CALL(*bridge, NotifyItemStarted(importer::HISTORY)); |
| 187 EXPECT_CALL(*bridge, SetHistoryItems(_, _)) |
| 188 .WillOnce(::testing::SaveArg<0>(&history)); |
| 189 EXPECT_CALL(*bridge, NotifyItemEnded(importer::HISTORY)); |
| 190 EXPECT_CALL(*bridge, NotifyEnded()); |
| 191 ff_importer->StartImport(profile, importer::HISTORY, bridge.get()); |
| 192 ASSERT_EQ(3u, history.size()); |
| 193 EXPECT_EQ("https://www.mozilla.org/en-US/firefox/48.0.2/firstrun/learnmore/", |
| 194 history[0].url.spec()); |
| 195 EXPECT_EQ("https://www.mozilla.org/en-US/firefox/48.0.2/firstrun/", |
| 196 history[1].url.spec()); |
| 197 EXPECT_EQ("http://google.com/", history[2].url.spec()); |
| 198 } |
OLD | NEW |