Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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" | 5 #include "chrome/browser/bookmarks/bookmark_html_reader.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | |
| 7 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 8 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 9 #include "base/string16.h" | 10 #include "base/string16.h" |
| 10 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/history/history_types.h" | 13 #include "chrome/browser/bookmarks/imported_bookmark_entry.h" |
| 13 #include "chrome/browser/importer/firefox2_importer.h" | |
| 14 #include "chrome/browser/importer/firefox_importer_unittest_utils.h" | |
| 15 #include "chrome/browser/importer/nss_decryptor.h" | |
| 16 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | |
| 17 | 16 |
| 18 // TODO(jschuh): Disabled on Win64 build. http://crbug.com/179688 | 17 namespace bookmark_html_reader { |
| 19 #if defined(OS_WIN) && defined(ARCH_CPU_X86_64) | |
| 20 #define MAYBE_NSS(x) DISABLED_##x | |
| 21 #else | |
| 22 #define MAYBE_NSS(x) x | |
| 23 #endif | |
| 24 | 18 |
| 25 // The following 2 tests require the use of the NSSDecryptor, on OSX this needs | 19 TEST(BookmarkHTMLReaderTest, ParseTests) { |
| 26 // to run in a separate process, so we use a proxy object so we can share the | |
| 27 // same test between platforms. | |
| 28 TEST(FirefoxImporterTest, MAYBE_NSS(Firefox2NSS3Decryptor)) { | |
| 29 base::FilePath nss_path; | |
| 30 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &nss_path)); | |
| 31 #if defined(OS_MACOSX) | |
| 32 nss_path = nss_path.AppendASCII("firefox2_nss_mac"); | |
| 33 #else | |
| 34 nss_path = nss_path.AppendASCII("firefox2_nss"); | |
| 35 #endif // !OS_MACOSX | |
| 36 base::FilePath db_path; | |
| 37 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &db_path)); | |
| 38 db_path = db_path.AppendASCII("firefox2_profile"); | |
| 39 | |
| 40 FFUnitTestDecryptorProxy decryptor_proxy; | |
| 41 ASSERT_TRUE(decryptor_proxy.Setup(nss_path)); | |
| 42 | |
| 43 ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path)); | |
| 44 EXPECT_EQ(ASCIIToUTF16("hello"), | |
| 45 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECBJ" | |
| 46 "M63MpT9rtBAjMCm7qo/EhlA==")); | |
| 47 // Test UTF-16 encoding. | |
| 48 EXPECT_EQ(WideToUTF16(L"\x4E2D"), | |
| 49 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECN9" | |
| 50 "OQ5ZFmhb8BAiFo1Z+fUvaIQ==")); | |
| 51 } | |
| 52 | |
| 53 TEST(FirefoxImporterTest, MAYBE_NSS(Firefox3NSS3Decryptor)) { | |
| 54 base::FilePath nss_path; | |
| 55 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &nss_path)); | |
| 56 #if defined(OS_MACOSX) | |
| 57 nss_path = nss_path.AppendASCII("firefox3_nss_mac"); | |
| 58 #else | |
| 59 nss_path = nss_path.AppendASCII("firefox3_nss"); | |
| 60 #endif // !OS_MACOSX | |
| 61 base::FilePath db_path; | |
| 62 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &db_path)); | |
| 63 db_path = db_path.AppendASCII("firefox3_profile"); | |
| 64 | |
| 65 FFUnitTestDecryptorProxy decryptor_proxy; | |
| 66 ASSERT_TRUE(decryptor_proxy.Setup(nss_path)); | |
| 67 | |
| 68 ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path)); | |
| 69 EXPECT_EQ(ASCIIToUTF16("hello"), | |
| 70 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECKa" | |
| 71 "jtRg4qFSHBAhv9luFkXgDJA==")); | |
| 72 // Test UTF-16 encoding. | |
| 73 EXPECT_EQ(WideToUTF16(L"\x4E2D"), | |
| 74 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECLW" | |
| 75 "qqiccfQHWBAie74hxnULxlw==")); | |
| 76 } | |
| 77 | |
| 78 TEST(FirefoxImporterTest, Firefox2BookmarkParse) { | |
| 79 bool result; | 20 bool result; |
| 80 | 21 |
| 81 // Tests charset. | 22 // Tests charset. |
| 82 std::string charset; | 23 std::string charset; |
| 83 result = Firefox2Importer::ParseCharsetFromLine( | 24 result = internal::ParseCharsetFromLine( |
| 84 "<META HTTP-EQUIV=\"Content-Type\" " | 25 "<META HTTP-EQUIV=\"Content-Type\" " |
| 85 "CONTENT=\"text/html; charset=UTF-8\">", | 26 "CONTENT=\"text/html; charset=UTF-8\">", |
| 86 &charset); | 27 &charset); |
| 87 EXPECT_TRUE(result); | 28 EXPECT_TRUE(result); |
| 88 EXPECT_EQ("UTF-8", charset); | 29 EXPECT_EQ("UTF-8", charset); |
| 89 | 30 |
| 90 // Escaped characters in name. | 31 // Escaped characters in name. |
| 91 string16 folder_name; | 32 base::string16 folder_name; |
| 92 bool is_toolbar_folder; | 33 bool is_toolbar_folder; |
| 93 base::Time folder_add_date; | 34 base::Time folder_add_date; |
| 94 result = Firefox2Importer::ParseFolderNameFromLine( | 35 result = internal::ParseFolderNameFromLine( |
| 95 "<DT><H3 ADD_DATE=\"1207558707\" >< >" | 36 "<DT><H3 ADD_DATE=\"1207558707\" >< >" |
| 96 " & " ' \\ /</H3>", | 37 " & " ' \\ /</H3>", |
| 97 charset, &folder_name, &is_toolbar_folder, &folder_add_date); | 38 charset, &folder_name, &is_toolbar_folder, &folder_add_date); |
| 98 EXPECT_TRUE(result); | 39 EXPECT_TRUE(result); |
| 99 EXPECT_EQ(ASCIIToUTF16("< > & \" ' \\ /"), folder_name); | 40 EXPECT_EQ(ASCIIToUTF16("< > & \" ' \\ /"), folder_name); |
| 100 EXPECT_FALSE(is_toolbar_folder); | 41 EXPECT_FALSE(is_toolbar_folder); |
| 101 EXPECT_TRUE(base::Time::FromTimeT(1207558707) == folder_add_date); | 42 EXPECT_TRUE(base::Time::FromTimeT(1207558707) == folder_add_date); |
| 102 | 43 |
| 103 // Empty name and toolbar folder attribute. | 44 // Empty name and toolbar folder attribute. |
| 104 result = Firefox2Importer::ParseFolderNameFromLine( | 45 result = internal::ParseFolderNameFromLine( |
| 105 "<DT><H3 PERSONAL_TOOLBAR_FOLDER=\"true\"></H3>", | 46 "<DT><H3 PERSONAL_TOOLBAR_FOLDER=\"true\"></H3>", |
| 106 charset, &folder_name, &is_toolbar_folder, &folder_add_date); | 47 charset, &folder_name, &is_toolbar_folder, &folder_add_date); |
| 107 EXPECT_TRUE(result); | 48 EXPECT_TRUE(result); |
| 108 EXPECT_EQ(string16(), folder_name); | 49 EXPECT_EQ(base::string16(), folder_name); |
| 109 EXPECT_TRUE(is_toolbar_folder); | 50 EXPECT_TRUE(is_toolbar_folder); |
| 110 | 51 |
| 111 // Unicode characters in title and shortcut. | 52 // Unicode characters in title and shortcut. |
| 112 string16 title; | 53 base::string16 title; |
| 113 GURL url, favicon; | 54 GURL url, favicon; |
| 114 string16 shortcut; | 55 base::string16 shortcut; |
| 115 string16 post_data; | 56 base::string16 post_data; |
| 116 base::Time add_date; | 57 base::Time add_date; |
| 117 result = Firefox2Importer::ParseBookmarkFromLine( | 58 result = internal::ParseBookmarkFromLine( |
| 118 "<DT><A HREF=\"http://chinese.site.cn/path?query=1#ref\" " | 59 "<DT><A HREF=\"http://chinese.site.cn/path?query=1#ref\" " |
| 119 "SHORTCUTURL=\"\xE4\xB8\xAD\">\xE4\xB8\xAD\xE6\x96\x87</A>", | 60 "SHORTCUTURL=\"\xE4\xB8\xAD\">\xE4\xB8\xAD\xE6\x96\x87</A>", |
| 120 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); | 61 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); |
| 121 EXPECT_TRUE(result); | 62 EXPECT_TRUE(result); |
| 122 EXPECT_EQ(L"\x4E2D\x6587", UTF16ToWide(title)); | 63 EXPECT_EQ(L"\x4E2D\x6587", UTF16ToWide(title)); |
| 123 EXPECT_EQ("http://chinese.site.cn/path?query=1#ref", url.spec()); | 64 EXPECT_EQ("http://chinese.site.cn/path?query=1#ref", url.spec()); |
| 124 EXPECT_EQ(L"\x4E2D", UTF16ToWide(shortcut)); | 65 EXPECT_EQ(L"\x4E2D", UTF16ToWide(shortcut)); |
| 125 EXPECT_EQ(string16(), post_data); | 66 EXPECT_EQ(base::string16(), post_data); |
| 126 EXPECT_TRUE(base::Time() == add_date); | 67 EXPECT_TRUE(base::Time() == add_date); |
| 127 | 68 |
| 128 // No shortcut, and url contains %22 ('"' character). | 69 // No shortcut, and url contains %22 ('"' character). |
| 129 result = Firefox2Importer::ParseBookmarkFromLine( | 70 result = internal::ParseBookmarkFromLine( |
| 130 "<DT><A HREF=\"http://domain.com/?q=%22<>%22\">name</A>", | 71 "<DT><A HREF=\"http://domain.com/?q=%22<>%22\">name</A>", |
| 131 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); | 72 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); |
| 132 EXPECT_TRUE(result); | 73 EXPECT_TRUE(result); |
| 133 EXPECT_EQ(ASCIIToUTF16("name"), title); | 74 EXPECT_EQ(ASCIIToUTF16("name"), title); |
| 134 EXPECT_EQ("http://domain.com/?q=%22%3C%3E%22", url.spec()); | 75 EXPECT_EQ("http://domain.com/?q=%22%3C%3E%22", url.spec()); |
| 135 EXPECT_EQ(string16(), shortcut); | 76 EXPECT_EQ(base::string16(), shortcut); |
| 136 EXPECT_EQ(string16(), post_data); | 77 EXPECT_EQ(base::string16(), post_data); |
| 137 EXPECT_TRUE(base::Time() == add_date); | 78 EXPECT_TRUE(base::Time() == add_date); |
| 138 | 79 |
| 139 result = Firefox2Importer::ParseBookmarkFromLine( | 80 result = internal::ParseBookmarkFromLine( |
| 140 "<DT><A HREF=\"http://domain.com/?g="\"\">name</A>", | 81 "<DT><A HREF=\"http://domain.com/?g="\"\">name</A>", |
| 141 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); | 82 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); |
| 142 EXPECT_TRUE(result); | 83 EXPECT_TRUE(result); |
| 143 EXPECT_EQ(ASCIIToUTF16("name"), title); | 84 EXPECT_EQ(ASCIIToUTF16("name"), title); |
| 144 EXPECT_EQ("http://domain.com/?g=%22", url.spec()); | 85 EXPECT_EQ("http://domain.com/?g=%22", url.spec()); |
| 145 EXPECT_EQ(string16(), shortcut); | 86 EXPECT_EQ(base::string16(), shortcut); |
| 146 EXPECT_EQ(string16(), post_data); | 87 EXPECT_EQ(base::string16(), post_data); |
| 147 EXPECT_TRUE(base::Time() == add_date); | 88 EXPECT_TRUE(base::Time() == add_date); |
| 148 | 89 |
| 149 // Creation date. | 90 // Creation date. |
| 150 result = Firefox2Importer::ParseBookmarkFromLine( | 91 result = internal::ParseBookmarkFromLine( |
| 151 "<DT><A HREF=\"http://site/\" ADD_DATE=\"1121301154\">name</A>", | 92 "<DT><A HREF=\"http://site/\" ADD_DATE=\"1121301154\">name</A>", |
| 152 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); | 93 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); |
| 153 EXPECT_TRUE(result); | 94 EXPECT_TRUE(result); |
| 154 EXPECT_EQ(ASCIIToUTF16("name"), title); | 95 EXPECT_EQ(ASCIIToUTF16("name"), title); |
| 155 EXPECT_EQ(GURL("http://site/"), url); | 96 EXPECT_EQ(GURL("http://site/"), url); |
| 156 EXPECT_EQ(string16(), shortcut); | 97 EXPECT_EQ(base::string16(), shortcut); |
| 157 EXPECT_EQ(string16(), post_data); | 98 EXPECT_EQ(base::string16(), post_data); |
| 158 EXPECT_TRUE(base::Time::FromTimeT(1121301154) == add_date); | 99 EXPECT_TRUE(base::Time::FromTimeT(1121301154) == add_date); |
| 159 | 100 |
| 160 // Post-data | 101 // Post-data |
| 161 result = Firefox2Importer::ParseBookmarkFromLine( | 102 result = internal::ParseBookmarkFromLine( |
| 162 "<DT><A HREF=\"http://localhost:8080/test/hello.html\" ADD_DATE=\"" | 103 "<DT><A HREF=\"http://localhost:8080/test/hello.html\" ADD_DATE=\"" |
| 163 "1212447159\" LAST_VISIT=\"1212447251\" LAST_MODIFIED=\"1212447248\"" | 104 "1212447159\" LAST_VISIT=\"1212447251\" LAST_MODIFIED=\"1212447248\"" |
| 164 "SHORTCUTURL=\"post\" ICON=\"data:\" POST_DATA=\"lname%3D%25s\"" | 105 "SHORTCUTURL=\"post\" ICON=\"data:\" POST_DATA=\"lname%3D%25s\"" |
| 165 "LAST_CHARSET=\"UTF-8\" ID=\"rdf:#$weKaR3\">Test Post keyword</A>", | 106 "LAST_CHARSET=\"UTF-8\" ID=\"rdf:#$weKaR3\">Test Post keyword</A>", |
| 166 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); | 107 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); |
| 167 EXPECT_TRUE(result); | 108 EXPECT_TRUE(result); |
| 168 EXPECT_EQ(ASCIIToUTF16("Test Post keyword"), title); | 109 EXPECT_EQ(ASCIIToUTF16("Test Post keyword"), title); |
| 169 EXPECT_EQ("http://localhost:8080/test/hello.html", url.spec()); | 110 EXPECT_EQ("http://localhost:8080/test/hello.html", url.spec()); |
| 170 EXPECT_EQ(ASCIIToUTF16("post"), shortcut); | 111 EXPECT_EQ(ASCIIToUTF16("post"), shortcut); |
| 171 EXPECT_EQ(ASCIIToUTF16("lname%3D%25s"), post_data); | 112 EXPECT_EQ(ASCIIToUTF16("lname%3D%25s"), post_data); |
| 172 EXPECT_TRUE(base::Time::FromTimeT(1212447159) == add_date); | 113 EXPECT_TRUE(base::Time::FromTimeT(1212447159) == add_date); |
| 173 | 114 |
| 174 // Invalid case. | 115 // Invalid case. |
| 175 result = Firefox2Importer::ParseBookmarkFromLine( | 116 result = internal::ParseBookmarkFromLine( |
| 176 "<DT><A HREF=\"http://domain.com/?q=%22", | 117 "<DT><A HREF=\"http://domain.com/?q=%22", |
| 177 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); | 118 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); |
| 178 EXPECT_FALSE(result); | 119 EXPECT_FALSE(result); |
| 179 EXPECT_EQ(string16(), title); | 120 EXPECT_EQ(base::string16(), title); |
| 180 EXPECT_EQ("", url.spec()); | 121 EXPECT_EQ("", url.spec()); |
| 181 EXPECT_EQ(string16(), shortcut); | 122 EXPECT_EQ(base::string16(), shortcut); |
| 182 EXPECT_EQ(string16(), post_data); | 123 EXPECT_EQ(base::string16(), post_data); |
| 183 EXPECT_TRUE(base::Time() == add_date); | 124 EXPECT_TRUE(base::Time() == add_date); |
| 184 | 125 |
| 185 // Epiphany format. | 126 // Epiphany format. |
| 186 result = Firefox2Importer::ParseMinimumBookmarkFromLine( | 127 result = internal::ParseMinimumBookmarkFromLine( |
| 187 "<dt><a href=\"http://www.google.com/\">Google</a></dt>", | 128 "<dt><a href=\"http://www.google.com/\">Google</a></dt>", |
| 188 charset, &title, &url); | 129 charset, &title, &url); |
| 189 EXPECT_TRUE(result); | 130 EXPECT_TRUE(result); |
| 190 EXPECT_EQ(ASCIIToUTF16("Google"), title); | 131 EXPECT_EQ(ASCIIToUTF16("Google"), title); |
| 191 EXPECT_EQ("http://www.google.com/", url.spec()); | 132 EXPECT_EQ("http://www.google.com/", url.spec()); |
| 192 } | 133 } |
| 193 | 134 |
| 194 TEST(FirefoxImporterTest, Firefox2BookmarkFileImport) { | 135 TEST(BookmarkHTMLReaderTest, BookmarkFileImport) { |
| 195 base::FilePath path; | 136 base::FilePath path; |
| 196 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); | 137 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); |
| 197 path = path.AppendASCII("firefox2_importer"); | 138 path = path.AppendASCII("bookmark_html_reader"); |
| 198 | 139 |
| 199 // Import all bookmarks from a file which include an empty folder entry. | 140 // Import all bookmarks from a file which include an empty folder entry. |
| 200 base::FilePath empty_folder_path = path.AppendASCII("empty_folder.html"); | 141 base::FilePath empty_folder_path = path.AppendASCII("firefox2.html"); |
| 201 std::set<GURL> default_urls; | 142 std::vector<ImportedBookmarkEntry> bookmarks; |
| 202 Firefox2Importer* importer = new Firefox2Importer(); | 143 ImportBookmarksFile(base::Callback<bool(void)>(), |
|
gab
2013/05/13 21:53:01
I suggest you also add tests to test the functiona
Avi (use Gerrit)
2013/05/13 23:34:19
Done.
| |
| 203 importer->AddRef(); | 144 base::Callback<bool(const GURL&)>(), |
| 204 std::vector<ProfileWriter::BookmarkEntry> bookmarks; | 145 empty_folder_path, &bookmarks, NULL); |
| 205 importer->ImportBookmarksFile(empty_folder_path, default_urls, | |
| 206 importer, &bookmarks, NULL, NULL); | |
| 207 EXPECT_EQ(3U, bookmarks.size()); | 146 EXPECT_EQ(3U, bookmarks.size()); |
| 208 std::vector<ProfileWriter::BookmarkEntry>::iterator it; | 147 std::vector<ImportedBookmarkEntry>::iterator it; |
| 209 ProfileWriter::BookmarkEntry entry; | 148 ImportedBookmarkEntry entry; |
| 210 std::vector<string16>::iterator path_it; | 149 std::vector<base::string16>::iterator path_it; |
| 211 if (bookmarks.size() == 3) { | 150 if (bookmarks.size() == 3) { |
| 212 it = bookmarks.begin(); | 151 it = bookmarks.begin(); |
| 213 entry = *it++; | 152 entry = *it++; |
| 214 EXPECT_EQ(ASCIIToUTF16("Empty"), entry.title); | 153 EXPECT_EQ(ASCIIToUTF16("Empty"), entry.title); |
| 215 EXPECT_TRUE(entry.is_folder); | 154 EXPECT_TRUE(entry.is_folder); |
| 216 EXPECT_EQ(base::Time::FromTimeT(1295938143), entry.creation_time); | 155 EXPECT_EQ(base::Time::FromTimeT(1295938143), entry.creation_time); |
| 217 EXPECT_EQ(1U, entry.path.size()); | 156 EXPECT_EQ(1U, entry.path.size()); |
| 218 if (entry.path.size() == 1) | 157 if (entry.path.size() == 1) |
| 219 EXPECT_EQ(ASCIIToUTF16("Empty's Parent"), entry.path.front()); | 158 EXPECT_EQ(ASCIIToUTF16("Empty's Parent"), entry.path.front()); |
| 220 | 159 |
| 221 entry = *it++; | 160 entry = *it++; |
| 222 EXPECT_EQ(ASCIIToUTF16("[Tamura Yukari.com]"), entry.title); | 161 EXPECT_EQ(ASCIIToUTF16("[Tamura Yukari.com]"), entry.title); |
| 223 EXPECT_FALSE(entry.is_folder); | 162 EXPECT_FALSE(entry.is_folder); |
| 224 EXPECT_EQ(base::Time::FromTimeT(1234567890), entry.creation_time); | 163 EXPECT_EQ(base::Time::FromTimeT(1234567890), entry.creation_time); |
| 225 EXPECT_EQ(1U, entry.path.size()); | 164 EXPECT_EQ(1U, entry.path.size()); |
| 226 if (entry.path.size() == 1) | 165 if (entry.path.size() == 1) |
| 227 EXPECT_EQ(ASCIIToUTF16("Not Empty"), entry.path.front()); | 166 EXPECT_EQ(ASCIIToUTF16("Not Empty"), entry.path.front()); |
| 228 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); | 167 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); |
| 229 | 168 |
| 230 entry = *it++; | 169 entry = *it++; |
| 231 EXPECT_EQ(ASCIIToUTF16("Google"), entry.title); | 170 EXPECT_EQ(ASCIIToUTF16("Google"), entry.title); |
| 232 EXPECT_FALSE(entry.is_folder); | 171 EXPECT_FALSE(entry.is_folder); |
| 233 EXPECT_EQ(base::Time::FromTimeT(0000000000), entry.creation_time); | 172 EXPECT_EQ(base::Time::FromTimeT(0000000000), entry.creation_time); |
| 234 EXPECT_EQ(1U, entry.path.size()); | 173 EXPECT_EQ(1U, entry.path.size()); |
| 235 if (entry.path.size() == 1) | 174 if (entry.path.size() == 1) |
| 236 EXPECT_EQ(ASCIIToUTF16("Not Empty But Default"), entry.path.front()); | 175 EXPECT_EQ(ASCIIToUTF16("Not Empty But Default"), entry.path.front()); |
| 237 EXPECT_EQ("http://www.google.com/", entry.url.spec()); | 176 EXPECT_EQ("http://www.google.com/", entry.url.spec()); |
| 238 } | 177 } |
| 239 | 178 |
| 240 // Import non-default bookmarks from a file. | |
| 241 bookmarks.clear(); | |
| 242 default_urls.insert(GURL("http://www.google.com/")); | |
| 243 importer->ImportBookmarksFile(empty_folder_path, default_urls, | |
| 244 importer, &bookmarks, NULL, NULL); | |
| 245 EXPECT_EQ(2U, bookmarks.size()); | |
| 246 if (bookmarks.size() == 2) { | |
| 247 it = bookmarks.begin(); | |
| 248 entry = *it++; | |
| 249 EXPECT_EQ(ASCIIToUTF16("Empty"), entry.title); | |
| 250 EXPECT_TRUE(entry.is_folder); | |
| 251 EXPECT_EQ(base::Time::FromTimeT(1295938143), entry.creation_time); | |
| 252 EXPECT_EQ(1U, entry.path.size()); | |
| 253 if (entry.path.size() == 1) | |
| 254 EXPECT_EQ(ASCIIToUTF16("Empty's Parent"), entry.path.front()); | |
| 255 | |
| 256 entry = *it++; | |
| 257 EXPECT_EQ(ASCIIToUTF16("[Tamura Yukari.com]"), entry.title); | |
| 258 EXPECT_FALSE(entry.is_folder); | |
| 259 EXPECT_EQ(base::Time::FromTimeT(1234567890), entry.creation_time); | |
| 260 EXPECT_EQ(1U, entry.path.size()); | |
| 261 if (entry.path.size() == 1) | |
| 262 EXPECT_EQ(ASCIIToUTF16("Not Empty"), entry.path.front()); | |
| 263 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); | |
| 264 } | |
| 265 | |
| 266 // Import Epiphany bookmarks from a file | 179 // Import Epiphany bookmarks from a file |
| 267 base::FilePath epiphany_path = path.AppendASCII("epiphany.html"); | 180 base::FilePath epiphany_path = path.AppendASCII("epiphany.html"); |
| 268 bookmarks.clear(); | 181 bookmarks.clear(); |
| 269 default_urls.clear(); | 182 ImportBookmarksFile(base::Callback<bool(void)>(), |
| 270 importer->ImportBookmarksFile(epiphany_path, default_urls, | 183 base::Callback<bool(const GURL&)>(), |
| 271 importer, &bookmarks, NULL, NULL); | 184 epiphany_path, &bookmarks, NULL); |
| 272 EXPECT_EQ(2U, bookmarks.size()); | 185 EXPECT_EQ(2U, bookmarks.size()); |
| 273 if (bookmarks.size() == 2) { | 186 if (bookmarks.size() == 2) { |
| 274 it = bookmarks.begin(); | 187 it = bookmarks.begin(); |
| 275 entry = *it++; | 188 entry = *it++; |
| 276 EXPECT_EQ(ASCIIToUTF16("[Tamura Yukari.com]"), entry.title); | 189 EXPECT_EQ(ASCIIToUTF16("[Tamura Yukari.com]"), entry.title); |
| 277 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); | 190 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); |
| 278 EXPECT_EQ(0U, entry.path.size()); | 191 EXPECT_EQ(0U, entry.path.size()); |
| 279 entry = *it++; | 192 entry = *it++; |
| 280 EXPECT_EQ(ASCIIToUTF16("Google"), entry.title); | 193 EXPECT_EQ(ASCIIToUTF16("Google"), entry.title); |
| 281 EXPECT_EQ("http://www.google.com/", entry.url.spec()); | 194 EXPECT_EQ("http://www.google.com/", entry.url.spec()); |
| 282 EXPECT_EQ(0U, entry.path.size()); | 195 EXPECT_EQ(0U, entry.path.size()); |
| 283 } | 196 } |
| 284 | 197 |
| 285 // Import Epiphany bookmarks from a file to bookmark bar. | 198 // Import Epiphany bookmarks from a file to bookmark bar. |
| 286 bookmarks.clear(); | 199 bookmarks.clear(); |
| 287 default_urls.clear(); | 200 ImportBookmarksFile(base::Callback<bool(void)>(), |
| 288 importer->ImportBookmarksFile(epiphany_path, default_urls, | 201 base::Callback<bool(const GURL&)>(), |
| 289 importer, &bookmarks, NULL, NULL); | 202 epiphany_path, &bookmarks, NULL); |
| 290 EXPECT_EQ(2U, bookmarks.size()); | 203 EXPECT_EQ(2U, bookmarks.size()); |
| 291 if (bookmarks.size() == 2) { | 204 if (bookmarks.size() == 2) { |
| 292 it = bookmarks.begin(); | 205 it = bookmarks.begin(); |
| 293 entry = *it++; | 206 entry = *it++; |
| 294 EXPECT_EQ(ASCIIToUTF16("[Tamura Yukari.com]"), entry.title); | 207 EXPECT_EQ(ASCIIToUTF16("[Tamura Yukari.com]"), entry.title); |
| 295 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); | 208 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); |
| 296 EXPECT_EQ(0U, entry.path.size()); | 209 EXPECT_EQ(0U, entry.path.size()); |
| 297 entry = *it++; | 210 entry = *it++; |
| 298 EXPECT_EQ(ASCIIToUTF16("Google"), entry.title); | 211 EXPECT_EQ(ASCIIToUTF16("Google"), entry.title); |
| 299 EXPECT_EQ("http://www.google.com/", entry.url.spec()); | 212 EXPECT_EQ("http://www.google.com/", entry.url.spec()); |
| 300 EXPECT_EQ(0U, entry.path.size()); | 213 EXPECT_EQ(0U, entry.path.size()); |
| 301 } | 214 } |
| 215 } | |
| 302 | 216 |
| 303 importer->Release(); | 217 } // namespace bookmark_html_reader |
| 304 } | |
| OLD | NEW |