| 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 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 // to calculate last visit time when building a row. | 128 // to calculate last visit time when building a row. |
| 129 base::Time now = base::Time::NowFromSystemTime(); | 129 base::Time now = base::Time::NowFromSystemTime(); |
| 130 | 130 |
| 131 history::URLRow row_a(MakeURLRow("http://fedcba", "abcd bcd", 3, 30, 1)); | 131 history::URLRow row_a(MakeURLRow("http://fedcba", "abcd bcd", 3, 30, 1)); |
| 132 RowWordStarts word_starts_a; | 132 RowWordStarts word_starts_a; |
| 133 PopulateWordStarts(row_a, &word_starts_a); | 133 PopulateWordStarts(row_a, &word_starts_a); |
| 134 WordStarts one_word_no_offset(1, 0u); | 134 WordStarts one_word_no_offset(1, 0u); |
| 135 VisitInfoVector visits_a = CreateVisitInfoVector(3, 30, now); | 135 VisitInfoVector visits_a = CreateVisitInfoVector(3, 30, now); |
| 136 // Mark one visit as typed. | 136 // Mark one visit as typed. |
| 137 visits_a[0].second = ui::PAGE_TRANSITION_TYPED; | 137 visits_a[0].second = ui::PAGE_TRANSITION_TYPED; |
| 138 ScoredHistoryMatch scored_a(row_a, visits_a, std::string(), | 138 ScoredHistoryMatch scored_a(row_a, visits_a, ASCIIToUTF16("abc"), |
| 139 ASCIIToUTF16("abc"), Make1Term("abc"), | 139 Make1Term("abc"), one_word_no_offset, |
| 140 one_word_no_offset, word_starts_a, false, nullptr, | 140 word_starts_a, false, nullptr, now); |
| 141 now); | |
| 142 | 141 |
| 143 // Test scores based on visit_count. | 142 // Test scores based on visit_count. |
| 144 history::URLRow row_b(MakeURLRow("http://abcdef", "abcd bcd", 10, 30, 1)); | 143 history::URLRow row_b(MakeURLRow("http://abcdef", "abcd bcd", 10, 30, 1)); |
| 145 RowWordStarts word_starts_b; | 144 RowWordStarts word_starts_b; |
| 146 PopulateWordStarts(row_b, &word_starts_b); | 145 PopulateWordStarts(row_b, &word_starts_b); |
| 147 VisitInfoVector visits_b = CreateVisitInfoVector(10, 30, now); | 146 VisitInfoVector visits_b = CreateVisitInfoVector(10, 30, now); |
| 148 visits_b[0].second = ui::PAGE_TRANSITION_TYPED; | 147 visits_b[0].second = ui::PAGE_TRANSITION_TYPED; |
| 149 ScoredHistoryMatch scored_b(row_b, visits_b, std::string(), | 148 ScoredHistoryMatch scored_b(row_b, visits_b, ASCIIToUTF16("abc"), |
| 150 ASCIIToUTF16("abc"), Make1Term("abc"), | 149 Make1Term("abc"), one_word_no_offset, |
| 151 one_word_no_offset, word_starts_b, false, nullptr, | 150 word_starts_b, false, nullptr, now); |
| 152 now); | |
| 153 EXPECT_GT(scored_b.raw_score, scored_a.raw_score); | 151 EXPECT_GT(scored_b.raw_score, scored_a.raw_score); |
| 154 | 152 |
| 155 // Test scores based on last_visit. | 153 // Test scores based on last_visit. |
| 156 history::URLRow row_c(MakeURLRow("http://abcdef", "abcd bcd", 3, 10, 1)); | 154 history::URLRow row_c(MakeURLRow("http://abcdef", "abcd bcd", 3, 10, 1)); |
| 157 RowWordStarts word_starts_c; | 155 RowWordStarts word_starts_c; |
| 158 PopulateWordStarts(row_c, &word_starts_c); | 156 PopulateWordStarts(row_c, &word_starts_c); |
| 159 VisitInfoVector visits_c = CreateVisitInfoVector(3, 10, now); | 157 VisitInfoVector visits_c = CreateVisitInfoVector(3, 10, now); |
| 160 visits_c[0].second = ui::PAGE_TRANSITION_TYPED; | 158 visits_c[0].second = ui::PAGE_TRANSITION_TYPED; |
| 161 ScoredHistoryMatch scored_c(row_c, visits_c, std::string(), | 159 ScoredHistoryMatch scored_c(row_c, visits_c, ASCIIToUTF16("abc"), |
| 162 ASCIIToUTF16("abc"), Make1Term("abc"), | 160 Make1Term("abc"), one_word_no_offset, |
| 163 one_word_no_offset, word_starts_c, false, nullptr, | 161 word_starts_c, false, nullptr, now); |
| 164 now); | |
| 165 EXPECT_GT(scored_c.raw_score, scored_a.raw_score); | 162 EXPECT_GT(scored_c.raw_score, scored_a.raw_score); |
| 166 | 163 |
| 167 // Test scores based on typed_count. | 164 // Test scores based on typed_count. |
| 168 history::URLRow row_d(MakeURLRow("http://abcdef", "abcd bcd", 3, 30, 3)); | 165 history::URLRow row_d(MakeURLRow("http://abcdef", "abcd bcd", 3, 30, 3)); |
| 169 RowWordStarts word_starts_d; | 166 RowWordStarts word_starts_d; |
| 170 PopulateWordStarts(row_d, &word_starts_d); | 167 PopulateWordStarts(row_d, &word_starts_d); |
| 171 VisitInfoVector visits_d = CreateVisitInfoVector(3, 30, now); | 168 VisitInfoVector visits_d = CreateVisitInfoVector(3, 30, now); |
| 172 visits_d[0].second = ui::PAGE_TRANSITION_TYPED; | 169 visits_d[0].second = ui::PAGE_TRANSITION_TYPED; |
| 173 visits_d[1].second = ui::PAGE_TRANSITION_TYPED; | 170 visits_d[1].second = ui::PAGE_TRANSITION_TYPED; |
| 174 visits_d[2].second = ui::PAGE_TRANSITION_TYPED; | 171 visits_d[2].second = ui::PAGE_TRANSITION_TYPED; |
| 175 ScoredHistoryMatch scored_d(row_d, visits_d, std::string(), | 172 ScoredHistoryMatch scored_d(row_d, visits_d, ASCIIToUTF16("abc"), |
| 176 ASCIIToUTF16("abc"), Make1Term("abc"), | 173 Make1Term("abc"), one_word_no_offset, |
| 177 one_word_no_offset, word_starts_d, false, nullptr, | 174 word_starts_d, false, nullptr, now); |
| 178 now); | |
| 179 EXPECT_GT(scored_d.raw_score, scored_a.raw_score); | 175 EXPECT_GT(scored_d.raw_score, scored_a.raw_score); |
| 180 | 176 |
| 181 // Test scores based on a terms appearing multiple times. | 177 // Test scores based on a terms appearing multiple times. |
| 182 history::URLRow row_e(MakeURLRow( | 178 history::URLRow row_e(MakeURLRow( |
| 183 "http://csi.csi.csi/csi_csi", | 179 "http://csi.csi.csi/csi_csi", |
| 184 "CSI Guide to CSI Las Vegas, CSI New York, CSI Provo", 3, 30, 3)); | 180 "CSI Guide to CSI Las Vegas, CSI New York, CSI Provo", 3, 30, 3)); |
| 185 RowWordStarts word_starts_e; | 181 RowWordStarts word_starts_e; |
| 186 PopulateWordStarts(row_e, &word_starts_e); | 182 PopulateWordStarts(row_e, &word_starts_e); |
| 187 const VisitInfoVector visits_e = visits_d; | 183 const VisitInfoVector visits_e = visits_d; |
| 188 ScoredHistoryMatch scored_e(row_e, visits_e, std::string(), | 184 ScoredHistoryMatch scored_e(row_e, visits_e, ASCIIToUTF16("csi"), |
| 189 ASCIIToUTF16("csi"), Make1Term("csi"), | 185 Make1Term("csi"), one_word_no_offset, |
| 190 one_word_no_offset, word_starts_e, false, nullptr, | 186 word_starts_e, false, nullptr, now); |
| 191 now); | |
| 192 EXPECT_LT(scored_e.raw_score, 1400); | 187 EXPECT_LT(scored_e.raw_score, 1400); |
| 193 | 188 |
| 194 // Test that a result with only a mid-term match (i.e., not at a word | 189 // Test that a result with only a mid-term match (i.e., not at a word |
| 195 // boundary) scores 0. | 190 // boundary) scores 0. |
| 196 ScoredHistoryMatch scored_f(row_a, visits_a, std::string(), | 191 ScoredHistoryMatch scored_f(row_a, visits_a, ASCIIToUTF16("cd"), |
| 197 ASCIIToUTF16("cd"), Make1Term("cd"), | 192 Make1Term("cd"), one_word_no_offset, |
| 198 one_word_no_offset, word_starts_a, false, nullptr, | 193 word_starts_a, false, nullptr, now); |
| 199 now); | |
| 200 EXPECT_EQ(scored_f.raw_score, 0); | 194 EXPECT_EQ(scored_f.raw_score, 0); |
| 201 } | 195 } |
| 202 | 196 |
| 203 TEST_F(ScoredHistoryMatchTest, ScoringBookmarks) { | 197 TEST_F(ScoredHistoryMatchTest, ScoringBookmarks) { |
| 204 // We use NowFromSystemTime() because MakeURLRow uses the same function | 198 // We use NowFromSystemTime() because MakeURLRow uses the same function |
| 205 // to calculate last visit time when building a row. | 199 // to calculate last visit time when building a row. |
| 206 base::Time now = base::Time::NowFromSystemTime(); | 200 base::Time now = base::Time::NowFromSystemTime(); |
| 207 | 201 |
| 208 std::string url_string("http://fedcba"); | 202 std::string url_string("http://fedcba"); |
| 209 const GURL url(url_string); | 203 const GURL url(url_string); |
| 210 history::URLRow row(MakeURLRow(url_string.c_str(), "abcd bcd", 8, 3, 1)); | 204 history::URLRow row(MakeURLRow(url_string.c_str(), "abcd bcd", 8, 3, 1)); |
| 211 RowWordStarts word_starts; | 205 RowWordStarts word_starts; |
| 212 PopulateWordStarts(row, &word_starts); | 206 PopulateWordStarts(row, &word_starts); |
| 213 WordStarts one_word_no_offset(1, 0u); | 207 WordStarts one_word_no_offset(1, 0u); |
| 214 VisitInfoVector visits = CreateVisitInfoVector(8, 3, now); | 208 VisitInfoVector visits = CreateVisitInfoVector(8, 3, now); |
| 215 ScoredHistoryMatch scored(row, visits, std::string(), ASCIIToUTF16("abc"), | 209 ScoredHistoryMatch scored(row, visits, ASCIIToUTF16("abc"), |
| 216 Make1Term("abc"), one_word_no_offset, word_starts, | 210 Make1Term("abc"), one_word_no_offset, word_starts, |
| 217 false, nullptr, now); | 211 false, nullptr, now); |
| 218 // Now check that if URL is bookmarked then its score increases. | 212 // Now check that if URL is bookmarked then its score increases. |
| 219 base::AutoReset<int> reset(&ScoredHistoryMatch::bookmark_value_, 5); | 213 base::AutoReset<int> reset(&ScoredHistoryMatch::bookmark_value_, 5); |
| 220 ScoredHistoryMatch scored_with_bookmark( | 214 ScoredHistoryMatch scored_with_bookmark( |
| 221 row, visits, std::string(), ASCIIToUTF16("abc"), Make1Term("abc"), | 215 row, visits, ASCIIToUTF16("abc"), Make1Term("abc"), |
| 222 one_word_no_offset, word_starts, true, nullptr, now); | 216 one_word_no_offset, word_starts, true, nullptr, now); |
| 223 EXPECT_GT(scored_with_bookmark.raw_score, scored.raw_score); | 217 EXPECT_GT(scored_with_bookmark.raw_score, scored.raw_score); |
| 224 } | 218 } |
| 225 | 219 |
| 226 TEST_F(ScoredHistoryMatchTest, ScoringTLD) { | 220 TEST_F(ScoredHistoryMatchTest, ScoringTLD) { |
| 227 // We use NowFromSystemTime() because MakeURLRow uses the same function | 221 // We use NowFromSystemTime() because MakeURLRow uses the same function |
| 228 // to calculate last visit time when building a row. | 222 // to calculate last visit time when building a row. |
| 229 base::Time now = base::Time::NowFromSystemTime(); | 223 base::Time now = base::Time::NowFromSystemTime(); |
| 230 | 224 |
| 231 // By default the URL should not be returned for a query that includes "com". | 225 // By default the URL should not be returned for a query that includes "com". |
| 232 std::string url_string("http://fedcba.com/"); | 226 std::string url_string("http://fedcba.com/"); |
| 233 const GURL url(url_string); | 227 const GURL url(url_string); |
| 234 history::URLRow row(MakeURLRow(url_string.c_str(), "", 8, 3, 1)); | 228 history::URLRow row(MakeURLRow(url_string.c_str(), "", 8, 3, 1)); |
| 235 RowWordStarts word_starts; | 229 RowWordStarts word_starts; |
| 236 PopulateWordStarts(row, &word_starts); | 230 PopulateWordStarts(row, &word_starts); |
| 237 WordStarts two_words_no_offsets(2, 0u); | 231 WordStarts two_words_no_offsets(2, 0u); |
| 238 VisitInfoVector visits = CreateVisitInfoVector(8, 3, now); | 232 VisitInfoVector visits = CreateVisitInfoVector(8, 3, now); |
| 239 ScoredHistoryMatch scored(row, visits, std::string(), ASCIIToUTF16("fed com"), | 233 ScoredHistoryMatch scored(row, visits, ASCIIToUTF16("fed com"), |
| 240 Make2Terms("fed", "com"), two_words_no_offsets, | 234 Make2Terms("fed", "com"), two_words_no_offsets, |
| 241 word_starts, false, nullptr, now); | 235 word_starts, false, nullptr, now); |
| 242 EXPECT_EQ(0, scored.raw_score); | 236 EXPECT_EQ(0, scored.raw_score); |
| 243 | 237 |
| 244 // Now allow credit for the match in the TLD. | 238 // Now allow credit for the match in the TLD. |
| 245 base::AutoReset<bool> reset(&ScoredHistoryMatch::allow_tld_matches_, true); | 239 base::AutoReset<bool> reset(&ScoredHistoryMatch::allow_tld_matches_, true); |
| 246 ScoredHistoryMatch scored_with_tld( | 240 ScoredHistoryMatch scored_with_tld(row, visits, ASCIIToUTF16("fed com"), |
| 247 row, visits, std::string(), ASCIIToUTF16("fed com"), | |
| 248 Make2Terms("fed", "com"), two_words_no_offsets, word_starts, false, | 241 Make2Terms("fed", "com"), two_words_no_offsets, word_starts, false, |
| 249 nullptr, now); | 242 nullptr, now); |
| 250 EXPECT_GT(scored_with_tld.raw_score, 0); | 243 EXPECT_GT(scored_with_tld.raw_score, 0); |
| 251 } | 244 } |
| 252 | 245 |
| 253 TEST_F(ScoredHistoryMatchTest, ScoringScheme) { | 246 TEST_F(ScoredHistoryMatchTest, ScoringScheme) { |
| 254 // We use NowFromSystemTime() because MakeURLRow uses the same function | 247 // We use NowFromSystemTime() because MakeURLRow uses the same function |
| 255 // to calculate last visit time when building a row. | 248 // to calculate last visit time when building a row. |
| 256 base::Time now = base::Time::NowFromSystemTime(); | 249 base::Time now = base::Time::NowFromSystemTime(); |
| 257 | 250 |
| 258 // By default the URL should not be returned for a query that includes "http". | 251 // By default the URL should not be returned for a query that includes "http". |
| 259 std::string url_string("http://fedcba/"); | 252 std::string url_string("http://fedcba/"); |
| 260 const GURL url(url_string); | 253 const GURL url(url_string); |
| 261 history::URLRow row(MakeURLRow(url_string.c_str(), "", 8, 3, 1)); | 254 history::URLRow row(MakeURLRow(url_string.c_str(), "", 8, 3, 1)); |
| 262 RowWordStarts word_starts; | 255 RowWordStarts word_starts; |
| 263 PopulateWordStarts(row, &word_starts); | 256 PopulateWordStarts(row, &word_starts); |
| 264 WordStarts two_words_no_offsets(2, 0u); | 257 WordStarts two_words_no_offsets(2, 0u); |
| 265 VisitInfoVector visits = CreateVisitInfoVector(8, 3, now); | 258 VisitInfoVector visits = CreateVisitInfoVector(8, 3, now); |
| 266 ScoredHistoryMatch scored(row, visits, std::string(), | 259 ScoredHistoryMatch scored(row, visits, ASCIIToUTF16("fed http"), |
| 267 ASCIIToUTF16("fed http"), Make2Terms("fed", "http"), | 260 Make2Terms("fed", "http"), two_words_no_offsets, |
| 268 two_words_no_offsets, word_starts, false, nullptr, | 261 word_starts, false, nullptr, now); |
| 269 now); | |
| 270 EXPECT_EQ(0, scored.raw_score); | 262 EXPECT_EQ(0, scored.raw_score); |
| 271 | 263 |
| 272 // Now allow credit for the match in the scheme. | 264 // Now allow credit for the match in the scheme. |
| 273 base::AutoReset<bool> reset(&ScoredHistoryMatch::allow_scheme_matches_, true); | 265 base::AutoReset<bool> reset(&ScoredHistoryMatch::allow_scheme_matches_, true); |
| 274 ScoredHistoryMatch scored_with_scheme( | 266 ScoredHistoryMatch scored_with_scheme(row, visits, ASCIIToUTF16("fed http"), |
| 275 row, visits, std::string(), ASCIIToUTF16("fed http"), | |
| 276 Make2Terms("fed", "http"), two_words_no_offsets, word_starts, false, | 267 Make2Terms("fed", "http"), two_words_no_offsets, word_starts, false, |
| 277 nullptr, now); | 268 nullptr, now); |
| 278 EXPECT_GT(scored_with_scheme.raw_score, 0); | 269 EXPECT_GT(scored_with_scheme.raw_score, 0); |
| 279 } | 270 } |
| 280 | 271 |
| 281 TEST_F(ScoredHistoryMatchTest, CullSearchResults) { | 272 TEST_F(ScoredHistoryMatchTest, CullSearchResults) { |
| 282 scoped_ptr<TemplateURLService> template_url_service = | 273 scoped_ptr<TemplateURLService> template_url_service = |
| 283 make_scoped_ptr(new TemplateURLService( | 274 make_scoped_ptr(new TemplateURLService( |
| 284 nullptr, make_scoped_ptr(new SearchTermsData), nullptr, | 275 nullptr, make_scoped_ptr(new SearchTermsData), nullptr, |
| 285 scoped_ptr<TemplateURLServiceClient>(), nullptr, nullptr, | 276 scoped_ptr<TemplateURLServiceClient>(), nullptr, nullptr, |
| 286 base::Closure())); | 277 base::Closure())); |
| 287 | 278 |
| 288 // We use NowFromSystemTime() because MakeURLRow uses the same function | 279 // We use NowFromSystemTime() because MakeURLRow uses the same function |
| 289 // to calculate last visit time when building a row. | 280 // to calculate last visit time when building a row. |
| 290 base::Time now = base::Time::NowFromSystemTime(); | 281 base::Time now = base::Time::NowFromSystemTime(); |
| 291 | 282 |
| 292 // Pretend we've visited a search engine query URL, but that it's not | 283 // Pretend we've visited a search engine query URL, but that it's not |
| 293 // associated with the default search engine. | 284 // associated with the default search engine. |
| 294 history::URLRow row(MakeURLRow( | 285 history::URLRow row(MakeURLRow( |
| 295 "http://testsearch.com/thequery", "Test Search Engine", 3, 30, 1)); | 286 "http://testsearch.com/thequery", "Test Search Engine", 3, 30, 1)); |
| 296 RowWordStarts word_starts; | 287 RowWordStarts word_starts; |
| 297 PopulateWordStarts(row, &word_starts); | 288 PopulateWordStarts(row, &word_starts); |
| 298 WordStarts one_word_no_offset(1, 0u); | 289 WordStarts one_word_no_offset(1, 0u); |
| 299 VisitInfoVector visits = CreateVisitInfoVector(3, 30, now); | 290 VisitInfoVector visits = CreateVisitInfoVector(3, 30, now); |
| 300 // Mark one visit as typed. | 291 // Mark one visit as typed. |
| 301 visits[0].second = ui::PAGE_TRANSITION_TYPED; | 292 visits[0].second = ui::PAGE_TRANSITION_TYPED; |
| 302 | 293 |
| 303 // This page should be returned if it's associated with the default search | 294 // This page should be returned if it's associated with the default search |
| 304 // engine. | 295 // engine. |
| 305 ScoredHistoryMatch scored_a(row, visits, std::string(), | 296 ScoredHistoryMatch scored_a(row, visits, ASCIIToUTF16("thequery"), |
| 306 ASCIIToUTF16("thequery"), Make1Term("thequery"), | 297 Make1Term("thequery"), one_word_no_offset, |
| 307 one_word_no_offset, word_starts, false, | 298 word_starts, false, template_url_service.get(), |
| 308 template_url_service.get(), now); | 299 now); |
| 309 EXPECT_GT(scored_a.raw_score, 0); | 300 EXPECT_GT(scored_a.raw_score, 0); |
| 310 | 301 |
| 311 // Likewise, it should be returned when typing the engine URL. | 302 // Likewise, it should be returned when typing the engine URL. |
| 312 ScoredHistoryMatch scored_b(row, visits, std::string(), | 303 ScoredHistoryMatch scored_b(row, visits, ASCIIToUTF16("testsearch"), |
| 313 ASCIIToUTF16("testsearch"), | |
| 314 Make1Term("testsearch"), one_word_no_offset, | 304 Make1Term("testsearch"), one_word_no_offset, |
| 315 word_starts, false, template_url_service.get(), | 305 word_starts, false, template_url_service.get(), |
| 316 now); | 306 now); |
| 317 EXPECT_GT(scored_b.raw_score, 0); | 307 EXPECT_GT(scored_b.raw_score, 0); |
| 318 | 308 |
| 319 // Set up a default search engine associated with this URL. | 309 // Set up a default search engine associated with this URL. |
| 320 TemplateURLData data; | 310 TemplateURLData data; |
| 321 data.SetShortName(ASCIIToUTF16("TestEngine")); | 311 data.SetShortName(ASCIIToUTF16("TestEngine")); |
| 322 data.SetKeyword(ASCIIToUTF16("TestEngine")); | 312 data.SetKeyword(ASCIIToUTF16("TestEngine")); |
| 323 data.SetURL("http://testsearch.com/{searchTerms}"); | 313 data.SetURL("http://testsearch.com/{searchTerms}"); |
| 324 TemplateURL* template_url = new TemplateURL(data); | 314 TemplateURL* template_url = new TemplateURL(data); |
| 325 template_url_service->Add(template_url); | 315 template_url_service->Add(template_url); |
| 326 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); | 316 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); |
| 327 template_url_service->Load(); | 317 template_url_service->Load(); |
| 328 | 318 |
| 329 // The search results page should not be returned when typing a query. | 319 // The search results page should not be returned when typing a query. |
| 330 ScoredHistoryMatch scored_c(row, visits, std::string(), | 320 ScoredHistoryMatch scored_c(row, visits, ASCIIToUTF16("thequery"), |
| 331 ASCIIToUTF16("thequery"), Make1Term("thequery"), | 321 Make1Term("thequery"), one_word_no_offset, |
| 332 one_word_no_offset, word_starts, false, | 322 word_starts, false, template_url_service.get(), |
| 333 template_url_service.get(), now); | 323 now); |
| 334 EXPECT_EQ(0, scored_c.raw_score); | 324 EXPECT_EQ(0, scored_c.raw_score); |
| 335 | 325 |
| 336 // Likewise, it shouldn't be returned when typing the engine URL. | 326 // Likewise, it shouldn't be returned when typing the engine URL. |
| 337 ScoredHistoryMatch scored_d(row, visits, std::string(), | 327 ScoredHistoryMatch scored_d(row, visits, ASCIIToUTF16("testsearch"), |
| 338 ASCIIToUTF16("testsearch"), | |
| 339 Make1Term("testsearch"), one_word_no_offset, | 328 Make1Term("testsearch"), one_word_no_offset, |
| 340 word_starts, false, template_url_service.get(), | 329 word_starts, false, template_url_service.get(), |
| 341 now); | 330 now); |
| 342 EXPECT_EQ(0, scored_d.raw_score); | 331 EXPECT_EQ(0, scored_d.raw_score); |
| 343 } | 332 } |
| 344 | 333 |
| 345 TEST_F(ScoredHistoryMatchTest, Inlining) { | 334 TEST_F(ScoredHistoryMatchTest, Inlining) { |
| 346 // We use NowFromSystemTime() because MakeURLRow uses the same function | 335 // We use NowFromSystemTime() because MakeURLRow uses the same function |
| 347 // to calculate last visit time when building a row. | 336 // to calculate last visit time when building a row. |
| 348 base::Time now = base::Time::NowFromSystemTime(); | 337 base::Time now = base::Time::NowFromSystemTime(); |
| 349 RowWordStarts word_starts; | 338 RowWordStarts word_starts; |
| 350 WordStarts one_word_no_offset(1, 0u); | 339 WordStarts one_word_no_offset(1, 0u); |
| 351 VisitInfoVector visits; | 340 VisitInfoVector visits; |
| 352 | 341 |
| 353 { | 342 { |
| 354 history::URLRow row( | 343 history::URLRow row( |
| 355 MakeURLRow("http://www.google.com", "abcdef", 3, 30, 1)); | 344 MakeURLRow("http://www.google.com", "abcdef", 3, 30, 1)); |
| 356 PopulateWordStarts(row, &word_starts); | 345 PopulateWordStarts(row, &word_starts); |
| 357 ScoredHistoryMatch scored_a(row, visits, std::string(), ASCIIToUTF16("g"), | 346 ScoredHistoryMatch scored_a(row, visits, ASCIIToUTF16("g"), |
| 358 Make1Term("g"), one_word_no_offset, word_starts, | 347 Make1Term("g"), one_word_no_offset, word_starts, |
| 359 false, nullptr, now); | 348 false, nullptr, now); |
| 360 EXPECT_FALSE(scored_a.match_in_scheme); | 349 EXPECT_FALSE(scored_a.match_in_scheme); |
| 361 ScoredHistoryMatch scored_b(row, visits, std::string(), ASCIIToUTF16("w"), | 350 ScoredHistoryMatch scored_b(row, visits, ASCIIToUTF16("w"), |
| 362 Make1Term("w"), one_word_no_offset, word_starts, | 351 Make1Term("w"), one_word_no_offset, word_starts, |
| 363 false, nullptr, now); | 352 false, nullptr, now); |
| 364 EXPECT_FALSE(scored_b.match_in_scheme); | 353 EXPECT_FALSE(scored_b.match_in_scheme); |
| 365 ScoredHistoryMatch scored_c(row, visits, std::string(), ASCIIToUTF16("h"), | 354 ScoredHistoryMatch scored_c(row, visits, ASCIIToUTF16("h"), |
| 366 Make1Term("h"), one_word_no_offset, word_starts, | 355 Make1Term("h"), one_word_no_offset, word_starts, |
| 367 false, nullptr, now); | 356 false, nullptr, now); |
| 368 EXPECT_TRUE(scored_c.match_in_scheme); | 357 EXPECT_TRUE(scored_c.match_in_scheme); |
| 369 ScoredHistoryMatch scored_d(row, visits, std::string(), ASCIIToUTF16("o"), | 358 ScoredHistoryMatch scored_d(row, visits, ASCIIToUTF16("o"), |
| 370 Make1Term("o"), one_word_no_offset, word_starts, | 359 Make1Term("o"), one_word_no_offset, word_starts, |
| 371 false, nullptr, now); | 360 false, nullptr, now); |
| 372 EXPECT_FALSE(scored_d.match_in_scheme); | 361 EXPECT_FALSE(scored_d.match_in_scheme); |
| 373 } | 362 } |
| 374 | 363 |
| 375 { | 364 { |
| 376 history::URLRow row(MakeURLRow("http://teams.foo.com", "abcdef", 3, 30, 1)); | 365 history::URLRow row(MakeURLRow("http://teams.foo.com", "abcdef", 3, 30, 1)); |
| 377 PopulateWordStarts(row, &word_starts); | 366 PopulateWordStarts(row, &word_starts); |
| 378 ScoredHistoryMatch scored_a(row, visits, std::string(), ASCIIToUTF16("t"), | 367 ScoredHistoryMatch scored_a(row, visits, ASCIIToUTF16("t"), |
| 379 Make1Term("t"), one_word_no_offset, word_starts, | 368 Make1Term("t"), one_word_no_offset, word_starts, |
| 380 false, nullptr, now); | 369 false, nullptr, now); |
| 381 EXPECT_FALSE(scored_a.match_in_scheme); | 370 EXPECT_FALSE(scored_a.match_in_scheme); |
| 382 ScoredHistoryMatch scored_b(row, visits, std::string(), ASCIIToUTF16("f"), | 371 ScoredHistoryMatch scored_b(row, visits, ASCIIToUTF16("f"), |
| 383 Make1Term("f"), one_word_no_offset, word_starts, | 372 Make1Term("f"), one_word_no_offset, word_starts, |
| 384 false, nullptr, now); | 373 false, nullptr, now); |
| 385 EXPECT_FALSE(scored_b.match_in_scheme); | 374 EXPECT_FALSE(scored_b.match_in_scheme); |
| 386 ScoredHistoryMatch scored_c(row, visits, std::string(), ASCIIToUTF16("o"), | 375 ScoredHistoryMatch scored_c(row, visits, ASCIIToUTF16("o"), |
| 387 Make1Term("o"), one_word_no_offset, word_starts, | 376 Make1Term("o"), one_word_no_offset, word_starts, |
| 388 false, nullptr, now); | 377 false, nullptr, now); |
| 389 EXPECT_FALSE(scored_c.match_in_scheme); | 378 EXPECT_FALSE(scored_c.match_in_scheme); |
| 390 } | 379 } |
| 391 | 380 |
| 392 { | 381 { |
| 393 history::URLRow row( | 382 history::URLRow row( |
| 394 MakeURLRow("https://www.testing.com", "abcdef", 3, 30, 1)); | 383 MakeURLRow("https://www.testing.com", "abcdef", 3, 30, 1)); |
| 395 PopulateWordStarts(row, &word_starts); | 384 PopulateWordStarts(row, &word_starts); |
| 396 ScoredHistoryMatch scored_a(row, visits, std::string(), ASCIIToUTF16("t"), | 385 ScoredHistoryMatch scored_a(row, visits, ASCIIToUTF16("t"), |
| 397 Make1Term("t"), one_word_no_offset, word_starts, | 386 Make1Term("t"), one_word_no_offset, word_starts, |
| 398 false, nullptr, now); | 387 false, nullptr, now); |
| 399 EXPECT_FALSE(scored_a.match_in_scheme); | 388 EXPECT_FALSE(scored_a.match_in_scheme); |
| 400 ScoredHistoryMatch scored_b(row, visits, std::string(), ASCIIToUTF16("h"), | 389 ScoredHistoryMatch scored_b(row, visits, ASCIIToUTF16("h"), |
| 401 Make1Term("h"), one_word_no_offset, word_starts, | 390 Make1Term("h"), one_word_no_offset, word_starts, |
| 402 false, nullptr, now); | 391 false, nullptr, now); |
| 403 EXPECT_TRUE(scored_b.match_in_scheme); | 392 EXPECT_TRUE(scored_b.match_in_scheme); |
| 404 ScoredHistoryMatch scored_c(row, visits, std::string(), ASCIIToUTF16("w"), | 393 ScoredHistoryMatch scored_c(row, visits, ASCIIToUTF16("w"), |
| 405 Make1Term("w"), one_word_no_offset, word_starts, | 394 Make1Term("w"), one_word_no_offset, word_starts, |
| 406 false, nullptr, now); | 395 false, nullptr, now); |
| 407 EXPECT_FALSE(scored_c.match_in_scheme); | 396 EXPECT_FALSE(scored_c.match_in_scheme); |
| 408 } | 397 } |
| 409 | 398 |
| 410 { | 399 { |
| 411 history::URLRow row( | 400 history::URLRow row( |
| 412 MakeURLRow("http://www.xn--1lq90ic7f1rc.cn/xnblah", "abcd", 3, 30, 1)); | 401 MakeURLRow("http://www.xn--1lq90ic7f1rc.cn/xnblah", "abcd", 3, 30, 1)); |
| 413 PopulateWordStarts(row, &word_starts); | 402 PopulateWordStarts(row, &word_starts); |
| 414 ScoredHistoryMatch scored_a(row, visits, "zh-CN", ASCIIToUTF16("x"), | 403 ScoredHistoryMatch scored_a(row, visits, ASCIIToUTF16("x"), |
| 415 Make1Term("x"), one_word_no_offset, word_starts, | 404 Make1Term("x"), one_word_no_offset, word_starts, |
| 416 false, nullptr, now); | 405 false, nullptr, now); |
| 417 EXPECT_FALSE(scored_a.match_in_scheme); | 406 EXPECT_FALSE(scored_a.match_in_scheme); |
| 418 ScoredHistoryMatch scored_b(row, visits, "zh-CN", ASCIIToUTF16("xn"), | 407 ScoredHistoryMatch scored_b(row, visits, ASCIIToUTF16("xn"), |
| 419 Make1Term("xn"), one_word_no_offset, | 408 Make1Term("xn"), one_word_no_offset, |
| 420 word_starts, false, nullptr, now); | 409 word_starts, false, nullptr, now); |
| 421 EXPECT_FALSE(scored_b.match_in_scheme); | 410 EXPECT_FALSE(scored_b.match_in_scheme); |
| 422 ScoredHistoryMatch scored_c(row, visits, "zh-CN", ASCIIToUTF16("w"), | 411 ScoredHistoryMatch scored_c(row, visits, ASCIIToUTF16("w"), |
| 423 Make1Term("w"), one_word_no_offset, | 412 Make1Term("w"), one_word_no_offset, |
| 424 word_starts, false, nullptr, now); | 413 word_starts, false, nullptr, now); |
| 425 EXPECT_FALSE(scored_c.match_in_scheme); | 414 EXPECT_FALSE(scored_c.match_in_scheme); |
| 426 } | 415 } |
| 427 } | 416 } |
| 428 | 417 |
| 429 TEST_F(ScoredHistoryMatchTest, GetTopicalityScoreTrailingSlash) { | 418 TEST_F(ScoredHistoryMatchTest, GetTopicalityScoreTrailingSlash) { |
| 430 const float hostname = GetTopicalityScoreOfTermAgainstURLAndTitle( | 419 const float hostname = GetTopicalityScoreOfTermAgainstURLAndTitle( |
| 431 ASCIIToUTF16("def"), ASCIIToUTF16("http://abc.def.com/"), | 420 ASCIIToUTF16("def"), ASCIIToUTF16("http://abc.def.com/"), |
| 432 ASCIIToUTF16("Non-Matching Title")); | 421 ASCIIToUTF16("Non-Matching Title")); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 | 653 |
| 665 EXPECT_TRUE( | 654 EXPECT_TRUE( |
| 666 ScoredHistoryMatch::GetHQPBucketsFromString(buckets_str, &hqp_buckets)); | 655 ScoredHistoryMatch::GetHQPBucketsFromString(buckets_str, &hqp_buckets)); |
| 667 EXPECT_THAT(hqp_buckets, ElementsAre(Pair(0.0, 400), Pair(1.5, 600), | 656 EXPECT_THAT(hqp_buckets, ElementsAre(Pair(0.0, 400), Pair(1.5, 600), |
| 668 Pair(12.0, 1300), Pair(20.0, 1399))); | 657 Pair(12.0, 1300), Pair(20.0, 1399))); |
| 669 // invalid string. | 658 // invalid string. |
| 670 buckets_str = "0.0,400,1.5,600"; | 659 buckets_str = "0.0,400,1.5,600"; |
| 671 EXPECT_FALSE( | 660 EXPECT_FALSE( |
| 672 ScoredHistoryMatch::GetHQPBucketsFromString(buckets_str, &hqp_buckets)); | 661 ScoredHistoryMatch::GetHQPBucketsFromString(buckets_str, &hqp_buckets)); |
| 673 } | 662 } |
| OLD | NEW |