Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / history / scored_history_match_unittest.cc
index bc8c88f..6e4f9a7 100644 (file)
@@ -7,8 +7,8 @@
 #include "base/auto_reset.h"
 #include "base/strings/string16.h"
 #include "base/strings/utf_string_conversions.h"
-#include "chrome/browser/bookmarks/bookmark_service.h"
 #include "chrome/browser/history/scored_history_match.h"
+#include "components/bookmarks/core/browser/bookmark_service.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 using base::ASCIIToUTF16;
@@ -106,7 +106,9 @@ float ScoredHistoryMatchTest::GetTopicalityScoreOfTermAgainstURLAndTitle(
   RowWordStarts word_starts;
   String16SetFromString16(url, &word_starts.url_word_starts_);
   String16SetFromString16(title, &word_starts.title_word_starts_);
-  return scored_match.GetTopicalityScore(1, url, word_starts);
+  WordStarts one_word_no_offset(1, 0u);
+  return scored_match.GetTopicalityScore(1, url, one_word_no_offset,
+                                         word_starts);
 }
 
 TEST_F(ScoredHistoryMatchTest, Scoring) {
@@ -117,12 +119,13 @@ TEST_F(ScoredHistoryMatchTest, Scoring) {
   URLRow row_a(MakeURLRow("http://fedcba", "abcd bcd", 3, 30, 1));
   RowWordStarts word_starts_a;
   PopulateWordStarts(row_a, &word_starts_a);
+  WordStarts one_word_no_offset(1, 0u);
   VisitInfoVector visits_a = CreateVisitInfoVector(3, 30, now);
   // Mark one visit as typed.
   visits_a[0].second = content::PAGE_TRANSITION_TYPED;
   ScoredHistoryMatch scored_a(row_a, visits_a, std::string(),
-                               ASCIIToUTF16("abc"), Make1Term("abc"),
-                               word_starts_a, now, NULL);
+                              ASCIIToUTF16("abc"), Make1Term("abc"),
+                              one_word_no_offset, word_starts_a, now, NULL);
 
   // Test scores based on visit_count.
   URLRow row_b(MakeURLRow("http://abcdef", "abcd bcd", 10, 30, 1));
@@ -132,7 +135,7 @@ TEST_F(ScoredHistoryMatchTest, Scoring) {
   visits_b[0].second = content::PAGE_TRANSITION_TYPED;
   ScoredHistoryMatch scored_b(row_b, visits_b, std::string(),
                               ASCIIToUTF16("abc"), Make1Term("abc"),
-                              word_starts_b, now, NULL);
+                              one_word_no_offset, word_starts_b, now, NULL);
   EXPECT_GT(scored_b.raw_score(), scored_a.raw_score());
 
   // Test scores based on last_visit.
@@ -143,7 +146,7 @@ TEST_F(ScoredHistoryMatchTest, Scoring) {
   visits_c[0].second = content::PAGE_TRANSITION_TYPED;
   ScoredHistoryMatch scored_c(row_c, visits_c, std::string(),
                               ASCIIToUTF16("abc"), Make1Term("abc"),
-                              word_starts_c, now, NULL);
+                              one_word_no_offset, word_starts_c, now, NULL);
   EXPECT_GT(scored_c.raw_score(), scored_a.raw_score());
 
   // Test scores based on typed_count.
@@ -156,7 +159,7 @@ TEST_F(ScoredHistoryMatchTest, Scoring) {
   visits_d[2].second = content::PAGE_TRANSITION_TYPED;
   ScoredHistoryMatch scored_d(row_d, visits_d, std::string(),
                               ASCIIToUTF16("abc"), Make1Term("abc"),
-                              word_starts_d, now, NULL);
+                              one_word_no_offset, word_starts_d, now, NULL);
   EXPECT_GT(scored_d.raw_score(), scored_a.raw_score());
 
   // Test scores based on a terms appearing multiple times.
@@ -167,14 +170,14 @@ TEST_F(ScoredHistoryMatchTest, Scoring) {
   const VisitInfoVector visits_e = visits_d;
   ScoredHistoryMatch scored_e(row_e, visits_e, std::string(),
                               ASCIIToUTF16("csi"), Make1Term("csi"),
-                              word_starts_e, now, NULL);
+                              one_word_no_offset, word_starts_e, now, NULL);
   EXPECT_LT(scored_e.raw_score(), 1400);
 
   // Test that a result with only a mid-term match (i.e., not at a word
   // boundary) scores 0.
   ScoredHistoryMatch scored_f(row_a, visits_a, std::string(),
                               ASCIIToUTF16("cd"), Make1Term("cd"),
-                              word_starts_a, now, NULL);
+                              one_word_no_offset, word_starts_a, now, NULL);
   EXPECT_EQ(scored_f.raw_score(), 0);
 }
 
@@ -215,42 +218,20 @@ TEST_F(ScoredHistoryMatchTest, ScoringBookmarks) {
   URLRow row(MakeURLRow(url_string.c_str(), "abcd bcd", 8, 3, 1));
   RowWordStarts word_starts;
   PopulateWordStarts(row, &word_starts);
+  WordStarts one_word_no_offset(1, 0u);
   VisitInfoVector visits = CreateVisitInfoVector(8, 3, now);
   ScoredHistoryMatch scored(row, visits, std::string(),
                             ASCIIToUTF16("abc"), Make1Term("abc"),
-                            word_starts, now, NULL);
+                            one_word_no_offset, word_starts, now, NULL);
   // Now bookmark that URL and make sure its score increases.
   base::AutoReset<int> reset(&ScoredHistoryMatch::bookmark_value_, 5);
-  BookmarkServiceMock bookmark_model_mock(url);
+  BookmarkServiceMock bookmark_service_mock(url);
   ScoredHistoryMatch scored_with_bookmark(
       row, visits, std::string(), ASCIIToUTF16("abc"), Make1Term("abc"),
-      word_starts, now, &bookmark_model_mock);
+      one_word_no_offset, word_starts, now, &bookmark_service_mock);
   EXPECT_GT(scored_with_bookmark.raw_score(), scored.raw_score());
 }
 
-TEST_F(ScoredHistoryMatchTest, ScoringDiscountFrecency) {
-  // We use NowFromSystemTime() because MakeURLRow uses the same function
-  // to calculate last visit time when building a row.
-  base::Time now = base::Time::NowFromSystemTime();
-
-  std::string url_string("http://fedcba.com/");
-  const GURL url(url_string);
-  URLRow row(MakeURLRow(url_string.c_str(), "", 1, 1, 1));
-  RowWordStarts word_starts;
-  PopulateWordStarts(row, &word_starts);
-  VisitInfoVector visits = CreateVisitInfoVector(1, 1, now);
-  ScoredHistoryMatch scored(row, visits, std::string(), ASCIIToUTF16("fed"),
-                            Make1Term("fed"), word_starts, now, NULL);
-
-  // With properly discounted scores, the final raw_score should be lower.
-  base::AutoReset<bool> reset(
-      &ScoredHistoryMatch::discount_frecency_when_few_visits_, true);
-  ScoredHistoryMatch scored_with_discount_frecency(
-      row, visits, std::string(), ASCIIToUTF16("fed"),
-      Make1Term("fed"), word_starts, now, NULL);
-  EXPECT_LT(scored_with_discount_frecency.raw_score(), scored.raw_score());
-}
-
 TEST_F(ScoredHistoryMatchTest, ScoringTLD) {
   // We use NowFromSystemTime() because MakeURLRow uses the same function
   // to calculate last visit time when building a row.
@@ -262,17 +243,18 @@ TEST_F(ScoredHistoryMatchTest, ScoringTLD) {
   URLRow row(MakeURLRow(url_string.c_str(), "", 8, 3, 1));
   RowWordStarts word_starts;
   PopulateWordStarts(row, &word_starts);
+  WordStarts two_words_no_offsets(2, 0u);
   VisitInfoVector visits = CreateVisitInfoVector(8, 3, now);
   ScoredHistoryMatch scored(row, visits, std::string(),
                             ASCIIToUTF16("fed com"), Make2Terms("fed", "com"),
-                            word_starts, now, NULL);
+                            two_words_no_offsets, word_starts, now, NULL);
   EXPECT_EQ(0, scored.raw_score());
 
   // Now allow credit for the match in the TLD.
   base::AutoReset<bool> reset(&ScoredHistoryMatch::allow_tld_matches_, true);
   ScoredHistoryMatch scored_with_tld(
       row, visits, std::string(), ASCIIToUTF16("fed com"),
-      Make2Terms("fed", "com"), word_starts, now, NULL);
+      Make2Terms("fed", "com"), two_words_no_offsets, word_starts, now, NULL);
   EXPECT_GT(scored_with_tld.raw_score(), 0);
 }
 
@@ -287,17 +269,18 @@ TEST_F(ScoredHistoryMatchTest, ScoringScheme) {
   URLRow row(MakeURLRow(url_string.c_str(), "", 8, 3, 1));
   RowWordStarts word_starts;
   PopulateWordStarts(row, &word_starts);
+  WordStarts two_words_no_offsets(2, 0u);
   VisitInfoVector visits = CreateVisitInfoVector(8, 3, now);
   ScoredHistoryMatch scored(row, visits, std::string(),
                             ASCIIToUTF16("fed http"), Make2Terms("fed", "http"),
-                            word_starts, now, NULL);
+                            two_words_no_offsets, word_starts, now, NULL);
   EXPECT_EQ(0, scored.raw_score());
 
   // Now allow credit for the match in the scheme.
   base::AutoReset<bool> reset(&ScoredHistoryMatch::allow_scheme_matches_, true);
   ScoredHistoryMatch scored_with_scheme(
       row, visits, std::string(), ASCIIToUTF16("fed http"),
-      Make2Terms("fed", "http"), word_starts, now, NULL);
+      Make2Terms("fed", "http"), two_words_no_offsets, word_starts, now, NULL);
   EXPECT_GT(scored_with_scheme.raw_score(), 0);
 }
 
@@ -306,6 +289,7 @@ TEST_F(ScoredHistoryMatchTest, Inlining) {
   // to calculate last visit time when building a row.
   base::Time now = base::Time::NowFromSystemTime();
   RowWordStarts word_starts;
+  WordStarts one_word_no_offset(1, 0u);
   VisitInfoVector visits;
 
   {
@@ -313,22 +297,22 @@ TEST_F(ScoredHistoryMatchTest, Inlining) {
     PopulateWordStarts(row, &word_starts);
     ScoredHistoryMatch scored_a(row, visits, std::string(),
                                 ASCIIToUTF16("g"), Make1Term("g"),
-                                word_starts, now, NULL);
+                                one_word_no_offset, word_starts, now, NULL);
     EXPECT_TRUE(scored_a.can_inline());
     EXPECT_FALSE(scored_a.match_in_scheme);
     ScoredHistoryMatch scored_b(row, visits, std::string(),
                                 ASCIIToUTF16("w"), Make1Term("w"),
-                                word_starts, now, NULL);
+                                one_word_no_offset, word_starts, now, NULL);
     EXPECT_TRUE(scored_b.can_inline());
     EXPECT_FALSE(scored_b.match_in_scheme);
     ScoredHistoryMatch scored_c(row, visits, std::string(),
                                 ASCIIToUTF16("h"), Make1Term("h"),
-                                word_starts, now, NULL);
+                                one_word_no_offset, word_starts, now, NULL);
     EXPECT_TRUE(scored_c.can_inline());
     EXPECT_TRUE(scored_c.match_in_scheme);
     ScoredHistoryMatch scored_d(row, visits, std::string(),
                                 ASCIIToUTF16("o"), Make1Term("o"),
-                                word_starts, now, NULL);
+                                one_word_no_offset, word_starts, now, NULL);
     EXPECT_FALSE(scored_d.can_inline());
     EXPECT_FALSE(scored_d.match_in_scheme);
   }
@@ -338,17 +322,17 @@ TEST_F(ScoredHistoryMatchTest, Inlining) {
     PopulateWordStarts(row, &word_starts);
     ScoredHistoryMatch scored_a(row, visits, std::string(),
                                 ASCIIToUTF16("t"), Make1Term("t"),
-                                word_starts, now, NULL);
+                                one_word_no_offset, word_starts, now, NULL);
     EXPECT_TRUE(scored_a.can_inline());
     EXPECT_FALSE(scored_a.match_in_scheme);
     ScoredHistoryMatch scored_b(row, visits, std::string(),
                                 ASCIIToUTF16("f"), Make1Term("f"),
-                                word_starts, now, NULL);
+                                one_word_no_offset, word_starts, now, NULL);
     EXPECT_FALSE(scored_b.can_inline());
     EXPECT_FALSE(scored_b.match_in_scheme);
     ScoredHistoryMatch scored_c(row, visits, std::string(),
                                 ASCIIToUTF16("o"), Make1Term("o"),
-                                word_starts, now, NULL);
+                                one_word_no_offset, word_starts, now, NULL);
     EXPECT_FALSE(scored_c.can_inline());
     EXPECT_FALSE(scored_c.match_in_scheme);
   }
@@ -358,17 +342,17 @@ TEST_F(ScoredHistoryMatchTest, Inlining) {
     PopulateWordStarts(row, &word_starts);
     ScoredHistoryMatch scored_a(row, visits, std::string(),
                                 ASCIIToUTF16("t"), Make1Term("t"),
-                                word_starts, now, NULL);
+                                one_word_no_offset, word_starts, now, NULL);
     EXPECT_TRUE(scored_a.can_inline());
     EXPECT_FALSE(scored_a.match_in_scheme);
     ScoredHistoryMatch scored_b(row, visits, std::string(),
                                 ASCIIToUTF16("h"), Make1Term("h"),
-                                word_starts, now, NULL);
+                                one_word_no_offset, word_starts, now, NULL);
     EXPECT_TRUE(scored_b.can_inline());
     EXPECT_TRUE(scored_b.match_in_scheme);
     ScoredHistoryMatch scored_c(row, visits, std::string(),
                                 ASCIIToUTF16("w"), Make1Term("w"),
-                                word_starts, now, NULL);
+                                one_word_no_offset, word_starts, now, NULL);
     EXPECT_TRUE(scored_c.can_inline());
     EXPECT_FALSE(scored_c.match_in_scheme);
   }