Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1336)

Unified Diff: chrome/browser/importer/bookmarks_file_importer_unittest.cc

Issue 14575004: Extract BookmarksFileImporter from Firefox2Importer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: extraneous include Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/importer/bookmarks_file_importer_unittest.cc
diff --git a/chrome/browser/importer/firefox_importer_unittest.cc b/chrome/browser/importer/bookmarks_file_importer_unittest.cc
similarity index 58%
copy from chrome/browser/importer/firefox_importer_unittest.cc
copy to chrome/browser/importer/bookmarks_file_importer_unittest.cc
index 632496c00e240c60b6c3b3532e40afdb8ecf94c1..904d53cf6e053a79542f55bd8ca336714e4c809b 100644
--- a/chrome/browser/importer/firefox_importer_unittest.cc
+++ b/chrome/browser/importer/bookmarks_file_importer_unittest.cc
@@ -1,86 +1,22 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "testing/gtest/include/gtest/gtest.h"
-
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "base/string16.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
-#include "chrome/browser/history/history_types.h"
-#include "chrome/browser/importer/firefox2_importer.h"
-#include "chrome/browser/importer/firefox_importer_unittest_utils.h"
-#include "chrome/browser/importer/nss_decryptor.h"
+#include "chrome/browser/importer/bookmarks_file_importer.h"
#include "chrome/common/chrome_paths.h"
+#include "testing/gtest/include/gtest/gtest.h"
-// TODO(jschuh): Disabled on Win64 build. http://crbug.com/179688
-#if defined(OS_WIN) && defined(ARCH_CPU_X86_64)
-#define MAYBE_NSS(x) DISABLED_##x
-#else
-#define MAYBE_NSS(x) x
-#endif
-
-// The following 2 tests require the use of the NSSDecryptor, on OSX this needs
-// to run in a separate process, so we use a proxy object so we can share the
-// same test between platforms.
-TEST(FirefoxImporterTest, MAYBE_NSS(Firefox2NSS3Decryptor)) {
- base::FilePath nss_path;
- ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &nss_path));
-#if defined(OS_MACOSX)
- nss_path = nss_path.AppendASCII("firefox2_nss_mac");
-#else
- nss_path = nss_path.AppendASCII("firefox2_nss");
-#endif // !OS_MACOSX
- base::FilePath db_path;
- ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &db_path));
- db_path = db_path.AppendASCII("firefox2_profile");
-
- FFUnitTestDecryptorProxy decryptor_proxy;
- ASSERT_TRUE(decryptor_proxy.Setup(nss_path));
-
- ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path));
- EXPECT_EQ(ASCIIToUTF16("hello"),
- decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECBJ"
- "M63MpT9rtBAjMCm7qo/EhlA=="));
- // Test UTF-16 encoding.
- EXPECT_EQ(WideToUTF16(L"\x4E2D"),
- decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECN9"
- "OQ5ZFmhb8BAiFo1Z+fUvaIQ=="));
-}
-
-TEST(FirefoxImporterTest, MAYBE_NSS(Firefox3NSS3Decryptor)) {
- base::FilePath nss_path;
- ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &nss_path));
-#if defined(OS_MACOSX)
- nss_path = nss_path.AppendASCII("firefox3_nss_mac");
-#else
- nss_path = nss_path.AppendASCII("firefox3_nss");
-#endif // !OS_MACOSX
- base::FilePath db_path;
- ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &db_path));
- db_path = db_path.AppendASCII("firefox3_profile");
-
- FFUnitTestDecryptorProxy decryptor_proxy;
- ASSERT_TRUE(decryptor_proxy.Setup(nss_path));
-
- ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path));
- EXPECT_EQ(ASCIIToUTF16("hello"),
- decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECKa"
- "jtRg4qFSHBAhv9luFkXgDJA=="));
- // Test UTF-16 encoding.
- EXPECT_EQ(WideToUTF16(L"\x4E2D"),
- decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECLW"
- "qqiccfQHWBAie74hxnULxlw=="));
-}
-
-TEST(FirefoxImporterTest, Firefox2BookmarkParse) {
+TEST(BookmarksFileImporterTest, ParseTests) {
bool result;
// Tests charset.
std::string charset;
- result = Firefox2Importer::ParseCharsetFromLine(
+ result = BookmarksFileImporter::ParseCharsetFromLine(
"<META HTTP-EQUIV=\"Content-Type\" "
"CONTENT=\"text/html; charset=UTF-8\">",
&charset);
@@ -91,7 +27,7 @@ TEST(FirefoxImporterTest, Firefox2BookmarkParse) {
string16 folder_name;
bool is_toolbar_folder;
base::Time folder_add_date;
- result = Firefox2Importer::ParseFolderNameFromLine(
+ result = BookmarksFileImporter::ParseFolderNameFromLine(
"<DT><H3 ADD_DATE=\"1207558707\" >&lt; &gt;"
" &amp; &quot; &#39; \\ /</H3>",
charset, &folder_name, &is_toolbar_folder, &folder_add_date);
@@ -101,7 +37,7 @@ TEST(FirefoxImporterTest, Firefox2BookmarkParse) {
EXPECT_TRUE(base::Time::FromTimeT(1207558707) == folder_add_date);
// Empty name and toolbar folder attribute.
- result = Firefox2Importer::ParseFolderNameFromLine(
+ result = BookmarksFileImporter::ParseFolderNameFromLine(
"<DT><H3 PERSONAL_TOOLBAR_FOLDER=\"true\"></H3>",
charset, &folder_name, &is_toolbar_folder, &folder_add_date);
EXPECT_TRUE(result);
@@ -114,7 +50,7 @@ TEST(FirefoxImporterTest, Firefox2BookmarkParse) {
string16 shortcut;
string16 post_data;
base::Time add_date;
- result = Firefox2Importer::ParseBookmarkFromLine(
+ result = BookmarksFileImporter::ParseBookmarkFromLine(
"<DT><A HREF=\"http://chinese.site.cn/path?query=1#ref\" "
"SHORTCUTURL=\"\xE4\xB8\xAD\">\xE4\xB8\xAD\xE6\x96\x87</A>",
charset, &title, &url, &favicon, &shortcut, &add_date, &post_data);
@@ -126,7 +62,7 @@ TEST(FirefoxImporterTest, Firefox2BookmarkParse) {
EXPECT_TRUE(base::Time() == add_date);
// No shortcut, and url contains %22 ('"' character).
- result = Firefox2Importer::ParseBookmarkFromLine(
+ result = BookmarksFileImporter::ParseBookmarkFromLine(
"<DT><A HREF=\"http://domain.com/?q=%22<>%22\">name</A>",
charset, &title, &url, &favicon, &shortcut, &add_date, &post_data);
EXPECT_TRUE(result);
@@ -136,7 +72,7 @@ TEST(FirefoxImporterTest, Firefox2BookmarkParse) {
EXPECT_EQ(string16(), post_data);
EXPECT_TRUE(base::Time() == add_date);
- result = Firefox2Importer::ParseBookmarkFromLine(
+ result = BookmarksFileImporter::ParseBookmarkFromLine(
"<DT><A HREF=\"http://domain.com/?g=&quot;\"\">name</A>",
charset, &title, &url, &favicon, &shortcut, &add_date, &post_data);
EXPECT_TRUE(result);
@@ -147,7 +83,7 @@ TEST(FirefoxImporterTest, Firefox2BookmarkParse) {
EXPECT_TRUE(base::Time() == add_date);
// Creation date.
- result = Firefox2Importer::ParseBookmarkFromLine(
+ result = BookmarksFileImporter::ParseBookmarkFromLine(
"<DT><A HREF=\"http://site/\" ADD_DATE=\"1121301154\">name</A>",
charset, &title, &url, &favicon, &shortcut, &add_date, &post_data);
EXPECT_TRUE(result);
@@ -158,7 +94,7 @@ TEST(FirefoxImporterTest, Firefox2BookmarkParse) {
EXPECT_TRUE(base::Time::FromTimeT(1121301154) == add_date);
// Post-data
- result = Firefox2Importer::ParseBookmarkFromLine(
+ result = BookmarksFileImporter::ParseBookmarkFromLine(
"<DT><A HREF=\"http://localhost:8080/test/hello.html\" ADD_DATE=\""
"1212447159\" LAST_VISIT=\"1212447251\" LAST_MODIFIED=\"1212447248\""
"SHORTCUTURL=\"post\" ICON=\"data:\" POST_DATA=\"lname%3D%25s\""
@@ -172,7 +108,7 @@ TEST(FirefoxImporterTest, Firefox2BookmarkParse) {
EXPECT_TRUE(base::Time::FromTimeT(1212447159) == add_date);
// Invalid case.
- result = Firefox2Importer::ParseBookmarkFromLine(
+ result = BookmarksFileImporter::ParseBookmarkFromLine(
"<DT><A HREF=\"http://domain.com/?q=%22",
charset, &title, &url, &favicon, &shortcut, &add_date, &post_data);
EXPECT_FALSE(result);
@@ -183,7 +119,7 @@ TEST(FirefoxImporterTest, Firefox2BookmarkParse) {
EXPECT_TRUE(base::Time() == add_date);
// Epiphany format.
- result = Firefox2Importer::ParseMinimumBookmarkFromLine(
+ result = BookmarksFileImporter::ParseMinimumBookmarkFromLine(
"<dt><a href=\"http://www.google.com/\">Google</a></dt>",
charset, &title, &url);
EXPECT_TRUE(result);
@@ -191,19 +127,17 @@ TEST(FirefoxImporterTest, Firefox2BookmarkParse) {
EXPECT_EQ("http://www.google.com/", url.spec());
}
-TEST(FirefoxImporterTest, Firefox2BookmarkFileImport) {
+TEST(BookmarksFileImporterTest, BookmarkFileImport) {
base::FilePath path;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
- path = path.AppendASCII("firefox2_importer");
+ path = path.AppendASCII("bookmarks_file_importer");
// Import all bookmarks from a file which include an empty folder entry.
- base::FilePath empty_folder_path = path.AppendASCII("empty_folder.html");
- std::set<GURL> default_urls;
- Firefox2Importer* importer = new Firefox2Importer();
+ base::FilePath empty_folder_path = path.AppendASCII("firefox2.html");
+ BookmarksFileImporter* importer = new BookmarksFileImporter();
importer->AddRef();
std::vector<ProfileWriter::BookmarkEntry> bookmarks;
- importer->ImportBookmarksFile(empty_folder_path, default_urls,
- importer, &bookmarks, NULL, NULL);
+ importer->ImportBookmarksFile(empty_folder_path, NULL, &bookmarks, NULL);
gab 2013/05/07 17:47:54 This is a static method, no need to create an impo
EXPECT_EQ(3U, bookmarks.size());
std::vector<ProfileWriter::BookmarkEntry>::iterator it;
ProfileWriter::BookmarkEntry entry;
@@ -237,38 +171,10 @@ TEST(FirefoxImporterTest, Firefox2BookmarkFileImport) {
EXPECT_EQ("http://www.google.com/", entry.url.spec());
}
- // Import non-default bookmarks from a file.
- bookmarks.clear();
- default_urls.insert(GURL("http://www.google.com/"));
- importer->ImportBookmarksFile(empty_folder_path, default_urls,
- importer, &bookmarks, NULL, NULL);
- EXPECT_EQ(2U, bookmarks.size());
- if (bookmarks.size() == 2) {
- it = bookmarks.begin();
- entry = *it++;
- EXPECT_EQ(ASCIIToUTF16("Empty"), entry.title);
- EXPECT_TRUE(entry.is_folder);
- EXPECT_EQ(base::Time::FromTimeT(1295938143), entry.creation_time);
- EXPECT_EQ(1U, entry.path.size());
- if (entry.path.size() == 1)
- EXPECT_EQ(ASCIIToUTF16("Empty's Parent"), entry.path.front());
-
- entry = *it++;
- EXPECT_EQ(ASCIIToUTF16("[Tamura Yukari.com]"), entry.title);
- EXPECT_FALSE(entry.is_folder);
- EXPECT_EQ(base::Time::FromTimeT(1234567890), entry.creation_time);
- EXPECT_EQ(1U, entry.path.size());
- if (entry.path.size() == 1)
- EXPECT_EQ(ASCIIToUTF16("Not Empty"), entry.path.front());
- EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec());
- }
-
// Import Epiphany bookmarks from a file
base::FilePath epiphany_path = path.AppendASCII("epiphany.html");
bookmarks.clear();
- default_urls.clear();
- importer->ImportBookmarksFile(epiphany_path, default_urls,
- importer, &bookmarks, NULL, NULL);
+ importer->ImportBookmarksFile(epiphany_path, NULL, &bookmarks, NULL);
EXPECT_EQ(2U, bookmarks.size());
if (bookmarks.size() == 2) {
it = bookmarks.begin();
@@ -284,9 +190,7 @@ TEST(FirefoxImporterTest, Firefox2BookmarkFileImport) {
// Import Epiphany bookmarks from a file to bookmark bar.
bookmarks.clear();
- default_urls.clear();
- importer->ImportBookmarksFile(epiphany_path, default_urls,
- importer, &bookmarks, NULL, NULL);
+ importer->ImportBookmarksFile(epiphany_path, NULL, &bookmarks, NULL);
EXPECT_EQ(2U, bookmarks.size());
if (bookmarks.size() == 2) {
it = bookmarks.begin();

Powered by Google App Engine
This is Rietveld 408576698