Index: components/omnibox/browser/scored_history_match_unittest.cc |
diff --git a/components/omnibox/browser/scored_history_match_unittest.cc b/components/omnibox/browser/scored_history_match_unittest.cc |
index a4d776115fcc7dfe11775c195f60a585c35a309c..5e7a22f2887879c335559052bb52a710417ad5ff 100644 |
--- a/components/omnibox/browser/scored_history_match_unittest.cc |
+++ b/components/omnibox/browser/scored_history_match_unittest.cc |
@@ -9,6 +9,7 @@ |
#include "base/auto_reset.h" |
#include "base/bind.h" |
+#include "base/i18n/break_iterator.h" |
#include "base/memory/ptr_util.h" |
#include "base/strings/string16.h" |
#include "base/strings/utf_string_conversions.h" |
@@ -119,8 +120,14 @@ float ScoredHistoryMatchTest::GetTopicalityScoreOfTermAgainstURLAndTitle( |
RowWordStarts word_starts; |
String16SetFromString16(url, &word_starts.url_word_starts_); |
String16SetFromString16(title, &word_starts.title_word_starts_); |
- WordStarts one_word_no_offset(1, 0u); |
- return scored_match.GetTopicalityScore(1, url, one_word_no_offset, |
+ WordStarts term_word_starts(1, 0u); |
+ base::i18n::BreakIterator iter(term, base::i18n::BreakIterator::BREAK_WORD); |
+ if (iter.Init()) { |
+ // Find the first word start. |
+ while (iter.Advance() && !iter.IsWord()) {} |
+ term_word_starts[0] = iter.prev(); |
+ } |
+ return scored_match.GetTopicalityScore(1, url, term_word_starts, |
word_starts); |
} |
@@ -554,23 +561,38 @@ TEST_F(ScoredHistoryMatchTest, GetTopicalityScore) { |
const float hostname_mid_word_score = |
GetTopicalityScoreOfTermAgainstURLAndTitle(ASCIIToUTF16("bc"), url, |
title); |
+ const float hostname_score_preceeding_punctuation = |
+ GetTopicalityScoreOfTermAgainstURLAndTitle(ASCIIToUTF16("://abc"), url, |
+ title); |
const float domain_name_score = GetTopicalityScoreOfTermAgainstURLAndTitle( |
ASCIIToUTF16("def"), url, title); |
const float domain_name_mid_word_score = |
GetTopicalityScoreOfTermAgainstURLAndTitle(ASCIIToUTF16("ef"), url, |
title); |
+ const float domain_name_score_preceeding_dot = |
+ GetTopicalityScoreOfTermAgainstURLAndTitle(ASCIIToUTF16(".def"), url, |
+ title); |
const float tld_score = GetTopicalityScoreOfTermAgainstURLAndTitle( |
ASCIIToUTF16("com"), url, title); |
const float tld_mid_word_score = GetTopicalityScoreOfTermAgainstURLAndTitle( |
ASCIIToUTF16("om"), url, title); |
+ const float tld_score_preceeding_dot = |
+ GetTopicalityScoreOfTermAgainstURLAndTitle(ASCIIToUTF16(".com"), url, |
+ title); |
const float path_score = GetTopicalityScoreOfTermAgainstURLAndTitle( |
ASCIIToUTF16("path1"), url, title); |
const float path_mid_word_score = GetTopicalityScoreOfTermAgainstURLAndTitle( |
ASCIIToUTF16("ath1"), url, title); |
+ const float path_score_preceeding_slash = |
+ GetTopicalityScoreOfTermAgainstURLAndTitle(ASCIIToUTF16("/path1"), url, |
+ title); |
const float arg_score = GetTopicalityScoreOfTermAgainstURLAndTitle( |
- ASCIIToUTF16("arg2"), url, title); |
+ ASCIIToUTF16("arg1"), url, title); |
const float arg_mid_word_score = GetTopicalityScoreOfTermAgainstURLAndTitle( |
- ASCIIToUTF16("rg2"), url, title); |
+ ASCIIToUTF16("rg1"), url, title); |
+ const float arg_score_preceeding_question_mark = |
+ GetTopicalityScoreOfTermAgainstURLAndTitle(ASCIIToUTF16("?arg1"), url, |
+ title); |
const float protocol_score = GetTopicalityScoreOfTermAgainstURLAndTitle( |
ASCIIToUTF16("htt"), url, title); |
const float protocol_mid_word_score = |
@@ -584,6 +606,12 @@ TEST_F(ScoredHistoryMatchTest, GetTopicalityScore) { |
EXPECT_GT(hostname_score, path_score); |
EXPECT_GT(domain_name_score, path_score); |
EXPECT_GT(path_score, arg_score); |
+ // Verify leading punctuation doesn't confuse scoring. |
+ EXPECT_EQ(hostname_score, hostname_score_preceeding_punctuation); |
+ EXPECT_EQ(domain_name_score, domain_name_score_preceeding_dot); |
+ EXPECT_EQ(tld_score, tld_score_preceeding_dot); |
+ EXPECT_EQ(path_score, path_score_preceeding_slash); |
+ EXPECT_EQ(arg_score, arg_score_preceeding_question_mark); |
// Verify that domain name > path and domain name > arg for non-word |
// boundaries. |
EXPECT_GT(hostname_mid_word_score, path_mid_word_score); |