| Index: chrome/browser/history/scored_history_match_unittest.cc
|
| diff --git a/chrome/browser/history/scored_history_match_unittest.cc b/chrome/browser/history/scored_history_match_unittest.cc
|
| index 229d28ed3af9ccf7516914ca15586e336e60f5b5..1a8a447e1e9bd1757423cebecf78589b78fe9ff3 100644
|
| --- a/chrome/browser/history/scored_history_match_unittest.cc
|
| +++ b/chrome/browser/history/scored_history_match_unittest.cc
|
| @@ -13,7 +13,7 @@
|
| namespace history {
|
|
|
| // Returns a VisitInfoVector that includes |num_visits| spread over the
|
| -// last |frecency|*|num_visits| days (relative to |now|). A frequency of
|
| +// last |frequency|*|num_visits| days (relative to |now|). A frequency of
|
| // one means one visit each day, two means every other day, etc.
|
| VisitInfoVector CreateVisitInfoVector(int num_visits,
|
| int frequency,
|
| @@ -53,6 +53,9 @@ class ScoredHistoryMatchTest : public testing::Test {
|
| float GetTopicalityScoreOfTermAgainstURLAndTitle(const string16& term,
|
| const string16& url,
|
| const string16& title);
|
| +
|
| + // Set ScoredHistoryMatch::bookmark_value_ to the provided |bookmark_value|.
|
| + void set_bookmark_value(int bookmark_value);
|
| };
|
|
|
| URLRow ScoredHistoryMatchTest::MakeURLRow(const char* url,
|
| @@ -106,6 +109,13 @@ float ScoredHistoryMatchTest::GetTopicalityScoreOfTermAgainstURLAndTitle(
|
| return scored_match.GetTopicalityScore(1, url, word_starts);
|
| }
|
|
|
| +void ScoredHistoryMatchTest::set_bookmark_value(int bookmark_value) {
|
| + // Make sure ScoredHistoryMatch::Init() gets called if it hasn't already.
|
| + ScoredHistoryMatch scored_match;
|
| +
|
| + scored_match.bookmark_value_ = bookmark_value;
|
| +}
|
| +
|
| TEST_F(ScoredHistoryMatchTest, Scoring) {
|
| // We use NowFromSystemTime() because MakeURLRow uses the same function
|
| // to calculate last visit time when building a row.
|
| @@ -175,6 +185,56 @@ TEST_F(ScoredHistoryMatchTest, Scoring) {
|
| EXPECT_EQ(scored_f.raw_score(), 0);
|
| }
|
|
|
| +class BookmarkServiceMock : public BookmarkService {
|
| + public:
|
| + explicit BookmarkServiceMock(const GURL& url);
|
| + virtual ~BookmarkServiceMock() {}
|
| +
|
| + // Returns true if the given |url| is the same as |url_|.
|
| + virtual bool IsBookmarked(const GURL& url) OVERRIDE;
|
| +
|
| + // Required but unused.
|
| + virtual void GetBookmarks(std::vector<URLAndTitle>* bookmarks) OVERRIDE {}
|
| + virtual void BlockTillLoaded() OVERRIDE {}
|
| +
|
| + private:
|
| + const GURL url_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(BookmarkServiceMock);
|
| +};
|
| +
|
| +BookmarkServiceMock::BookmarkServiceMock(const GURL& url)
|
| + : BookmarkService(),
|
| + url_(url) {
|
| +}
|
| +
|
| +bool BookmarkServiceMock::IsBookmarked(const GURL& url) {
|
| + return url == url_;
|
| +}
|
| +
|
| +TEST_F(ScoredHistoryMatchTest, ScoringBookmarks) {
|
| + // 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");
|
| + const GURL url(url_string);
|
| + URLRow row(MakeURLRow(url_string.c_str(), "abcd bcd", 8, 3, 1));
|
| + RowWordStarts word_starts;
|
| + PopulateWordStarts(row, &word_starts);
|
| + VisitInfoVector visits = CreateVisitInfoVector(8, 3, now);
|
| + ScoredHistoryMatch scored(row, visits, std::string(),
|
| + ASCIIToUTF16("abc"), Make1Term("abc"),
|
| + word_starts, now, NULL);
|
| + // Now bookmark that URL and make sure its score increases.
|
| + set_bookmark_value(5);
|
| + BookmarkServiceMock bookmark_model_mock(url);
|
| + ScoredHistoryMatch scored_with_bookmark(
|
| + row, visits, std::string(), ASCIIToUTF16("abc"), Make1Term("abc"),
|
| + word_starts, now, &bookmark_model_mock);
|
| + EXPECT_GT(scored_with_bookmark.raw_score(), scored.raw_score());
|
| +}
|
| +
|
| TEST_F(ScoredHistoryMatchTest, Inlining) {
|
| // We use NowFromSystemTime() because MakeURLRow uses the same function
|
| // to calculate last visit time when building a row.
|
|
|