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

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: 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..65980dcc8a3cb34259a12f25df60e02eceac7e5c 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,27 @@ 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 GetDummyNowTime() {
vitaliii 2017/05/19 07:09:07 How about == CODE STARTS == base::Time GetTimeFro
+ static base::Time now;
+ static bool now_set = false;
+ if (!now_set) {
+ CHECK(base::Time::FromUTCString("2017-01-31 13:00:00", &now));
+ now_set = true;
+ }
+ return now;
+}
+
+base::Time GetDummyNotOutdatedTime() {
+ return GetDummyNowTime() -
+ base::TimeDelta::FromHours(kDefaultMaxDownloadAgeHours) +
+ base::TimeDelta::FromSeconds(1);
+}
+
+base::Time GetDummyOutdatedTime() {
+ return GetDummyNowTime() -
+ 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 +491,19 @@ 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 =
+ GetDummyNowTime() - 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 =
+ GetDummyNowTime() - 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(GetDummyNowTime());
EXPECT_CALL(*observer(),
OnNewSuggestions(_, downloads_category(),
ElementsAre(HasUrl("http://dummy.com/1"),
@@ -493,10 +515,12 @@ 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(GetDummyNowTime() -
+ 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(GetDummyNowTime() -
+ base::TimeDelta::FromMinutes(7));
EXPECT_CALL(*observer(),
OnNewSuggestions(_, downloads_category(),
@@ -1035,12 +1059,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 +1090,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(GetDummyNowTime());
CreateLoadedProvider(/*show_assets=*/true, /*show_offline_pages=*/true,
std::move(test_clock));
}
@@ -1080,12 +1100,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 +1122,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(GetDummyNowTime());
CreateProvider(/*show_assets=*/false, /*show_offline_pages=*/true,
std::move(test_clock));
}
@@ -1116,12 +1132,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 +1155,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(GetDummyNowTime());
CreateLoadedProvider(/*show_assets=*/true, /*show_offline_pages=*/false,
std::move(test_clock));
}
« 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