| OLD | NEW |
| 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 "base/macros.h" | 5 #include "base/macros.h" |
| 6 #include "components/prefs/default_pref_store.h" | 6 #include "components/prefs/default_pref_store.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 using base::StringValue; | |
| 10 using base::Value; | 9 using base::Value; |
| 11 | 10 |
| 12 namespace { | 11 namespace { |
| 13 | 12 |
| 14 class MockPrefStoreObserver : public PrefStore::Observer { | 13 class MockPrefStoreObserver : public PrefStore::Observer { |
| 15 public: | 14 public: |
| 16 explicit MockPrefStoreObserver(DefaultPrefStore* pref_store); | 15 explicit MockPrefStoreObserver(DefaultPrefStore* pref_store); |
| 17 ~MockPrefStoreObserver() override; | 16 ~MockPrefStoreObserver() override; |
| 18 | 17 |
| 19 int change_count() { | 18 int change_count() { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 47 | 46 |
| 48 } // namespace | 47 } // namespace |
| 49 | 48 |
| 50 TEST(DefaultPrefStoreTest, NotifyPrefValueChanged) { | 49 TEST(DefaultPrefStoreTest, NotifyPrefValueChanged) { |
| 51 scoped_refptr<DefaultPrefStore> pref_store(new DefaultPrefStore); | 50 scoped_refptr<DefaultPrefStore> pref_store(new DefaultPrefStore); |
| 52 MockPrefStoreObserver observer(pref_store.get()); | 51 MockPrefStoreObserver observer(pref_store.get()); |
| 53 std::string kPrefKey("pref_key"); | 52 std::string kPrefKey("pref_key"); |
| 54 | 53 |
| 55 // Setting a default value shouldn't send a change notification. | 54 // Setting a default value shouldn't send a change notification. |
| 56 pref_store->SetDefaultValue(kPrefKey, | 55 pref_store->SetDefaultValue(kPrefKey, |
| 57 std::unique_ptr<Value>(new StringValue("foo"))); | 56 std::unique_ptr<Value>(new Value("foo"))); |
| 58 EXPECT_EQ(0, observer.change_count()); | 57 EXPECT_EQ(0, observer.change_count()); |
| 59 | 58 |
| 60 // Replacing the default value should send a change notification... | 59 // Replacing the default value should send a change notification... |
| 61 pref_store->ReplaceDefaultValue( | 60 pref_store->ReplaceDefaultValue(kPrefKey, |
| 62 kPrefKey, std::unique_ptr<Value>(new StringValue("bar"))); | 61 std::unique_ptr<Value>(new Value("bar"))); |
| 63 EXPECT_EQ(1, observer.change_count()); | 62 EXPECT_EQ(1, observer.change_count()); |
| 64 | 63 |
| 65 // But only if the value actually changed. | 64 // But only if the value actually changed. |
| 66 pref_store->ReplaceDefaultValue( | 65 pref_store->ReplaceDefaultValue(kPrefKey, |
| 67 kPrefKey, std::unique_ptr<Value>(new StringValue("bar"))); | 66 std::unique_ptr<Value>(new Value("bar"))); |
| 68 EXPECT_EQ(1, observer.change_count()); | 67 EXPECT_EQ(1, observer.change_count()); |
| 69 } | 68 } |
| 70 | 69 |
| OLD | NEW |