OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 // Exact and prefix match. | 128 // Exact and prefix match. |
129 { "ab cdef ghij;ab;cde;cdef;ghi;cdef ab;ghij ab", | 129 { "ab cdef ghij;ab;cde;cdef;ghi;cdef ab;ghij ab", |
130 "ab cde ghi", | 130 "ab cde ghi", |
131 "ab cdef ghij"}, | 131 "ab cdef ghij"}, |
132 | 132 |
133 // Title with term multiple times. | 133 // Title with term multiple times. |
134 { "ab ab", "ab", "ab ab"}, | 134 { "ab ab", "ab", "ab ab"}, |
135 | 135 |
136 // Make sure quotes don't do a prefix match. | 136 // Make sure quotes don't do a prefix match. |
137 { "think", "\"thi\"", ""}, | 137 { "think", "\"thi\"", ""}, |
| 138 |
| 139 // Prefix matches against multiple candidates. |
| 140 { "abc1 abc2 abc3 abc4", "abc", "abc1 abc2 abc3 abc4"}, |
138 }; | 141 }; |
139 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { | 142 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { |
140 std::vector<std::string> titles; | 143 std::vector<std::string> titles; |
141 base::SplitString(data[i].input, ';', &titles); | 144 base::SplitString(data[i].input, ';', &titles); |
142 AddBookmarksWithTitles(titles); | 145 AddBookmarksWithTitles(titles); |
143 | 146 |
144 std::vector<std::string> expected; | 147 std::vector<std::string> expected; |
145 if (!data[i].expected.empty()) | 148 if (!data[i].expected.empty()) |
146 base::SplitString(data[i].expected, ';', &expected); | 149 base::SplitString(data[i].expected, ';', &expected); |
147 | 150 |
148 ExpectMatches(data[i].query, expected); | 151 ExpectMatches(data[i].query, expected); |
149 | 152 |
150 model_.reset(new BookmarkModel(NULL)); | 153 model_.reset(new BookmarkModel(NULL)); |
151 } | 154 } |
152 } | 155 } |
153 | 156 |
154 // Makes sure match positions are updated appropriately. | 157 // Makes sure match positions are updated appropriately. |
155 TEST_F(BookmarkIndexTest, MatchPositions) { | 158 TEST_F(BookmarkIndexTest, MatchPositions) { |
156 struct TestData { | 159 struct TestData { |
157 const std::string title; | 160 const std::string title; |
158 const std::string query; | 161 const std::string query; |
159 const std::string expected; | 162 const std::string expected; |
160 } data[] = { | 163 } data[] = { |
161 // Trivial test case of only one term, exact match. | 164 // Trivial test case of only one term, exact match. |
162 { "a", "A", "0,1" }, | 165 { "a", "A", "0,1" }, |
163 { "foo bar", "bar", "4,7" }, | 166 { "foo bar", "bar", "4,7" }, |
164 { "fooey bark", "bar foo", "0,3:6,9"}, | 167 { "fooey bark", "bar foo", "0,3:6,9"}, |
| 168 // Non-trivial tests. |
| 169 { "foobar foo", "foobar foo", "0,6:7,10" }, |
| 170 { "foobar foo", "foo foobar", "0,6:7,10" }, |
| 171 { "foobar foobar", "foobar foo", "0,6:7,13" }, |
| 172 { "foobar foobar", "foo foobar", "0,6:7,13" }, |
165 }; | 173 }; |
166 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { | 174 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { |
167 std::vector<std::string> titles; | 175 std::vector<std::string> titles; |
168 titles.push_back(data[i].title); | 176 titles.push_back(data[i].title); |
169 AddBookmarksWithTitles(titles); | 177 AddBookmarksWithTitles(titles); |
170 | 178 |
171 Snippet::MatchPositions expected_matches; | 179 Snippet::MatchPositions expected_matches; |
172 ExtractMatchPositions(data[i].expected, &expected_matches); | 180 ExtractMatchPositions(data[i].expected, &expected_matches); |
173 ExpectMatchPositions(data[i].query, expected_matches); | 181 ExpectMatchPositions(data[i].query, expected_matches); |
174 | 182 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 EXPECT_EQ(data[1].url, matches[3].node->url()); | 304 EXPECT_EQ(data[1].url, matches[3].node->url()); |
297 | 305 |
298 matches.clear(); | 306 matches.clear(); |
299 // Select top two matches. | 307 // Select top two matches. |
300 model->GetBookmarksWithTitlesMatching(ASCIIToUTF16("google"), 2, &matches); | 308 model->GetBookmarksWithTitlesMatching(ASCIIToUTF16("google"), 2, &matches); |
301 | 309 |
302 EXPECT_EQ(2, static_cast<int>(matches.size())); | 310 EXPECT_EQ(2, static_cast<int>(matches.size())); |
303 EXPECT_EQ(data[0].url, matches[0].node->url()); | 311 EXPECT_EQ(data[0].url, matches[0].node->url()); |
304 EXPECT_EQ(data[3].url, matches[1].node->url()); | 312 EXPECT_EQ(data[3].url, matches[1].node->url()); |
305 } | 313 } |
OLD | NEW |