| 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | |
| 8 #include "base/file_util.h" | |
| 9 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 10 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 11 #include "base/stl_util.h" | |
| 12 #include "base/string16.h" | 9 #include "base/string16.h" |
| 13 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 14 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/browser/history/history_types.h" | 12 #include "chrome/browser/history/history_types.h" |
| 16 #include "chrome/browser/importer/firefox2_importer.h" | 13 #include "chrome/browser/importer/firefox2_importer.h" |
| 17 #include "chrome/browser/importer/firefox_importer_unittest_utils.h" | 14 #include "chrome/browser/importer/firefox_importer_unittest_utils.h" |
| 18 #include "chrome/browser/importer/firefox_importer_utils.h" | |
| 19 #include "chrome/browser/importer/importer_bridge.h" | |
| 20 #include "chrome/browser/importer/importer_data_types.h" | |
| 21 #include "chrome/browser/importer/importer_host.h" | |
| 22 #include "chrome/browser/importer/importer_progress_observer.h" | |
| 23 #include "chrome/browser/importer/importer_unittest_utils.h" | |
| 24 #include "chrome/browser/importer/nss_decryptor.h" | 15 #include "chrome/browser/importer/nss_decryptor.h" |
| 25 #include "chrome/browser/search_engines/template_url.h" | |
| 26 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
| 27 #include "chrome/test/base/testing_profile.h" | |
| 28 #include "content/public/common/password_form.h" | |
| 29 | |
| 30 // TODO(estade): some of these are disabled on mac. http://crbug.com/48007 | |
| 31 // TODO(jschuh): Disabled on Win64 build. http://crbug.com/179688 | |
| 32 #if defined(OS_MACOSX) || (defined(OS_WIN) && defined(ARCH_CPU_X86_64)) | |
| 33 #define MAYBE_IMPORTER(x) DISABLED_##x | |
| 34 #else | |
| 35 #define MAYBE_IMPORTER(x) x | |
| 36 #endif | |
| 37 | 17 |
| 38 // TODO(jschuh): Disabled on Win64 build. http://crbug.com/179688 | 18 // TODO(jschuh): Disabled on Win64 build. http://crbug.com/179688 |
| 39 #if defined(OS_WIN) && defined(ARCH_CPU_X86_64) | 19 #if defined(OS_WIN) && defined(ARCH_CPU_X86_64) |
| 40 #define MAYBE_NSS(x) DISABLED_##x | 20 #define MAYBE_NSS(x) DISABLED_##x |
| 41 #else | 21 #else |
| 42 #define MAYBE_NSS(x) x | 22 #define MAYBE_NSS(x) x |
| 43 #endif | 23 #endif |
| 44 | 24 |
| 45 namespace { | |
| 46 | |
| 47 const BookmarkInfo kFirefox2Bookmarks[] = { | |
| 48 {true, 2, {L"Bookmarks Toolbar Folder", L"Folder"}, | |
| 49 L"On Toolbar's Subfolder", | |
| 50 "http://on.toolbar/bookmark/folder"}, | |
| 51 {true, 1, {L"Bookmarks Toolbar Folder"}, | |
| 52 L"On Bookmark Toolbar", | |
| 53 "http://on.toolbar/bookmark"}, | |
| 54 {false, 1, {L"Folder"}, | |
| 55 L"New Bookmark", | |
| 56 "http://domain/"}, | |
| 57 {false, 0, {}, | |
| 58 L"<Name>", | |
| 59 "http://domain.com/q?a=%22er%22&b=%3C%20%20%3E"}, | |
| 60 {false, 0, {}, | |
| 61 L"Google Home Page", | |
| 62 "http://www.google.com/"}, | |
| 63 {false, 0, {}, | |
| 64 L"\x4E2D\x6587", | |
| 65 "http://chinese.site.cn/path?query=1#ref"}, | |
| 66 {false, 0, {}, | |
| 67 L"mail", | |
| 68 "mailto:username@host"}, | |
| 69 }; | |
| 70 | |
| 71 struct PasswordInfo { | |
| 72 const char* origin; | |
| 73 const char* action; | |
| 74 const char* realm; | |
| 75 const wchar_t* username_element; | |
| 76 const wchar_t* username; | |
| 77 const wchar_t* password_element; | |
| 78 const wchar_t* password; | |
| 79 bool blacklisted; | |
| 80 }; | |
| 81 | |
| 82 const PasswordInfo kFirefox2Passwords[] = { | |
| 83 {"https://www.google.com/", "", "https://www.google.com/", | |
| 84 L"", L"", L"", L"", true}, | |
| 85 {"http://localhost:8080/", "", "http://localhost:8080/corp.google.com", | |
| 86 L"", L"http", L"", L"Http1+1abcdefg", false}, | |
| 87 {"http://localhost:8080/", "http://localhost:8080/", "http://localhost:8080/", | |
| 88 L"loginuser", L"usr", L"loginpass", L"pwd", false}, | |
| 89 {"http://localhost:8080/", "http://localhost:8080/", "http://localhost:8080/", | |
| 90 L"loginuser", L"firefox", L"loginpass", L"firefox", false}, | |
| 91 {"http://localhost/", "", "http://localhost/", | |
| 92 L"loginuser", L"hello", L"", L"world", false}, | |
| 93 }; | |
| 94 | |
| 95 struct KeywordInfo { | |
| 96 const wchar_t* keyword; | |
| 97 const char* url; | |
| 98 }; | |
| 99 | |
| 100 const KeywordInfo kFirefox2Keywords[] = { | |
| 101 // Searh plugins | |
| 102 { L"amazon.com", | |
| 103 "http://www.amazon.com/exec/obidos/external-search/?field-keywords=" | |
| 104 "{searchTerms}&mode=blended" }, | |
| 105 { L"answers.com", | |
| 106 "http://www.answers.com/main/ntquery?s={searchTerms}&gwp=13" }, | |
| 107 { L"search.creativecommons.org", | |
| 108 "http://search.creativecommons.org/?q={searchTerms}" }, | |
| 109 { L"search.ebay.com", | |
| 110 "http://search.ebay.com/search/search.dll?query={searchTerms}&" | |
| 111 "MfcISAPICommand=GetResult&ht=1&ebaytag1=ebayreg&srchdesc=n&" | |
| 112 "maxRecordsReturned=300&maxRecordsPerPage=50&SortProperty=MetaEndSort" }, | |
| 113 { L"google.com", | |
| 114 "http://www.google.com/search?q={searchTerms}&ie=utf-8&oe=utf-8&aq=t" }, | |
| 115 { L"search.yahoo.com", | |
| 116 "http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8" }, | |
| 117 { L"flickr.com", | |
| 118 "http://www.flickr.com/photos/tags/?q={searchTerms}" }, | |
| 119 { L"imdb.com", | |
| 120 "http://www.imdb.com/find?q={searchTerms}" }, | |
| 121 { L"webster.com", | |
| 122 "http://www.webster.com/cgi-bin/dictionary?va={searchTerms}" }, | |
| 123 // Search keywords. | |
| 124 { L"google", "http://www.google.com/" }, | |
| 125 { L"< > & \" ' \\ /", "http://g.cn/"}, | |
| 126 }; | |
| 127 | |
| 128 const int kDefaultFirefox2KeywordIndex = 8; | |
| 129 | |
| 130 class FirefoxObserver : public ProfileWriter, | |
| 131 public importer::ImporterProgressObserver { | |
| 132 public: | |
| 133 FirefoxObserver() : ProfileWriter(NULL) { | |
| 134 bookmark_count_ = 0; | |
| 135 history_count_ = 0; | |
| 136 password_count_ = 0; | |
| 137 keyword_count_ = 0; | |
| 138 } | |
| 139 | |
| 140 // importer::ImporterProgressObserver: | |
| 141 virtual void ImportStarted() OVERRIDE {} | |
| 142 virtual void ImportItemStarted(importer::ImportItem item) OVERRIDE {} | |
| 143 virtual void ImportItemEnded(importer::ImportItem item) OVERRIDE {} | |
| 144 virtual void ImportEnded() OVERRIDE { | |
| 145 MessageLoop::current()->Quit(); | |
| 146 EXPECT_EQ(arraysize(kFirefox2Bookmarks), bookmark_count_); | |
| 147 EXPECT_EQ(1U, history_count_); | |
| 148 EXPECT_EQ(arraysize(kFirefox2Passwords), password_count_); | |
| 149 EXPECT_EQ(arraysize(kFirefox2Keywords), keyword_count_); | |
| 150 } | |
| 151 | |
| 152 virtual bool BookmarkModelIsLoaded() const OVERRIDE { | |
| 153 // Profile is ready for writing. | |
| 154 return true; | |
| 155 } | |
| 156 | |
| 157 virtual bool TemplateURLServiceIsLoaded() const OVERRIDE { | |
| 158 return true; | |
| 159 } | |
| 160 | |
| 161 virtual void AddPasswordForm(const content::PasswordForm& form) OVERRIDE { | |
| 162 PasswordInfo p = kFirefox2Passwords[password_count_]; | |
| 163 EXPECT_EQ(p.origin, form.origin.spec()); | |
| 164 EXPECT_EQ(p.realm, form.signon_realm); | |
| 165 EXPECT_EQ(p.action, form.action.spec()); | |
| 166 EXPECT_EQ(WideToUTF16(p.username_element), form.username_element); | |
| 167 EXPECT_EQ(WideToUTF16(p.username), form.username_value); | |
| 168 EXPECT_EQ(WideToUTF16(p.password_element), form.password_element); | |
| 169 EXPECT_EQ(WideToUTF16(p.password), form.password_value); | |
| 170 EXPECT_EQ(p.blacklisted, form.blacklisted_by_user); | |
| 171 ++password_count_; | |
| 172 } | |
| 173 | |
| 174 virtual void AddHistoryPage(const history::URLRows& page, | |
| 175 history::VisitSource visit_source) OVERRIDE { | |
| 176 ASSERT_EQ(1U, page.size()); | |
| 177 EXPECT_EQ("http://en-us.www.mozilla.com/", page[0].url().spec()); | |
| 178 EXPECT_EQ(ASCIIToUTF16("Firefox Updated"), page[0].title()); | |
| 179 EXPECT_EQ(history::SOURCE_FIREFOX_IMPORTED, visit_source); | |
| 180 ++history_count_; | |
| 181 } | |
| 182 | |
| 183 virtual void AddBookmarks(const std::vector<BookmarkEntry>& bookmarks, | |
| 184 const string16& top_level_folder_name) OVERRIDE { | |
| 185 for (size_t i = 0; i < bookmarks.size(); ++i) { | |
| 186 if (FindBookmarkEntry(bookmarks[i], kFirefox2Bookmarks, | |
| 187 arraysize(kFirefox2Bookmarks))) | |
| 188 ++bookmark_count_; | |
| 189 } | |
| 190 } | |
| 191 | |
| 192 virtual void AddKeywords(ScopedVector<TemplateURL> template_urls, | |
| 193 bool unique_on_host_and_path) OVERRIDE { | |
| 194 for (size_t i = 0; i < template_urls.size(); ++i) { | |
| 195 // The order might not be deterministic, look in the expected list for | |
| 196 // that template URL. | |
| 197 bool found = false; | |
| 198 string16 keyword = template_urls[i]->keyword(); | |
| 199 for (size_t j = 0; j < arraysize(kFirefox2Keywords); ++j) { | |
| 200 if (template_urls[i]->keyword() == | |
| 201 WideToUTF16Hack(kFirefox2Keywords[j].keyword)) { | |
| 202 EXPECT_EQ(kFirefox2Keywords[j].url, template_urls[i]->url()); | |
| 203 found = true; | |
| 204 break; | |
| 205 } | |
| 206 } | |
| 207 EXPECT_TRUE(found); | |
| 208 ++keyword_count_; | |
| 209 } | |
| 210 } | |
| 211 | |
| 212 virtual void AddFavicons( | |
| 213 const std::vector<history::ImportedFaviconUsage>& favicons) OVERRIDE { | |
| 214 } | |
| 215 | |
| 216 private: | |
| 217 virtual ~FirefoxObserver() {} | |
| 218 | |
| 219 size_t bookmark_count_; | |
| 220 size_t history_count_; | |
| 221 size_t password_count_; | |
| 222 size_t keyword_count_; | |
| 223 }; | |
| 224 | |
| 225 const BookmarkInfo kFirefox3Bookmarks[] = { | |
| 226 {true, 1, {L"Bookmarks Toolbar"}, | |
| 227 L"Toolbar", | |
| 228 "http://site/"}, | |
| 229 {false, 0, {}, | |
| 230 L"Title", | |
| 231 "http://www.google.com/"}, | |
| 232 }; | |
| 233 | |
| 234 const PasswordInfo kFirefox3Passwords[] = { | |
| 235 {"http://localhost:8080/", "http://localhost:8080/", "http://localhost:8080/", | |
| 236 L"loginuser", L"abc", L"loginpass", L"123", false}, | |
| 237 {"http://localhost:8080/", "", "http://localhost:8080/localhost", | |
| 238 L"", L"http", L"", L"Http1+1abcdefg", false}, | |
| 239 }; | |
| 240 | |
| 241 const KeywordInfo kFirefox3Keywords[] = { | |
| 242 { L"amazon.com", | |
| 243 "http://www.amazon.com/exec/obidos/external-search/?field-keywords=" | |
| 244 "{searchTerms}&mode=blended" }, | |
| 245 { L"answers.com", | |
| 246 "http://www.answers.com/main/ntquery?s={searchTerms}&gwp=13" }, | |
| 247 { L"search.creativecommons.org", | |
| 248 "http://search.creativecommons.org/?q={searchTerms}" }, | |
| 249 { L"search.ebay.com", | |
| 250 "http://search.ebay.com/search/search.dll?query={searchTerms}&" | |
| 251 "MfcISAPICommand=GetResult&ht=1&ebaytag1=ebayreg&srchdesc=n&" | |
| 252 "maxRecordsReturned=300&maxRecordsPerPage=50&SortProperty=MetaEndSort" }, | |
| 253 { L"google.com", | |
| 254 "http://www.google.com/search?q={searchTerms}&ie=utf-8&oe=utf-8&aq=t" }, | |
| 255 { L"en.wikipedia.org", | |
| 256 "http://en.wikipedia.org/wiki/Special:Search?search={searchTerms}" }, | |
| 257 { L"search.yahoo.com", | |
| 258 "http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8" }, | |
| 259 { L"flickr.com", | |
| 260 "http://www.flickr.com/photos/tags/?q={searchTerms}" }, | |
| 261 { L"imdb.com", | |
| 262 "http://www.imdb.com/find?q={searchTerms}" }, | |
| 263 { L"webster.com", | |
| 264 "http://www.webster.com/cgi-bin/dictionary?va={searchTerms}" }, | |
| 265 // Search keywords. | |
| 266 { L"\x4E2D\x6587", "http://www.google.com/" }, | |
| 267 }; | |
| 268 | |
| 269 const int kDefaultFirefox3KeywordIndex = 8; | |
| 270 | |
| 271 class Firefox3Observer : public ProfileWriter, | |
| 272 public importer::ImporterProgressObserver { | |
| 273 public: | |
| 274 Firefox3Observer() | |
| 275 : ProfileWriter(NULL), bookmark_count_(0), history_count_(0), | |
| 276 password_count_(0), keyword_count_(0), import_search_engines_(true) { | |
| 277 } | |
| 278 | |
| 279 explicit Firefox3Observer(bool import_search_engines) | |
| 280 : ProfileWriter(NULL), bookmark_count_(0), history_count_(0), | |
| 281 password_count_(0), keyword_count_(0), | |
| 282 import_search_engines_(import_search_engines) { | |
| 283 } | |
| 284 | |
| 285 // importer::ImporterProgressObserver: | |
| 286 virtual void ImportStarted() OVERRIDE {} | |
| 287 virtual void ImportItemStarted(importer::ImportItem item) OVERRIDE {} | |
| 288 virtual void ImportItemEnded(importer::ImportItem item) OVERRIDE {} | |
| 289 virtual void ImportEnded() OVERRIDE { | |
| 290 MessageLoop::current()->Quit(); | |
| 291 EXPECT_EQ(arraysize(kFirefox3Bookmarks), bookmark_count_); | |
| 292 EXPECT_EQ(1U, history_count_); | |
| 293 EXPECT_EQ(arraysize(kFirefox3Passwords), password_count_); | |
| 294 if (import_search_engines_) | |
| 295 EXPECT_EQ(arraysize(kFirefox3Keywords), keyword_count_); | |
| 296 } | |
| 297 | |
| 298 virtual bool BookmarkModelIsLoaded() const OVERRIDE { | |
| 299 // Profile is ready for writing. | |
| 300 return true; | |
| 301 } | |
| 302 | |
| 303 virtual bool TemplateURLServiceIsLoaded() const OVERRIDE { | |
| 304 return true; | |
| 305 } | |
| 306 | |
| 307 virtual void AddPasswordForm(const content::PasswordForm& form) OVERRIDE { | |
| 308 PasswordInfo p = kFirefox3Passwords[password_count_]; | |
| 309 EXPECT_EQ(p.origin, form.origin.spec()); | |
| 310 EXPECT_EQ(p.realm, form.signon_realm); | |
| 311 EXPECT_EQ(p.action, form.action.spec()); | |
| 312 EXPECT_EQ(WideToUTF16(p.username_element), form.username_element); | |
| 313 EXPECT_EQ(WideToUTF16(p.username), form.username_value); | |
| 314 EXPECT_EQ(WideToUTF16(p.password_element), form.password_element); | |
| 315 EXPECT_EQ(WideToUTF16(p.password), form.password_value); | |
| 316 EXPECT_EQ(p.blacklisted, form.blacklisted_by_user); | |
| 317 ++password_count_; | |
| 318 } | |
| 319 | |
| 320 virtual void AddHistoryPage(const history::URLRows& page, | |
| 321 history::VisitSource visit_source) OVERRIDE { | |
| 322 ASSERT_EQ(3U, page.size()); | |
| 323 EXPECT_EQ("http://www.google.com/", page[0].url().spec()); | |
| 324 EXPECT_EQ(ASCIIToUTF16("Google"), page[0].title()); | |
| 325 EXPECT_EQ("http://www.google.com/", page[1].url().spec()); | |
| 326 EXPECT_EQ(ASCIIToUTF16("Google"), page[1].title()); | |
| 327 EXPECT_EQ("http://www.cs.unc.edu/~jbs/resources/perl/perl-cgi/programs/" | |
| 328 "form1-POST.html", page[2].url().spec()); | |
| 329 EXPECT_EQ(ASCIIToUTF16("example form (POST)"), page[2].title()); | |
| 330 EXPECT_EQ(history::SOURCE_FIREFOX_IMPORTED, visit_source); | |
| 331 ++history_count_; | |
| 332 } | |
| 333 | |
| 334 virtual void AddBookmarks(const std::vector<BookmarkEntry>& bookmarks, | |
| 335 const string16& top_level_folder_name) OVERRIDE { | |
| 336 for (size_t i = 0; i < bookmarks.size(); ++i) { | |
| 337 if (FindBookmarkEntry(bookmarks[i], kFirefox3Bookmarks, | |
| 338 arraysize(kFirefox3Bookmarks))) | |
| 339 ++bookmark_count_; | |
| 340 } | |
| 341 } | |
| 342 | |
| 343 virtual void AddKeywords(ScopedVector<TemplateURL> template_urls, | |
| 344 bool unique_on_host_and_path) OVERRIDE { | |
| 345 for (size_t i = 0; i < template_urls.size(); ++i) { | |
| 346 // The order might not be deterministic, look in the expected list for | |
| 347 // that template URL. | |
| 348 bool found = false; | |
| 349 string16 keyword = template_urls[i]->keyword(); | |
| 350 for (size_t j = 0; j < arraysize(kFirefox3Keywords); ++j) { | |
| 351 if (template_urls[i]->keyword() == | |
| 352 WideToUTF16Hack(kFirefox3Keywords[j].keyword)) { | |
| 353 EXPECT_EQ(kFirefox3Keywords[j].url, template_urls[i]->url()); | |
| 354 found = true; | |
| 355 break; | |
| 356 } | |
| 357 } | |
| 358 EXPECT_TRUE(found); | |
| 359 ++keyword_count_; | |
| 360 } | |
| 361 } | |
| 362 | |
| 363 virtual void AddFavicons( | |
| 364 const std::vector<history::ImportedFaviconUsage>& favicons) OVERRIDE { | |
| 365 } | |
| 366 | |
| 367 private: | |
| 368 virtual ~Firefox3Observer() {} | |
| 369 | |
| 370 size_t bookmark_count_; | |
| 371 size_t history_count_; | |
| 372 size_t password_count_; | |
| 373 size_t keyword_count_; | |
| 374 bool import_search_engines_; | |
| 375 }; | |
| 376 | |
| 377 } // namespace | |
| 378 | |
| 379 class FirefoxProfileImporterTest : public ImporterTest { | |
| 380 protected: | |
| 381 virtual void SetUp() OVERRIDE { | |
| 382 ImporterTest::SetUp(); | |
| 383 // Creates a new profile in a new subdirectory in the temp directory. | |
| 384 base::FilePath test_path = temp_dir_.path().AppendASCII("ImporterTest"); | |
| 385 file_util::Delete(test_path, true); | |
| 386 file_util::CreateDirectory(test_path); | |
| 387 profile_path_ = test_path.AppendASCII("profile"); | |
| 388 app_path_ = test_path.AppendASCII("app"); | |
| 389 file_util::CreateDirectory(app_path_); | |
| 390 } | |
| 391 | |
| 392 void Firefox3xImporterTest(std::string profile_dir, | |
| 393 importer::ImporterProgressObserver* observer, | |
| 394 ProfileWriter* writer, | |
| 395 bool import_search_plugins) { | |
| 396 base::FilePath data_path; | |
| 397 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); | |
| 398 data_path = data_path.AppendASCII(profile_dir); | |
| 399 ASSERT_TRUE(file_util::CopyDirectory(data_path, profile_path_, true)); | |
| 400 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); | |
| 401 data_path = data_path.AppendASCII("firefox3_nss"); | |
| 402 ASSERT_TRUE(file_util::CopyDirectory(data_path, profile_path_, false)); | |
| 403 | |
| 404 base::FilePath search_engine_path = app_path_; | |
| 405 search_engine_path = search_engine_path.AppendASCII("searchplugins"); | |
| 406 file_util::CreateDirectory(search_engine_path); | |
| 407 if (import_search_plugins) { | |
| 408 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); | |
| 409 data_path = data_path.AppendASCII("firefox3_searchplugins"); | |
| 410 if (!file_util::PathExists(data_path)) { | |
| 411 // TODO(maruel): Create search test data that we can open source! | |
| 412 LOG(ERROR) << L"Missing internal test data"; | |
| 413 return; | |
| 414 } | |
| 415 ASSERT_TRUE(file_util::CopyDirectory(data_path, | |
| 416 search_engine_path, false)); | |
| 417 } | |
| 418 | |
| 419 MessageLoop* loop = MessageLoop::current(); | |
| 420 importer::SourceProfile source_profile; | |
| 421 source_profile.importer_type = importer::TYPE_FIREFOX3; | |
| 422 source_profile.app_path = app_path_; | |
| 423 source_profile.source_path = profile_path_; | |
| 424 scoped_refptr<ImporterHost> host(new ImporterHost); | |
| 425 host->SetObserver(observer); | |
| 426 int items = importer::HISTORY | importer::PASSWORDS | importer::FAVORITES; | |
| 427 if (import_search_plugins) | |
| 428 items = items | importer::SEARCH_ENGINES; | |
| 429 loop->PostTask(FROM_HERE, base::Bind( | |
| 430 &ImporterHost::StartImportSettings, host.get(), source_profile, | |
| 431 profile_.get(), items, make_scoped_refptr(writer))); | |
| 432 loop->Run(); | |
| 433 } | |
| 434 | |
| 435 base::FilePath profile_path_; | |
| 436 base::FilePath app_path_; | |
| 437 }; | |
| 438 | |
| 439 TEST_F(FirefoxProfileImporterTest, MAYBE_IMPORTER(Firefox2Importer)) { | |
| 440 base::FilePath data_path; | |
| 441 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); | |
| 442 data_path = data_path.AppendASCII("firefox2_profile"); | |
| 443 ASSERT_TRUE(file_util::CopyDirectory(data_path, profile_path_, true)); | |
| 444 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); | |
| 445 data_path = data_path.AppendASCII("firefox2_nss"); | |
| 446 ASSERT_TRUE(file_util::CopyDirectory(data_path, profile_path_, false)); | |
| 447 | |
| 448 base::FilePath search_engine_path = app_path_; | |
| 449 search_engine_path = search_engine_path.AppendASCII("searchplugins"); | |
| 450 file_util::CreateDirectory(search_engine_path); | |
| 451 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); | |
| 452 data_path = data_path.AppendASCII("firefox2_searchplugins"); | |
| 453 if (!file_util::PathExists(data_path)) { | |
| 454 // TODO(maruel): Create test data that we can open source! | |
| 455 LOG(ERROR) << L"Missing internal test data"; | |
| 456 return; | |
| 457 } | |
| 458 ASSERT_TRUE(file_util::CopyDirectory(data_path, search_engine_path, false)); | |
| 459 | |
| 460 MessageLoop* loop = MessageLoop::current(); | |
| 461 scoped_refptr<ImporterHost> host(new ImporterHost); | |
| 462 FirefoxObserver* observer = new FirefoxObserver(); | |
| 463 host->SetObserver(observer); | |
| 464 importer::SourceProfile source_profile; | |
| 465 source_profile.importer_type = importer::TYPE_FIREFOX2; | |
| 466 source_profile.app_path = app_path_; | |
| 467 source_profile.source_path = profile_path_; | |
| 468 | |
| 469 loop->PostTask(FROM_HERE, base::Bind( | |
| 470 &ImporterHost::StartImportSettings, | |
| 471 host.get(), | |
| 472 source_profile, | |
| 473 profile_.get(), | |
| 474 importer::HISTORY | importer::PASSWORDS | | |
| 475 importer::FAVORITES | importer::SEARCH_ENGINES, | |
| 476 make_scoped_refptr(observer))); | |
| 477 loop->Run(); | |
| 478 } | |
| 479 | |
| 480 TEST_F(FirefoxProfileImporterTest, MAYBE_IMPORTER(Firefox30Importer)) { | |
| 481 scoped_refptr<Firefox3Observer> observer(new Firefox3Observer()); | |
| 482 Firefox3xImporterTest("firefox3_profile", observer.get(), observer.get(), | |
| 483 true); | |
| 484 } | |
| 485 | |
| 486 TEST_F(FirefoxProfileImporterTest, MAYBE_IMPORTER(Firefox35Importer)) { | |
| 487 bool import_search_engines = false; | |
| 488 scoped_refptr<Firefox3Observer> observer( | |
| 489 new Firefox3Observer(import_search_engines)); | |
| 490 Firefox3xImporterTest("firefox35_profile", observer.get(), observer.get(), | |
| 491 import_search_engines); | |
| 492 } | |
| 493 | |
| 494 // The following 2 tests require the use of the NSSDecryptor, on OSX this needs | 25 // The following 2 tests require the use of the NSSDecryptor, on OSX this needs |
| 495 // to run in a separate process, so we use a proxy object so we can share the | 26 // to run in a separate process, so we use a proxy object so we can share the |
| 496 // same test between platforms. | 27 // same test between platforms. |
| 497 TEST(FirefoxImporterTest, MAYBE_NSS(Firefox2NSS3Decryptor)) { | 28 TEST(FirefoxImporterTest, MAYBE_NSS(Firefox2NSS3Decryptor)) { |
| 498 base::FilePath nss_path; | 29 base::FilePath nss_path; |
| 499 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &nss_path)); | 30 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &nss_path)); |
| 500 #if defined(OS_MACOSX) | 31 #if defined(OS_MACOSX) |
| 501 nss_path = nss_path.AppendASCII("firefox2_nss_mac"); | 32 nss_path = nss_path.AppendASCII("firefox2_nss_mac"); |
| 502 #else | 33 #else |
| 503 nss_path = nss_path.AppendASCII("firefox2_nss"); | 34 nss_path = nss_path.AppendASCII("firefox2_nss"); |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); | 295 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); |
| 765 EXPECT_EQ(0U, entry.path.size()); | 296 EXPECT_EQ(0U, entry.path.size()); |
| 766 entry = *it++; | 297 entry = *it++; |
| 767 EXPECT_EQ(ASCIIToUTF16("Google"), entry.title); | 298 EXPECT_EQ(ASCIIToUTF16("Google"), entry.title); |
| 768 EXPECT_EQ("http://www.google.com/", entry.url.spec()); | 299 EXPECT_EQ("http://www.google.com/", entry.url.spec()); |
| 769 EXPECT_EQ(0U, entry.path.size()); | 300 EXPECT_EQ(0U, entry.path.size()); |
| 770 } | 301 } |
| 771 | 302 |
| 772 importer->Release(); | 303 importer->Release(); |
| 773 } | 304 } |
| OLD | NEW |