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

Side by Side Diff: base/prefs/default_pref_store_unittest.cc

Issue 1647803004: Move base to DEPS (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 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 | « base/prefs/default_pref_store.cc ('k') | base/prefs/json_pref_store.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/prefs/default_pref_store.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7
8 using base::StringValue;
9 using base::Value;
10
11 namespace {
12
13 class MockPrefStoreObserver : public PrefStore::Observer {
14 public:
15 explicit MockPrefStoreObserver(DefaultPrefStore* pref_store);
16 ~MockPrefStoreObserver() override;
17
18 int change_count() {
19 return change_count_;
20 }
21
22 // PrefStore::Observer implementation:
23 void OnPrefValueChanged(const std::string& key) override;
24 void OnInitializationCompleted(bool succeeded) override {}
25
26 private:
27 DefaultPrefStore* pref_store_;
28
29 int change_count_;
30
31 DISALLOW_COPY_AND_ASSIGN(MockPrefStoreObserver);
32 };
33
34 MockPrefStoreObserver::MockPrefStoreObserver(DefaultPrefStore* pref_store)
35 : pref_store_(pref_store), change_count_(0) {
36 pref_store_->AddObserver(this);
37 }
38
39 MockPrefStoreObserver::~MockPrefStoreObserver() {
40 pref_store_->RemoveObserver(this);
41 }
42
43 void MockPrefStoreObserver::OnPrefValueChanged(const std::string& key) {
44 change_count_++;
45 }
46
47 } // namespace
48
49 TEST(DefaultPrefStoreTest, NotifyPrefValueChanged) {
50 scoped_refptr<DefaultPrefStore> pref_store(new DefaultPrefStore);
51 MockPrefStoreObserver observer(pref_store.get());
52 std::string kPrefKey("pref_key");
53
54 // Setting a default value shouldn't send a change notification.
55 pref_store->SetDefaultValue(kPrefKey,
56 scoped_ptr<Value>(new StringValue("foo")));
57 EXPECT_EQ(0, observer.change_count());
58
59 // Replacing the default value should send a change notification...
60 pref_store->ReplaceDefaultValue(kPrefKey,
61 scoped_ptr<Value>(new StringValue("bar")));
62 EXPECT_EQ(1, observer.change_count());
63
64 // But only if the value actually changed.
65 pref_store->ReplaceDefaultValue(kPrefKey,
66 scoped_ptr<Value>(new StringValue("bar")));
67 EXPECT_EQ(1, observer.change_count());
68 }
69
OLDNEW
« no previous file with comments | « base/prefs/default_pref_store.cc ('k') | base/prefs/json_pref_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698