| OLD | NEW |
| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 void ExpectThirdFirefox2Bookmark(const ImportedBookmarkEntry& entry); | 181 void ExpectThirdFirefox2Bookmark(const ImportedBookmarkEntry& entry); |
| 182 void ExpectFirstEpiphanyBookmark(const ImportedBookmarkEntry& entry); | 182 void ExpectFirstEpiphanyBookmark(const ImportedBookmarkEntry& entry); |
| 183 void ExpectSecondEpiphanyBookmark(const ImportedBookmarkEntry& entry); | 183 void ExpectSecondEpiphanyBookmark(const ImportedBookmarkEntry& entry); |
| 184 void ExpectFirstFirefox23Bookmark(const ImportedBookmarkEntry& entry); | 184 void ExpectFirstFirefox23Bookmark(const ImportedBookmarkEntry& entry); |
| 185 void ExpectSecondFirefox23Bookmark(const ImportedBookmarkEntry& entry); | 185 void ExpectSecondFirefox23Bookmark(const ImportedBookmarkEntry& entry); |
| 186 void ExpectThirdFirefox23Bookmark(const ImportedBookmarkEntry& entry); | 186 void ExpectThirdFirefox23Bookmark(const ImportedBookmarkEntry& entry); |
| 187 void ExpectFirstFirefoxBookmarkWithKeyword( | 187 void ExpectFirstFirefoxBookmarkWithKeyword( |
| 188 const importer::SearchEngineInfo& info); | 188 const importer::SearchEngineInfo& info); |
| 189 void ExpectSecondFirefoxBookmarkWithKeyword( | 189 void ExpectSecondFirefoxBookmarkWithKeyword( |
| 190 const importer::SearchEngineInfo& info); | 190 const importer::SearchEngineInfo& info); |
| 191 void ExpectFirstEmptyFolderBookmark(const ImportedBookmarkEntry& entry); |
| 192 void ExpectSecondEmptyFolderBookmark(const ImportedBookmarkEntry& entry); |
| 191 | 193 |
| 192 base::FilePath test_data_path_; | 194 base::FilePath test_data_path_; |
| 193 }; | 195 }; |
| 194 | 196 |
| 195 void BookmarkHTMLReaderTestWithData::SetUp() { | 197 void BookmarkHTMLReaderTestWithData::SetUp() { |
| 196 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_path_)); | 198 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_path_)); |
| 197 test_data_path_ = test_data_path_.AppendASCII("bookmark_html_reader"); | 199 test_data_path_ = test_data_path_.AppendASCII("bookmark_html_reader"); |
| 198 } | 200 } |
| 199 | 201 |
| 200 void BookmarkHTMLReaderTestWithData::ExpectFirstFirefox2Bookmark( | 202 void BookmarkHTMLReaderTestWithData::ExpectFirstFirefox2Bookmark( |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 EXPECT_EQ(ASCIIToUTF16("Bookmark Keyword"), info.display_name); | 281 EXPECT_EQ(ASCIIToUTF16("Bookmark Keyword"), info.display_name); |
| 280 } | 282 } |
| 281 | 283 |
| 282 void BookmarkHTMLReaderTestWithData::ExpectSecondFirefoxBookmarkWithKeyword( | 284 void BookmarkHTMLReaderTestWithData::ExpectSecondFirefoxBookmarkWithKeyword( |
| 283 const importer::SearchEngineInfo& info) { | 285 const importer::SearchEngineInfo& info) { |
| 284 EXPECT_EQ(ASCIIToUTF16("http://example.com/?q={searchTerms}"), info.url); | 286 EXPECT_EQ(ASCIIToUTF16("http://example.com/?q={searchTerms}"), info.url); |
| 285 EXPECT_EQ(ASCIIToUTF16("keyword"), info.keyword); | 287 EXPECT_EQ(ASCIIToUTF16("keyword"), info.keyword); |
| 286 EXPECT_EQ(ASCIIToUTF16("BookmarkName"), info.display_name); | 288 EXPECT_EQ(ASCIIToUTF16("BookmarkName"), info.display_name); |
| 287 } | 289 } |
| 288 | 290 |
| 291 void BookmarkHTMLReaderTestWithData::ExpectFirstEmptyFolderBookmark( |
| 292 const ImportedBookmarkEntry& entry) { |
| 293 EXPECT_EQ(base::string16(), entry.title); |
| 294 EXPECT_TRUE(entry.is_folder); |
| 295 EXPECT_EQ(base::Time::FromTimeT(1295938143), entry.creation_time); |
| 296 EXPECT_EQ(1U, entry.path.size()); |
| 297 if (entry.path.size() == 1) |
| 298 EXPECT_EQ(ASCIIToUTF16("Empty's Parent"), entry.path.front()); |
| 299 } |
| 300 |
| 301 void BookmarkHTMLReaderTestWithData::ExpectSecondEmptyFolderBookmark( |
| 302 const ImportedBookmarkEntry& entry) { |
| 303 EXPECT_EQ(ASCIIToUTF16("[Tamura Yukari.com]"), entry.title); |
| 304 EXPECT_FALSE(entry.is_folder); |
| 305 EXPECT_EQ(base::Time::FromTimeT(1234567890), entry.creation_time); |
| 306 EXPECT_EQ(1U, entry.path.size()); |
| 307 if (entry.path.size() == 1) |
| 308 EXPECT_EQ(base::string16(), entry.path.front()); |
| 309 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); |
| 310 } |
| 311 |
| 289 } // namespace | 312 } // namespace |
| 290 | 313 |
| 291 TEST_F(BookmarkHTMLReaderTestWithData, Firefox2BookmarkFileImport) { | 314 TEST_F(BookmarkHTMLReaderTestWithData, Firefox2BookmarkFileImport) { |
| 292 base::FilePath path = test_data_path_.AppendASCII("firefox2.html"); | 315 base::FilePath path = test_data_path_.AppendASCII("firefox2.html"); |
| 293 | 316 |
| 294 std::vector<ImportedBookmarkEntry> bookmarks; | 317 std::vector<ImportedBookmarkEntry> bookmarks; |
| 295 ImportBookmarksFile(base::Callback<bool(void)>(), | 318 ImportBookmarksFile(base::Callback<bool(void)>(), |
| 296 base::Callback<bool(const GURL&)>(), | 319 base::Callback<bool(const GURL&)>(), |
| 297 path, &bookmarks, NULL, NULL); | 320 path, &bookmarks, NULL, NULL); |
| 298 | 321 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 std::vector<importer::SearchEngineInfo> search_engines; | 359 std::vector<importer::SearchEngineInfo> search_engines; |
| 337 ImportBookmarksFile(base::Callback<bool(void)>(), | 360 ImportBookmarksFile(base::Callback<bool(void)>(), |
| 338 base::Callback<bool(const GURL&)>(), | 361 base::Callback<bool(const GURL&)>(), |
| 339 path, NULL, &search_engines, NULL); | 362 path, NULL, &search_engines, NULL); |
| 340 | 363 |
| 341 ASSERT_EQ(2U, search_engines.size()); | 364 ASSERT_EQ(2U, search_engines.size()); |
| 342 ExpectFirstFirefoxBookmarkWithKeyword(search_engines[0]); | 365 ExpectFirstFirefoxBookmarkWithKeyword(search_engines[0]); |
| 343 ExpectSecondFirefoxBookmarkWithKeyword(search_engines[1]); | 366 ExpectSecondFirefoxBookmarkWithKeyword(search_engines[1]); |
| 344 } | 367 } |
| 345 | 368 |
| 369 TEST_F(BookmarkHTMLReaderTestWithData, EmptyFolderImport) { |
| 370 base::FilePath path = test_data_path_.AppendASCII("empty_folder.html"); |
| 371 |
| 372 std::vector<ImportedBookmarkEntry> bookmarks; |
| 373 ImportBookmarksFile(base::Callback<bool(void)>(), |
| 374 base::Callback<bool(const GURL&)>(), path, &bookmarks, |
| 375 NULL, NULL); |
| 376 |
| 377 ASSERT_EQ(3U, bookmarks.size()); |
| 378 ExpectFirstEmptyFolderBookmark(bookmarks[0]); |
| 379 ExpectSecondEmptyFolderBookmark(bookmarks[1]); |
| 380 ExpectThirdFirefox2Bookmark(bookmarks[2]); |
| 381 } |
| 382 |
| 346 TEST_F(BookmarkHTMLReaderTestWithData, | 383 TEST_F(BookmarkHTMLReaderTestWithData, |
| 347 RedditSaverFileImport) { | 384 RedditSaverFileImport) { |
| 348 base::FilePath path = test_data_path_.AppendASCII("redditsaver.html"); | 385 base::FilePath path = test_data_path_.AppendASCII("redditsaver.html"); |
| 349 | 386 |
| 350 std::vector<ImportedBookmarkEntry> bookmarks; | 387 std::vector<ImportedBookmarkEntry> bookmarks; |
| 351 ImportBookmarksFile(base::Callback<bool(void)>(), | 388 ImportBookmarksFile(base::Callback<bool(void)>(), |
| 352 base::Callback<bool(const GURL&)>(), | 389 base::Callback<bool(const GURL&)>(), |
| 353 path, &bookmarks, NULL, NULL); | 390 path, &bookmarks, NULL, NULL); |
| 354 | 391 |
| 355 ASSERT_EQ(2U, bookmarks.size()); | 392 ASSERT_EQ(2U, bookmarks.size()); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 ImportBookmarksFile(base::Callback<bool(void)>(), | 460 ImportBookmarksFile(base::Callback<bool(void)>(), |
| 424 base::Bind(&IsURLValid), | 461 base::Bind(&IsURLValid), |
| 425 path, &bookmarks, NULL, NULL); | 462 path, &bookmarks, NULL, NULL); |
| 426 | 463 |
| 427 ASSERT_EQ(2U, bookmarks.size()); | 464 ASSERT_EQ(2U, bookmarks.size()); |
| 428 ExpectFirstFirefox2Bookmark(bookmarks[0]); | 465 ExpectFirstFirefox2Bookmark(bookmarks[0]); |
| 429 ExpectThirdFirefox2Bookmark(bookmarks[1]); | 466 ExpectThirdFirefox2Bookmark(bookmarks[1]); |
| 430 } | 467 } |
| 431 | 468 |
| 432 } // namespace bookmark_html_reader | 469 } // namespace bookmark_html_reader |
| OLD | NEW |