OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/file_util.h" | 5 #include "base/file_util.h" |
9 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
7 #include "base/files/scoped_temp_dir.h" | |
8 #include "base/message_loop.h" | |
10 #include "base/path_service.h" | 9 #include "base/path_service.h" |
11 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
12 #include "base/string16.h" | 11 #include "base/string16.h" |
13 #include "base/string_util.h" | 12 #include "base/string_util.h" |
14 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
15 #include "chrome/browser/history/history_types.h" | 14 #include "chrome/browser/history/history_types.h" |
16 #include "chrome/browser/importer/firefox2_importer.h" | 15 #include "chrome/browser/importer/external_process_importer_host.h" |
17 #include "chrome/browser/importer/firefox_importer_unittest_utils.h" | 16 #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" | 17 #include "chrome/browser/importer/importer_data_types.h" |
21 #include "chrome/browser/importer/importer_host.h" | 18 #include "chrome/browser/importer/importer_host.h" |
22 #include "chrome/browser/importer/importer_progress_observer.h" | 19 #include "chrome/browser/importer/importer_progress_observer.h" |
23 #include "chrome/browser/importer/importer_unittest_utils.h" | 20 #include "chrome/browser/importer/importer_unittest_utils.h" |
24 #include "chrome/browser/importer/nss_decryptor.h" | |
25 #include "chrome/browser/search_engines/template_url.h" | 21 #include "chrome/browser/search_engines/template_url.h" |
22 #include "chrome/browser/ui/browser.h" | |
26 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
27 #include "chrome/test/base/testing_profile.h" | 24 #include "chrome/test/base/in_process_browser_test.h" |
28 #include "content/public/common/password_form.h" | 25 #include "content/public/common/password_form.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | |
29 | 27 |
30 // TODO(estade): some of these are disabled on mac. http://crbug.com/48007 | 28 // TODO(estade): some of these are disabled on mac. http://crbug.com/48007 |
31 // TODO(jschuh): Disabled on Win64 build. http://crbug.com/179688 | 29 // TODO(jschuh): Disabled on Win64 build. http://crbug.com/179688 |
32 #if defined(OS_MACOSX) || (defined(OS_WIN) && defined(ARCH_CPU_X86_64)) | 30 #if defined(OS_MACOSX) || (defined(OS_WIN) && defined(ARCH_CPU_X86_64)) |
33 #define MAYBE_IMPORTER(x) DISABLED_##x | 31 #define MAYBE_IMPORTER(x) DISABLED_##x |
34 #else | 32 #else |
35 #define MAYBE_IMPORTER(x) x | 33 #define MAYBE_IMPORTER(x) x |
36 #endif | 34 #endif |
37 | 35 |
38 // TODO(jschuh): Disabled on Win64 build. http://crbug.com/179688 | |
39 #if defined(OS_WIN) && defined(ARCH_CPU_X86_64) | |
40 #define MAYBE_NSS(x) DISABLED_##x | |
41 #else | |
42 #define MAYBE_NSS(x) x | |
43 #endif | |
44 | |
45 namespace { | 36 namespace { |
46 | 37 |
47 const BookmarkInfo kFirefox2Bookmarks[] = { | 38 const BookmarkInfo kFirefox2Bookmarks[] = { |
48 {true, 2, {L"Bookmarks Toolbar Folder", L"Folder"}, | 39 {true, 2, {L"Bookmarks Toolbar Folder", L"Folder"}, |
49 L"On Toolbar's Subfolder", | 40 L"On Toolbar's Subfolder", |
50 "http://on.toolbar/bookmark/folder"}, | 41 "http://on.toolbar/bookmark/folder"}, |
51 {true, 1, {L"Bookmarks Toolbar Folder"}, | 42 {true, 1, {L"Bookmarks Toolbar Folder"}, |
52 L"On Bookmark Toolbar", | 43 L"On Bookmark Toolbar", |
53 "http://on.toolbar/bookmark"}, | 44 "http://on.toolbar/bookmark"}, |
54 {false, 1, {L"Folder"}, | 45 {false, 1, {L"Folder"}, |
55 L"New Bookmark", | 46 L"New Bookmark", |
56 "http://domain/"}, | 47 "http://domain/"}, |
57 {false, 0, {}, | 48 {false, 0, {}, |
58 L"<Name>", | 49 L"<Name>", |
59 "http://domain.com/q?a=%22er%22&b=%3C%20%20%3E"}, | 50 "http://domain.com/q?a=%22er%22&b=%3C%20%20%3E"}, |
60 {false, 0, {}, | 51 {false, 0, {}, |
61 L"Google Home Page", | 52 L"Google Home Page", |
62 "http://www.google.com/"}, | 53 "http://www.google.com/"}, |
63 {false, 0, {}, | 54 {false, 0, {}, |
64 L"\x4E2D\x6587", | 55 L"\x4E2D\x6587", |
65 "http://chinese.site.cn/path?query=1#ref"}, | 56 "http://chinese.site.cn/path?query=1#ref"}, |
57 {false, 1, {L"< > & \" ' \\ /"}, | |
gab
2013/04/18 18:09:44
Was missing from the list of actually imported tes
Miranda Callahan
2013/04/18 18:25:19
Nice catch!
On 2013/04/18 18:09:44, gab wrote:
| |
58 L"< > & \" ' \\ /", | |
59 "http://g.cn/"}, | |
66 {false, 0, {}, | 60 {false, 0, {}, |
67 L"mail", | 61 L"mail", |
68 "mailto:username@host"}, | 62 "mailto:username@host"}, |
69 }; | 63 }; |
70 | 64 |
71 struct PasswordInfo { | 65 struct PasswordInfo { |
72 const char* origin; | 66 const char* origin; |
73 const char* action; | 67 const char* action; |
74 const char* realm; | 68 const char* realm; |
75 const wchar_t* username_element; | 69 const wchar_t* username_element; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 history::VisitSource visit_source) OVERRIDE { | 169 history::VisitSource visit_source) OVERRIDE { |
176 ASSERT_EQ(1U, page.size()); | 170 ASSERT_EQ(1U, page.size()); |
177 EXPECT_EQ("http://en-us.www.mozilla.com/", page[0].url().spec()); | 171 EXPECT_EQ("http://en-us.www.mozilla.com/", page[0].url().spec()); |
178 EXPECT_EQ(ASCIIToUTF16("Firefox Updated"), page[0].title()); | 172 EXPECT_EQ(ASCIIToUTF16("Firefox Updated"), page[0].title()); |
179 EXPECT_EQ(history::SOURCE_FIREFOX_IMPORTED, visit_source); | 173 EXPECT_EQ(history::SOURCE_FIREFOX_IMPORTED, visit_source); |
180 ++history_count_; | 174 ++history_count_; |
181 } | 175 } |
182 | 176 |
183 virtual void AddBookmarks(const std::vector<BookmarkEntry>& bookmarks, | 177 virtual void AddBookmarks(const std::vector<BookmarkEntry>& bookmarks, |
184 const string16& top_level_folder_name) OVERRIDE { | 178 const string16& top_level_folder_name) OVERRIDE { |
179 ASSERT_LE(bookmark_count_ + bookmarks.size(), | |
180 arraysize(kFirefox2Bookmarks)); | |
181 // Importer should import the FF favorites the same as the list, in the same | |
182 // order. | |
185 for (size_t i = 0; i < bookmarks.size(); ++i) { | 183 for (size_t i = 0; i < bookmarks.size(); ++i) { |
186 if (FindBookmarkEntry(bookmarks[i], kFirefox2Bookmarks, | 184 EXPECT_NO_FATAL_FAILURE( |
187 arraysize(kFirefox2Bookmarks))) | 185 TestEqualBookmarkEntry(bookmarks[i], |
188 ++bookmark_count_; | 186 kFirefox2Bookmarks[bookmark_count_])) << i; |
187 ++bookmark_count_; | |
189 } | 188 } |
190 } | 189 } |
191 | 190 |
192 virtual void AddKeywords(ScopedVector<TemplateURL> template_urls, | 191 virtual void AddKeywords(ScopedVector<TemplateURL> template_urls, |
193 bool unique_on_host_and_path) OVERRIDE { | 192 bool unique_on_host_and_path) OVERRIDE { |
194 for (size_t i = 0; i < template_urls.size(); ++i) { | 193 for (size_t i = 0; i < template_urls.size(); ++i) { |
195 // The order might not be deterministic, look in the expected list for | 194 // The order might not be deterministic, look in the expected list for |
196 // that template URL. | 195 // that template URL. |
197 bool found = false; | 196 bool found = false; |
198 string16 keyword = template_urls[i]->keyword(); | 197 string16 keyword = template_urls[i]->keyword(); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
326 EXPECT_EQ(ASCIIToUTF16("Google"), page[1].title()); | 325 EXPECT_EQ(ASCIIToUTF16("Google"), page[1].title()); |
327 EXPECT_EQ("http://www.cs.unc.edu/~jbs/resources/perl/perl-cgi/programs/" | 326 EXPECT_EQ("http://www.cs.unc.edu/~jbs/resources/perl/perl-cgi/programs/" |
328 "form1-POST.html", page[2].url().spec()); | 327 "form1-POST.html", page[2].url().spec()); |
329 EXPECT_EQ(ASCIIToUTF16("example form (POST)"), page[2].title()); | 328 EXPECT_EQ(ASCIIToUTF16("example form (POST)"), page[2].title()); |
330 EXPECT_EQ(history::SOURCE_FIREFOX_IMPORTED, visit_source); | 329 EXPECT_EQ(history::SOURCE_FIREFOX_IMPORTED, visit_source); |
331 ++history_count_; | 330 ++history_count_; |
332 } | 331 } |
333 | 332 |
334 virtual void AddBookmarks(const std::vector<BookmarkEntry>& bookmarks, | 333 virtual void AddBookmarks(const std::vector<BookmarkEntry>& bookmarks, |
335 const string16& top_level_folder_name) OVERRIDE { | 334 const string16& top_level_folder_name) OVERRIDE { |
335 | |
336 ASSERT_LE(bookmark_count_ + bookmarks.size(), | |
337 arraysize(kFirefox3Bookmarks)); | |
338 // Importer should import the FF favorites the same as the list, in the same | |
339 // order. | |
336 for (size_t i = 0; i < bookmarks.size(); ++i) { | 340 for (size_t i = 0; i < bookmarks.size(); ++i) { |
337 if (FindBookmarkEntry(bookmarks[i], kFirefox3Bookmarks, | 341 EXPECT_NO_FATAL_FAILURE( |
338 arraysize(kFirefox3Bookmarks))) | 342 TestEqualBookmarkEntry(bookmarks[i], |
339 ++bookmark_count_; | 343 kFirefox3Bookmarks[bookmark_count_])) << i; |
344 ++bookmark_count_; | |
340 } | 345 } |
341 } | 346 } |
342 | 347 |
343 virtual void AddKeywords(ScopedVector<TemplateURL> template_urls, | 348 virtual void AddKeywords(ScopedVector<TemplateURL> template_urls, |
344 bool unique_on_host_and_path) OVERRIDE { | 349 bool unique_on_host_and_path) OVERRIDE { |
345 for (size_t i = 0; i < template_urls.size(); ++i) { | 350 for (size_t i = 0; i < template_urls.size(); ++i) { |
346 // The order might not be deterministic, look in the expected list for | 351 // The order might not be deterministic, look in the expected list for |
347 // that template URL. | 352 // that template URL. |
348 bool found = false; | 353 bool found = false; |
349 string16 keyword = template_urls[i]->keyword(); | 354 string16 keyword = template_urls[i]->keyword(); |
(...skipping 19 matching lines...) Expand all Loading... | |
369 | 374 |
370 size_t bookmark_count_; | 375 size_t bookmark_count_; |
371 size_t history_count_; | 376 size_t history_count_; |
372 size_t password_count_; | 377 size_t password_count_; |
373 size_t keyword_count_; | 378 size_t keyword_count_; |
374 bool import_search_engines_; | 379 bool import_search_engines_; |
375 }; | 380 }; |
376 | 381 |
377 } // namespace | 382 } // namespace |
378 | 383 |
379 class FirefoxProfileImporterTest : public ImporterTest { | 384 // These tests need to be browser tests in order to be able to run the OOP |
385 // import (via ExternalProcessImporterHost) which launches a utility process on | |
386 // supported platforms. | |
387 class FirefoxProfileImporterBrowserTest : public InProcessBrowserTest { | |
380 protected: | 388 protected: |
381 virtual void SetUp() OVERRIDE { | 389 virtual void SetUp() OVERRIDE { |
382 ImporterTest::SetUp(); | |
383 // Creates a new profile in a new subdirectory in the temp directory. | 390 // Creates a new profile in a new subdirectory in the temp directory. |
391 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
384 base::FilePath test_path = temp_dir_.path().AppendASCII("ImporterTest"); | 392 base::FilePath test_path = temp_dir_.path().AppendASCII("ImporterTest"); |
385 file_util::Delete(test_path, true); | 393 file_util::Delete(test_path, true); |
386 file_util::CreateDirectory(test_path); | 394 file_util::CreateDirectory(test_path); |
387 profile_path_ = test_path.AppendASCII("profile"); | 395 profile_path_ = test_path.AppendASCII("profile"); |
388 app_path_ = test_path.AppendASCII("app"); | 396 app_path_ = test_path.AppendASCII("app"); |
389 file_util::CreateDirectory(app_path_); | 397 file_util::CreateDirectory(app_path_); |
390 } | 398 |
391 | 399 // This will launch the browser test and thus needs to happen last. |
392 void Firefox3xImporterTest(std::string profile_dir, | 400 InProcessBrowserTest::SetUp(); |
393 importer::ImporterProgressObserver* observer, | 401 } |
394 ProfileWriter* writer, | 402 |
395 bool import_search_plugins) { | 403 void Firefox3xImporterBrowserTest( |
404 std::string profile_dir, | |
405 importer::ImporterProgressObserver* observer, | |
406 ProfileWriter* writer, | |
407 bool import_search_plugins) { | |
396 base::FilePath data_path; | 408 base::FilePath data_path; |
397 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); | 409 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); |
398 data_path = data_path.AppendASCII(profile_dir); | 410 data_path = data_path.AppendASCII(profile_dir); |
399 ASSERT_TRUE(file_util::CopyDirectory(data_path, profile_path_, true)); | 411 ASSERT_TRUE(file_util::CopyDirectory(data_path, profile_path_, true)); |
400 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); | 412 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); |
401 data_path = data_path.AppendASCII("firefox3_nss"); | 413 data_path = data_path.AppendASCII("firefox3_nss"); |
402 ASSERT_TRUE(file_util::CopyDirectory(data_path, profile_path_, false)); | 414 ASSERT_TRUE(file_util::CopyDirectory(data_path, profile_path_, false)); |
403 | 415 |
404 base::FilePath search_engine_path = app_path_; | 416 base::FilePath search_engine_path = app_path_; |
405 search_engine_path = search_engine_path.AppendASCII("searchplugins"); | 417 search_engine_path = search_engine_path.AppendASCII("searchplugins"); |
406 file_util::CreateDirectory(search_engine_path); | 418 file_util::CreateDirectory(search_engine_path); |
407 if (import_search_plugins) { | 419 if (import_search_plugins) { |
408 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); | 420 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); |
409 data_path = data_path.AppendASCII("firefox3_searchplugins"); | 421 data_path = data_path.AppendASCII("firefox3_searchplugins"); |
410 if (!file_util::PathExists(data_path)) { | 422 if (!file_util::PathExists(data_path)) { |
411 // TODO(maruel): Create search test data that we can open source! | 423 // TODO(maruel): Create search test data that we can open source! |
412 LOG(ERROR) << L"Missing internal test data"; | 424 LOG(ERROR) << L"Missing internal test data"; |
413 return; | 425 return; |
414 } | 426 } |
415 ASSERT_TRUE(file_util::CopyDirectory(data_path, | 427 ASSERT_TRUE(file_util::CopyDirectory(data_path, |
416 search_engine_path, false)); | 428 search_engine_path, false)); |
417 } | 429 } |
418 | 430 |
419 MessageLoop* loop = MessageLoop::current(); | |
420 importer::SourceProfile source_profile; | 431 importer::SourceProfile source_profile; |
421 source_profile.importer_type = importer::TYPE_FIREFOX3; | 432 source_profile.importer_type = importer::TYPE_FIREFOX3; |
422 source_profile.app_path = app_path_; | 433 source_profile.app_path = app_path_; |
423 source_profile.source_path = profile_path_; | 434 source_profile.source_path = profile_path_; |
424 scoped_refptr<ImporterHost> host(new ImporterHost); | 435 |
425 host->SetObserver(observer); | |
426 int items = importer::HISTORY | importer::PASSWORDS | importer::FAVORITES; | 436 int items = importer::HISTORY | importer::PASSWORDS | importer::FAVORITES; |
427 if (import_search_plugins) | 437 if (import_search_plugins) |
428 items = items | importer::SEARCH_ENGINES; | 438 items = items | importer::SEARCH_ENGINES; |
429 loop->PostTask(FROM_HERE, base::Bind( | 439 |
430 &ImporterHost::StartImportSettings, host.get(), source_profile, | 440 // TODO(gab): Use ExternalProcessImporterHost on both Windows and Linux. |
431 profile_.get(), items, make_scoped_refptr(writer))); | 441 scoped_refptr<ImporterHost> host; |
432 loop->Run(); | 442 #if defined(OS_MACOSX) |
433 } | 443 host = new ExternalProcessImporterHost; |
434 | 444 #else |
445 host = new ImporterHost; | |
446 #endif | |
447 host->SetObserver(observer); | |
448 host->StartImportSettings(source_profile, browser()->profile(), | |
449 items, make_scoped_refptr(writer)); | |
450 MessageLoop::current()->Run(); | |
451 } | |
452 | |
453 base::ScopedTempDir temp_dir_; | |
435 base::FilePath profile_path_; | 454 base::FilePath profile_path_; |
436 base::FilePath app_path_; | 455 base::FilePath app_path_; |
437 }; | 456 }; |
438 | 457 |
439 TEST_F(FirefoxProfileImporterTest, MAYBE_IMPORTER(Firefox2Importer)) { | 458 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, |
459 MAYBE_IMPORTER(Firefox2Importer)) { | |
440 base::FilePath data_path; | 460 base::FilePath data_path; |
441 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); | 461 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); |
442 data_path = data_path.AppendASCII("firefox2_profile"); | 462 data_path = data_path.AppendASCII("firefox2_profile"); |
443 ASSERT_TRUE(file_util::CopyDirectory(data_path, profile_path_, true)); | 463 ASSERT_TRUE(file_util::CopyDirectory(data_path, profile_path_, true)); |
444 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); | 464 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); |
445 data_path = data_path.AppendASCII("firefox2_nss"); | 465 data_path = data_path.AppendASCII("firefox2_nss"); |
446 ASSERT_TRUE(file_util::CopyDirectory(data_path, profile_path_, false)); | 466 ASSERT_TRUE(file_util::CopyDirectory(data_path, profile_path_, false)); |
447 | 467 |
448 base::FilePath search_engine_path = app_path_; | 468 base::FilePath search_engine_path = app_path_; |
449 search_engine_path = search_engine_path.AppendASCII("searchplugins"); | 469 search_engine_path = search_engine_path.AppendASCII("searchplugins"); |
450 file_util::CreateDirectory(search_engine_path); | 470 file_util::CreateDirectory(search_engine_path); |
451 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); | 471 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); |
452 data_path = data_path.AppendASCII("firefox2_searchplugins"); | 472 data_path = data_path.AppendASCII("firefox2_searchplugins"); |
453 if (!file_util::PathExists(data_path)) { | 473 if (!file_util::PathExists(data_path)) { |
454 // TODO(maruel): Create test data that we can open source! | 474 // TODO(maruel): Create test data that we can open source! |
455 LOG(ERROR) << L"Missing internal test data"; | 475 LOG(ERROR) << L"Missing internal test data"; |
456 return; | 476 return; |
457 } | 477 } |
458 ASSERT_TRUE(file_util::CopyDirectory(data_path, search_engine_path, false)); | 478 ASSERT_TRUE(file_util::CopyDirectory(data_path, search_engine_path, false)); |
459 | 479 |
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; | 480 importer::SourceProfile source_profile; |
465 source_profile.importer_type = importer::TYPE_FIREFOX2; | 481 source_profile.importer_type = importer::TYPE_FIREFOX2; |
466 source_profile.app_path = app_path_; | 482 source_profile.app_path = app_path_; |
467 source_profile.source_path = profile_path_; | 483 source_profile.source_path = profile_path_; |
468 | 484 |
469 loop->PostTask(FROM_HERE, base::Bind( | 485 // TODO(gab): Use ExternalProcessImporterHost on both Windows and Linux. |
470 &ImporterHost::StartImportSettings, | 486 scoped_refptr<ImporterHost> host; |
471 host.get(), | 487 #if defined(OS_MACOSX) |
488 host = new ExternalProcessImporterHost; | |
489 #else | |
490 host = new ImporterHost; | |
491 #endif | |
492 FirefoxObserver* observer = new FirefoxObserver(); | |
493 host->SetObserver(observer); | |
494 host->StartImportSettings( | |
472 source_profile, | 495 source_profile, |
473 profile_.get(), | 496 browser()->profile(), |
474 importer::HISTORY | importer::PASSWORDS | | 497 importer::HISTORY | importer::PASSWORDS | |
475 importer::FAVORITES | importer::SEARCH_ENGINES, | 498 importer::FAVORITES | importer::SEARCH_ENGINES, |
476 make_scoped_refptr(observer))); | 499 make_scoped_refptr(observer)); |
477 loop->Run(); | 500 MessageLoop::current()->Run(); |
478 } | 501 } |
479 | 502 |
480 TEST_F(FirefoxProfileImporterTest, MAYBE_IMPORTER(Firefox30Importer)) { | 503 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, |
504 MAYBE_IMPORTER(Firefox30Importer)) { | |
481 scoped_refptr<Firefox3Observer> observer(new Firefox3Observer()); | 505 scoped_refptr<Firefox3Observer> observer(new Firefox3Observer()); |
482 Firefox3xImporterTest("firefox3_profile", observer.get(), observer.get(), | 506 Firefox3xImporterBrowserTest("firefox3_profile", observer.get(), |
483 true); | 507 observer.get(), true); |
484 } | 508 } |
485 | 509 |
486 TEST_F(FirefoxProfileImporterTest, MAYBE_IMPORTER(Firefox35Importer)) { | 510 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, |
511 MAYBE_IMPORTER(Firefox35Importer)) { | |
487 bool import_search_engines = false; | 512 bool import_search_engines = false; |
488 scoped_refptr<Firefox3Observer> observer( | 513 scoped_refptr<Firefox3Observer> observer( |
489 new Firefox3Observer(import_search_engines)); | 514 new Firefox3Observer(import_search_engines)); |
490 Firefox3xImporterTest("firefox35_profile", observer.get(), observer.get(), | 515 Firefox3xImporterBrowserTest("firefox35_profile", observer.get(), |
491 import_search_engines); | 516 observer.get(), import_search_engines); |
492 } | 517 } |
493 | |
494 // 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 | |
496 // same test between platforms. | |
497 TEST(FirefoxImporterTest, MAYBE_NSS(Firefox2NSS3Decryptor)) { | |
498 base::FilePath nss_path; | |
499 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &nss_path)); | |
500 #if defined(OS_MACOSX) | |
501 nss_path = nss_path.AppendASCII("firefox2_nss_mac"); | |
502 #else | |
503 nss_path = nss_path.AppendASCII("firefox2_nss"); | |
504 #endif // !OS_MACOSX | |
505 base::FilePath db_path; | |
506 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &db_path)); | |
507 db_path = db_path.AppendASCII("firefox2_profile"); | |
508 | |
509 FFUnitTestDecryptorProxy decryptor_proxy; | |
510 ASSERT_TRUE(decryptor_proxy.Setup(nss_path)); | |
511 | |
512 ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path)); | |
513 EXPECT_EQ(ASCIIToUTF16("hello"), | |
514 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECBJ" | |
515 "M63MpT9rtBAjMCm7qo/EhlA==")); | |
516 // Test UTF-16 encoding. | |
517 EXPECT_EQ(WideToUTF16(L"\x4E2D"), | |
518 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECN9" | |
519 "OQ5ZFmhb8BAiFo1Z+fUvaIQ==")); | |
520 } | |
521 | |
522 TEST(FirefoxImporterTest, MAYBE_NSS(Firefox3NSS3Decryptor)) { | |
523 base::FilePath nss_path; | |
524 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &nss_path)); | |
525 #if defined(OS_MACOSX) | |
526 nss_path = nss_path.AppendASCII("firefox3_nss_mac"); | |
527 #else | |
528 nss_path = nss_path.AppendASCII("firefox3_nss"); | |
529 #endif // !OS_MACOSX | |
530 base::FilePath db_path; | |
531 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &db_path)); | |
532 db_path = db_path.AppendASCII("firefox3_profile"); | |
533 | |
534 FFUnitTestDecryptorProxy decryptor_proxy; | |
535 ASSERT_TRUE(decryptor_proxy.Setup(nss_path)); | |
536 | |
537 ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path)); | |
538 EXPECT_EQ(ASCIIToUTF16("hello"), | |
539 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECKa" | |
540 "jtRg4qFSHBAhv9luFkXgDJA==")); | |
541 // Test UTF-16 encoding. | |
542 EXPECT_EQ(WideToUTF16(L"\x4E2D"), | |
543 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECLW" | |
544 "qqiccfQHWBAie74hxnULxlw==")); | |
545 } | |
546 | |
547 TEST(FirefoxImporterTest, Firefox2BookmarkParse) { | |
548 bool result; | |
549 | |
550 // Tests charset. | |
551 std::string charset; | |
552 result = Firefox2Importer::ParseCharsetFromLine( | |
553 "<META HTTP-EQUIV=\"Content-Type\" " | |
554 "CONTENT=\"text/html; charset=UTF-8\">", | |
555 &charset); | |
556 EXPECT_TRUE(result); | |
557 EXPECT_EQ("UTF-8", charset); | |
558 | |
559 // Escaped characters in name. | |
560 string16 folder_name; | |
561 bool is_toolbar_folder; | |
562 base::Time folder_add_date; | |
563 result = Firefox2Importer::ParseFolderNameFromLine( | |
564 "<DT><H3 ADD_DATE=\"1207558707\" >< >" | |
565 " & " ' \\ /</H3>", | |
566 charset, &folder_name, &is_toolbar_folder, &folder_add_date); | |
567 EXPECT_TRUE(result); | |
568 EXPECT_EQ(ASCIIToUTF16("< > & \" ' \\ /"), folder_name); | |
569 EXPECT_FALSE(is_toolbar_folder); | |
570 EXPECT_TRUE(base::Time::FromTimeT(1207558707) == folder_add_date); | |
571 | |
572 // Empty name and toolbar folder attribute. | |
573 result = Firefox2Importer::ParseFolderNameFromLine( | |
574 "<DT><H3 PERSONAL_TOOLBAR_FOLDER=\"true\"></H3>", | |
575 charset, &folder_name, &is_toolbar_folder, &folder_add_date); | |
576 EXPECT_TRUE(result); | |
577 EXPECT_EQ(string16(), folder_name); | |
578 EXPECT_TRUE(is_toolbar_folder); | |
579 | |
580 // Unicode characters in title and shortcut. | |
581 string16 title; | |
582 GURL url, favicon; | |
583 string16 shortcut; | |
584 string16 post_data; | |
585 base::Time add_date; | |
586 result = Firefox2Importer::ParseBookmarkFromLine( | |
587 "<DT><A HREF=\"http://chinese.site.cn/path?query=1#ref\" " | |
588 "SHORTCUTURL=\"\xE4\xB8\xAD\">\xE4\xB8\xAD\xE6\x96\x87</A>", | |
589 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); | |
590 EXPECT_TRUE(result); | |
591 EXPECT_EQ(L"\x4E2D\x6587", UTF16ToWide(title)); | |
592 EXPECT_EQ("http://chinese.site.cn/path?query=1#ref", url.spec()); | |
593 EXPECT_EQ(L"\x4E2D", UTF16ToWide(shortcut)); | |
594 EXPECT_EQ(string16(), post_data); | |
595 EXPECT_TRUE(base::Time() == add_date); | |
596 | |
597 // No shortcut, and url contains %22 ('"' character). | |
598 result = Firefox2Importer::ParseBookmarkFromLine( | |
599 "<DT><A HREF=\"http://domain.com/?q=%22<>%22\">name</A>", | |
600 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); | |
601 EXPECT_TRUE(result); | |
602 EXPECT_EQ(ASCIIToUTF16("name"), title); | |
603 EXPECT_EQ("http://domain.com/?q=%22%3C%3E%22", url.spec()); | |
604 EXPECT_EQ(string16(), shortcut); | |
605 EXPECT_EQ(string16(), post_data); | |
606 EXPECT_TRUE(base::Time() == add_date); | |
607 | |
608 result = Firefox2Importer::ParseBookmarkFromLine( | |
609 "<DT><A HREF=\"http://domain.com/?g="\"\">name</A>", | |
610 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); | |
611 EXPECT_TRUE(result); | |
612 EXPECT_EQ(ASCIIToUTF16("name"), title); | |
613 EXPECT_EQ("http://domain.com/?g=%22", url.spec()); | |
614 EXPECT_EQ(string16(), shortcut); | |
615 EXPECT_EQ(string16(), post_data); | |
616 EXPECT_TRUE(base::Time() == add_date); | |
617 | |
618 // Creation date. | |
619 result = Firefox2Importer::ParseBookmarkFromLine( | |
620 "<DT><A HREF=\"http://site/\" ADD_DATE=\"1121301154\">name</A>", | |
621 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); | |
622 EXPECT_TRUE(result); | |
623 EXPECT_EQ(ASCIIToUTF16("name"), title); | |
624 EXPECT_EQ(GURL("http://site/"), url); | |
625 EXPECT_EQ(string16(), shortcut); | |
626 EXPECT_EQ(string16(), post_data); | |
627 EXPECT_TRUE(base::Time::FromTimeT(1121301154) == add_date); | |
628 | |
629 // Post-data | |
630 result = Firefox2Importer::ParseBookmarkFromLine( | |
631 "<DT><A HREF=\"http://localhost:8080/test/hello.html\" ADD_DATE=\"" | |
632 "1212447159\" LAST_VISIT=\"1212447251\" LAST_MODIFIED=\"1212447248\"" | |
633 "SHORTCUTURL=\"post\" ICON=\"data:\" POST_DATA=\"lname%3D%25s\"" | |
634 "LAST_CHARSET=\"UTF-8\" ID=\"rdf:#$weKaR3\">Test Post keyword</A>", | |
635 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); | |
636 EXPECT_TRUE(result); | |
637 EXPECT_EQ(ASCIIToUTF16("Test Post keyword"), title); | |
638 EXPECT_EQ("http://localhost:8080/test/hello.html", url.spec()); | |
639 EXPECT_EQ(ASCIIToUTF16("post"), shortcut); | |
640 EXPECT_EQ(ASCIIToUTF16("lname%3D%25s"), post_data); | |
641 EXPECT_TRUE(base::Time::FromTimeT(1212447159) == add_date); | |
642 | |
643 // Invalid case. | |
644 result = Firefox2Importer::ParseBookmarkFromLine( | |
645 "<DT><A HREF=\"http://domain.com/?q=%22", | |
646 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); | |
647 EXPECT_FALSE(result); | |
648 EXPECT_EQ(string16(), title); | |
649 EXPECT_EQ("", url.spec()); | |
650 EXPECT_EQ(string16(), shortcut); | |
651 EXPECT_EQ(string16(), post_data); | |
652 EXPECT_TRUE(base::Time() == add_date); | |
653 | |
654 // Epiphany format. | |
655 result = Firefox2Importer::ParseMinimumBookmarkFromLine( | |
656 "<dt><a href=\"http://www.google.com/\">Google</a></dt>", | |
657 charset, &title, &url); | |
658 EXPECT_TRUE(result); | |
659 EXPECT_EQ(ASCIIToUTF16("Google"), title); | |
660 EXPECT_EQ("http://www.google.com/", url.spec()); | |
661 } | |
662 | |
663 TEST(FirefoxImporterTest, Firefox2BookmarkFileImport) { | |
664 base::FilePath path; | |
665 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); | |
666 path = path.AppendASCII("firefox2_importer"); | |
667 | |
668 // Import all bookmarks from a file which include an empty folder entry. | |
669 base::FilePath empty_folder_path = path.AppendASCII("empty_folder.html"); | |
670 std::set<GURL> default_urls; | |
671 Firefox2Importer* importer = new Firefox2Importer(); | |
672 importer->AddRef(); | |
673 std::vector<ProfileWriter::BookmarkEntry> bookmarks; | |
674 importer->ImportBookmarksFile(empty_folder_path, default_urls, | |
675 importer, &bookmarks, NULL, NULL); | |
676 EXPECT_EQ(3U, bookmarks.size()); | |
677 std::vector<ProfileWriter::BookmarkEntry>::iterator it; | |
678 ProfileWriter::BookmarkEntry entry; | |
679 std::vector<string16>::iterator path_it; | |
680 if (bookmarks.size() == 3) { | |
681 it = bookmarks.begin(); | |
682 entry = *it++; | |
683 EXPECT_EQ(ASCIIToUTF16("Empty"), entry.title); | |
684 EXPECT_TRUE(entry.is_folder); | |
685 EXPECT_EQ(base::Time::FromTimeT(1295938143), entry.creation_time); | |
686 EXPECT_EQ(1U, entry.path.size()); | |
687 if (entry.path.size() == 1) | |
688 EXPECT_EQ(ASCIIToUTF16("Empty's Parent"), entry.path.front()); | |
689 | |
690 entry = *it++; | |
691 EXPECT_EQ(ASCIIToUTF16("[Tamura Yukari.com]"), entry.title); | |
692 EXPECT_FALSE(entry.is_folder); | |
693 EXPECT_EQ(base::Time::FromTimeT(1234567890), entry.creation_time); | |
694 EXPECT_EQ(1U, entry.path.size()); | |
695 if (entry.path.size() == 1) | |
696 EXPECT_EQ(ASCIIToUTF16("Not Empty"), entry.path.front()); | |
697 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); | |
698 | |
699 entry = *it++; | |
700 EXPECT_EQ(ASCIIToUTF16("Google"), entry.title); | |
701 EXPECT_FALSE(entry.is_folder); | |
702 EXPECT_EQ(base::Time::FromTimeT(0000000000), entry.creation_time); | |
703 EXPECT_EQ(1U, entry.path.size()); | |
704 if (entry.path.size() == 1) | |
705 EXPECT_EQ(ASCIIToUTF16("Not Empty But Default"), entry.path.front()); | |
706 EXPECT_EQ("http://www.google.com/", entry.url.spec()); | |
707 } | |
708 | |
709 // Import non-default bookmarks from a file. | |
710 bookmarks.clear(); | |
711 default_urls.insert(GURL("http://www.google.com/")); | |
712 importer->ImportBookmarksFile(empty_folder_path, default_urls, | |
713 importer, &bookmarks, NULL, NULL); | |
714 EXPECT_EQ(2U, bookmarks.size()); | |
715 if (bookmarks.size() == 2) { | |
716 it = bookmarks.begin(); | |
717 entry = *it++; | |
718 EXPECT_EQ(ASCIIToUTF16("Empty"), entry.title); | |
719 EXPECT_TRUE(entry.is_folder); | |
720 EXPECT_EQ(base::Time::FromTimeT(1295938143), entry.creation_time); | |
721 EXPECT_EQ(1U, entry.path.size()); | |
722 if (entry.path.size() == 1) | |
723 EXPECT_EQ(ASCIIToUTF16("Empty's Parent"), entry.path.front()); | |
724 | |
725 entry = *it++; | |
726 EXPECT_EQ(ASCIIToUTF16("[Tamura Yukari.com]"), entry.title); | |
727 EXPECT_FALSE(entry.is_folder); | |
728 EXPECT_EQ(base::Time::FromTimeT(1234567890), entry.creation_time); | |
729 EXPECT_EQ(1U, entry.path.size()); | |
730 if (entry.path.size() == 1) | |
731 EXPECT_EQ(ASCIIToUTF16("Not Empty"), entry.path.front()); | |
732 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); | |
733 } | |
734 | |
735 // Import Epiphany bookmarks from a file | |
736 base::FilePath epiphany_path = path.AppendASCII("epiphany.html"); | |
737 bookmarks.clear(); | |
738 default_urls.clear(); | |
739 importer->ImportBookmarksFile(epiphany_path, default_urls, | |
740 importer, &bookmarks, NULL, NULL); | |
741 EXPECT_EQ(2U, bookmarks.size()); | |
742 if (bookmarks.size() == 2) { | |
743 it = bookmarks.begin(); | |
744 entry = *it++; | |
745 EXPECT_EQ(ASCIIToUTF16("[Tamura Yukari.com]"), entry.title); | |
746 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); | |
747 EXPECT_EQ(0U, entry.path.size()); | |
748 entry = *it++; | |
749 EXPECT_EQ(ASCIIToUTF16("Google"), entry.title); | |
750 EXPECT_EQ("http://www.google.com/", entry.url.spec()); | |
751 EXPECT_EQ(0U, entry.path.size()); | |
752 } | |
753 | |
754 // Import Epiphany bookmarks from a file to bookmark bar. | |
755 bookmarks.clear(); | |
756 default_urls.clear(); | |
757 importer->ImportBookmarksFile(epiphany_path, default_urls, | |
758 importer, &bookmarks, NULL, NULL); | |
759 EXPECT_EQ(2U, bookmarks.size()); | |
760 if (bookmarks.size() == 2) { | |
761 it = bookmarks.begin(); | |
762 entry = *it++; | |
763 EXPECT_EQ(ASCIIToUTF16("[Tamura Yukari.com]"), entry.title); | |
764 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); | |
765 EXPECT_EQ(0U, entry.path.size()); | |
766 entry = *it++; | |
767 EXPECT_EQ(ASCIIToUTF16("Google"), entry.title); | |
768 EXPECT_EQ("http://www.google.com/", entry.url.spec()); | |
769 EXPECT_EQ(0U, entry.path.size()); | |
770 } | |
771 | |
772 importer->Release(); | |
773 } | |
OLD | NEW |