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 "components/omnibox/browser/scored_history_match.h" | 5 #include "components/omnibox/browser/scored_history_match.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 // Find the first word start. | 115 // Find the first word start. |
116 while (iter.Advance() && !iter.IsWord()) { | 116 while (iter.Advance() && !iter.IsWord()) { |
117 } | 117 } |
118 term_word_starts[0] = iter.prev(); | 118 term_word_starts[0] = iter.prev(); |
119 } | 119 } |
120 RowWordStarts row_word_starts; | 120 RowWordStarts row_word_starts; |
121 String16SetFromString16(url, &row_word_starts.url_word_starts_); | 121 String16SetFromString16(url, &row_word_starts.url_word_starts_); |
122 String16SetFromString16(title, &row_word_starts.title_word_starts_); | 122 String16SetFromString16(title, &row_word_starts.title_word_starts_); |
123 ScoredHistoryMatch scored_match(history::URLRow(GURL(url)), VisitInfoVector(), | 123 ScoredHistoryMatch scored_match(history::URLRow(GURL(url)), VisitInfoVector(), |
124 term, term_vector, term_word_starts, | 124 term, term_vector, term_word_starts, |
125 row_word_starts, false, base::Time::Max()); | 125 row_word_starts, false, 1, base::Time::Max()); |
126 scored_match.url_matches = MatchTermInString(term, url, 0); | 126 scored_match.url_matches = MatchTermInString(term, url, 0); |
127 scored_match.title_matches = MatchTermInString(term, title, 0); | 127 scored_match.title_matches = MatchTermInString(term, title, 0); |
128 scored_match.topicality_threshold_ = -1; | 128 scored_match.topicality_threshold_ = -1; |
129 return scored_match.GetTopicalityScore(1, url, term_word_starts, | 129 return scored_match.GetTopicalityScore(1, url, term_word_starts, |
130 row_word_starts); | 130 row_word_starts); |
131 } | 131 } |
132 | 132 |
133 TEST_F(ScoredHistoryMatchTest, Scoring) { | 133 TEST_F(ScoredHistoryMatchTest, Scoring) { |
134 // We use NowFromSystemTime() because MakeURLRow uses the same function | 134 // We use NowFromSystemTime() because MakeURLRow uses the same function |
135 // to calculate last visit time when building a row. | 135 // to calculate last visit time when building a row. |
136 base::Time now = base::Time::NowFromSystemTime(); | 136 base::Time now = base::Time::NowFromSystemTime(); |
137 | 137 |
138 history::URLRow row_a(MakeURLRow("http://fedcba", "abcd bcd", 3, 30, 1)); | 138 history::URLRow row_a(MakeURLRow("http://fedcba", "abcd bcd", 3, 30, 1)); |
139 RowWordStarts word_starts_a; | 139 RowWordStarts word_starts_a; |
140 PopulateWordStarts(row_a, &word_starts_a); | 140 PopulateWordStarts(row_a, &word_starts_a); |
141 WordStarts one_word_no_offset(1, 0u); | 141 WordStarts one_word_no_offset(1, 0u); |
142 VisitInfoVector visits_a = CreateVisitInfoVector(3, 30, now); | 142 VisitInfoVector visits_a = CreateVisitInfoVector(3, 30, now); |
143 // Mark one visit as typed. | 143 // Mark one visit as typed. |
144 visits_a[0].second = ui::PAGE_TRANSITION_TYPED; | 144 visits_a[0].second = ui::PAGE_TRANSITION_TYPED; |
145 ScoredHistoryMatch scored_a(row_a, visits_a, ASCIIToUTF16("abc"), | 145 ScoredHistoryMatch scored_a(row_a, visits_a, ASCIIToUTF16("abc"), |
146 Make1Term("abc"), one_word_no_offset, | 146 Make1Term("abc"), one_word_no_offset, |
147 word_starts_a, false, now); | 147 word_starts_a, false, 1, now); |
148 | 148 |
149 // Test scores based on visit_count. | 149 // Test scores based on visit_count. |
150 history::URLRow row_b(MakeURLRow("http://abcdef", "abcd bcd", 10, 30, 1)); | 150 history::URLRow row_b(MakeURLRow("http://abcdef", "abcd bcd", 10, 30, 1)); |
151 RowWordStarts word_starts_b; | 151 RowWordStarts word_starts_b; |
152 PopulateWordStarts(row_b, &word_starts_b); | 152 PopulateWordStarts(row_b, &word_starts_b); |
153 VisitInfoVector visits_b = CreateVisitInfoVector(10, 30, now); | 153 VisitInfoVector visits_b = CreateVisitInfoVector(10, 30, now); |
154 visits_b[0].second = ui::PAGE_TRANSITION_TYPED; | 154 visits_b[0].second = ui::PAGE_TRANSITION_TYPED; |
155 ScoredHistoryMatch scored_b(row_b, visits_b, ASCIIToUTF16("abc"), | 155 ScoredHistoryMatch scored_b(row_b, visits_b, ASCIIToUTF16("abc"), |
156 Make1Term("abc"), one_word_no_offset, | 156 Make1Term("abc"), one_word_no_offset, |
157 word_starts_b, false, now); | 157 word_starts_b, false, 1, now); |
158 EXPECT_GT(scored_b.raw_score, scored_a.raw_score); | 158 EXPECT_GT(scored_b.raw_score, scored_a.raw_score); |
159 | 159 |
160 // Test scores based on last_visit. | 160 // Test scores based on last_visit. |
161 history::URLRow row_c(MakeURLRow("http://abcdef", "abcd bcd", 3, 10, 1)); | 161 history::URLRow row_c(MakeURLRow("http://abcdef", "abcd bcd", 3, 10, 1)); |
162 RowWordStarts word_starts_c; | 162 RowWordStarts word_starts_c; |
163 PopulateWordStarts(row_c, &word_starts_c); | 163 PopulateWordStarts(row_c, &word_starts_c); |
164 VisitInfoVector visits_c = CreateVisitInfoVector(3, 10, now); | 164 VisitInfoVector visits_c = CreateVisitInfoVector(3, 10, now); |
165 visits_c[0].second = ui::PAGE_TRANSITION_TYPED; | 165 visits_c[0].second = ui::PAGE_TRANSITION_TYPED; |
166 ScoredHistoryMatch scored_c(row_c, visits_c, ASCIIToUTF16("abc"), | 166 ScoredHistoryMatch scored_c(row_c, visits_c, ASCIIToUTF16("abc"), |
167 Make1Term("abc"), one_word_no_offset, | 167 Make1Term("abc"), one_word_no_offset, |
168 word_starts_c, false, now); | 168 word_starts_c, false, 1, now); |
169 EXPECT_GT(scored_c.raw_score, scored_a.raw_score); | 169 EXPECT_GT(scored_c.raw_score, scored_a.raw_score); |
170 | 170 |
171 // Test scores based on typed_count. | 171 // Test scores based on typed_count. |
172 history::URLRow row_d(MakeURLRow("http://abcdef", "abcd bcd", 3, 30, 3)); | 172 history::URLRow row_d(MakeURLRow("http://abcdef", "abcd bcd", 3, 30, 3)); |
173 RowWordStarts word_starts_d; | 173 RowWordStarts word_starts_d; |
174 PopulateWordStarts(row_d, &word_starts_d); | 174 PopulateWordStarts(row_d, &word_starts_d); |
175 VisitInfoVector visits_d = CreateVisitInfoVector(3, 30, now); | 175 VisitInfoVector visits_d = CreateVisitInfoVector(3, 30, now); |
176 visits_d[0].second = ui::PAGE_TRANSITION_TYPED; | 176 visits_d[0].second = ui::PAGE_TRANSITION_TYPED; |
177 visits_d[1].second = ui::PAGE_TRANSITION_TYPED; | 177 visits_d[1].second = ui::PAGE_TRANSITION_TYPED; |
178 visits_d[2].second = ui::PAGE_TRANSITION_TYPED; | 178 visits_d[2].second = ui::PAGE_TRANSITION_TYPED; |
179 ScoredHistoryMatch scored_d(row_d, visits_d, ASCIIToUTF16("abc"), | 179 ScoredHistoryMatch scored_d(row_d, visits_d, ASCIIToUTF16("abc"), |
180 Make1Term("abc"), one_word_no_offset, | 180 Make1Term("abc"), one_word_no_offset, |
181 word_starts_d, false, now); | 181 word_starts_d, false, 1, now); |
182 EXPECT_GT(scored_d.raw_score, scored_a.raw_score); | 182 EXPECT_GT(scored_d.raw_score, scored_a.raw_score); |
183 | 183 |
184 // Test scores based on a terms appearing multiple times. | 184 // Test scores based on a terms appearing multiple times. |
185 history::URLRow row_e(MakeURLRow( | 185 history::URLRow row_e(MakeURLRow( |
186 "http://csi.csi.csi/csi_csi", | 186 "http://csi.csi.csi/csi_csi", |
187 "CSI Guide to CSI Las Vegas, CSI New York, CSI Provo", 3, 30, 3)); | 187 "CSI Guide to CSI Las Vegas, CSI New York, CSI Provo", 3, 30, 3)); |
188 RowWordStarts word_starts_e; | 188 RowWordStarts word_starts_e; |
189 PopulateWordStarts(row_e, &word_starts_e); | 189 PopulateWordStarts(row_e, &word_starts_e); |
190 const VisitInfoVector visits_e = visits_d; | 190 const VisitInfoVector visits_e = visits_d; |
191 ScoredHistoryMatch scored_e(row_e, visits_e, ASCIIToUTF16("csi"), | 191 ScoredHistoryMatch scored_e(row_e, visits_e, ASCIIToUTF16("csi"), |
192 Make1Term("csi"), one_word_no_offset, | 192 Make1Term("csi"), one_word_no_offset, |
193 word_starts_e, false, now); | 193 word_starts_e, false, 1, now); |
194 EXPECT_LT(scored_e.raw_score, 1400); | 194 EXPECT_LT(scored_e.raw_score, 1400); |
195 | 195 |
196 // Test that a result with only a mid-term match (i.e., not at a word | 196 // Test that a result with only a mid-term match (i.e., not at a word |
197 // boundary) scores 0. | 197 // boundary) scores 0. |
198 ScoredHistoryMatch scored_f(row_a, visits_a, ASCIIToUTF16("cd"), | 198 ScoredHistoryMatch scored_f(row_a, visits_a, ASCIIToUTF16("cd"), |
199 Make1Term("cd"), one_word_no_offset, | 199 Make1Term("cd"), one_word_no_offset, |
200 word_starts_a, false, now); | 200 word_starts_a, false, 1, now); |
201 EXPECT_EQ(scored_f.raw_score, 0); | 201 EXPECT_EQ(scored_f.raw_score, 0); |
202 } | 202 } |
203 | 203 |
204 TEST_F(ScoredHistoryMatchTest, ScoringBookmarks) { | 204 TEST_F(ScoredHistoryMatchTest, ScoringBookmarks) { |
205 // We use NowFromSystemTime() because MakeURLRow uses the same function | 205 // We use NowFromSystemTime() because MakeURLRow uses the same function |
206 // to calculate last visit time when building a row. | 206 // to calculate last visit time when building a row. |
207 base::Time now = base::Time::NowFromSystemTime(); | 207 base::Time now = base::Time::NowFromSystemTime(); |
208 | 208 |
209 std::string url_string("http://fedcba"); | 209 std::string url_string("http://fedcba"); |
210 const GURL url(url_string); | 210 const GURL url(url_string); |
211 history::URLRow row(MakeURLRow(url_string.c_str(), "abcd bcd", 8, 3, 1)); | 211 history::URLRow row(MakeURLRow(url_string.c_str(), "abcd bcd", 8, 3, 1)); |
212 RowWordStarts word_starts; | 212 RowWordStarts word_starts; |
213 PopulateWordStarts(row, &word_starts); | 213 PopulateWordStarts(row, &word_starts); |
214 WordStarts one_word_no_offset(1, 0u); | 214 WordStarts one_word_no_offset(1, 0u); |
215 VisitInfoVector visits = CreateVisitInfoVector(8, 3, now); | 215 VisitInfoVector visits = CreateVisitInfoVector(8, 3, now); |
216 ScoredHistoryMatch scored(row, visits, ASCIIToUTF16("abc"), Make1Term("abc"), | 216 ScoredHistoryMatch scored(row, visits, ASCIIToUTF16("abc"), Make1Term("abc"), |
217 one_word_no_offset, word_starts, false, now); | 217 one_word_no_offset, word_starts, false, 1, now); |
218 // Now check that if URL is bookmarked then its score increases. | 218 // Now check that if URL is bookmarked then its score increases. |
219 base::AutoReset<float> reset(&ScoredHistoryMatch::bookmark_value_, 5); | 219 base::AutoReset<float> reset(&ScoredHistoryMatch::bookmark_value_, 5); |
220 ScoredHistoryMatch scored_with_bookmark(row, visits, ASCIIToUTF16("abc"), | 220 ScoredHistoryMatch scored_with_bookmark(row, visits, ASCIIToUTF16("abc"), |
221 Make1Term("abc"), one_word_no_offset, | 221 Make1Term("abc"), one_word_no_offset, |
222 word_starts, true, now); | 222 word_starts, true, 1, now); |
223 EXPECT_GT(scored_with_bookmark.raw_score, scored.raw_score); | 223 EXPECT_GT(scored_with_bookmark.raw_score, scored.raw_score); |
224 } | 224 } |
225 | 225 |
226 TEST_F(ScoredHistoryMatchTest, ScoringTLD) { | 226 TEST_F(ScoredHistoryMatchTest, ScoringTLD) { |
227 // We use NowFromSystemTime() because MakeURLRow uses the same function | 227 // We use NowFromSystemTime() because MakeURLRow uses the same function |
228 // to calculate last visit time when building a row. | 228 // to calculate last visit time when building a row. |
229 base::Time now = base::Time::NowFromSystemTime(); | 229 base::Time now = base::Time::NowFromSystemTime(); |
230 | 230 |
231 // By default the URL should not be returned for a query that includes "com". | 231 // By default the URL should not be returned for a query that includes "com". |
232 std::string url_string("http://fedcba.com/"); | 232 std::string url_string("http://fedcba.com/"); |
233 const GURL url(url_string); | 233 const GURL url(url_string); |
234 history::URLRow row(MakeURLRow(url_string.c_str(), "", 8, 3, 1)); | 234 history::URLRow row(MakeURLRow(url_string.c_str(), "", 8, 3, 1)); |
235 RowWordStarts word_starts; | 235 RowWordStarts word_starts; |
236 PopulateWordStarts(row, &word_starts); | 236 PopulateWordStarts(row, &word_starts); |
237 WordStarts two_words_no_offsets(2, 0u); | 237 WordStarts two_words_no_offsets(2, 0u); |
238 VisitInfoVector visits = CreateVisitInfoVector(8, 3, now); | 238 VisitInfoVector visits = CreateVisitInfoVector(8, 3, now); |
239 ScoredHistoryMatch scored(row, visits, ASCIIToUTF16("fed com"), | 239 ScoredHistoryMatch scored(row, visits, ASCIIToUTF16("fed com"), |
240 Make2Terms("fed", "com"), two_words_no_offsets, | 240 Make2Terms("fed", "com"), two_words_no_offsets, |
241 word_starts, false, now); | 241 word_starts, false, 1, now); |
242 EXPECT_EQ(0, scored.raw_score); | 242 EXPECT_EQ(0, scored.raw_score); |
243 | 243 |
244 // Now allow credit for the match in the TLD. | 244 // Now allow credit for the match in the TLD. |
245 base::AutoReset<bool> reset(&ScoredHistoryMatch::allow_tld_matches_, true); | 245 base::AutoReset<bool> reset(&ScoredHistoryMatch::allow_tld_matches_, true); |
246 ScoredHistoryMatch scored_with_tld( | 246 ScoredHistoryMatch scored_with_tld( |
247 row, visits, ASCIIToUTF16("fed com"), Make2Terms("fed", "com"), | 247 row, visits, ASCIIToUTF16("fed com"), Make2Terms("fed", "com"), |
248 two_words_no_offsets, word_starts, false, now); | 248 two_words_no_offsets, word_starts, false, 1, now); |
249 EXPECT_GT(scored_with_tld.raw_score, 0); | 249 EXPECT_GT(scored_with_tld.raw_score, 0); |
250 } | 250 } |
251 | 251 |
252 TEST_F(ScoredHistoryMatchTest, ScoringScheme) { | 252 TEST_F(ScoredHistoryMatchTest, ScoringScheme) { |
253 // We use NowFromSystemTime() because MakeURLRow uses the same function | 253 // We use NowFromSystemTime() because MakeURLRow uses the same function |
254 // to calculate last visit time when building a row. | 254 // to calculate last visit time when building a row. |
255 base::Time now = base::Time::NowFromSystemTime(); | 255 base::Time now = base::Time::NowFromSystemTime(); |
256 | 256 |
257 // By default the URL should not be returned for a query that includes "http". | 257 // By default the URL should not be returned for a query that includes "http". |
258 std::string url_string("http://fedcba/"); | 258 std::string url_string("http://fedcba/"); |
259 const GURL url(url_string); | 259 const GURL url(url_string); |
260 history::URLRow row(MakeURLRow(url_string.c_str(), "", 8, 3, 1)); | 260 history::URLRow row(MakeURLRow(url_string.c_str(), "", 8, 3, 1)); |
261 RowWordStarts word_starts; | 261 RowWordStarts word_starts; |
262 PopulateWordStarts(row, &word_starts); | 262 PopulateWordStarts(row, &word_starts); |
263 WordStarts two_words_no_offsets(2, 0u); | 263 WordStarts two_words_no_offsets(2, 0u); |
264 VisitInfoVector visits = CreateVisitInfoVector(8, 3, now); | 264 VisitInfoVector visits = CreateVisitInfoVector(8, 3, now); |
265 ScoredHistoryMatch scored(row, visits, ASCIIToUTF16("fed http"), | 265 ScoredHistoryMatch scored(row, visits, ASCIIToUTF16("fed http"), |
266 Make2Terms("fed", "http"), two_words_no_offsets, | 266 Make2Terms("fed", "http"), two_words_no_offsets, |
267 word_starts, false, now); | 267 word_starts, false, 1, now); |
268 EXPECT_EQ(0, scored.raw_score); | 268 EXPECT_EQ(0, scored.raw_score); |
269 | 269 |
270 // Now allow credit for the match in the scheme. | 270 // Now allow credit for the match in the scheme. |
271 base::AutoReset<bool> reset(&ScoredHistoryMatch::allow_scheme_matches_, true); | 271 base::AutoReset<bool> reset(&ScoredHistoryMatch::allow_scheme_matches_, true); |
272 ScoredHistoryMatch scored_with_scheme( | 272 ScoredHistoryMatch scored_with_scheme( |
273 row, visits, ASCIIToUTF16("fed http"), Make2Terms("fed", "http"), | 273 row, visits, ASCIIToUTF16("fed http"), Make2Terms("fed", "http"), |
274 two_words_no_offsets, word_starts, false, now); | 274 two_words_no_offsets, word_starts, false, 1, now); |
275 EXPECT_GT(scored_with_scheme.raw_score, 0); | 275 EXPECT_GT(scored_with_scheme.raw_score, 0); |
276 } | 276 } |
277 | 277 |
278 TEST_F(ScoredHistoryMatchTest, Inlining) { | 278 TEST_F(ScoredHistoryMatchTest, Inlining) { |
279 // We use NowFromSystemTime() because MakeURLRow uses the same function | 279 // We use NowFromSystemTime() because MakeURLRow uses the same function |
280 // to calculate last visit time when building a row. | 280 // to calculate last visit time when building a row. |
281 base::Time now = base::Time::NowFromSystemTime(); | 281 base::Time now = base::Time::NowFromSystemTime(); |
282 RowWordStarts word_starts; | 282 RowWordStarts word_starts; |
283 WordStarts one_word_no_offset(1, 0u); | 283 WordStarts one_word_no_offset(1, 0u); |
284 VisitInfoVector visits; | 284 VisitInfoVector visits; |
285 | 285 |
286 { | 286 { |
287 history::URLRow row( | 287 history::URLRow row( |
288 MakeURLRow("http://www.google.com", "abcdef", 3, 30, 1)); | 288 MakeURLRow("http://www.google.com", "abcdef", 3, 30, 1)); |
289 PopulateWordStarts(row, &word_starts); | 289 PopulateWordStarts(row, &word_starts); |
290 ScoredHistoryMatch scored_a(row, visits, ASCIIToUTF16("g"), Make1Term("g"), | 290 ScoredHistoryMatch scored_a(row, visits, ASCIIToUTF16("g"), Make1Term("g"), |
291 one_word_no_offset, word_starts, false, now); | 291 one_word_no_offset, word_starts, false, 1, now); |
292 EXPECT_FALSE(scored_a.match_in_scheme); | 292 EXPECT_FALSE(scored_a.match_in_scheme); |
293 ScoredHistoryMatch scored_b(row, visits, ASCIIToUTF16("w"), Make1Term("w"), | 293 ScoredHistoryMatch scored_b(row, visits, ASCIIToUTF16("w"), Make1Term("w"), |
294 one_word_no_offset, word_starts, false, now); | 294 one_word_no_offset, word_starts, false, 1, now); |
295 EXPECT_FALSE(scored_b.match_in_scheme); | 295 EXPECT_FALSE(scored_b.match_in_scheme); |
296 ScoredHistoryMatch scored_c(row, visits, ASCIIToUTF16("h"), Make1Term("h"), | 296 ScoredHistoryMatch scored_c(row, visits, ASCIIToUTF16("h"), Make1Term("h"), |
297 one_word_no_offset, word_starts, false, now); | 297 one_word_no_offset, word_starts, false, 1, now); |
298 EXPECT_TRUE(scored_c.match_in_scheme); | 298 EXPECT_TRUE(scored_c.match_in_scheme); |
299 ScoredHistoryMatch scored_d(row, visits, ASCIIToUTF16("o"), Make1Term("o"), | 299 ScoredHistoryMatch scored_d(row, visits, ASCIIToUTF16("o"), Make1Term("o"), |
300 one_word_no_offset, word_starts, false, now); | 300 one_word_no_offset, word_starts, false, 1, now); |
301 EXPECT_FALSE(scored_d.match_in_scheme); | 301 EXPECT_FALSE(scored_d.match_in_scheme); |
302 } | 302 } |
303 | 303 |
304 { | 304 { |
305 history::URLRow row(MakeURLRow("http://teams.foo.com", "abcdef", 3, 30, 1)); | 305 history::URLRow row(MakeURLRow("http://teams.foo.com", "abcdef", 3, 30, 1)); |
306 PopulateWordStarts(row, &word_starts); | 306 PopulateWordStarts(row, &word_starts); |
307 ScoredHistoryMatch scored_a(row, visits, ASCIIToUTF16("t"), Make1Term("t"), | 307 ScoredHistoryMatch scored_a(row, visits, ASCIIToUTF16("t"), Make1Term("t"), |
308 one_word_no_offset, word_starts, false, now); | 308 one_word_no_offset, word_starts, false, 1, now); |
309 EXPECT_FALSE(scored_a.match_in_scheme); | 309 EXPECT_FALSE(scored_a.match_in_scheme); |
310 ScoredHistoryMatch scored_b(row, visits, ASCIIToUTF16("f"), Make1Term("f"), | 310 ScoredHistoryMatch scored_b(row, visits, ASCIIToUTF16("f"), Make1Term("f"), |
311 one_word_no_offset, word_starts, false, now); | 311 one_word_no_offset, word_starts, false, 1, now); |
312 EXPECT_FALSE(scored_b.match_in_scheme); | 312 EXPECT_FALSE(scored_b.match_in_scheme); |
313 ScoredHistoryMatch scored_c(row, visits, ASCIIToUTF16("o"), Make1Term("o"), | 313 ScoredHistoryMatch scored_c(row, visits, ASCIIToUTF16("o"), Make1Term("o"), |
314 one_word_no_offset, word_starts, false, now); | 314 one_word_no_offset, word_starts, false, 1, now); |
315 EXPECT_FALSE(scored_c.match_in_scheme); | 315 EXPECT_FALSE(scored_c.match_in_scheme); |
316 } | 316 } |
317 | 317 |
318 { | 318 { |
319 history::URLRow row( | 319 history::URLRow row( |
320 MakeURLRow("https://www.testing.com", "abcdef", 3, 30, 1)); | 320 MakeURLRow("https://www.testing.com", "abcdef", 3, 30, 1)); |
321 PopulateWordStarts(row, &word_starts); | 321 PopulateWordStarts(row, &word_starts); |
322 ScoredHistoryMatch scored_a(row, visits, ASCIIToUTF16("t"), Make1Term("t"), | 322 ScoredHistoryMatch scored_a(row, visits, ASCIIToUTF16("t"), Make1Term("t"), |
323 one_word_no_offset, word_starts, false, now); | 323 one_word_no_offset, word_starts, false, 1, now); |
324 EXPECT_FALSE(scored_a.match_in_scheme); | 324 EXPECT_FALSE(scored_a.match_in_scheme); |
325 ScoredHistoryMatch scored_b(row, visits, ASCIIToUTF16("h"), Make1Term("h"), | 325 ScoredHistoryMatch scored_b(row, visits, ASCIIToUTF16("h"), Make1Term("h"), |
326 one_word_no_offset, word_starts, false, now); | 326 one_word_no_offset, word_starts, false, 1, now); |
327 EXPECT_TRUE(scored_b.match_in_scheme); | 327 EXPECT_TRUE(scored_b.match_in_scheme); |
328 ScoredHistoryMatch scored_c(row, visits, ASCIIToUTF16("w"), Make1Term("w"), | 328 ScoredHistoryMatch scored_c(row, visits, ASCIIToUTF16("w"), Make1Term("w"), |
329 one_word_no_offset, word_starts, false, now); | 329 one_word_no_offset, word_starts, false, 1, now); |
330 EXPECT_FALSE(scored_c.match_in_scheme); | 330 EXPECT_FALSE(scored_c.match_in_scheme); |
331 } | 331 } |
332 | 332 |
333 { | 333 { |
334 history::URLRow row( | 334 history::URLRow row( |
335 MakeURLRow("http://www.xn--1lq90ic7f1rc.cn/xnblah", "abcd", 3, 30, 1)); | 335 MakeURLRow("http://www.xn--1lq90ic7f1rc.cn/xnblah", "abcd", 3, 30, 1)); |
336 PopulateWordStarts(row, &word_starts); | 336 PopulateWordStarts(row, &word_starts); |
337 ScoredHistoryMatch scored_a(row, visits, ASCIIToUTF16("x"), Make1Term("x"), | 337 ScoredHistoryMatch scored_a(row, visits, ASCIIToUTF16("x"), Make1Term("x"), |
338 one_word_no_offset, word_starts, false, now); | 338 one_word_no_offset, word_starts, false, 1, now); |
339 EXPECT_FALSE(scored_a.match_in_scheme); | 339 EXPECT_FALSE(scored_a.match_in_scheme); |
340 ScoredHistoryMatch scored_b(row, visits, ASCIIToUTF16("xn"), | 340 ScoredHistoryMatch scored_b(row, visits, ASCIIToUTF16("xn"), |
341 Make1Term("xn"), one_word_no_offset, | 341 Make1Term("xn"), one_word_no_offset, |
342 word_starts, false, now); | 342 word_starts, false, 1, now); |
343 EXPECT_FALSE(scored_b.match_in_scheme); | 343 EXPECT_FALSE(scored_b.match_in_scheme); |
344 ScoredHistoryMatch scored_c(row, visits, ASCIIToUTF16("w"), Make1Term("w"), | 344 ScoredHistoryMatch scored_c(row, visits, ASCIIToUTF16("w"), Make1Term("w"), |
345 one_word_no_offset, word_starts, false, now); | 345 one_word_no_offset, word_starts, false, 1, now); |
346 EXPECT_FALSE(scored_c.match_in_scheme); | 346 EXPECT_FALSE(scored_c.match_in_scheme); |
347 } | 347 } |
348 } | 348 } |
349 | 349 |
350 TEST_F(ScoredHistoryMatchTest, GetTopicalityScoreTrailingSlash) { | 350 TEST_F(ScoredHistoryMatchTest, GetTopicalityScoreTrailingSlash) { |
351 const float hostname = GetTopicalityScoreOfTermAgainstURLAndTitle( | 351 const float hostname = GetTopicalityScoreOfTermAgainstURLAndTitle( |
352 ASCIIToUTF16("def"), ASCIIToUTF16("http://abc.def.com/"), | 352 ASCIIToUTF16("def"), ASCIIToUTF16("http://abc.def.com/"), |
353 ASCIIToUTF16("Non-Matching Title")); | 353 ASCIIToUTF16("Non-Matching Title")); |
354 const float hostname_no_slash = GetTopicalityScoreOfTermAgainstURLAndTitle( | 354 const float hostname_no_slash = GetTopicalityScoreOfTermAgainstURLAndTitle( |
355 ASCIIToUTF16("def"), ASCIIToUTF16("http://abc.def.com"), | 355 ASCIIToUTF16("def"), ASCIIToUTF16("http://abc.def.com"), |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
474 } | 474 } |
475 | 475 |
476 TEST_F(ScoredHistoryMatchTest, GetFrequency) { | 476 TEST_F(ScoredHistoryMatchTest, GetFrequency) { |
477 // Build a fake ScoredHistoryMatch, which we'll then reuse multiple times. | 477 // Build a fake ScoredHistoryMatch, which we'll then reuse multiple times. |
478 history::URLRow row(GURL("http://foo")); | 478 history::URLRow row(GURL("http://foo")); |
479 RowWordStarts row_word_starts; | 479 RowWordStarts row_word_starts; |
480 PopulateWordStarts(row, &row_word_starts); | 480 PopulateWordStarts(row, &row_word_starts); |
481 base::Time now(base::Time::Max()); | 481 base::Time now(base::Time::Max()); |
482 VisitInfoVector visits; | 482 VisitInfoVector visits; |
483 ScoredHistoryMatch match(row, visits, ASCIIToUTF16("foo"), Make1Term("foo"), | 483 ScoredHistoryMatch match(row, visits, ASCIIToUTF16("foo"), Make1Term("foo"), |
484 WordStarts{0}, row_word_starts, false, now); | 484 WordStarts{0}, row_word_starts, false, 1, now); |
485 | 485 |
486 // Record the score for one untyped visit. | 486 // Record the score for one untyped visit. |
487 visits = {{now, ui::PAGE_TRANSITION_LINK}}; | 487 visits = {{now, ui::PAGE_TRANSITION_LINK}}; |
488 const float one_untyped_score = match.GetFrequency(now, false, visits); | 488 const float one_untyped_score = match.GetFrequency(now, false, visits, 1); |
489 | 489 |
490 // The score for one typed visit should be larger. | 490 // The score for one typed visit should be larger. |
491 visits = VisitInfoVector{{now, ui::PAGE_TRANSITION_TYPED}}; | 491 visits = VisitInfoVector{{now, ui::PAGE_TRANSITION_TYPED}}; |
492 const float one_typed_score = match.GetFrequency(now, false, visits); | 492 const float one_typed_score = match.GetFrequency(now, false, visits, 1); |
493 EXPECT_GT(one_typed_score, one_untyped_score); | 493 EXPECT_GT(one_typed_score, one_untyped_score); |
494 | 494 |
495 // It shouldn't matter if the typed visit has a transition qualifier. | 495 // It shouldn't matter if the typed visit has a transition qualifier. |
496 visits = { | 496 visits = { |
497 {now, ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | | 497 {now, ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | |
498 ui::PAGE_TRANSITION_SERVER_REDIRECT)}}; | 498 ui::PAGE_TRANSITION_SERVER_REDIRECT)}}; |
499 EXPECT_EQ(one_typed_score, match.GetFrequency(now, false, visits)); | 499 EXPECT_EQ(one_typed_score, match.GetFrequency(now, false, visits, 1)); |
500 | 500 |
501 // A score for one untyped visit to a bookmarked page should be larger than | 501 // A score for one untyped visit to a bookmarked page should be larger than |
502 // the one untyped visit to a non-bookmarked page. | 502 // the one untyped visit to a non-bookmarked page. |
503 visits = {{now, ui::PAGE_TRANSITION_LINK}}; | 503 visits = {{now, ui::PAGE_TRANSITION_LINK}}; |
504 EXPECT_GE(match.GetFrequency(now, true, visits), one_untyped_score); | 504 EXPECT_GE(match.GetFrequency(now, true, visits, 1), one_untyped_score); |
505 | |
506 // If we pretend there are five items matching the input, the score should | |
507 // not change. | |
508 EXPECT_EQ(match.GetFrequency(now, false, visits, 5), one_untyped_score); | |
509 { | |
510 // With different parameters, however, it can change. In this case, the | |
Peter Kasting
2016/12/01 07:07:53
Nit: parameters -> match multiplier parameters? (
Mark P
2016/12/04 01:06:42
Now moot.
| |
511 // score when there's one matching page should be boosted but if there are | |
512 // five, the score remains unchanged. | |
513 base::AutoReset<OmniboxFieldTrial::NumMatchesMultipliers> tmp( | |
514 ScoredHistoryMatch::num_matches_to_frequency_multiplier_, | |
515 OmniboxFieldTrial::NumMatchesMultipliers{{1, 3.0}}); | |
516 EXPECT_GT(match.GetFrequency(now, false, visits, 1), one_untyped_score); | |
517 EXPECT_EQ(match.GetFrequency(now, false, visits, 5), one_untyped_score); | |
518 } | |
Peter Kasting
2016/12/01 07:07:53
You test this three times. Helper function?
Do t
Mark P
2016/12/04 01:06:42
Now moot.
| |
505 | 519 |
506 // Now consider pages visited twice, with one visit being typed and one | 520 // Now consider pages visited twice, with one visit being typed and one |
507 // untyped. | 521 // untyped. |
508 | 522 |
509 // With default scoring, a two-visit score should have a higher score than the | 523 // With default scoring, a two-visit score should have a higher score than the |
510 // single typed visit score. | 524 // single typed visit score. |
511 visits = {{now, ui::PAGE_TRANSITION_TYPED}, | 525 visits = {{now, ui::PAGE_TRANSITION_TYPED}, |
512 {now - base::TimeDelta::FromDays(1), ui::PAGE_TRANSITION_LINK}}; | 526 {now - base::TimeDelta::FromDays(1), ui::PAGE_TRANSITION_LINK}}; |
513 const float two_visits_score = match.GetFrequency(now, false, visits); | 527 const float two_visits_score = match.GetFrequency(now, false, visits, 1); |
514 EXPECT_GT(two_visits_score, one_typed_score); | 528 EXPECT_GT(two_visits_score, one_typed_score); |
515 | 529 |
516 // Likewise, with |frequency_uses_sum_|, the two-visit score should be higher | 530 // Likewise, with |frequency_uses_sum_|, the two-visit score should be higher |
517 // than the single typed visit score because the sum is greater. | 531 // than the single typed visit score because the sum is greater. |
518 float two_visits_score_uses_sum; | 532 float two_visits_score_uses_sum; |
519 { | 533 { |
520 base::AutoReset<bool> tmp(&ScoredHistoryMatch::frequency_uses_sum_, true); | 534 base::AutoReset<bool> tmp(&ScoredHistoryMatch::frequency_uses_sum_, true); |
521 two_visits_score_uses_sum = match.GetFrequency(now, false, visits); | 535 two_visits_score_uses_sum = match.GetFrequency(now, false, visits, 1); |
522 EXPECT_GT(two_visits_score_uses_sum, one_typed_score); | 536 EXPECT_GT(two_visits_score_uses_sum, one_typed_score); |
523 } | 537 } |
524 | 538 |
525 // With |fix_few_visits_bug_|, its two-visit score should be higher than the | 539 // With |fix_few_visits_bug_|, its two-visit score should be higher than the |
526 // one-visit score but lower than the regular two-visit score because the | 540 // one-visit score but lower than the regular two-visit score because the |
527 // fix-few-visits score computes the average visit score and the untyped | 541 // fix-few-visits score computes the average visit score and the untyped |
528 // visit brings the average down. | 542 // visit brings the average down. The behavior with respect to boosting |
543 // the score based on the number of matching pages should remain unchanged. | |
529 float two_visits_score_fix_few_visits; | 544 float two_visits_score_fix_few_visits; |
530 { | 545 { |
531 base::AutoReset<bool> tmp(&ScoredHistoryMatch::fix_few_visits_bug_, true); | 546 base::AutoReset<bool> tmp(&ScoredHistoryMatch::fix_few_visits_bug_, true); |
532 two_visits_score_fix_few_visits = match.GetFrequency(now, false, visits); | 547 two_visits_score_fix_few_visits = match.GetFrequency(now, false, visits, 1); |
533 EXPECT_GT(two_visits_score_fix_few_visits, one_typed_score); | 548 EXPECT_GT(two_visits_score_fix_few_visits, one_typed_score); |
534 EXPECT_LT(two_visits_score_fix_few_visits, two_visits_score); | 549 EXPECT_LT(two_visits_score_fix_few_visits, two_visits_score); |
550 | |
551 EXPECT_EQ(match.GetFrequency(now, false, visits, 5), | |
552 two_visits_score_fix_few_visits); | |
553 { | |
554 base::AutoReset<OmniboxFieldTrial::NumMatchesMultipliers> tmp2( | |
555 ScoredHistoryMatch::num_matches_to_frequency_multiplier_, | |
556 OmniboxFieldTrial::NumMatchesMultipliers{{1, 3.0}}); | |
557 EXPECT_GT(match.GetFrequency(now, false, visits, 1), | |
558 two_visits_score_fix_few_visits); | |
559 EXPECT_EQ(match.GetFrequency(now, false, visits, 5), | |
560 two_visits_score_fix_few_visits); | |
561 } | |
535 } | 562 } |
536 | 563 |
537 // Add an third untyped visit. | 564 // Add an third untyped visit. |
538 visits.push_back( | 565 visits.push_back( |
539 {now - base::TimeDelta::FromDays(2), ui::PAGE_TRANSITION_LINK}); | 566 {now - base::TimeDelta::FromDays(2), ui::PAGE_TRANSITION_LINK}); |
540 | 567 |
541 // With default scoring and with |frequency_uses_sum_|, the score should be | 568 // With default scoring and with |frequency_uses_sum_|, the score should be |
542 // higher than the two-visit score. | 569 // higher than the two-visit score. The behavior with respect to boosting |
543 const float three_visits_score = match.GetFrequency(now, false, visits); | 570 // the score based on the number of matching pages should remain unchanged |
571 const float three_visits_score = match.GetFrequency(now, false, visits, 1); | |
544 EXPECT_GT(three_visits_score, two_visits_score); | 572 EXPECT_GT(three_visits_score, two_visits_score); |
545 { | 573 { |
546 base::AutoReset<bool> tmp(&ScoredHistoryMatch::frequency_uses_sum_, true); | 574 base::AutoReset<bool> tmp(&ScoredHistoryMatch::frequency_uses_sum_, true); |
547 const float three_visits_score_uses_sum = | 575 const float three_visits_score_uses_sum = |
548 match.GetFrequency(now, false, visits); | 576 match.GetFrequency(now, false, visits, 1); |
549 EXPECT_GT(three_visits_score_uses_sum, two_visits_score); | 577 EXPECT_GT(three_visits_score_uses_sum, two_visits_score); |
550 EXPECT_GT(three_visits_score_uses_sum, two_visits_score_uses_sum); | 578 EXPECT_GT(three_visits_score_uses_sum, two_visits_score_uses_sum); |
579 | |
580 EXPECT_EQ(match.GetFrequency(now, false, visits, 5), | |
581 three_visits_score_uses_sum); | |
582 { | |
583 base::AutoReset<OmniboxFieldTrial::NumMatchesMultipliers> tmp2( | |
584 ScoredHistoryMatch::num_matches_to_frequency_multiplier_, | |
585 OmniboxFieldTrial::NumMatchesMultipliers{{1, 3.0}}); | |
586 EXPECT_GT(match.GetFrequency(now, false, visits, 1), | |
587 three_visits_score_uses_sum); | |
588 EXPECT_EQ(match.GetFrequency(now, false, visits, 5), | |
589 three_visits_score_uses_sum); | |
590 } | |
551 } | 591 } |
552 | 592 |
553 // With |fix_few_visits_bug_|, the score should also go up but not as much as | 593 // With |fix_few_visits_bug_|, the score should also go up but not as much as |
554 // under regular scoring. | 594 // under regular scoring. |
555 { | 595 { |
556 base::AutoReset<bool> tmp(&ScoredHistoryMatch::fix_few_visits_bug_, true); | 596 base::AutoReset<bool> tmp(&ScoredHistoryMatch::fix_few_visits_bug_, true); |
557 const float three_visits_score_fix_few_visits = | 597 const float three_visits_score_fix_few_visits = |
558 match.GetFrequency(now, false, visits); | 598 match.GetFrequency(now, false, visits, 1); |
559 EXPECT_GT(three_visits_score_fix_few_visits, | 599 EXPECT_GT(three_visits_score_fix_few_visits, |
560 two_visits_score_fix_few_visits); | 600 two_visits_score_fix_few_visits); |
561 EXPECT_LT(three_visits_score_fix_few_visits, three_visits_score); | 601 EXPECT_LT(three_visits_score_fix_few_visits, three_visits_score); |
562 } | 602 } |
563 | 603 |
564 // In the uses-sum case, if we're only supposed to consider the most recent | 604 // In the uses-sum case, if we're only supposed to consider the most recent |
565 // two visits, then all the scores should be the same as in the two-visit | 605 // two visits, then all the scores should be the same as in the two-visit |
566 // case. (For the regular scoring and the fix-few-visits cases, the | 606 // case. (For the regular scoring and the fix-few-visits cases, the |
567 // situation is more complicated because in these cases both the numerator-- | 607 // situation is more complicated because in these cases both the numerator-- |
568 // the value of the visits used--and the denominator--the number of visits | 608 // the value of the visits used--and the denominator--the number of visits |
569 // used--changed. We don't test this complicated logic separately from having | 609 // used--changed. We don't test this complicated logic separately from having |
570 // tested the simpler components already.) | 610 // tested the simpler components already.) |
571 { | 611 { |
572 base::AutoReset<size_t> tmp1(&ScoredHistoryMatch::max_visits_to_score_, 2); | 612 base::AutoReset<size_t> tmp1(&ScoredHistoryMatch::max_visits_to_score_, 2); |
573 base::AutoReset<bool> tmp2(&ScoredHistoryMatch::frequency_uses_sum_, true); | 613 base::AutoReset<bool> tmp2(&ScoredHistoryMatch::frequency_uses_sum_, true); |
574 EXPECT_EQ(two_visits_score_uses_sum, | 614 EXPECT_EQ(two_visits_score_uses_sum, |
575 match.GetFrequency(now, false, visits)); | 615 match.GetFrequency(now, false, visits, 1)); |
576 | 616 |
577 // Check again with the third visit being typed. | 617 // Check again with the third visit being typed. |
578 visits[2].second = ui::PAGE_TRANSITION_TYPED; | 618 visits[2].second = ui::PAGE_TRANSITION_TYPED; |
579 EXPECT_EQ(two_visits_score_uses_sum, | 619 EXPECT_EQ(two_visits_score_uses_sum, |
580 match.GetFrequency(now, false, visits)); | 620 match.GetFrequency(now, false, visits, 1)); |
581 } | 621 } |
582 } | 622 } |
583 | 623 |
584 // This function only tests scoring of single terms that match exactly | 624 // This function only tests scoring of single terms that match exactly |
585 // once somewhere in the URL or title. | 625 // once somewhere in the URL or title. |
586 TEST_F(ScoredHistoryMatchTest, GetTopicalityScore) { | 626 TEST_F(ScoredHistoryMatchTest, GetTopicalityScore) { |
587 base::string16 url = ASCIIToUTF16( | 627 base::string16 url = ASCIIToUTF16( |
588 "http://abc.def.com/path1/path2?" | 628 "http://abc.def.com/path1/path2?" |
589 "arg1=val1&arg2=val2#hash_component"); | 629 "arg1=val1&arg2=val2#hash_component"); |
590 base::string16 title = ASCIIToUTF16("here is a title"); | 630 base::string16 title = ASCIIToUTF16("here is a title"); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
691 | 731 |
692 EXPECT_TRUE( | 732 EXPECT_TRUE( |
693 ScoredHistoryMatch::GetHQPBucketsFromString(buckets_str, &hqp_buckets)); | 733 ScoredHistoryMatch::GetHQPBucketsFromString(buckets_str, &hqp_buckets)); |
694 EXPECT_THAT(hqp_buckets, ElementsAre(Pair(0.0, 400), Pair(1.5, 600), | 734 EXPECT_THAT(hqp_buckets, ElementsAre(Pair(0.0, 400), Pair(1.5, 600), |
695 Pair(12.0, 1300), Pair(20.0, 1399))); | 735 Pair(12.0, 1300), Pair(20.0, 1399))); |
696 // invalid string. | 736 // invalid string. |
697 buckets_str = "0.0,400,1.5,600"; | 737 buckets_str = "0.0,400,1.5,600"; |
698 EXPECT_FALSE( | 738 EXPECT_FALSE( |
699 ScoredHistoryMatch::GetHQPBucketsFromString(buckets_str, &hqp_buckets)); | 739 ScoredHistoryMatch::GetHQPBucketsFromString(buckets_str, &hqp_buckets)); |
700 } | 740 } |
OLD | NEW |