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

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

Issue 2892553005: Avoid base::Time::FromJavaTime() when not dealing with Java. (Closed)
Patch Set: address comment 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
« no previous file with comments | « no previous file | 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..3eb3471e1e27e781f246634636800da198780e20 100644
--- a/chrome/browser/ntp_snippets/download_suggestions_provider_unittest.cc
+++ b/chrome/browser/ntp_snippets/download_suggestions_provider_unittest.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/ntp_snippets/download_suggestions_provider.h"
#include <memory>
+#include <utility>
#include "base/bind.h"
#include "base/memory/ptr_util.h"
@@ -89,8 +90,23 @@ namespace {
const int kDefaultMaxDownloadAgeHours = 6 * 7 * 24;
-// Tue, 31 Jan 2017 13:00:00 UTC
-const base::Time now = base::Time::FromJavaTime(1485867600000);
+base::Time CalculateDummyNowTime() {
+ base::Time now;
+ CHECK(base::Time::FromUTCString("2017-01-31 13:00:00", &now));
+ return now;
+}
+
+const base::Time now = CalculateDummyNowTime();
miu 2017/05/22 21:45:31 Global static initializer here. So, this goes agai
Lei Zhang 2017/05/22 22:03:57 Yes, which is what I was avoiding in patch set 1.
+
+base::Time GetDummyNotOutdatedTime() {
+ return now - base::TimeDelta::FromHours(kDefaultMaxDownloadAgeHours) +
+ base::TimeDelta::FromSeconds(1);
+}
+
+base::Time GetDummyOutdatedTime() {
+ return now - 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"))|.
@@ -1035,12 +1051,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});
@@ -1080,12 +1092,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});
@@ -1116,12 +1124,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});
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698