| Index: chrome/browser/ui/webui/browsing_history_handler_unittest.cc
|
| diff --git a/chrome/browser/ui/webui/browsing_history_handler_unittest.cc b/chrome/browser/ui/webui/browsing_history_handler_unittest.cc
|
| index 0d026cb40f5f189bf942fcc3426bed5bfca3ecf2..c19fb1e68007d881c90a1dddb1525fa60da4bbe0 100644
|
| --- a/chrome/browser/ui/webui/browsing_history_handler_unittest.cc
|
| +++ b/chrome/browser/ui/webui/browsing_history_handler_unittest.cc
|
| @@ -11,6 +11,7 @@
|
| #include "base/macros.h"
|
| #include "base/memory/ptr_util.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| +#include "base/test/simple_test_clock.h"
|
| #include "base/values.h"
|
| #include "chrome/browser/history/web_history_service_factory.h"
|
| #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
|
| @@ -48,6 +49,23 @@ struct TestResult {
|
| // baseline time in local time.
|
| const base::Time baseline_time = base::Time::UnixEpoch().LocalMidnight();
|
|
|
| +base::Time PretendNow() {
|
| + base::Time::Exploded exploded_reference_time;
|
| + exploded_reference_time.year = 2015;
|
| + exploded_reference_time.month = 1;
|
| + exploded_reference_time.day_of_month = 2;
|
| + exploded_reference_time.day_of_week = 5;
|
| + exploded_reference_time.hour = 11;
|
| + exploded_reference_time.minute = 0;
|
| + exploded_reference_time.second = 0;
|
| + exploded_reference_time.millisecond = 0;
|
| +
|
| + base::Time out_time;
|
| + EXPECT_TRUE(
|
| + base::Time::FromLocalExploded(exploded_reference_time, &out_time));
|
| + return out_time;
|
| +}
|
| +
|
| // For each item in |results|, create a new Value representing the visit, and
|
| // insert it into |list_value|.
|
| void AddQueryResults(
|
| @@ -102,10 +120,19 @@ class TestSyncService : public browser_sync::TestProfileSyncService {
|
| class BrowsingHistoryHandlerWithWebUIForTesting
|
| : public BrowsingHistoryHandler {
|
| public:
|
| - explicit BrowsingHistoryHandlerWithWebUIForTesting(content::WebUI* web_ui) {
|
| + explicit BrowsingHistoryHandlerWithWebUIForTesting(content::WebUI* web_ui)
|
| + : test_clock_(new base::SimpleTestClock()) {
|
| + set_clock(base::WrapUnique(test_clock_));
|
| set_web_ui(web_ui);
|
| + test_clock_->SetNow(PretendNow());
|
| +
|
| }
|
| using BrowsingHistoryHandler::QueryComplete;
|
| +
|
| + base::SimpleTestClock* test_clock() { return test_clock_; }
|
| +
|
| + private:
|
| + base::SimpleTestClock* test_clock_;
|
| };
|
|
|
| } // namespace
|
| @@ -265,6 +292,67 @@ TEST_F(BrowsingHistoryHandlerTest, MAYBE_MergeDuplicateResults) {
|
| }
|
| }
|
|
|
| +TEST_F(BrowsingHistoryHandlerTest, SetQueryTimeInWeeks) {
|
| + BrowsingHistoryHandlerWithWebUIForTesting handler(web_ui());
|
| + history::QueryOptions options;
|
| +
|
| + // Querying this week should result in end time being midnight tonight and
|
| + // begin time being midnight a week ago.
|
| + handler.SetQueryTimeInWeeks(0, &options);
|
| + base::Time midnight_tonight =
|
| + PretendNow().LocalMidnight() + base::TimeDelta::FromDays(1);
|
| + EXPECT_EQ(midnight_tonight, options.end_time);
|
| + base::Time midnight_a_week_ago =
|
| + midnight_tonight - base::TimeDelta::FromDays(7);
|
| + EXPECT_EQ(midnight_a_week_ago, options.begin_time);
|
| +
|
| + // Querying 4 weeks ago should result in end time being midnight 4 weeks ago
|
| + // and begin time being midnight 5 weeks ago.
|
| + handler.SetQueryTimeInWeeks(4, &options);
|
| + base::Time midnight_4_weeks_ago =
|
| + PretendNow().LocalMidnight() - base::TimeDelta::FromDays(27);
|
| + EXPECT_EQ(midnight_4_weeks_ago, options.end_time);
|
| + base::Time midnight_5_weeks_ago =
|
| + midnight_4_weeks_ago - base::TimeDelta::FromDays(7);
|
| + EXPECT_EQ(midnight_5_weeks_ago, options.begin_time);
|
| +}
|
| +
|
| +TEST_F(BrowsingHistoryHandlerTest, SetQueryTimeInMonths) {
|
| + BrowsingHistoryHandlerWithWebUIForTesting handler(web_ui());
|
| + history::QueryOptions options;
|
| +
|
| + base::Time::Exploded exploded_expected_time;
|
| + PretendNow().LocalExplode(&exploded_expected_time);
|
| +
|
| + // Querying this month should result in end time being unset and begin time
|
| + // being midnight of the first.
|
| + handler.SetQueryTimeInMonths(0, &options);
|
| + EXPECT_EQ(base::Time(), options.end_time);
|
| +
|
| + exploded_expected_time.day_of_month = 1;
|
| + exploded_expected_time.hour = 0;
|
| + base::Time first_jan_2015_midnight;
|
| + EXPECT_TRUE(base::Time::FromLocalExploded(exploded_expected_time,
|
| + &first_jan_2015_midnight));
|
| + EXPECT_EQ(first_jan_2015_midnight, options.begin_time);
|
| +
|
| + // Querying 6 months ago should result in end time being 2014-08-01 and begin
|
| + // time being 2014-07-01.
|
| + handler.SetQueryTimeInMonths(6, &options);
|
| +
|
| + exploded_expected_time.year = 2014;
|
| + exploded_expected_time.month = 8;
|
| + base::Time first_aug_2014_midnight;
|
| + EXPECT_TRUE(base::Time::FromLocalExploded(exploded_expected_time,
|
| + &first_aug_2014_midnight));
|
| + EXPECT_EQ(first_aug_2014_midnight, options.end_time);
|
| + exploded_expected_time.month = 7;
|
| + base::Time first_jul_2014_midnight;
|
| + EXPECT_TRUE(base::Time::FromLocalExploded(exploded_expected_time,
|
| + &first_jul_2014_midnight));
|
| + EXPECT_EQ(first_jul_2014_midnight, options.begin_time);
|
| +}
|
| +
|
| // Tests that BrowsingHistoryHandler observes WebHistoryService deletions.
|
| TEST_F(BrowsingHistoryHandlerTest, ObservingWebHistoryDeletions) {
|
| base::Callback<void(bool)> callback = base::Bind(&IgnoreBoolAndDoNothing);
|
|
|