Chromium Code Reviews| Index: chrome/utility/importer/bookmark_html_reader_unittest.cc |
| diff --git a/chrome/utility/importer/bookmark_html_reader_unittest.cc b/chrome/utility/importer/bookmark_html_reader_unittest.cc |
| index fd68f5470fafb05c2d629ca4c4c881baebb286f8..37f15fded80a6fcc51391ec41f8a6e100a24ebe2 100644 |
| --- a/chrome/utility/importer/bookmark_html_reader_unittest.cc |
| +++ b/chrome/utility/importer/bookmark_html_reader_unittest.cc |
| @@ -137,6 +137,40 @@ TEST(BookmarkHTMLReaderTest, ParseTests) { |
| EXPECT_EQ("http://www.google.com/", url.spec()); |
| } |
| +TEST(BookmarkHTMLReaderTest, CanImportURLAsSearchEngineTest) { |
| + struct TestCase { |
| + const std::string url; |
| + const base::string16 keyword; |
| + const base::string16 title; |
| + const bool can_be_imported_as_search_engine; |
| + } test_cases[] = { |
| + { |
| + "http://www.example.%s.com", |
| + base::UTF8ToUTF16("keyword1"), |
| + base::UTF8ToUTF16("title1"), |
|
Ilya Sherman
2014/11/10 23:00:22
nit: Looks like you could omit the keyword and tit
Ilya Sherman
2014/11/10 23:00:22
nit: Please use ASCIIToUTF16; below as well.
Tapu Ghose
2014/11/15 05:22:20
Removed keyword and title from test cases.
Tapu Ghose
2014/11/15 05:22:20
Acknowledged.
|
| + true |
| + }, |
| + { |
| + "http://www.example.com", |
| + base::UTF8ToUTF16("keyword1"), |
| + base::UTF8ToUTF16("title1"), |
| + false |
| + }, |
|
Ilya Sherman
2014/11/10 23:00:22
Please also test: (1) and empty URL, (2) a URL tha
Tapu Ghose
2014/11/15 05:22:20
Done.
|
| + }; |
| + |
| + importer::SearchEngineInfo search_engine; |
| + for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| + EXPECT_EQ(test_cases[i].can_be_imported_as_search_engine, |
|
Ilya Sherman
2014/11/10 23:00:22
nit: Please either wrap the arg, or align the subs
Tapu Ghose
2014/11/15 05:22:20
Done.
|
| + CanImportURLAsSearchEngine( |
| + GURL(test_cases[i].url), |
| + test_cases[i].keyword, |
| + test_cases[i].title, |
| + &search_engine)); |
| + EXPECT_EQ(test_cases[i].keyword, search_engine.keyword); |
| + EXPECT_EQ(test_cases[i].title, search_engine.display_name); |
| + } |
| +} |
| + |
| namespace { |
| class BookmarkHTMLReaderTestWithData : public testing::Test { |
| @@ -152,6 +186,10 @@ class BookmarkHTMLReaderTestWithData : public testing::Test { |
| void ExpectFirstFirefox23Bookmark(const ImportedBookmarkEntry& entry); |
| void ExpectSecondFirefox23Bookmark(const ImportedBookmarkEntry& entry); |
| void ExpectThirdFirefox23Bookmark(const ImportedBookmarkEntry& entry); |
| + void ExpectFirstFirefoxBookmarkWithKeyword( |
| + const importer::SearchEngineInfo& info); |
| + void ExpectSecondFirefoxBookmarkWithKeyword( |
| + const importer::SearchEngineInfo& info); |
| base::FilePath test_data_path_; |
| }; |
| @@ -236,6 +274,20 @@ void BookmarkHTMLReaderTestWithData::ExpectThirdFirefox23Bookmark( |
| EXPECT_EQ("http://code.google.com/p/chromium/codesearch", entry.url.spec()); |
| } |
| +void BookmarkHTMLReaderTestWithData::ExpectFirstFirefoxBookmarkWithKeyword( |
| + const importer::SearchEngineInfo& info) { |
| + EXPECT_EQ(ASCIIToUTF16("http://example.%s.com/"), info.url); |
| + EXPECT_EQ(ASCIIToUTF16("keyword"), info.keyword); |
| + EXPECT_EQ(ASCIIToUTF16("Bookmark Keyword"), info.display_name); |
| +} |
| + |
| +void BookmarkHTMLReaderTestWithData::ExpectSecondFirefoxBookmarkWithKeyword( |
| + const importer::SearchEngineInfo& info) { |
| + EXPECT_EQ(ASCIIToUTF16("http://example.com/?q=%s"), info.url); |
| + EXPECT_EQ(ASCIIToUTF16("keyword"), info.keyword); |
| + EXPECT_EQ(ASCIIToUTF16("BookmarkName"), info.display_name); |
| +} |
| + |
| } // namespace |
| TEST_F(BookmarkHTMLReaderTestWithData, Firefox2BookmarkFileImport) { |
| @@ -244,7 +296,7 @@ TEST_F(BookmarkHTMLReaderTestWithData, Firefox2BookmarkFileImport) { |
| std::vector<ImportedBookmarkEntry> bookmarks; |
| ImportBookmarksFile(base::Callback<bool(void)>(), |
| base::Callback<bool(const GURL&)>(), |
| - path, &bookmarks, NULL); |
| + path, &bookmarks, NULL, NULL); |
| ASSERT_EQ(3U, bookmarks.size()); |
| ExpectFirstFirefox2Bookmark(bookmarks[0]); |
| @@ -258,7 +310,7 @@ TEST_F(BookmarkHTMLReaderTestWithData, BookmarkFileWithHrTagImport) { |
| std::vector<ImportedBookmarkEntry> bookmarks; |
| ImportBookmarksFile(base::Callback<bool(void)>(), |
| base::Callback<bool(const GURL&)>(), |
| - path, &bookmarks, NULL); |
| + path, &bookmarks, NULL, NULL); |
| ASSERT_EQ(3U, bookmarks.size()); |
| ExpectFirstFirefox23Bookmark(bookmarks[0]); |
| @@ -272,13 +324,27 @@ TEST_F(BookmarkHTMLReaderTestWithData, EpiphanyBookmarkFileImport) { |
| std::vector<ImportedBookmarkEntry> bookmarks; |
| ImportBookmarksFile(base::Callback<bool(void)>(), |
| base::Callback<bool(const GURL&)>(), |
| - path, &bookmarks, NULL); |
| + path, &bookmarks, NULL, NULL); |
| ASSERT_EQ(2U, bookmarks.size()); |
| ExpectFirstEpiphanyBookmark(bookmarks[0]); |
| ExpectSecondEpiphanyBookmark(bookmarks[1]); |
| } |
| +TEST_F(BookmarkHTMLReaderTestWithData, FirefoxBookmarkFileWithKeywordImport) { |
| + base::FilePath path = test_data_path_.AppendASCII( |
| + "firefox_bookmark_keyword.html"); |
| + |
| + std::vector<importer::SearchEngineInfo> search_engines; |
| + ImportBookmarksFile(base::Callback<bool(void)>(), |
| + base::Callback<bool(const GURL&)>(), |
| + path, NULL, &search_engines, NULL); |
| + |
| + ASSERT_EQ(2U, search_engines.size()); |
| + ExpectFirstFirefoxBookmarkWithKeyword(search_engines[0]); |
| + ExpectSecondFirefoxBookmarkWithKeyword(search_engines[1]); |
| +} |
| + |
| namespace { |
| class CancelAfterFifteenCalls { |
| @@ -301,7 +367,7 @@ TEST_F(BookmarkHTMLReaderTestWithData, CancellationCallback) { |
| ImportBookmarksFile(base::Bind(&CancelAfterFifteenCalls::ShouldCancel, |
| base::Unretained(&cancel_fifteen)), |
| base::Callback<bool(const GURL&)>(), |
| - path, &bookmarks, NULL); |
| + path, &bookmarks, NULL, NULL); |
| // The cancellation callback is checked before each line is read, so fifteen |
| // lines are imported. The first fifteen lines of firefox2.html include only |
| @@ -326,7 +392,7 @@ TEST_F(BookmarkHTMLReaderTestWithData, ValidURLCallback) { |
| std::vector<ImportedBookmarkEntry> bookmarks; |
| ImportBookmarksFile(base::Callback<bool(void)>(), |
| base::Bind(&IsURLValid), |
| - path, &bookmarks, NULL); |
| + path, &bookmarks, NULL, NULL); |
| ASSERT_EQ(2U, bookmarks.size()); |
| ExpectFirstFirefox2Bookmark(bookmarks[0]); |