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

Unified Diff: components/prefs/pref_service_unittest.cc

Issue 2276043004: Add PrefMember<base::Time> Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add PrefService::{Get,Set}Time(..., base::Time) Created 4 years, 4 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 | « components/prefs/pref_service.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/prefs/pref_service_unittest.cc
diff --git a/components/prefs/pref_service_unittest.cc b/components/prefs/pref_service_unittest.cc
index 373c01bcb3f3c2b37ef1966362f100936e61f12a..83a2172633df39da86332efd399b8ae66f4e40ae 100644
--- a/components/prefs/pref_service_unittest.cc
+++ b/components/prefs/pref_service_unittest.cc
@@ -232,6 +232,25 @@ TEST(PrefServiceTest, GetValueAndGetRecommendedValue) {
EXPECT_EQ(kRecommendedValue, actual_int_value);
}
+TEST(PrefServiceTest, GetAndSetTime) {
+ const base::Time::Exploded kAugust25 = {2016, 8, 4, 25, 16, 07, 13, 846};
+
+ TestingPrefServiceSimple prefs;
+ prefs.registry()->RegisterInt64Pref(kPrefName, 0);
+ EXPECT_EQ(0, prefs.GetInt64(kPrefName));
+ EXPECT_TRUE(prefs.GetTime(kPrefName).is_null());
+
+ const base::Time t1 = base::Time::FromUTCExploded(kAugust25);
+ prefs.SetTime(kPrefName, t1);
+ EXPECT_EQ(t1, prefs.GetTime(kPrefName));
+ EXPECT_EQ(t1, base::Time::FromInternalValue(prefs.GetInt64(kPrefName)));
+
+ const base::Time t2 = t1 + base::TimeDelta::FromHours(12);
+ prefs.SetInt64(kPrefName, t2.ToInternalValue());
+ EXPECT_EQ(t2, prefs.GetTime(kPrefName));
+ EXPECT_EQ(t2, base::Time::FromInternalValue(prefs.GetInt64(kPrefName)));
+}
+
// A PrefStore which just stores the last write flags that were used to write
// values to it.
class WriteFlagChecker : public TestingPrefStore {
« no previous file with comments | « components/prefs/pref_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698