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

Side by Side Diff: chrome/utility/importer/bookmark_html_reader_unittest.cc

Issue 616763002: Importing certain bookmarks from firefox and HTML file as search engines. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
OLDNEW
1 // Copyright 2013 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 "chrome/utility/importer/bookmark_html_reader.h" 5 #include "chrome/utility/importer/bookmark_html_reader.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 } 237 }
238 238
239 } // namespace 239 } // namespace
240 240
241 TEST_F(BookmarkHTMLReaderTestWithData, Firefox2BookmarkFileImport) { 241 TEST_F(BookmarkHTMLReaderTestWithData, Firefox2BookmarkFileImport) {
242 base::FilePath path = test_data_path_.AppendASCII("firefox2.html"); 242 base::FilePath path = test_data_path_.AppendASCII("firefox2.html");
243 243
244 std::vector<ImportedBookmarkEntry> bookmarks; 244 std::vector<ImportedBookmarkEntry> bookmarks;
245 ImportBookmarksFile(base::Callback<bool(void)>(), 245 ImportBookmarksFile(base::Callback<bool(void)>(),
246 base::Callback<bool(const GURL&)>(), 246 base::Callback<bool(const GURL&)>(),
247 path, &bookmarks, NULL); 247 path, &bookmarks, NULL, NULL);
248 248
249 ASSERT_EQ(3U, bookmarks.size()); 249 ASSERT_EQ(3U, bookmarks.size());
250 ExpectFirstFirefox2Bookmark(bookmarks[0]); 250 ExpectFirstFirefox2Bookmark(bookmarks[0]);
251 ExpectSecondFirefox2Bookmark(bookmarks[1]); 251 ExpectSecondFirefox2Bookmark(bookmarks[1]);
252 ExpectThirdFirefox2Bookmark(bookmarks[2]); 252 ExpectThirdFirefox2Bookmark(bookmarks[2]);
253 } 253 }
254 254
255 TEST_F(BookmarkHTMLReaderTestWithData, BookmarkFileWithHrTagImport) { 255 TEST_F(BookmarkHTMLReaderTestWithData, BookmarkFileWithHrTagImport) {
256 base::FilePath path = test_data_path_.AppendASCII("firefox23.html"); 256 base::FilePath path = test_data_path_.AppendASCII("firefox23.html");
257 257
258 std::vector<ImportedBookmarkEntry> bookmarks; 258 std::vector<ImportedBookmarkEntry> bookmarks;
259 ImportBookmarksFile(base::Callback<bool(void)>(), 259 ImportBookmarksFile(base::Callback<bool(void)>(),
260 base::Callback<bool(const GURL&)>(), 260 base::Callback<bool(const GURL&)>(),
261 path, &bookmarks, NULL); 261 path, &bookmarks, NULL, NULL);
262 262
263 ASSERT_EQ(3U, bookmarks.size()); 263 ASSERT_EQ(3U, bookmarks.size());
264 ExpectFirstFirefox23Bookmark(bookmarks[0]); 264 ExpectFirstFirefox23Bookmark(bookmarks[0]);
265 ExpectSecondFirefox23Bookmark(bookmarks[1]); 265 ExpectSecondFirefox23Bookmark(bookmarks[1]);
266 ExpectThirdFirefox23Bookmark(bookmarks[2]); 266 ExpectThirdFirefox23Bookmark(bookmarks[2]);
267 } 267 }
268 268
269 TEST_F(BookmarkHTMLReaderTestWithData, EpiphanyBookmarkFileImport) { 269 TEST_F(BookmarkHTMLReaderTestWithData, EpiphanyBookmarkFileImport) {
270 base::FilePath path = test_data_path_.AppendASCII("epiphany.html"); 270 base::FilePath path = test_data_path_.AppendASCII("epiphany.html");
271 271
272 std::vector<ImportedBookmarkEntry> bookmarks; 272 std::vector<ImportedBookmarkEntry> bookmarks;
273 ImportBookmarksFile(base::Callback<bool(void)>(), 273 ImportBookmarksFile(base::Callback<bool(void)>(),
274 base::Callback<bool(const GURL&)>(), 274 base::Callback<bool(const GURL&)>(),
275 path, &bookmarks, NULL); 275 path, &bookmarks, NULL, NULL);
276 276
277 ASSERT_EQ(2U, bookmarks.size()); 277 ASSERT_EQ(2U, bookmarks.size());
278 ExpectFirstEpiphanyBookmark(bookmarks[0]); 278 ExpectFirstEpiphanyBookmark(bookmarks[0]);
279 ExpectSecondEpiphanyBookmark(bookmarks[1]); 279 ExpectSecondEpiphanyBookmark(bookmarks[1]);
280 } 280 }
281 281
282 namespace { 282 namespace {
283 283
284 class CancelAfterFifteenCalls { 284 class CancelAfterFifteenCalls {
285 int count; 285 int count;
286 public: 286 public:
287 CancelAfterFifteenCalls() : count(0) { } 287 CancelAfterFifteenCalls() : count(0) { }
288 bool ShouldCancel() { 288 bool ShouldCancel() {
289 return ++count > 16; 289 return ++count > 16;
290 } 290 }
291 }; 291 };
292 292
293 } // namespace 293 } // namespace
294 294
295 TEST_F(BookmarkHTMLReaderTestWithData, CancellationCallback) { 295 TEST_F(BookmarkHTMLReaderTestWithData, CancellationCallback) {
296 // Use a file for testing that has multiple bookmarks. 296 // Use a file for testing that has multiple bookmarks.
297 base::FilePath path = test_data_path_.AppendASCII("firefox2.html"); 297 base::FilePath path = test_data_path_.AppendASCII("firefox2.html");
298 298
299 std::vector<ImportedBookmarkEntry> bookmarks; 299 std::vector<ImportedBookmarkEntry> bookmarks;
300 CancelAfterFifteenCalls cancel_fifteen; 300 CancelAfterFifteenCalls cancel_fifteen;
301 ImportBookmarksFile(base::Bind(&CancelAfterFifteenCalls::ShouldCancel, 301 ImportBookmarksFile(base::Bind(&CancelAfterFifteenCalls::ShouldCancel,
302 base::Unretained(&cancel_fifteen)), 302 base::Unretained(&cancel_fifteen)),
303 base::Callback<bool(const GURL&)>(), 303 base::Callback<bool(const GURL&)>(),
304 path, &bookmarks, NULL); 304 path, &bookmarks, NULL, NULL);
305 305
306 // The cancellation callback is checked before each line is read, so fifteen 306 // The cancellation callback is checked before each line is read, so fifteen
307 // lines are imported. The first fifteen lines of firefox2.html include only 307 // lines are imported. The first fifteen lines of firefox2.html include only
308 // one bookmark. 308 // one bookmark.
309 ASSERT_EQ(1U, bookmarks.size()); 309 ASSERT_EQ(1U, bookmarks.size());
310 ExpectFirstFirefox2Bookmark(bookmarks[0]); 310 ExpectFirstFirefox2Bookmark(bookmarks[0]);
311 } 311 }
312 312
313 namespace { 313 namespace {
314 314
315 bool IsURLValid(const GURL& url) { 315 bool IsURLValid(const GURL& url) {
316 // No offense to whomever owns this domain... 316 // No offense to whomever owns this domain...
317 return !url.DomainIs("tamurayukari.com"); 317 return !url.DomainIs("tamurayukari.com");
318 } 318 }
319 319
320 } // namespace 320 } // namespace
321 321
322 TEST_F(BookmarkHTMLReaderTestWithData, ValidURLCallback) { 322 TEST_F(BookmarkHTMLReaderTestWithData, ValidURLCallback) {
323 // Use a file for testing that has multiple bookmarks. 323 // Use a file for testing that has multiple bookmarks.
324 base::FilePath path = test_data_path_.AppendASCII("firefox2.html"); 324 base::FilePath path = test_data_path_.AppendASCII("firefox2.html");
325 325
326 std::vector<ImportedBookmarkEntry> bookmarks; 326 std::vector<ImportedBookmarkEntry> bookmarks;
327 ImportBookmarksFile(base::Callback<bool(void)>(), 327 ImportBookmarksFile(base::Callback<bool(void)>(),
328 base::Bind(&IsURLValid), 328 base::Bind(&IsURLValid),
329 path, &bookmarks, NULL); 329 path, &bookmarks, NULL, NULL);
330 330
331 ASSERT_EQ(2U, bookmarks.size()); 331 ASSERT_EQ(2U, bookmarks.size());
332 ExpectFirstFirefox2Bookmark(bookmarks[0]); 332 ExpectFirstFirefox2Bookmark(bookmarks[0]);
333 ExpectThirdFirefox2Bookmark(bookmarks[1]); 333 ExpectThirdFirefox2Bookmark(bookmarks[1]);
334 } 334 }
335 335
336 } // namespace bookmark_html_reader 336 } // namespace bookmark_html_reader
Ilya Sherman 2014/09/30 20:54:12 Please add test coverage for your changes.
Tapu Ghose 2014/10/07 02:02:44 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698