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

Side by Side Diff: chrome/browser/bookmarks/bookmark_html_reader_unittest.cc

Issue 14575004: Extract BookmarksFileImporter from Firefox2Importer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix again? 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/callback.h"
7 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
8 #include "base/path_service.h" 11 #include "base/path_service.h"
9 #include "base/string16.h" 12 #include "base/string16.h"
10 #include "base/string_util.h" 13 #include "base/string_util.h"
11 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/history/history_types.h" 15 #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" 16 #include "chrome/common/chrome_paths.h"
17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 // TODO(jschuh): Disabled on Win64 build. http://crbug.com/179688 19 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 20
25 // The following 2 tests require the use of the NSSDecryptor, on OSX this needs 21 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; 22 bool result;
80 23
81 // Tests charset. 24 // Tests charset.
82 std::string charset; 25 std::string charset;
83 result = Firefox2Importer::ParseCharsetFromLine( 26 result = internal::ParseCharsetFromLine(
84 "<META HTTP-EQUIV=\"Content-Type\" " 27 "<META HTTP-EQUIV=\"Content-Type\" "
85 "CONTENT=\"text/html; charset=UTF-8\">", 28 "CONTENT=\"text/html; charset=UTF-8\">",
86 &charset); 29 &charset);
87 EXPECT_TRUE(result); 30 EXPECT_TRUE(result);
88 EXPECT_EQ("UTF-8", charset); 31 EXPECT_EQ("UTF-8", charset);
89 32
90 // Escaped characters in name. 33 // Escaped characters in name.
91 string16 folder_name; 34 base::string16 folder_name;
92 bool is_toolbar_folder; 35 bool is_toolbar_folder;
93 base::Time folder_add_date; 36 base::Time folder_add_date;
94 result = Firefox2Importer::ParseFolderNameFromLine( 37 result = internal::ParseFolderNameFromLine(
95 "<DT><H3 ADD_DATE=\"1207558707\" >&lt; &gt;" 38 "<DT><H3 ADD_DATE=\"1207558707\" >&lt; &gt;"
96 " &amp; &quot; &#39; \\ /</H3>", 39 " &amp; &quot; &#39; \\ /</H3>",
97 charset, &folder_name, &is_toolbar_folder, &folder_add_date); 40 charset, &folder_name, &is_toolbar_folder, &folder_add_date);
98 EXPECT_TRUE(result); 41 EXPECT_TRUE(result);
99 EXPECT_EQ(ASCIIToUTF16("< > & \" ' \\ /"), folder_name); 42 EXPECT_EQ(ASCIIToUTF16("< > & \" ' \\ /"), folder_name);
100 EXPECT_FALSE(is_toolbar_folder); 43 EXPECT_FALSE(is_toolbar_folder);
101 EXPECT_TRUE(base::Time::FromTimeT(1207558707) == folder_add_date); 44 EXPECT_TRUE(base::Time::FromTimeT(1207558707) == folder_add_date);
102 45
103 // Empty name and toolbar folder attribute. 46 // Empty name and toolbar folder attribute.
104 result = Firefox2Importer::ParseFolderNameFromLine( 47 result = internal::ParseFolderNameFromLine(
105 "<DT><H3 PERSONAL_TOOLBAR_FOLDER=\"true\"></H3>", 48 "<DT><H3 PERSONAL_TOOLBAR_FOLDER=\"true\"></H3>",
106 charset, &folder_name, &is_toolbar_folder, &folder_add_date); 49 charset, &folder_name, &is_toolbar_folder, &folder_add_date);
107 EXPECT_TRUE(result); 50 EXPECT_TRUE(result);
108 EXPECT_EQ(string16(), folder_name); 51 EXPECT_EQ(base::string16(), folder_name);
109 EXPECT_TRUE(is_toolbar_folder); 52 EXPECT_TRUE(is_toolbar_folder);
110 53
111 // Unicode characters in title and shortcut. 54 // Unicode characters in title and shortcut.
112 string16 title; 55 base::string16 title;
113 GURL url, favicon; 56 GURL url, favicon;
114 string16 shortcut; 57 base::string16 shortcut;
115 string16 post_data; 58 base::string16 post_data;
116 base::Time add_date; 59 base::Time add_date;
117 result = Firefox2Importer::ParseBookmarkFromLine( 60 result = internal::ParseBookmarkFromLine(
118 "<DT><A HREF=\"http://chinese.site.cn/path?query=1#ref\" " 61 "<DT><A HREF=\"http://chinese.site.cn/path?query=1#ref\" "
119 "SHORTCUTURL=\"\xE4\xB8\xAD\">\xE4\xB8\xAD\xE6\x96\x87</A>", 62 "SHORTCUTURL=\"\xE4\xB8\xAD\">\xE4\xB8\xAD\xE6\x96\x87</A>",
120 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); 63 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data);
121 EXPECT_TRUE(result); 64 EXPECT_TRUE(result);
122 EXPECT_EQ(L"\x4E2D\x6587", UTF16ToWide(title)); 65 EXPECT_EQ(L"\x4E2D\x6587", UTF16ToWide(title));
123 EXPECT_EQ("http://chinese.site.cn/path?query=1#ref", url.spec()); 66 EXPECT_EQ("http://chinese.site.cn/path?query=1#ref", url.spec());
124 EXPECT_EQ(L"\x4E2D", UTF16ToWide(shortcut)); 67 EXPECT_EQ(L"\x4E2D", UTF16ToWide(shortcut));
125 EXPECT_EQ(string16(), post_data); 68 EXPECT_EQ(base::string16(), post_data);
126 EXPECT_TRUE(base::Time() == add_date); 69 EXPECT_TRUE(base::Time() == add_date);
127 70
128 // No shortcut, and url contains %22 ('"' character). 71 // No shortcut, and url contains %22 ('"' character).
129 result = Firefox2Importer::ParseBookmarkFromLine( 72 result = internal::ParseBookmarkFromLine(
130 "<DT><A HREF=\"http://domain.com/?q=%22<>%22\">name</A>", 73 "<DT><A HREF=\"http://domain.com/?q=%22<>%22\">name</A>",
131 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); 74 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data);
132 EXPECT_TRUE(result); 75 EXPECT_TRUE(result);
133 EXPECT_EQ(ASCIIToUTF16("name"), title); 76 EXPECT_EQ(ASCIIToUTF16("name"), title);
134 EXPECT_EQ("http://domain.com/?q=%22%3C%3E%22", url.spec()); 77 EXPECT_EQ("http://domain.com/?q=%22%3C%3E%22", url.spec());
135 EXPECT_EQ(string16(), shortcut); 78 EXPECT_EQ(base::string16(), shortcut);
136 EXPECT_EQ(string16(), post_data); 79 EXPECT_EQ(base::string16(), post_data);
137 EXPECT_TRUE(base::Time() == add_date); 80 EXPECT_TRUE(base::Time() == add_date);
138 81
139 result = Firefox2Importer::ParseBookmarkFromLine( 82 result = internal::ParseBookmarkFromLine(
140 "<DT><A HREF=\"http://domain.com/?g=&quot;\"\">name</A>", 83 "<DT><A HREF=\"http://domain.com/?g=&quot;\"\">name</A>",
141 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); 84 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data);
142 EXPECT_TRUE(result); 85 EXPECT_TRUE(result);
143 EXPECT_EQ(ASCIIToUTF16("name"), title); 86 EXPECT_EQ(ASCIIToUTF16("name"), title);
144 EXPECT_EQ("http://domain.com/?g=%22", url.spec()); 87 EXPECT_EQ("http://domain.com/?g=%22", url.spec());
145 EXPECT_EQ(string16(), shortcut); 88 EXPECT_EQ(base::string16(), shortcut);
146 EXPECT_EQ(string16(), post_data); 89 EXPECT_EQ(base::string16(), post_data);
147 EXPECT_TRUE(base::Time() == add_date); 90 EXPECT_TRUE(base::Time() == add_date);
148 91
149 // Creation date. 92 // Creation date.
150 result = Firefox2Importer::ParseBookmarkFromLine( 93 result = internal::ParseBookmarkFromLine(
151 "<DT><A HREF=\"http://site/\" ADD_DATE=\"1121301154\">name</A>", 94 "<DT><A HREF=\"http://site/\" ADD_DATE=\"1121301154\">name</A>",
152 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); 95 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data);
153 EXPECT_TRUE(result); 96 EXPECT_TRUE(result);
154 EXPECT_EQ(ASCIIToUTF16("name"), title); 97 EXPECT_EQ(ASCIIToUTF16("name"), title);
155 EXPECT_EQ(GURL("http://site/"), url); 98 EXPECT_EQ(GURL("http://site/"), url);
156 EXPECT_EQ(string16(), shortcut); 99 EXPECT_EQ(base::string16(), shortcut);
157 EXPECT_EQ(string16(), post_data); 100 EXPECT_EQ(base::string16(), post_data);
158 EXPECT_TRUE(base::Time::FromTimeT(1121301154) == add_date); 101 EXPECT_TRUE(base::Time::FromTimeT(1121301154) == add_date);
159 102
160 // Post-data 103 // Post-data
161 result = Firefox2Importer::ParseBookmarkFromLine( 104 result = internal::ParseBookmarkFromLine(
162 "<DT><A HREF=\"http://localhost:8080/test/hello.html\" ADD_DATE=\"" 105 "<DT><A HREF=\"http://localhost:8080/test/hello.html\" ADD_DATE=\""
163 "1212447159\" LAST_VISIT=\"1212447251\" LAST_MODIFIED=\"1212447248\"" 106 "1212447159\" LAST_VISIT=\"1212447251\" LAST_MODIFIED=\"1212447248\""
164 "SHORTCUTURL=\"post\" ICON=\"data:\" POST_DATA=\"lname%3D%25s\"" 107 "SHORTCUTURL=\"post\" ICON=\"data:\" POST_DATA=\"lname%3D%25s\""
165 "LAST_CHARSET=\"UTF-8\" ID=\"rdf:#$weKaR3\">Test Post keyword</A>", 108 "LAST_CHARSET=\"UTF-8\" ID=\"rdf:#$weKaR3\">Test Post keyword</A>",
166 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); 109 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data);
167 EXPECT_TRUE(result); 110 EXPECT_TRUE(result);
168 EXPECT_EQ(ASCIIToUTF16("Test Post keyword"), title); 111 EXPECT_EQ(ASCIIToUTF16("Test Post keyword"), title);
169 EXPECT_EQ("http://localhost:8080/test/hello.html", url.spec()); 112 EXPECT_EQ("http://localhost:8080/test/hello.html", url.spec());
170 EXPECT_EQ(ASCIIToUTF16("post"), shortcut); 113 EXPECT_EQ(ASCIIToUTF16("post"), shortcut);
171 EXPECT_EQ(ASCIIToUTF16("lname%3D%25s"), post_data); 114 EXPECT_EQ(ASCIIToUTF16("lname%3D%25s"), post_data);
172 EXPECT_TRUE(base::Time::FromTimeT(1212447159) == add_date); 115 EXPECT_TRUE(base::Time::FromTimeT(1212447159) == add_date);
173 116
174 // Invalid case. 117 // Invalid case.
175 result = Firefox2Importer::ParseBookmarkFromLine( 118 result = internal::ParseBookmarkFromLine(
176 "<DT><A HREF=\"http://domain.com/?q=%22", 119 "<DT><A HREF=\"http://domain.com/?q=%22",
177 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); 120 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data);
178 EXPECT_FALSE(result); 121 EXPECT_FALSE(result);
179 EXPECT_EQ(string16(), title); 122 EXPECT_EQ(base::string16(), title);
180 EXPECT_EQ("", url.spec()); 123 EXPECT_EQ("", url.spec());
181 EXPECT_EQ(string16(), shortcut); 124 EXPECT_EQ(base::string16(), shortcut);
182 EXPECT_EQ(string16(), post_data); 125 EXPECT_EQ(base::string16(), post_data);
183 EXPECT_TRUE(base::Time() == add_date); 126 EXPECT_TRUE(base::Time() == add_date);
184 127
185 // Epiphany format. 128 // Epiphany format.
186 result = Firefox2Importer::ParseMinimumBookmarkFromLine( 129 result = internal::ParseMinimumBookmarkFromLine(
187 "<dt><a href=\"http://www.google.com/\">Google</a></dt>", 130 "<dt><a href=\"http://www.google.com/\">Google</a></dt>",
188 charset, &title, &url); 131 charset, &title, &url);
189 EXPECT_TRUE(result); 132 EXPECT_TRUE(result);
190 EXPECT_EQ(ASCIIToUTF16("Google"), title); 133 EXPECT_EQ(ASCIIToUTF16("Google"), title);
191 EXPECT_EQ("http://www.google.com/", url.spec()); 134 EXPECT_EQ("http://www.google.com/", url.spec());
192 } 135 }
193 136
194 TEST(FirefoxImporterTest, Firefox2BookmarkFileImport) { 137 TEST(BookmarkHTMLReaderTest, BookmarkFileImport) {
195 base::FilePath path; 138 base::FilePath path;
196 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); 139 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
197 path = path.AppendASCII("firefox2_importer"); 140 path = path.AppendASCII("bookmark_html_reader");
198 141
199 // Import all bookmarks from a file which include an empty folder entry. 142 // Import all bookmarks from a file which include an empty folder entry.
200 base::FilePath empty_folder_path = path.AppendASCII("empty_folder.html"); 143 base::FilePath firefox2_path = path.AppendASCII("firefox2.html");
201 std::set<GURL> default_urls; 144 std::vector<ImportedBookmarkEntry> bookmarks;
202 Firefox2Importer* importer = new Firefox2Importer(); 145 ImportBookmarksFile(base::Callback<bool(void)>(),
203 importer->AddRef(); 146 base::Callback<bool(const GURL&)>(),
204 std::vector<ProfileWriter::BookmarkEntry> bookmarks; 147 firefox2_path, &bookmarks, NULL);
205 importer->ImportBookmarksFile(empty_folder_path, default_urls,
206 importer, &bookmarks, NULL, NULL);
207 EXPECT_EQ(3U, bookmarks.size()); 148 EXPECT_EQ(3U, bookmarks.size());
208 std::vector<ProfileWriter::BookmarkEntry>::iterator it; 149 std::vector<ImportedBookmarkEntry>::iterator it;
209 ProfileWriter::BookmarkEntry entry; 150 ImportedBookmarkEntry entry;
210 std::vector<string16>::iterator path_it; 151 std::vector<base::string16>::iterator path_it;
211 if (bookmarks.size() == 3) { 152 if (bookmarks.size() == 3) {
212 it = bookmarks.begin(); 153 it = bookmarks.begin();
213 entry = *it++; 154 entry = *it++;
214 EXPECT_EQ(ASCIIToUTF16("Empty"), entry.title); 155 EXPECT_EQ(ASCIIToUTF16("Empty"), entry.title);
215 EXPECT_TRUE(entry.is_folder); 156 EXPECT_TRUE(entry.is_folder);
216 EXPECT_EQ(base::Time::FromTimeT(1295938143), entry.creation_time); 157 EXPECT_EQ(base::Time::FromTimeT(1295938143), entry.creation_time);
217 EXPECT_EQ(1U, entry.path.size()); 158 EXPECT_EQ(1U, entry.path.size());
218 if (entry.path.size() == 1) 159 if (entry.path.size() == 1)
219 EXPECT_EQ(ASCIIToUTF16("Empty's Parent"), entry.path.front()); 160 EXPECT_EQ(ASCIIToUTF16("Empty's Parent"), entry.path.front());
220 161
221 entry = *it++; 162 entry = *it++;
222 EXPECT_EQ(ASCIIToUTF16("[Tamura Yukari.com]"), entry.title); 163 EXPECT_EQ(ASCIIToUTF16("[Tamura Yukari.com]"), entry.title);
223 EXPECT_FALSE(entry.is_folder); 164 EXPECT_FALSE(entry.is_folder);
224 EXPECT_EQ(base::Time::FromTimeT(1234567890), entry.creation_time); 165 EXPECT_EQ(base::Time::FromTimeT(1234567890), entry.creation_time);
225 EXPECT_EQ(1U, entry.path.size()); 166 EXPECT_EQ(1U, entry.path.size());
226 if (entry.path.size() == 1) 167 if (entry.path.size() == 1)
227 EXPECT_EQ(ASCIIToUTF16("Not Empty"), entry.path.front()); 168 EXPECT_EQ(ASCIIToUTF16("Not Empty"), entry.path.front());
228 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); 169 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec());
229 170
230 entry = *it++; 171 entry = *it++;
231 EXPECT_EQ(ASCIIToUTF16("Google"), entry.title); 172 EXPECT_EQ(ASCIIToUTF16("Google"), entry.title);
232 EXPECT_FALSE(entry.is_folder); 173 EXPECT_FALSE(entry.is_folder);
233 EXPECT_EQ(base::Time::FromTimeT(0000000000), entry.creation_time); 174 EXPECT_EQ(base::Time::FromTimeT(0000000000), entry.creation_time);
234 EXPECT_EQ(1U, entry.path.size()); 175 EXPECT_EQ(1U, entry.path.size());
235 if (entry.path.size() == 1) 176 if (entry.path.size() == 1)
236 EXPECT_EQ(ASCIIToUTF16("Not Empty But Default"), entry.path.front()); 177 EXPECT_EQ(ASCIIToUTF16("Not Empty But Default"), entry.path.front());
237 EXPECT_EQ("http://www.google.com/", entry.url.spec()); 178 EXPECT_EQ("http://www.google.com/", entry.url.spec());
238 } 179 }
239 180
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 181 // Import Epiphany bookmarks from a file
267 base::FilePath epiphany_path = path.AppendASCII("epiphany.html"); 182 base::FilePath epiphany_path = path.AppendASCII("epiphany.html");
268 bookmarks.clear(); 183 bookmarks.clear();
269 default_urls.clear(); 184 ImportBookmarksFile(base::Callback<bool(void)>(),
270 importer->ImportBookmarksFile(epiphany_path, default_urls, 185 base::Callback<bool(const GURL&)>(),
271 importer, &bookmarks, NULL, NULL); 186 epiphany_path, &bookmarks, NULL);
272 EXPECT_EQ(2U, bookmarks.size()); 187 EXPECT_EQ(2U, bookmarks.size());
273 if (bookmarks.size() == 2) { 188 if (bookmarks.size() == 2) {
274 it = bookmarks.begin(); 189 it = bookmarks.begin();
190 entry = *it++;
191 EXPECT_EQ(ASCIIToUTF16("[Tamura Yukari.com]"), entry.title);
192 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec());
193 EXPECT_EQ(0U, entry.path.size());
194 entry = *it++;
195 EXPECT_EQ(ASCIIToUTF16("Google"), entry.title);
196 EXPECT_EQ("http://www.google.com/", entry.url.spec());
197 EXPECT_EQ(0U, entry.path.size());
198 }
199
200 // Import Epiphany bookmarks from a file to bookmark bar.
gab 2013/05/14 02:19:22 I think the EXPECT block below is the same as the
201 bookmarks.clear();
202 ImportBookmarksFile(base::Callback<bool(void)>(),
203 base::Callback<bool(const GURL&)>(),
204 epiphany_path, &bookmarks, NULL);
205 EXPECT_EQ(2U, bookmarks.size());
206 if (bookmarks.size() == 2) {
207 it = bookmarks.begin();
275 entry = *it++; 208 entry = *it++;
276 EXPECT_EQ(ASCIIToUTF16("[Tamura Yukari.com]"), entry.title); 209 EXPECT_EQ(ASCIIToUTF16("[Tamura Yukari.com]"), entry.title);
277 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); 210 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec());
278 EXPECT_EQ(0U, entry.path.size()); 211 EXPECT_EQ(0U, entry.path.size());
279 entry = *it++; 212 entry = *it++;
280 EXPECT_EQ(ASCIIToUTF16("Google"), entry.title); 213 EXPECT_EQ(ASCIIToUTF16("Google"), entry.title);
281 EXPECT_EQ("http://www.google.com/", entry.url.spec()); 214 EXPECT_EQ("http://www.google.com/", entry.url.spec());
282 EXPECT_EQ(0U, entry.path.size()); 215 EXPECT_EQ(0U, entry.path.size());
283 } 216 }
217 }
284 218
285 // Import Epiphany bookmarks from a file to bookmark bar. 219 TEST(BookmarkHTMLReaderTest, Callbacks) {
220 base::FilePath path;
221 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path));
222 path = path.AppendASCII("bookmark_html_reader");
223
224 // Use a file for testing that has multiple bookmarks.
225 base::FilePath firefox2_path = path.AppendASCII("firefox2.html");
226
227 class CancelAfterFifteenCalls {
228 int count;
229 public:
230 CancelAfterFifteenCalls() : count(0) { }
231 bool ShouldCancel() {
232 return ++count > 16;
233 }
234 } cancel_fifteen;
235
236 std::vector<ImportedBookmarkEntry> bookmarks;
237 ImportBookmarksFile(base::Bind(&CancelAfterFifteenCalls::ShouldCancel,
238 base::Unretained(&cancel_fifteen)),
239 base::Callback<bool(const GURL&)>(),
240 firefox2_path, &bookmarks, NULL);
241 // The cancellation callback is checked before each line is read, so fifteen
242 // lines are imported. The first fifteen lines of firefox2.html include only
243 // one bookmark.
244 EXPECT_EQ(1U, bookmarks.size());
245 ImportedBookmarkEntry entry;
246 std::vector<ImportedBookmarkEntry>::iterator it;
247 if (bookmarks.size() == 1) {
248 it = bookmarks.begin();
249 entry = *it++;
gab 2013/05/14 02:19:22 nit: You can simplify this to entry = bookmarks[0]
250 EXPECT_EQ(ASCIIToUTF16("Empty"), entry.title);
251 EXPECT_TRUE(entry.is_folder);
252 EXPECT_EQ(base::Time::FromTimeT(1295938143), entry.creation_time);
253 EXPECT_EQ(1U, entry.path.size());
254 if (entry.path.size() == 1)
255 EXPECT_EQ(ASCIIToUTF16("Empty's Parent"), entry.path.front());
256 }
257
258 class InvalidDomain {
gab 2013/05/14 02:19:22 I think this should be a separate test, it doesn't
259 public:
260 static bool IsValid(const GURL& url) {
gab 2013/05/14 02:19:22 Add a method comment like: // Accepts all domains
261 return !url.DomainIs("tamurayukari.com");
262 }
263 };
264
286 bookmarks.clear(); 265 bookmarks.clear();
287 default_urls.clear(); 266 ImportBookmarksFile(base::Callback<bool(void)>(),
288 importer->ImportBookmarksFile(epiphany_path, default_urls, 267 base::Bind(&InvalidDomain::IsValid),
289 importer, &bookmarks, NULL, NULL); 268 firefox2_path, &bookmarks, NULL);
290 EXPECT_EQ(2U, bookmarks.size()); 269 EXPECT_EQ(2U, bookmarks.size());
291 if (bookmarks.size() == 2) { 270 if (bookmarks.size() == 2) {
292 it = bookmarks.begin(); 271 it = bookmarks.begin();
293 entry = *it++; 272 entry = *it++;
gab 2013/05/14 02:19:22 entry = bookmarks[0];
294 EXPECT_EQ(ASCIIToUTF16("[Tamura Yukari.com]"), entry.title); 273 EXPECT_EQ(ASCIIToUTF16("Empty"), entry.title);
gab 2013/05/14 02:19:22 These EXPECT blocks are duplicated all over the pl
295 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); 274 EXPECT_TRUE(entry.is_folder);
296 EXPECT_EQ(0U, entry.path.size()); 275 EXPECT_EQ(base::Time::FromTimeT(1295938143), entry.creation_time);
276 EXPECT_EQ(1U, entry.path.size());
277 if (entry.path.size() == 1)
278 EXPECT_EQ(ASCIIToUTF16("Empty's Parent"), entry.path.front());
279
297 entry = *it++; 280 entry = *it++;
gab 2013/05/14 02:19:22 entry = bookmarks[1];
298 EXPECT_EQ(ASCIIToUTF16("Google"), entry.title); 281 EXPECT_EQ(ASCIIToUTF16("Google"), entry.title);
282 EXPECT_FALSE(entry.is_folder);
283 EXPECT_EQ(base::Time::FromTimeT(0000000000), entry.creation_time);
284 EXPECT_EQ(1U, entry.path.size());
285 if (entry.path.size() == 1)
286 EXPECT_EQ(ASCIIToUTF16("Not Empty But Default"), entry.path.front());
299 EXPECT_EQ("http://www.google.com/", entry.url.spec()); 287 EXPECT_EQ("http://www.google.com/", entry.url.spec());
300 EXPECT_EQ(0U, entry.path.size());
301 } 288 }
289 }
302 290
303 importer->Release(); 291 } // namespace bookmark_html_reader
304 }
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_html_reader.cc ('k') | chrome/browser/bookmarks/bookmark_html_writer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698