OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/bookmarks/browser/bookmark_index.h" | 5 #include "components/bookmarks/browser/bookmark_index.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 // all query paths. | 146 // all query paths. |
147 TEST_F(BookmarkIndexTest, GetBookmarksMatching) { | 147 TEST_F(BookmarkIndexTest, GetBookmarksMatching) { |
148 struct TestData { | 148 struct TestData { |
149 const std::string titles; | 149 const std::string titles; |
150 const std::string query; | 150 const std::string query; |
151 const std::string expected; | 151 const std::string expected; |
152 } data[] = { | 152 } data[] = { |
153 // Trivial test case of only one term, exact match. | 153 // Trivial test case of only one term, exact match. |
154 { "a;b", "A", "a" }, | 154 { "a;b", "A", "a" }, |
155 | 155 |
| 156 // Two terms, exact matches. |
| 157 { "a b;b", "a b", "a b" }, |
| 158 |
156 // Prefix match, one term. | 159 // Prefix match, one term. |
157 { "abcd;abc;b", "abc", "abcd;abc" }, | 160 { "abcd;abc;b", "abc", "abcd;abc" }, |
158 | 161 |
159 // Prefix match, multiple terms. | 162 // Prefix match, multiple terms. |
160 { "abcd cdef;abcd;abcd cdefg", "abc cde", "abcd cdef;abcd cdefg"}, | 163 { "abcd cdef;abcd;abcd cdefg", "abc cde", "abcd cdef;abcd cdefg"}, |
161 | 164 |
162 // Exact and prefix match. | 165 // Exact and prefix match. |
163 { "ab cdef;abcd;abcd cdefg", "ab cdef", "ab cdef"}, | 166 { "ab cdef;abcd;abcd cdefg", "ab cdef", "ab cdef"}, |
164 | 167 |
165 // Exact and prefix match. | 168 // Exact and prefix match. |
166 { "ab cdef ghij;ab;cde;cdef;ghi;cdef ab;ghij ab", | 169 { "ab cdef ghij;ab;cde;cdef;ghi;cdef ab;ghij ab", |
167 "ab cde ghi", | 170 "ab cde ghi", |
168 "ab cdef ghij"}, | 171 "ab cdef ghij"}, |
169 | 172 |
170 // Title with term multiple times. | 173 // Title with term multiple times. |
171 { "ab ab", "ab", "ab ab"}, | 174 { "ab ab", "ab", "ab ab"}, |
172 | 175 |
173 // Make sure quotes don't do a prefix match. | 176 // Make sure quotes don't do a prefix match. |
174 { "think", "\"thi\"", ""}, | 177 { "think", "\"thi\"", ""}, |
175 | 178 |
176 // Prefix matches against multiple candidates. | 179 // Prefix matches against multiple candidates. |
177 { "abc1 abc2 abc3 abc4", "abc", "abc1 abc2 abc3 abc4"}, | 180 { "abc1 abc2 abc3 abc4", "abc", "abc1 abc2 abc3 abc4"}, |
178 | 181 |
| 182 // Multiple prefix matches (with a lot of redundancy) against multiple |
| 183 // candidates. |
| 184 { "abc1 abc2 abc3 abc4 def1 def2 def3 def4", |
| 185 "abc def abc def abc def abc def abc def", |
| 186 "abc1 abc2 abc3 abc4 def1 def2 def3 def4"}, |
| 187 |
179 // Prefix match on the first term. | 188 // Prefix match on the first term. |
180 { "abc", "a", "" }, | 189 { "abc", "a", "" }, |
181 | 190 |
182 // Prefix match on subsequent terms. | 191 // Prefix match on subsequent terms. |
183 { "abc def", "abc d", "" }, | 192 { "abc def", "abc d", "" }, |
184 | |
185 | |
186 }; | 193 }; |
187 for (size_t i = 0; i < arraysize(data); ++i) { | 194 for (size_t i = 0; i < arraysize(data); ++i) { |
188 std::vector<std::string> titles; | 195 std::vector<std::string> titles; |
189 base::SplitString(data[i].titles, ';', &titles); | 196 base::SplitString(data[i].titles, ';', &titles); |
190 std::vector<TitleAndURL> bookmarks; | 197 std::vector<TitleAndURL> bookmarks; |
191 for (size_t j = 0; j < titles.size(); ++j) { | 198 for (size_t j = 0; j < titles.size(); ++j) { |
192 TitleAndURL bookmark(titles[j], kAboutBlankURL); | 199 TitleAndURL bookmark(titles[j], kAboutBlankURL); |
193 bookmarks.push_back(bookmark); | 200 bookmarks.push_back(bookmark); |
194 } | 201 } |
195 AddBookmarks(bookmarks); | 202 AddBookmarks(bookmarks); |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 // Select top two matches. | 548 // Select top two matches. |
542 model->GetBookmarksMatching(ASCIIToUTF16("google"), 2, &matches); | 549 model->GetBookmarksMatching(ASCIIToUTF16("google"), 2, &matches); |
543 | 550 |
544 ASSERT_EQ(2U, matches.size()); | 551 ASSERT_EQ(2U, matches.size()); |
545 EXPECT_EQ(data[0].url, matches[0].node->url()); | 552 EXPECT_EQ(data[0].url, matches[0].node->url()); |
546 EXPECT_EQ(data[3].url, matches[1].node->url()); | 553 EXPECT_EQ(data[3].url, matches[1].node->url()); |
547 } | 554 } |
548 | 555 |
549 } // namespace | 556 } // namespace |
550 } // namespace bookmarks | 557 } // namespace bookmarks |
OLD | NEW |