This source file includes following definitions.
- CheckHistoryResultConsistency
- AddSimpleData
- TEST
- TEST
- TEST
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/history/history_types.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace history {
namespace {
void CheckHistoryResultConsistency(const QueryResults& result) {
for (size_t i = 0; i < result.size(); i++) {
size_t match_count;
const size_t* matches = result.MatchesForURL(result[i].url(), &match_count);
bool found = false;
for (size_t match = 0; match < match_count; match++) {
if (matches[match] == i) {
found = true;
break;
}
}
EXPECT_TRUE(found) << "The URL had no index referring to it.";
}
}
const char kURL1[] = "http://www.google.com/";
const char kURL2[] = "http://news.google.com/";
void AddSimpleData(QueryResults* results) {
GURL url1(kURL1);
GURL url2(kURL2);
URLResult result1(url1, base::Time::Now());
URLResult result2(url1, base::Time::Now());
URLResult result3(url2, base::Time::Now());
results->AppendURLBySwapping(&result1);
results->AppendURLBySwapping(&result2);
results->AppendURLBySwapping(&result3);
CheckHistoryResultConsistency(*results);
}
}
TEST(HistoryQueryResult, DeleteRange) {
GURL url1(kURL1);
GURL url2(kURL2);
QueryResults results;
AddSimpleData(&results);
size_t match_count;
const size_t* matches = results.MatchesForURL(url1, &match_count);
ASSERT_EQ(2U, match_count);
EXPECT_TRUE((matches[0] == 0 && matches[1] == 1) ||
(matches[0] == 1 && matches[1] == 0));
matches = results.MatchesForURL(url2, &match_count);
ASSERT_EQ(1U, match_count);
EXPECT_TRUE(matches[0] == 2);
results.DeleteRange(0, 0);
CheckHistoryResultConsistency(results);
matches = results.MatchesForURL(url1, &match_count);
ASSERT_EQ(1U, match_count);
EXPECT_TRUE(matches[0] == 0);
matches = results.MatchesForURL(url2, &match_count);
ASSERT_EQ(1U, match_count);
EXPECT_TRUE(matches[0] == 1);
results.DeleteRange(0, 1);
EXPECT_EQ(0U, results.size());
EXPECT_FALSE(results.MatchesForURL(url1, NULL));
EXPECT_FALSE(results.MatchesForURL(url2, NULL));
}
TEST(HistoryQueryResult, ResultDeleteURL) {
GURL url1(kURL1);
GURL url2(kURL2);
QueryResults results;
AddSimpleData(&results);
results.DeleteURL(url1);
CheckHistoryResultConsistency(results);
EXPECT_EQ(1U, results.size());
size_t match_count;
EXPECT_FALSE(results.MatchesForURL(url1, NULL));
const size_t* matches = results.MatchesForURL(url2, &match_count);
ASSERT_EQ(1U, match_count);
EXPECT_TRUE(matches[0] == 0);
results.DeleteURL(url2);
EXPECT_EQ(0U, results.size());
EXPECT_FALSE(results.MatchesForURL(url2, NULL));
}
TEST(HistoryQueryResult, RowSignificance) {
const base::Time& threshold(AutocompleteAgeThreshold());
const GURL url("http://www.google.com/");
URLRow url_row(url);
url_row.set_title(base::UTF8ToUTF16("Google"));
EXPECT_FALSE(RowQualifiesAsSignificant(url_row, threshold));
EXPECT_FALSE(RowQualifiesAsSignificant(url_row, base::Time()));
url_row.set_visit_count(kLowQualityMatchVisitLimit);
EXPECT_TRUE(RowQualifiesAsSignificant(url_row, threshold));
EXPECT_TRUE(RowQualifiesAsSignificant(url_row, base::Time()));
url_row.set_visit_count(1);
EXPECT_FALSE(RowQualifiesAsSignificant(url_row, threshold));
EXPECT_FALSE(RowQualifiesAsSignificant(url_row, base::Time()));
url_row.set_typed_count(kLowQualityMatchTypedLimit);
EXPECT_TRUE(RowQualifiesAsSignificant(url_row, threshold));
EXPECT_TRUE(RowQualifiesAsSignificant(url_row, base::Time()));
url_row.set_typed_count(0);
EXPECT_FALSE(RowQualifiesAsSignificant(url_row, threshold));
EXPECT_FALSE(RowQualifiesAsSignificant(url_row, base::Time()));
url_row.set_last_visit(base::Time::Now() - base::TimeDelta::FromDays(1));
EXPECT_TRUE(RowQualifiesAsSignificant(url_row, threshold));
EXPECT_TRUE(RowQualifiesAsSignificant(url_row, base::Time()));
url_row.set_last_visit(base::Time::Now() -
base::TimeDelta::FromDays(kLowQualityMatchAgeLimitInDays + 1));
EXPECT_FALSE(RowQualifiesAsSignificant(url_row, threshold));
EXPECT_FALSE(RowQualifiesAsSignificant(url_row, base::Time()));
}
}