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/importer_data_types.h" |
| 12 #include "chrome/common/importer/mock_importer_bridge.h" |
| 13 #include "chrome/utility/importer/firefox_importer.h" |
11 #include "chrome/utility/importer/firefox_importer_unittest_utils.h" | 14 #include "chrome/utility/importer/firefox_importer_unittest_utils.h" |
12 #include "chrome/utility/importer/nss_decryptor.h" | 15 #include "chrome/utility/importer/nss_decryptor.h" |
13 #include "sql/connection.h" | 16 #include "sql/connection.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
15 | 18 |
16 // TODO(jschuh): Disabled on Win64 build. http://crbug.com/179688 | 19 // TODO(jschuh): Disabled on Win64 build. http://crbug.com/179688 |
17 #if defined(OS_WIN) && defined(ARCH_CPU_X86_64) | 20 #if defined(OS_WIN) && defined(ARCH_CPU_X86_64) |
18 #define MAYBE_NSS(x) DISABLED_##x | 21 #define MAYBE_NSS(x) DISABLED_##x |
19 #else | 22 #else |
20 #define MAYBE_NSS(x) x | 23 #define MAYBE_NSS(x) x |
(...skipping 11 matching lines...) Expand all Loading... |
32 nss_path = nss_path.AppendASCII("firefox3_nss"); | 35 nss_path = nss_path.AppendASCII("firefox3_nss"); |
33 #endif // !OS_MACOSX | 36 #endif // !OS_MACOSX |
34 base::FilePath db_path; | 37 base::FilePath db_path; |
35 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &db_path)); | 38 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &db_path)); |
36 db_path = db_path.AppendASCII("firefox3_profile"); | 39 db_path = db_path.AppendASCII("firefox3_profile"); |
37 | 40 |
38 FFUnitTestDecryptorProxy decryptor_proxy; | 41 FFUnitTestDecryptorProxy decryptor_proxy; |
39 ASSERT_TRUE(decryptor_proxy.Setup(nss_path)); | 42 ASSERT_TRUE(decryptor_proxy.Setup(nss_path)); |
40 | 43 |
41 ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path)); | 44 ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path)); |
42 EXPECT_EQ(base::ASCIIToUTF16("hello"), | 45 EXPECT_EQ( |
| 46 base::ASCIIToUTF16("hello"), |
43 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECKa" | 47 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECKa" |
44 "jtRg4qFSHBAhv9luFkXgDJA==")); | 48 "jtRg4qFSHBAhv9luFkXgDJA==")); |
45 // Test UTF-16 encoding. | 49 // Test UTF-16 encoding. |
46 EXPECT_EQ(base::WideToUTF16(L"\x4E2D"), | 50 EXPECT_EQ( |
| 51 base::WideToUTF16(L"\x4E2D"), |
47 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECLW" | 52 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECLW" |
48 "qqiccfQHWBAie74hxnULxlw==")); | 53 "qqiccfQHWBAie74hxnULxlw==")); |
49 | 54 |
50 // Test empty string edge case. | 55 // Test empty string edge case. |
51 EXPECT_EQ(base::string16(), decryptor_proxy.Decrypt(std::string())); | 56 EXPECT_EQ(base::string16(), decryptor_proxy.Decrypt(std::string())); |
52 | 57 |
53 // Test invalid base64. | 58 // Test invalid base64. |
54 EXPECT_EQ(base::string16(), decryptor_proxy.Decrypt("Not! Valid! Base64!")); | 59 EXPECT_EQ(base::string16(), decryptor_proxy.Decrypt("Not! Valid! Base64!")); |
55 } | 60 } |
56 | 61 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 ASSERT_TRUE(decryptor_proxy.Setup(nss_path)); | 112 ASSERT_TRUE(decryptor_proxy.Setup(nss_path)); |
108 | 113 |
109 ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path)); | 114 ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path)); |
110 std::vector<autofill::PasswordForm> forms = | 115 std::vector<autofill::PasswordForm> forms = |
111 decryptor_proxy.ParseSignons(signons_path); | 116 decryptor_proxy.ParseSignons(signons_path); |
112 | 117 |
113 ASSERT_EQ(2u, forms.size()); | 118 ASSERT_EQ(2u, forms.size()); |
114 EXPECT_EQ(autofill::PasswordForm::SCHEME_BASIC, forms[0].scheme); | 119 EXPECT_EQ(autofill::PasswordForm::SCHEME_BASIC, forms[0].scheme); |
115 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, forms[1].scheme); | 120 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, forms[1].scheme); |
116 } | 121 } |
| 122 |
| 123 TEST(FirefoxImporterTest, ImportBookmarksSchemaV11) { |
| 124 using ::testing::_; |
| 125 base::FilePath places_path; |
| 126 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &places_path)); |
| 127 places_path = |
| 128 places_path.AppendASCII("import").AppendASCII("firefox").AppendASCII( |
| 129 "4.0"); |
| 130 scoped_refptr<FirefoxImporter> importer = new FirefoxImporter; |
| 131 importer::SourceProfile profile; |
| 132 profile.source_path = places_path; |
| 133 scoped_refptr<MockImporterBridge> bridge = new MockImporterBridge; |
| 134 std::vector<ImportedBookmarkEntry> bookmarks; |
| 135 favicon_base::FaviconUsageDataList favicons; |
| 136 EXPECT_CALL(*bridge, NotifyStarted()); |
| 137 EXPECT_CALL(*bridge, NotifyItemStarted(importer::FAVORITES)); |
| 138 EXPECT_CALL(*bridge, AddBookmarks(_, _)) |
| 139 .WillOnce(::testing::SaveArg<0>(&(bookmarks))); |
| 140 EXPECT_CALL(*bridge, SetFavicons(_)) |
| 141 .WillOnce(::testing::SaveArg<0>(&(favicons))); |
| 142 EXPECT_CALL(*bridge, NotifyItemEnded(importer::FAVORITES)); |
| 143 EXPECT_CALL(*bridge, NotifyEnded()); |
| 144 importer->StartImport(profile, importer::FAVORITES, bridge.get()); |
| 145 EXPECT_EQ(6, bookmarks.size()); |
| 146 EXPECT_EQ("http://www.mozilla.com/en-US/firefox/central/", |
| 147 bookmarks[0].url.spec()); |
| 148 EXPECT_EQ("http://www.mozilla.com/en-US/firefox/help/", |
| 149 bookmarks[1].url.spec()); |
| 150 EXPECT_EQ("http://www.mozilla.com/en-US/firefox/customize/", |
| 151 bookmarks[2].url.spec()); |
| 152 EXPECT_EQ("http://www.mozilla.com/en-US/firefox/community/", |
| 153 bookmarks[3].url.spec()); |
| 154 EXPECT_EQ("http://www.mozilla.com/en-US/about/", |
| 155 bookmarks[4].url.spec()); |
| 156 EXPECT_EQ("http://www.google.com/", |
| 157 bookmarks[5].url.spec()); |
| 158 EXPECT_EQ(4, favicons.size()); |
| 159 EXPECT_EQ("http://www.mozilla.org/2005/made-up-favicon/0-1473342759588000", |
| 160 favicons[0].favicon_url.spec()); |
| 161 EXPECT_EQ("http://www.mozilla.org/2005/made-up-favicon/1-1473342759589000", |
| 162 favicons[1].favicon_url.spec()); |
| 163 EXPECT_EQ("http://www.mozilla.org/2005/made-up-favicon/2-1473342759589000", |
| 164 favicons[2].favicon_url.spec()); |
| 165 EXPECT_EQ("http://www.mozilla.org/2005/made-up-favicon/3-1473342759590000", |
| 166 favicons[3].favicon_url.spec()); |
| 167 } |
| 168 |
| 169 TEST(FirefoxImporterTest, ImportHistorySchemaV11) { |
| 170 using ::testing::_; |
| 171 base::FilePath places_path; |
| 172 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &places_path)); |
| 173 places_path = |
| 174 places_path.AppendASCII("import").AppendASCII("firefox").AppendASCII( |
| 175 "4.0"); |
| 176 scoped_refptr<FirefoxImporter> importer = new FirefoxImporter; |
| 177 importer::SourceProfile profile; |
| 178 profile.source_path = places_path; |
| 179 scoped_refptr<MockImporterBridge> bridge = new MockImporterBridge; |
| 180 std::vector<ImporterURLRow> history; |
| 181 EXPECT_CALL(*bridge, NotifyStarted()); |
| 182 EXPECT_CALL(*bridge, NotifyItemStarted(importer::HISTORY)); |
| 183 EXPECT_CALL(*bridge, SetHistoryItems(_, _)) |
| 184 .WillOnce(::testing::SaveArg<0>(&(history))); |
| 185 EXPECT_CALL(*bridge, NotifyItemEnded(importer::HISTORY)); |
| 186 EXPECT_CALL(*bridge, NotifyEnded()); |
| 187 importer->StartImport(profile, importer::HISTORY, bridge.get()); |
| 188 EXPECT_EQ(2, history.size()); |
| 189 EXPECT_EQ("http://www.mozilla.com/en-US/firefox/4.0/firstrun/", |
| 190 history[0].url.spec()); |
| 191 EXPECT_EQ("http://google.com/", history[1].url.spec()); |
| 192 } |
| 193 |
| 194 TEST(FirefoxImporterTest, ImportBookmarksSchemaV25) { |
| 195 using ::testing::_; |
| 196 base::FilePath places_path; |
| 197 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &places_path)); |
| 198 places_path = |
| 199 places_path.AppendASCII("import").AppendASCII("firefox").AppendASCII( |
| 200 "36.0.1"); |
| 201 scoped_refptr<FirefoxImporter> importer = new FirefoxImporter; |
| 202 importer::SourceProfile profile; |
| 203 profile.source_path = places_path; |
| 204 scoped_refptr<MockImporterBridge> bridge = new MockImporterBridge; |
| 205 std::vector<ImportedBookmarkEntry> bookmarks; |
| 206 favicon_base::FaviconUsageDataList favicons; |
| 207 EXPECT_CALL(*bridge, NotifyStarted()); |
| 208 EXPECT_CALL(*bridge, NotifyItemStarted(importer::FAVORITES)); |
| 209 EXPECT_CALL(*bridge, AddBookmarks(_, _)) |
| 210 .WillOnce(::testing::SaveArg<0>(&(bookmarks))); |
| 211 EXPECT_CALL(*bridge, SetFavicons(_)) |
| 212 .WillOnce(::testing::SaveArg<0>(&(favicons))); |
| 213 EXPECT_CALL(*bridge, NotifyItemEnded(importer::FAVORITES)); |
| 214 EXPECT_CALL(*bridge, NotifyEnded()); |
| 215 importer->StartImport(profile, importer::FAVORITES, bridge.get()); |
| 216 EXPECT_EQ(6, bookmarks.size()); |
| 217 EXPECT_EQ("https://www.mozilla.org/en-US/firefox/central/", |
| 218 bookmarks[0].url.spec()); |
| 219 EXPECT_EQ("https://www.mozilla.org/en-US/firefox/help/", |
| 220 bookmarks[1].url.spec()); |
| 221 EXPECT_EQ("https://www.mozilla.org/en-US/firefox/customize/", |
| 222 bookmarks[2].url.spec()); |
| 223 EXPECT_EQ("https://www.mozilla.org/en-US/contribute/", |
| 224 bookmarks[3].url.spec()); |
| 225 EXPECT_EQ("https://www.mozilla.org/en-US/about/", |
| 226 bookmarks[4].url.spec()); |
| 227 EXPECT_EQ("https://www.google.com/", |
| 228 bookmarks[5].url.spec()); |
| 229 EXPECT_EQ(4, favicons.size()); |
| 230 EXPECT_EQ("http://www.mozilla.org/2005/made-up-favicon/0-1473412028106", |
| 231 favicons[0].favicon_url.spec()); |
| 232 EXPECT_EQ("http://www.mozilla.org/2005/made-up-favicon/1-1473412028107", |
| 233 favicons[1].favicon_url.spec()); |
| 234 EXPECT_EQ("http://www.mozilla.org/2005/made-up-favicon/2-1473412028107", |
| 235 favicons[2].favicon_url.spec()); |
| 236 EXPECT_EQ("http://www.mozilla.org/2005/made-up-favicon/3-1473412028108", |
| 237 favicons[3].favicon_url.spec()); |
| 238 } |
| 239 |
| 240 TEST(FirefoxImporterTest, ImportHistorySchemaV25) { |
| 241 using ::testing::_; |
| 242 base::FilePath places_path; |
| 243 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &places_path)); |
| 244 places_path = |
| 245 places_path.AppendASCII("import").AppendASCII("firefox").AppendASCII( |
| 246 "36.0.1"); |
| 247 scoped_refptr<FirefoxImporter> importer = new FirefoxImporter; |
| 248 importer::SourceProfile profile; |
| 249 profile.source_path = places_path; |
| 250 scoped_refptr<MockImporterBridge> bridge = new MockImporterBridge; |
| 251 std::vector<ImporterURLRow> history; |
| 252 EXPECT_CALL(*bridge, NotifyStarted()); |
| 253 EXPECT_CALL(*bridge, NotifyItemStarted(importer::HISTORY)); |
| 254 EXPECT_CALL(*bridge, SetHistoryItems(_, _)) |
| 255 .WillOnce(::testing::SaveArg<0>(&(history))); |
| 256 EXPECT_CALL(*bridge, NotifyItemEnded(importer::HISTORY)); |
| 257 EXPECT_CALL(*bridge, NotifyEnded()); |
| 258 importer->StartImport(profile, importer::HISTORY, bridge.get()); |
| 259 EXPECT_EQ(2, history.size()); |
| 260 EXPECT_EQ("https://www.mozilla.org/en-US/firefox/36.0.1/firstrun/", |
| 261 history[0].url.spec()); |
| 262 EXPECT_EQ("http://google.com/", history[1].url.spec()); |
| 263 } |
| 264 |
| 265 TEST(FirefoxImporterTest, ImportBookmarksSchemaV31) { |
| 266 using ::testing::_; |
| 267 base::FilePath places_path; |
| 268 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &places_path)); |
| 269 places_path = |
| 270 places_path.AppendASCII("import").AppendASCII("firefox").AppendASCII( |
| 271 "48.0.2"); |
| 272 scoped_refptr<FirefoxImporter> importer = new FirefoxImporter; |
| 273 importer::SourceProfile profile; |
| 274 profile.source_path = places_path; |
| 275 scoped_refptr<MockImporterBridge> bridge = new MockImporterBridge; |
| 276 std::vector<ImportedBookmarkEntry> bookmarks; |
| 277 favicon_base::FaviconUsageDataList favicons; |
| 278 EXPECT_CALL(*bridge, NotifyStarted()); |
| 279 EXPECT_CALL(*bridge, NotifyItemStarted(importer::FAVORITES)); |
| 280 EXPECT_CALL(*bridge, AddBookmarks(_, _)) |
| 281 .WillOnce(::testing::SaveArg<0>(&(bookmarks))); |
| 282 EXPECT_CALL(*bridge, SetFavicons(_)) |
| 283 .WillOnce(::testing::SaveArg<0>(&(favicons))); |
| 284 EXPECT_CALL(*bridge, NotifyItemEnded(importer::FAVORITES)); |
| 285 EXPECT_CALL(*bridge, NotifyEnded()); |
| 286 importer->StartImport(profile, importer::FAVORITES, bridge.get()); |
| 287 ASSERT_EQ(6, bookmarks.size()); |
| 288 EXPECT_EQ("https://www.mozilla.org/en-US/firefox/central/", |
| 289 bookmarks[0].url.spec()); |
| 290 EXPECT_EQ("https://www.mozilla.org/en-US/firefox/help/", |
| 291 bookmarks[1].url.spec()); |
| 292 EXPECT_EQ("https://www.mozilla.org/en-US/firefox/customize/", |
| 293 bookmarks[2].url.spec()); |
| 294 EXPECT_EQ("https://www.mozilla.org/en-US/contribute/", |
| 295 bookmarks[3].url.spec()); |
| 296 EXPECT_EQ("https://www.mozilla.org/en-US/about/", bookmarks[4].url.spec()); |
| 297 EXPECT_EQ("https://www.google.com/", bookmarks[5].url.spec()); |
| 298 ASSERT_EQ(5, favicons.size()); |
| 299 EXPECT_EQ("http://www.mozilla.org/2005/made-up-favicon/0-1473403921346", |
| 300 favicons[0].favicon_url.spec()); |
| 301 EXPECT_EQ("http://www.mozilla.org/2005/made-up-favicon/1-1473403921347", |
| 302 favicons[1].favicon_url.spec()); |
| 303 EXPECT_EQ("http://www.mozilla.org/2005/made-up-favicon/2-1473403921348", |
| 304 favicons[2].favicon_url.spec()); |
| 305 EXPECT_EQ("http://www.mozilla.org/2005/made-up-favicon/3-1473403921349", |
| 306 favicons[3].favicon_url.spec()); |
| 307 EXPECT_EQ("http://www.mozilla.org/2005/made-up-favicon/4-1473403921349", |
| 308 favicons[4].favicon_url.spec()); |
| 309 } |
| 310 |
| 311 TEST(FirefoxImporterTest, ImportHistorySchemaV31) { |
| 312 using ::testing::_; |
| 313 base::FilePath places_path; |
| 314 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &places_path)); |
| 315 places_path = |
| 316 places_path.AppendASCII("import").AppendASCII("firefox").AppendASCII( |
| 317 "48.0.2"); |
| 318 scoped_refptr<FirefoxImporter> importer = new FirefoxImporter; |
| 319 importer::SourceProfile profile; |
| 320 profile.source_path = places_path; |
| 321 scoped_refptr<MockImporterBridge> bridge = new MockImporterBridge; |
| 322 std::vector<ImporterURLRow> history; |
| 323 EXPECT_CALL(*bridge, NotifyStarted()); |
| 324 EXPECT_CALL(*bridge, NotifyItemStarted(importer::HISTORY)); |
| 325 EXPECT_CALL(*bridge, SetHistoryItems(_, _)) |
| 326 .WillOnce(::testing::SaveArg<0>(&(history))); |
| 327 EXPECT_CALL(*bridge, NotifyItemEnded(importer::HISTORY)); |
| 328 EXPECT_CALL(*bridge, NotifyEnded()); |
| 329 importer->StartImport(profile, importer::HISTORY, bridge.get()); |
| 330 ASSERT_EQ(3, history.size()); |
| 331 EXPECT_EQ("https://www.mozilla.org/en-US/firefox/48.0.2/firstrun/learnmore/", |
| 332 history[0].url.spec()); |
| 333 EXPECT_EQ("https://www.mozilla.org/en-US/firefox/48.0.2/firstrun/", |
| 334 history[1].url.spec()); |
| 335 EXPECT_EQ("http://google.com/", history[2].url.spec()); |
| 336 } |
OLD | NEW |