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

Side by Side 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, 3 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 unified diff | Download patch
« no previous file with comments | « components/prefs/pref_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 225
226 // Check that GetRecommendedValue() returns the recommended value. 226 // Check that GetRecommendedValue() returns the recommended value.
227 value = pref->GetRecommendedValue(); 227 value = pref->GetRecommendedValue();
228 ASSERT_TRUE(value); 228 ASSERT_TRUE(value);
229 EXPECT_EQ(base::Value::TYPE_INTEGER, value->GetType()); 229 EXPECT_EQ(base::Value::TYPE_INTEGER, value->GetType());
230 actual_int_value = -1; 230 actual_int_value = -1;
231 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); 231 EXPECT_TRUE(value->GetAsInteger(&actual_int_value));
232 EXPECT_EQ(kRecommendedValue, actual_int_value); 232 EXPECT_EQ(kRecommendedValue, actual_int_value);
233 } 233 }
234 234
235 TEST(PrefServiceTest, GetAndSetTime) {
236 const base::Time::Exploded kAugust25 = {2016, 8, 4, 25, 16, 07, 13, 846};
237
238 TestingPrefServiceSimple prefs;
239 prefs.registry()->RegisterInt64Pref(kPrefName, 0);
240 EXPECT_EQ(0, prefs.GetInt64(kPrefName));
241 EXPECT_TRUE(prefs.GetTime(kPrefName).is_null());
242
243 const base::Time t1 = base::Time::FromUTCExploded(kAugust25);
244 prefs.SetTime(kPrefName, t1);
245 EXPECT_EQ(t1, prefs.GetTime(kPrefName));
246 EXPECT_EQ(t1, base::Time::FromInternalValue(prefs.GetInt64(kPrefName)));
247
248 const base::Time t2 = t1 + base::TimeDelta::FromHours(12);
249 prefs.SetInt64(kPrefName, t2.ToInternalValue());
250 EXPECT_EQ(t2, prefs.GetTime(kPrefName));
251 EXPECT_EQ(t2, base::Time::FromInternalValue(prefs.GetInt64(kPrefName)));
252 }
253
235 // A PrefStore which just stores the last write flags that were used to write 254 // A PrefStore which just stores the last write flags that were used to write
236 // values to it. 255 // values to it.
237 class WriteFlagChecker : public TestingPrefStore { 256 class WriteFlagChecker : public TestingPrefStore {
238 public: 257 public:
239 WriteFlagChecker() {} 258 WriteFlagChecker() {}
240 259
241 void ReportValueChanged(const std::string& key, uint32_t flags) override { 260 void ReportValueChanged(const std::string& key, uint32_t flags) override {
242 SetLastWriteFlags(flags); 261 SetLastWriteFlags(flags);
243 } 262 }
244 263
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 440
422 EXPECT_CALL(observer_, OnPreferenceChanged(_)).Times(0); 441 EXPECT_CALL(observer_, OnPreferenceChanged(_)).Times(0);
423 prefs_.Set(kName, new_value); 442 prefs_.Set(kName, new_value);
424 Mock::VerifyAndClearExpectations(&observer_); 443 Mock::VerifyAndClearExpectations(&observer_);
425 444
426 base::ListValue empty; 445 base::ListValue empty;
427 observer_.Expect(kName, &empty); 446 observer_.Expect(kName, &empty);
428 prefs_.Set(kName, empty); 447 prefs_.Set(kName, empty);
429 Mock::VerifyAndClearExpectations(&observer_); 448 Mock::VerifyAndClearExpectations(&observer_);
430 } 449 }
OLDNEW
« 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