| Index: components/bookmarks/browser/bookmark_index_unittest.cc
|
| diff --git a/components/bookmarks/browser/bookmark_index_unittest.cc b/components/bookmarks/browser/bookmark_index_unittest.cc
|
| index 90168ffbcc7c566b0ee19da7ef94077906394e79..be8eec092ee22b5f0bebecc527977472f5854980 100644
|
| --- a/components/bookmarks/browser/bookmark_index_unittest.cc
|
| +++ b/components/bookmarks/browser/bookmark_index_unittest.cc
|
| @@ -83,13 +83,17 @@ class BookmarkIndexTest : public testing::Test {
|
| std::vector<std::string> title_vector;
|
| for (size_t i = 0; i < expected_count; ++i)
|
| title_vector.push_back(expected_titles[i]);
|
| - ExpectMatches(query, title_vector);
|
| + ExpectMatches(query, false /* always_prefix_search */, title_vector);
|
| }
|
|
|
| void ExpectMatches(const std::string& query,
|
| + bool always_prefix_search,
|
| const std::vector<std::string>& expected_titles) {
|
| std::vector<BookmarkMatch> matches;
|
| - model_->GetBookmarksMatching(ASCIIToUTF16(query), 1000, &matches);
|
| + if (always_prefix_search)
|
| + model_->GetBookmarksMatchingPrefixes(ASCIIToUTF16(query), 1000, &matches);
|
| + else
|
| + model_->GetBookmarksMatching(ASCIIToUTF16(query), 1000, &matches);
|
| ASSERT_EQ(expected_titles.size(), matches.size());
|
| for (size_t i = 0; i < expected_titles.size(); ++i) {
|
| bool found = false;
|
| @@ -171,7 +175,73 @@ TEST_F(BookmarkIndexTest, GetBookmarksMatching) {
|
| { "think", "\"thi\"", ""},
|
|
|
| // Prefix matches against multiple candidates.
|
| - { "abc1 abc2 abc3 abc4", "abc", "abc1 abc2 abc3 abc4"},
|
| + { "abc1 abc2 abc3 abc4", "abc", "abc1 abc2 abc3 abc4"},
|
| +
|
| + // Prefix match on the first term.
|
| + { "abc", "a", "" },
|
| +
|
| + // Prefix match on subsequent terms.
|
| + { "abc def", "abc d", "" },
|
| +
|
| +
|
| + };
|
| + for (size_t i = 0; i < arraysize(data); ++i) {
|
| + std::vector<std::string> titles;
|
| + base::SplitString(data[i].titles, ';', &titles);
|
| + std::vector<TitleAndURL> bookmarks;
|
| + for (size_t j = 0; j < titles.size(); ++j) {
|
| + TitleAndURL bookmark(titles[j], kAboutBlankURL);
|
| + bookmarks.push_back(bookmark);
|
| + }
|
| + AddBookmarks(bookmarks);
|
| +
|
| + std::vector<std::string> expected;
|
| + if (!data[i].expected.empty())
|
| + base::SplitString(data[i].expected, ';', &expected);
|
| +
|
| + ExpectMatches(data[i].query, false /* always_prefix_search */, expected);
|
| +
|
| + model_ = client_.CreateModel();
|
| + }
|
| +}
|
| +
|
| +TEST_F(BookmarkIndexTest, GetBookmarksMatchingAlwaysPrefixSearch) {
|
| + struct TestData {
|
| + const std::string titles;
|
| + const std::string query;
|
| + const std::string expected;
|
| + } data[] = {
|
| + // Trivial test case of only one term, exact match.
|
| + { "z;y", "Z", "z" },
|
| +
|
| + // Prefix match, one term.
|
| + { "abcd;abc;b", "abc", "abcd;abc" },
|
| +
|
| + // Prefix match, multiple terms.
|
| + { "abcd cdef;abcd;abcd cdefg", "abc cde", "abcd cdef;abcd cdefg" },
|
| +
|
| + // Exact and prefix match.
|
| + { "ab cdef ghij;ab;cde;cdef;ghi;cdef ab;ghij ab",
|
| + "ab cde ghi",
|
| + "ab cdef ghij" },
|
| +
|
| + // Title with term multiple times.
|
| + { "ab ab", "ab", "ab ab" },
|
| +
|
| + // Make sure quotes don't do a prefix match.
|
| + { "think", "\"thi\"", "" },
|
| +
|
| + // Prefix matches against multiple candidates.
|
| + { "abc1 abc2 abc3 abc4", "abc", "abc1 abc2 abc3 abc4" },
|
| +
|
| + // Prefix match on the first term.
|
| + { "abc", "a", "abc" },
|
| +
|
| + // Prefix match on subsequent terms.
|
| + { "abc def", "abc d", "abc def" },
|
| +
|
| + // Exact and prefix match.
|
| + { "ab cdef;abcd;abcd cdefg", "ab cdef", "ab cdef;abcd cdefg" },
|
| };
|
| for (size_t i = 0; i < arraysize(data); ++i) {
|
| std::vector<std::string> titles;
|
| @@ -187,7 +257,7 @@ TEST_F(BookmarkIndexTest, GetBookmarksMatching) {
|
| if (!data[i].expected.empty())
|
| base::SplitString(data[i].expected, ';', &expected);
|
|
|
| - ExpectMatches(data[i].query, expected);
|
| + ExpectMatches(data[i].query, true /* always_prefix_search */, expected);
|
|
|
| model_ = client_.CreateModel();
|
| }
|
| @@ -247,7 +317,7 @@ TEST_F(BookmarkIndexTest, GetBookmarksMatchingWithURLs) {
|
| if (data[i].should_be_retrieved)
|
| expected.push_back(data[i].title);
|
|
|
| - ExpectMatches(data[i].query, expected);
|
| + ExpectMatches(data[i].query, false /* always_prefix_search */, expected);
|
| }
|
| }
|
|
|
|
|