OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 } | 185 } |
186 | 186 |
187 TEST(FirefoxImporterTest, Firefox2BookmarkFileImport) { | 187 TEST(FirefoxImporterTest, Firefox2BookmarkFileImport) { |
188 FilePath path; | 188 FilePath path; |
189 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); | 189 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); |
190 path = path.AppendASCII("firefox2_importer"); | 190 path = path.AppendASCII("firefox2_importer"); |
191 | 191 |
192 // Import all bookmarks from a file which include an empty folder entry. | 192 // Import all bookmarks from a file which include an empty folder entry. |
193 FilePath empty_folder_path = path.AppendASCII("empty_folder.html"); | 193 FilePath empty_folder_path = path.AppendASCII("empty_folder.html"); |
194 std::set<GURL> default_urls; | 194 std::set<GURL> default_urls; |
195 string16 first_folder_name = ASCIIToUTF16("xyzzy"); | |
196 Firefox2Importer* importer = new Firefox2Importer(); | 195 Firefox2Importer* importer = new Firefox2Importer(); |
197 importer->AddRef(); | 196 importer->AddRef(); |
198 std::vector<ProfileWriter::BookmarkEntry> bookmarks; | 197 std::vector<ProfileWriter::BookmarkEntry> bookmarks; |
199 importer->ImportBookmarksFile(empty_folder_path, default_urls, false, | 198 importer->ImportBookmarksFile(empty_folder_path, default_urls, |
200 first_folder_name, importer, &bookmarks, | 199 importer, &bookmarks, NULL, NULL); |
201 NULL, NULL); | 200 EXPECT_EQ(3U, bookmarks.size()); |
202 EXPECT_EQ(3, static_cast<int>(bookmarks.size())); | |
203 std::vector<ProfileWriter::BookmarkEntry>::iterator it; | 201 std::vector<ProfileWriter::BookmarkEntry>::iterator it; |
204 ProfileWriter::BookmarkEntry entry; | 202 ProfileWriter::BookmarkEntry entry; |
205 std::vector<string16>::iterator path_it; | 203 std::vector<string16>::iterator path_it; |
206 if (bookmarks.size() == 3) { | 204 if (bookmarks.size() == 3) { |
207 it = bookmarks.begin(); | 205 it = bookmarks.begin(); |
208 entry = *it++; | 206 entry = *it++; |
209 EXPECT_EQ(ASCIIToUTF16("Empty"), entry.title); | 207 EXPECT_EQ(ASCIIToUTF16("Empty"), entry.title); |
210 EXPECT_TRUE(entry.is_folder); | 208 EXPECT_TRUE(entry.is_folder); |
211 EXPECT_EQ(base::Time::FromTimeT(1295938143), entry.creation_time); | 209 EXPECT_EQ(base::Time::FromTimeT(1295938143), entry.creation_time); |
212 EXPECT_EQ(2, static_cast<int>(entry.path.size())); | 210 EXPECT_EQ(1U, entry.path.size()); |
213 if (entry.path.size() == 2) { | 211 if (entry.path.size() == 1) |
214 path_it = entry.path.begin(); | 212 EXPECT_EQ(ASCIIToUTF16("Empty's Parent"), entry.path.front()); |
215 EXPECT_EQ(ASCIIToUTF16("xyzzy"), *path_it++); | |
216 EXPECT_EQ(ASCIIToUTF16("Empty's Parent"), *path_it); | |
217 } | |
218 | 213 |
219 entry = *it++; | 214 entry = *it++; |
220 EXPECT_EQ(ASCIIToUTF16("[Tamura Yukari.com]"), entry.title); | 215 EXPECT_EQ(ASCIIToUTF16("[Tamura Yukari.com]"), entry.title); |
221 EXPECT_FALSE(entry.is_folder); | 216 EXPECT_FALSE(entry.is_folder); |
222 EXPECT_EQ(base::Time::FromTimeT(1234567890), entry.creation_time); | 217 EXPECT_EQ(base::Time::FromTimeT(1234567890), entry.creation_time); |
223 EXPECT_EQ(2, static_cast<int>(entry.path.size())); | 218 EXPECT_EQ(1U, entry.path.size()); |
224 if (entry.path.size() == 2) { | 219 if (entry.path.size() == 1) |
225 path_it = entry.path.begin(); | 220 EXPECT_EQ(ASCIIToUTF16("Not Empty"), entry.path.front()); |
226 EXPECT_EQ(ASCIIToUTF16("xyzzy"), *path_it++); | |
227 EXPECT_EQ(ASCIIToUTF16("Not Empty"), *path_it); | |
228 } | |
229 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); | 221 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); |
230 | 222 |
231 entry = *it++; | 223 entry = *it++; |
232 EXPECT_EQ(ASCIIToUTF16("Google"), entry.title); | 224 EXPECT_EQ(ASCIIToUTF16("Google"), entry.title); |
233 EXPECT_FALSE(entry.is_folder); | 225 EXPECT_FALSE(entry.is_folder); |
234 EXPECT_EQ(base::Time::FromTimeT(0000000000), entry.creation_time); | 226 EXPECT_EQ(base::Time::FromTimeT(0000000000), entry.creation_time); |
235 EXPECT_EQ(2, static_cast<int>(entry.path.size())); | 227 EXPECT_EQ(1U, entry.path.size()); |
236 if (entry.path.size() == 2) { | 228 if (entry.path.size() == 1) |
237 path_it = entry.path.begin(); | 229 EXPECT_EQ(ASCIIToUTF16("Not Empty But Default"), entry.path.front()); |
238 EXPECT_EQ(ASCIIToUTF16("xyzzy"), *path_it++); | |
239 EXPECT_EQ(ASCIIToUTF16("Not Empty But Default"), *path_it); | |
240 } | |
241 EXPECT_EQ("http://www.google.com/", entry.url.spec()); | 230 EXPECT_EQ("http://www.google.com/", entry.url.spec()); |
242 } | 231 } |
243 | 232 |
244 // Import non-default bookmarks from a file. | 233 // Import non-default bookmarks from a file. |
245 bookmarks.clear(); | 234 bookmarks.clear(); |
246 default_urls.insert(GURL("http://www.google.com/")); | 235 default_urls.insert(GURL("http://www.google.com/")); |
247 importer->ImportBookmarksFile(empty_folder_path, default_urls, false, | 236 importer->ImportBookmarksFile(empty_folder_path, default_urls, |
248 first_folder_name, importer, &bookmarks, | 237 importer, &bookmarks, NULL, NULL); |
249 NULL, NULL); | 238 EXPECT_EQ(2U, bookmarks.size()); |
250 EXPECT_EQ(2, static_cast<int>(bookmarks.size())); | |
251 if (bookmarks.size() == 2) { | 239 if (bookmarks.size() == 2) { |
252 it = bookmarks.begin(); | 240 it = bookmarks.begin(); |
253 entry = *it++; | 241 entry = *it++; |
254 EXPECT_EQ(ASCIIToUTF16("Empty"), entry.title); | 242 EXPECT_EQ(ASCIIToUTF16("Empty"), entry.title); |
255 EXPECT_TRUE(entry.is_folder); | 243 EXPECT_TRUE(entry.is_folder); |
256 EXPECT_EQ(base::Time::FromTimeT(1295938143), entry.creation_time); | 244 EXPECT_EQ(base::Time::FromTimeT(1295938143), entry.creation_time); |
257 EXPECT_EQ(2, static_cast<int>(entry.path.size())); | 245 EXPECT_EQ(1U, entry.path.size()); |
258 if (entry.path.size() == 2) { | 246 if (entry.path.size() == 1) |
259 path_it = entry.path.begin(); | 247 EXPECT_EQ(ASCIIToUTF16("Empty's Parent"), entry.path.front()); |
260 EXPECT_EQ(ASCIIToUTF16("xyzzy"), *path_it++); | |
261 EXPECT_EQ(ASCIIToUTF16("Empty's Parent"), *path_it); | |
262 } | |
263 | 248 |
264 entry = *it++; | 249 entry = *it++; |
265 EXPECT_EQ(ASCIIToUTF16("[Tamura Yukari.com]"), entry.title); | 250 EXPECT_EQ(ASCIIToUTF16("[Tamura Yukari.com]"), entry.title); |
266 EXPECT_FALSE(entry.is_folder); | 251 EXPECT_FALSE(entry.is_folder); |
267 EXPECT_EQ(base::Time::FromTimeT(1234567890), entry.creation_time); | 252 EXPECT_EQ(base::Time::FromTimeT(1234567890), entry.creation_time); |
268 EXPECT_EQ(2, static_cast<int>(entry.path.size())); | 253 EXPECT_EQ(1U, entry.path.size()); |
269 if (entry.path.size() == 2) { | 254 if (entry.path.size() == 1) |
270 path_it = entry.path.begin(); | 255 EXPECT_EQ(ASCIIToUTF16("Not Empty"), entry.path.front()); |
271 EXPECT_EQ(ASCIIToUTF16("xyzzy"), *path_it++); | |
272 EXPECT_EQ(ASCIIToUTF16("Not Empty"), *path_it); | |
273 } | |
274 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); | 256 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); |
275 } | 257 } |
276 | 258 |
277 // Import Epiphany bookmarks from a file | 259 // Import Epiphany bookmarks from a file |
278 FilePath epiphany_path = path.AppendASCII("epiphany.html"); | 260 FilePath epiphany_path = path.AppendASCII("epiphany.html"); |
279 bookmarks.clear(); | 261 bookmarks.clear(); |
280 default_urls.clear(); | 262 default_urls.clear(); |
281 importer->ImportBookmarksFile(epiphany_path, default_urls, false, | 263 importer->ImportBookmarksFile(epiphany_path, default_urls, |
282 first_folder_name, importer, &bookmarks, | 264 importer, &bookmarks, NULL, NULL); |
283 NULL, NULL); | 265 EXPECT_EQ(2U, bookmarks.size()); |
284 EXPECT_EQ(2, static_cast<int>(bookmarks.size())); | |
285 if (bookmarks.size() == 2) { | 266 if (bookmarks.size() == 2) { |
286 it = bookmarks.begin(); | 267 it = bookmarks.begin(); |
287 entry = *it++; | 268 entry = *it++; |
288 EXPECT_EQ(ASCIIToUTF16("[Tamura Yukari.com]"), entry.title); | 269 EXPECT_EQ(ASCIIToUTF16("[Tamura Yukari.com]"), entry.title); |
289 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); | 270 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); |
290 EXPECT_EQ(1, static_cast<int>(entry.path.size())); | 271 EXPECT_EQ(0U, entry.path.size()); |
291 if (entry.path.size() == 1) { | |
292 path_it = entry.path.begin(); | |
293 EXPECT_EQ(ASCIIToUTF16("xyzzy"), *path_it); | |
294 } | |
295 entry = *it++; | 272 entry = *it++; |
296 EXPECT_EQ(ASCIIToUTF16("Google"), entry.title); | 273 EXPECT_EQ(ASCIIToUTF16("Google"), entry.title); |
297 EXPECT_EQ("http://www.google.com/", entry.url.spec()); | 274 EXPECT_EQ("http://www.google.com/", entry.url.spec()); |
298 EXPECT_EQ(1, static_cast<int>(entry.path.size())); | 275 EXPECT_EQ(0U, entry.path.size()); |
299 if (entry.path.size() == 1) { | |
300 path_it = entry.path.begin(); | |
301 EXPECT_EQ(ASCIIToUTF16("xyzzy"), *path_it); | |
302 } | |
303 } | 276 } |
304 | 277 |
305 // Import Epiphany bookmarks from a file to bookmark bar. | 278 // Import Epiphany bookmarks from a file to bookmark bar. |
306 bookmarks.clear(); | 279 bookmarks.clear(); |
307 default_urls.clear(); | 280 default_urls.clear(); |
308 importer->ImportBookmarksFile(epiphany_path, default_urls, true, | 281 importer->ImportBookmarksFile(epiphany_path, default_urls, |
309 first_folder_name, importer, &bookmarks, | 282 importer, &bookmarks, NULL, NULL); |
310 NULL, NULL); | 283 EXPECT_EQ(2U, bookmarks.size()); |
311 EXPECT_EQ(2, static_cast<int>(bookmarks.size())); | |
312 if (bookmarks.size() == 2) { | 284 if (bookmarks.size() == 2) { |
313 it = bookmarks.begin(); | 285 it = bookmarks.begin(); |
314 entry = *it++; | 286 entry = *it++; |
315 EXPECT_EQ(ASCIIToUTF16("[Tamura Yukari.com]"), entry.title); | 287 EXPECT_EQ(ASCIIToUTF16("[Tamura Yukari.com]"), entry.title); |
316 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); | 288 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); |
317 EXPECT_EQ(0, static_cast<int>(entry.path.size())); | 289 EXPECT_EQ(0U, entry.path.size()); |
318 entry = *it++; | 290 entry = *it++; |
319 EXPECT_EQ(ASCIIToUTF16("Google"), entry.title); | 291 EXPECT_EQ(ASCIIToUTF16("Google"), entry.title); |
320 EXPECT_EQ("http://www.google.com/", entry.url.spec()); | 292 EXPECT_EQ("http://www.google.com/", entry.url.spec()); |
321 EXPECT_EQ(0, static_cast<int>(entry.path.size())); | 293 EXPECT_EQ(0U, entry.path.size()); |
322 } | 294 } |
323 | 295 |
324 importer->Release(); | 296 importer->Release(); |
325 } | 297 } |
OLD | NEW |