| 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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 EXPECT_EQ(0, scored.raw_score); | 237 EXPECT_EQ(0, scored.raw_score); |
| 238 | 238 |
| 239 // Now allow credit for the match in the TLD. | 239 // Now allow credit for the match in the TLD. |
| 240 base::AutoReset<bool> reset(&ScoredHistoryMatch::allow_tld_matches_, true); | 240 base::AutoReset<bool> reset(&ScoredHistoryMatch::allow_tld_matches_, true); |
| 241 ScoredHistoryMatch scored_with_tld(row, visits, ASCIIToUTF16("fed com"), | 241 ScoredHistoryMatch scored_with_tld(row, visits, ASCIIToUTF16("fed com"), |
| 242 Make2Terms("fed", "com"), two_words_no_offsets, word_starts, false, | 242 Make2Terms("fed", "com"), two_words_no_offsets, word_starts, false, |
| 243 nullptr, now); | 243 nullptr, now); |
| 244 EXPECT_GT(scored_with_tld.raw_score, 0); | 244 EXPECT_GT(scored_with_tld.raw_score, 0); |
| 245 } | 245 } |
| 246 | 246 |
| 247 TEST_F(ScoredHistoryMatchTest, ScoringPort) { |
| 248 // Reset the topicality threshold to 0, otherwise the port matches will not |
| 249 // score above the minimum to be returned. |
| 250 base::AutoReset<float> reset(&ScoredHistoryMatch::topicality_threshold_, 0.0); |
| 251 |
| 252 // We use NowFromSystemTime() because MakeURLRow uses the same function |
| 253 // to calculate last visit time when building a row. |
| 254 base::Time now = base::Time::NowFromSystemTime(); |
| 255 |
| 256 // The URL should be returned with a positive score for a query that includes |
| 257 // "8000". |
| 258 std::string url_string("http://fedcba.com:8000/"); |
| 259 GURL url(url_string); |
| 260 history::URLRow row(MakeURLRow(url_string.c_str(), "", 8, 3, 1)); |
| 261 RowWordStarts word_starts; |
| 262 PopulateWordStarts(row, &word_starts); |
| 263 WordStarts one_word_no_offsets(1, 0u); |
| 264 VisitInfoVector visits = CreateVisitInfoVector(8, 3, now); |
| 265 ScoredHistoryMatch scored(row, visits, ASCIIToUTF16("8000"), |
| 266 Make1Term("8000"), one_word_no_offsets, |
| 267 word_starts, false, nullptr, now); |
| 268 EXPECT_GT(scored.raw_score, 0); |
| 269 |
| 270 // Ditto for intranet URLs. |
| 271 url_string = "http://fedcba:8000/"; |
| 272 url = GURL(url_string); |
| 273 row = MakeURLRow(url_string.c_str(), "", 8, 3, 1); |
| 274 scored = ScoredHistoryMatch(row, visits, ASCIIToUTF16("8000"), |
| 275 Make1Term("8000"), one_word_no_offsets, |
| 276 word_starts, false, nullptr, now); |
| 277 EXPECT_GT(scored.raw_score, 0); |
| 278 } |
| 279 |
| 247 TEST_F(ScoredHistoryMatchTest, ScoringScheme) { | 280 TEST_F(ScoredHistoryMatchTest, ScoringScheme) { |
| 248 // We use NowFromSystemTime() because MakeURLRow uses the same function | 281 // We use NowFromSystemTime() because MakeURLRow uses the same function |
| 249 // to calculate last visit time when building a row. | 282 // to calculate last visit time when building a row. |
| 250 base::Time now = base::Time::NowFromSystemTime(); | 283 base::Time now = base::Time::NowFromSystemTime(); |
| 251 | 284 |
| 252 // By default the URL should not be returned for a query that includes "http". | 285 // By default the URL should not be returned for a query that includes "http". |
| 253 std::string url_string("http://fedcba/"); | 286 std::string url_string("http://fedcba/"); |
| 254 const GURL url(url_string); | 287 const GURL url(url_string); |
| 255 history::URLRow row(MakeURLRow(url_string.c_str(), "", 8, 3, 1)); | 288 history::URLRow row(MakeURLRow(url_string.c_str(), "", 8, 3, 1)); |
| 256 RowWordStarts word_starts; | 289 RowWordStarts word_starts; |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 | 687 |
| 655 EXPECT_TRUE( | 688 EXPECT_TRUE( |
| 656 ScoredHistoryMatch::GetHQPBucketsFromString(buckets_str, &hqp_buckets)); | 689 ScoredHistoryMatch::GetHQPBucketsFromString(buckets_str, &hqp_buckets)); |
| 657 EXPECT_THAT(hqp_buckets, ElementsAre(Pair(0.0, 400), Pair(1.5, 600), | 690 EXPECT_THAT(hqp_buckets, ElementsAre(Pair(0.0, 400), Pair(1.5, 600), |
| 658 Pair(12.0, 1300), Pair(20.0, 1399))); | 691 Pair(12.0, 1300), Pair(20.0, 1399))); |
| 659 // invalid string. | 692 // invalid string. |
| 660 buckets_str = "0.0,400,1.5,600"; | 693 buckets_str = "0.0,400,1.5,600"; |
| 661 EXPECT_FALSE( | 694 EXPECT_FALSE( |
| 662 ScoredHistoryMatch::GetHQPBucketsFromString(buckets_str, &hqp_buckets)); | 695 ScoredHistoryMatch::GetHQPBucketsFromString(buckets_str, &hqp_buckets)); |
| 663 } | 696 } |
| OLD | NEW |