Index: components/history/core/browser/visit_database_unittest.cc |
diff --git a/components/history/core/browser/visit_database_unittest.cc b/components/history/core/browser/visit_database_unittest.cc |
index be2594a1ba4363da10af992eb78173cfdf61bf42..19cdd10fbcad19686ec0d02c56dd00c7c93431a0 100644 |
--- a/components/history/core/browser/visit_database_unittest.cc |
+++ b/components/history/core/browser/visit_database_unittest.cc |
@@ -416,4 +416,107 @@ TEST_F(VisitDatabaseTest, GetVisibleVisitsForURL) { |
EXPECT_TRUE(IsVisitInfoEqual(results[2], test_visit_rows[0])); |
} |
+TEST_F(VisitDatabaseTest, GetHistoryCount) { |
+ Time today = Time::Now().LocalMidnight(); |
+ Time tomorrow = today + TimeDelta::FromDays(1); |
+ Time after_tomorrow = today + TimeDelta::FromDays(2); |
+ Time now = today; |
lwchkg
2015/09/25 04:06:35
The test will fail when the day is near DST switch
msramek
2015/09/25 10:44:35
Done. Thanks for reminding me, I forgot about DST
|
+ |
lwchkg
2015/09/25 04:06:35
Anyway, any plans to test time zone and DST handli
msramek
2015/09/25 10:44:35
I've added DST-specific tests at the end. This is
|
+ ui::PageTransition standard_transition = ui::PageTransitionFromInt( |
+ ui::PAGE_TRANSITION_TYPED | |
+ ui::PAGE_TRANSITION_CHAIN_START | |
+ ui::PAGE_TRANSITION_CHAIN_END); |
+ |
+ // Add 5 visits (3 distinct URLs) for today. Whether the URL was browsed |
+ // on this machine or synced has no effect. |
+ VisitRow today_1(1, now, 0, standard_transition, 0); |
+ today_1.visit_id = 1; |
+ AddVisit(&today_1, SOURCE_BROWSED); |
+ now += TimeDelta::FromHours(1); |
+ |
+ VisitRow today_2(2, now, 0, standard_transition, 0); |
+ today_2.visit_id = 2; |
+ AddVisit(&today_2, SOURCE_BROWSED); |
+ now += TimeDelta::FromHours(1); |
+ |
+ VisitRow today_3(1, now, 0, standard_transition, 0); |
+ today_3.visit_id = 3; |
+ AddVisit(&today_3, SOURCE_SYNCED); |
+ now += TimeDelta::FromHours(1); |
+ |
+ VisitRow today_4(3, now, 0, standard_transition, 0); |
+ today_4.visit_id = 4; |
+ AddVisit(&today_4, SOURCE_SYNCED); |
+ now += TimeDelta::FromHours(1); |
+ |
+ VisitRow today_5(2, now, 0, standard_transition, 0); |
+ today_5.visit_id = 5; |
+ AddVisit(&today_5, SOURCE_BROWSED); |
+ now += TimeDelta::FromHours(1); |
+ |
+ // Add 4 more visits for tomorrow. One of them is invalid, as it's not |
+ // a user-visible navigation. Of the remaining 3, only 2 are unique. |
+ now = tomorrow; |
+ |
+ VisitRow tomorrow_1(1, now, 0, standard_transition, 0); |
+ tomorrow_1.visit_id = 6; |
+ AddVisit(&tomorrow_1, SOURCE_BROWSED); |
+ now += TimeDelta::FromHours(1); |
+ |
+ VisitRow tomorrow_2(1, now, 0, standard_transition, 0); |
+ tomorrow_2.visit_id = 7; |
+ AddVisit(&tomorrow_2, SOURCE_BROWSED); |
+ now += TimeDelta::FromHours(1); |
+ |
+ VisitRow tomorrow_3(2, now, 0, ui::PAGE_TRANSITION_AUTO_SUBFRAME, 0); |
+ tomorrow_3.visit_id = 8; |
+ AddVisit(&tomorrow_3, SOURCE_BROWSED); |
+ now += TimeDelta::FromHours(1); |
+ |
+ VisitRow tomorrow_4(3, now, 0, standard_transition, 0); |
+ tomorrow_4.visit_id = 9; |
+ AddVisit(&tomorrow_4, SOURCE_BROWSED); |
+ now += TimeDelta::FromHours(1); |
+ |
+ int result; |
+ |
+ // There are 3 distinct URLs today. |
+ EXPECT_TRUE(GetHistoryCount(today, tomorrow, &result)); |
+ EXPECT_EQ(3, result); |
+ |
+ // For today and tomorrow, there should be 5 per-day unique URLs. |
+ EXPECT_TRUE(GetHistoryCount(today, after_tomorrow, &result)); |
+ EXPECT_EQ(5, result); |
+ |
+ // Since we only have entries for today and tomorrow, the infinite time |
+ // range should yield the same result. |
+ EXPECT_TRUE(GetHistoryCount(Time(), Time::Max(), &result)); |
+ EXPECT_EQ(5, result); |
+ |
+ // Narrowing the range to exclude |today_1| will still return 5, |
+ // because |today_1| is not unique. |
+ EXPECT_TRUE(GetHistoryCount( |
+ today + TimeDelta::FromHours(2), after_tomorrow, &result)); |
+ EXPECT_EQ(5, result); |
+ |
+ // Narrowing the range to exclude |tomorrow_4| will return 4, |
+ // because |tomorrow_4| is unique. |
+ EXPECT_TRUE(GetHistoryCount( |
+ today, tomorrow + TimeDelta::FromHours(3), &result)); |
+ EXPECT_EQ(4, result); |
+ |
+ // Narrowing the range to exclude both |today_1| and |tomorrow_4| will |
+ // still return 4. |
+ EXPECT_TRUE(GetHistoryCount(today + TimeDelta::FromHours(2), |
+ tomorrow + TimeDelta::FromHours(3), |
+ &result)); |
+ EXPECT_EQ(4, result); |
+ |
+ // A range that contains no visits will return 0. |
+ EXPECT_TRUE(GetHistoryCount(today + TimeDelta::FromMicroseconds(1), |
+ today + TimeDelta::FromHours(1), |
+ &result)); |
+ EXPECT_EQ(0, result); |
+} |
+ |
} // namespace history |