Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2495)

Unified Diff: chrome/browser/ntp_snippets/download_suggestions_provider_unittest.cc

Issue 2870223003: Avoid base::Time::FromJavaTime() when not dealing with Java. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« base/time/time.h ('K') | « base/time/time.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ntp_snippets/download_suggestions_provider_unittest.cc
diff --git a/chrome/browser/ntp_snippets/download_suggestions_provider_unittest.cc b/chrome/browser/ntp_snippets/download_suggestions_provider_unittest.cc
index 5a08ebdf1eb1d0d9c436c32cf7336deeec242376..6c7f97525b94d32e58134a17271140fa146e6f8f 100644
--- a/chrome/browser/ntp_snippets/download_suggestions_provider_unittest.cc
+++ b/chrome/browser/ntp_snippets/download_suggestions_provider_unittest.cc
@@ -90,7 +90,17 @@ namespace {
const int kDefaultMaxDownloadAgeHours = 6 * 7 * 24;
// Tue, 31 Jan 2017 13:00:00 UTC
-const base::Time now = base::Time::FromJavaTime(1485867600000);
+const base::Time kDummyNow = base::Time::FromInternalValue(13130341200000000);
miu 2017/05/10 21:43:02 nit: Rather than FromInternalValue, how about some
+
+base::Time GetDummyNotOutdatedTime() {
+ return kDummyNow - base::TimeDelta::FromHours(kDefaultMaxDownloadAgeHours) +
+ base::TimeDelta::FromSeconds(1);
+}
+
+base::Time GetDummyOutdatedTime() {
+ return kDummyNow - base::TimeDelta::FromHours(kDefaultMaxDownloadAgeHours) -
+ base::TimeDelta::FromSeconds(1);
+}
// TODO(vitaliii): Move this and outputting functions above to common file and
// replace remaining |Property(&ContentSuggestion::url, GURL("some_url"))|.
@@ -471,17 +481,17 @@ TEST_F(DownloadSuggestionsProviderTest, ShouldSortSuggestions) {
std::vector<OfflinePageItem> offline_pages = CreateDummyOfflinePages({0, 1});
offline_pages[0].url = GURL("http://dummy.com/0");
- offline_pages[0].creation_time = now - base::TimeDelta::FromMinutes(10);
+ offline_pages[0].creation_time = kDummyNow - base::TimeDelta::FromMinutes(10);
offline_pages[0].last_access_time = offline_pages[0].creation_time;
offline_pages[1].url = GURL("http://dummy.com/1");
- offline_pages[1].creation_time = now - base::TimeDelta::FromMinutes(5);
+ offline_pages[1].creation_time = kDummyNow - base::TimeDelta::FromMinutes(5);
offline_pages[1].last_access_time = offline_pages[1].creation_time;
*(offline_pages_model()->mutable_items()) = offline_pages;
auto test_clock = base::MakeUnique<base::SimpleTestClock>();
- test_clock->SetNow(now);
+ test_clock->SetNow(kDummyNow);
EXPECT_CALL(*observer(),
OnNewSuggestions(_, downloads_category(),
ElementsAre(HasUrl("http://dummy.com/1"),
@@ -493,10 +503,10 @@ TEST_F(DownloadSuggestionsProviderTest, ShouldSortSuggestions) {
CreateDummyAssetDownloads({2, 3});
asset_downloads[0]->SetURL(GURL("http://download.com/2"));
- asset_downloads[0]->SetStartTime(now - base::TimeDelta::FromMinutes(3));
+ asset_downloads[0]->SetStartTime(kDummyNow - base::TimeDelta::FromMinutes(3));
asset_downloads[1]->SetURL(GURL("http://download.com/3"));
- asset_downloads[1]->SetStartTime(now - base::TimeDelta::FromMinutes(7));
+ asset_downloads[1]->SetStartTime(kDummyNow - base::TimeDelta::FromMinutes(7));
EXPECT_CALL(*observer(),
OnNewSuggestions(_, downloads_category(),
@@ -1035,12 +1045,8 @@ TEST_F(DownloadSuggestionsProviderTest, ShouldNotShowOutdatedDownloads) {
IgnoreOnCategoryStatusChangedToAvailable();
IgnoreOnSuggestionInvalidated();
- const base::Time not_outdated =
- now - base::TimeDelta::FromHours(kDefaultMaxDownloadAgeHours) +
- base::TimeDelta::FromSeconds(1);
- const base::Time outdated =
- now - base::TimeDelta::FromHours(kDefaultMaxDownloadAgeHours) -
- base::TimeDelta::FromSeconds(1);
+ const base::Time not_outdated = GetDummyNotOutdatedTime();
+ const base::Time outdated = GetDummyOutdatedTime();
*(offline_pages_model()->mutable_items()) = CreateDummyOfflinePages({0, 1});
@@ -1070,7 +1076,7 @@ TEST_F(DownloadSuggestionsProviderTest, ShouldNotShowOutdatedDownloads) {
UnorderedElementsAre(HasUrl("http://dummy.com/0"),
HasUrl("http://download.com/0"))));
auto test_clock = base::MakeUnique<base::SimpleTestClock>();
- test_clock->SetNow(now);
+ test_clock->SetNow(kDummyNow);
CreateLoadedProvider(/*show_assets=*/true, /*show_offline_pages=*/true,
std::move(test_clock));
}
@@ -1080,12 +1086,8 @@ TEST_F(DownloadSuggestionsProviderTest,
IgnoreOnCategoryStatusChangedToAvailable();
IgnoreOnSuggestionInvalidated();
- const base::Time not_outdated =
- now - base::TimeDelta::FromHours(kDefaultMaxDownloadAgeHours) +
- base::TimeDelta::FromSeconds(1);
- const base::Time outdated =
- now - base::TimeDelta::FromHours(kDefaultMaxDownloadAgeHours) -
- base::TimeDelta::FromSeconds(1);
+ const base::Time not_outdated = GetDummyNotOutdatedTime();
+ const base::Time outdated = GetDummyOutdatedTime();
std::vector<OfflinePageItem> offline_pages = CreateDummyOfflinePages({0, 1});
@@ -1106,7 +1108,7 @@ TEST_F(DownloadSuggestionsProviderTest,
OnNewSuggestions(_, downloads_category(),
UnorderedElementsAre(HasUrl("http://dummy.com/0"))));
auto test_clock = base::MakeUnique<base::SimpleTestClock>();
- test_clock->SetNow(now);
+ test_clock->SetNow(kDummyNow);
CreateProvider(/*show_assets=*/false, /*show_offline_pages=*/true,
std::move(test_clock));
}
@@ -1116,12 +1118,8 @@ TEST_F(DownloadSuggestionsProviderTest,
IgnoreOnCategoryStatusChangedToAvailable();
IgnoreOnSuggestionInvalidated();
- const base::Time not_outdated =
- now - base::TimeDelta::FromHours(kDefaultMaxDownloadAgeHours) +
- base::TimeDelta::FromSeconds(1);
- const base::Time outdated =
- now - base::TimeDelta::FromHours(kDefaultMaxDownloadAgeHours) -
- base::TimeDelta::FromSeconds(1);
+ const base::Time not_outdated = GetDummyNotOutdatedTime();
+ const base::Time outdated = GetDummyOutdatedTime();
*(downloads_manager()->mutable_items()) = CreateDummyAssetDownloads({0, 1});
@@ -1143,7 +1141,7 @@ TEST_F(DownloadSuggestionsProviderTest,
OnNewSuggestions(_, downloads_category(),
UnorderedElementsAre(HasUrl("http://download.com/0"))));
auto test_clock = base::MakeUnique<base::SimpleTestClock>();
- test_clock->SetNow(now);
+ test_clock->SetNow(kDummyNow);
CreateLoadedProvider(/*show_assets=*/true, /*show_offline_pages=*/false,
std::move(test_clock));
}
« base/time/time.h ('K') | « base/time/time.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698