[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | ecde274 | 2010-04-02 17:36:18 | [diff] [blame] | 5 | #include <string> |
| 6 | |
[email protected] | 3184cba4 | 2009-05-15 01:25:29 | [diff] [blame] | 7 | #include "app/test/data/resource.h" |
[email protected] | ecde274 | 2010-04-02 17:36:18 | [diff] [blame] | 8 | #include "base/scoped_ptr.h" |
| 9 | #include "base/values.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 10 | #include "chrome/browser/prefs/dummy_pref_store.h" |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame^] | 11 | #include "chrome/browser/prefs/pref_change_registrar.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 12 | #include "chrome/browser/prefs/pref_value_store.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 13 | #include "chrome/common/chrome_paths.h" |
[email protected] | ecde274 | 2010-04-02 17:36:18 | [diff] [blame] | 14 | #include "chrome/common/notification_observer_mock.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 15 | #include "chrome/common/notification_service.h" |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 16 | #include "chrome/common/notification_type.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 17 | #include "chrome/common/pref_names.h" |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 18 | #include "chrome/test/testing_pref_service.h" |
[email protected] | ecde274 | 2010-04-02 17:36:18 | [diff] [blame] | 19 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 20 | #include "testing/gtest/include/gtest/gtest.h" |
| 21 | |
[email protected] | ecde274 | 2010-04-02 17:36:18 | [diff] [blame] | 22 | using testing::_; |
| 23 | using testing::Mock; |
| 24 | using testing::Pointee; |
| 25 | using testing::Property; |
| 26 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 27 | class TestPrefObserver : public NotificationObserver { |
| 28 | public: |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 29 | TestPrefObserver(const PrefService* prefs, |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 30 | const std::string& pref_name, |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 31 | const std::string& new_pref_value) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 32 | : observer_fired_(false), |
| 33 | prefs_(prefs), |
| 34 | pref_name_(pref_name), |
| 35 | new_pref_value_(new_pref_value) { |
| 36 | } |
| 37 | virtual ~TestPrefObserver() {} |
| 38 | |
| 39 | virtual void Observe(NotificationType type, |
| 40 | const NotificationSource& source, |
| 41 | const NotificationDetails& details) { |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 42 | EXPECT_EQ(type.value, NotificationType::PREF_CHANGED); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 43 | PrefService* prefs_in = Source<PrefService>(source).ptr(); |
| 44 | EXPECT_EQ(prefs_in, prefs_); |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 45 | std::string* pref_name_in = Details<std::string>(details).ptr(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 46 | EXPECT_EQ(*pref_name_in, pref_name_); |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 47 | EXPECT_EQ(new_pref_value_, prefs_in->GetString("homepage")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 48 | observer_fired_ = true; |
| 49 | } |
| 50 | |
| 51 | bool observer_fired() { return observer_fired_; } |
| 52 | |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 53 | void Reset(const std::string& new_pref_value) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 54 | observer_fired_ = false; |
| 55 | new_pref_value_ = new_pref_value; |
| 56 | } |
| 57 | |
| 58 | private: |
| 59 | bool observer_fired_; |
| 60 | const PrefService* prefs_; |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 61 | const std::string pref_name_; |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 62 | std::string new_pref_value_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 63 | }; |
| 64 | |
[email protected] | 7aa0a96 | 2010-04-21 17:24:42 | [diff] [blame] | 65 | // TODO(port): port this test to POSIX. |
| 66 | #if defined(OS_WIN) |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 67 | TEST(PrefServiceTest, LocalizedPrefs) { |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 68 | TestingPrefService prefs; |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 69 | const char kBoolean[] = "boolean"; |
| 70 | const char kInteger[] = "integer"; |
| 71 | const char kString[] = "string"; |
[email protected] | 7aa0a96 | 2010-04-21 17:24:42 | [diff] [blame] | 72 | prefs.RegisterLocalizedBooleanPref(kBoolean, IDS_LOCALE_BOOL); |
| 73 | prefs.RegisterLocalizedIntegerPref(kInteger, IDS_LOCALE_INT); |
| 74 | prefs.RegisterLocalizedStringPref(kString, IDS_LOCALE_STRING); |
| 75 | |
| 76 | // The locale default should take preference over the user default. |
| 77 | EXPECT_FALSE(prefs.GetBoolean(kBoolean)); |
| 78 | EXPECT_EQ(1, prefs.GetInteger(kInteger)); |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 79 | EXPECT_EQ("hello", prefs.GetString(kString)); |
[email protected] | 7aa0a96 | 2010-04-21 17:24:42 | [diff] [blame] | 80 | |
| 81 | prefs.SetBoolean(kBoolean, true); |
| 82 | EXPECT_TRUE(prefs.GetBoolean(kBoolean)); |
| 83 | prefs.SetInteger(kInteger, 5); |
| 84 | EXPECT_EQ(5, prefs.GetInteger(kInteger)); |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 85 | prefs.SetString(kString, "foo"); |
| 86 | EXPECT_EQ("foo", prefs.GetString(kString)); |
[email protected] | 7aa0a96 | 2010-04-21 17:24:42 | [diff] [blame] | 87 | } |
| 88 | #endif |
| 89 | |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 90 | TEST(PrefServiceTest, NoObserverFire) { |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 91 | TestingPrefService prefs; |
[email protected] | 7aa0a96 | 2010-04-21 17:24:42 | [diff] [blame] | 92 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 93 | const char pref_name[] = "homepage"; |
[email protected] | 20ce516d | 2010-06-18 02:20:04 | [diff] [blame] | 94 | prefs.RegisterStringPref(pref_name, ""); |
[email protected] | 7aa0a96 | 2010-04-21 17:24:42 | [diff] [blame] | 95 | |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 96 | const std::string new_pref_value("http://www.google.com/"); |
[email protected] | 7aa0a96 | 2010-04-21 17:24:42 | [diff] [blame] | 97 | TestPrefObserver obs(&prefs, pref_name, new_pref_value); |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame^] | 98 | |
| 99 | PrefChangeRegistrar registrar; |
| 100 | registrar.Init(&prefs); |
| 101 | registrar.Add(pref_name, &obs); |
[email protected] | 7aa0a96 | 2010-04-21 17:24:42 | [diff] [blame] | 102 | // This should fire the checks in TestPrefObserver::Observe. |
| 103 | prefs.SetString(pref_name, new_pref_value); |
| 104 | |
| 105 | // Make sure the observer was actually fired. |
| 106 | EXPECT_TRUE(obs.observer_fired()); |
| 107 | |
| 108 | // Setting the pref to the same value should not set the pref value a second |
| 109 | // time. |
| 110 | obs.Reset(new_pref_value); |
| 111 | prefs.SetString(pref_name, new_pref_value); |
[email protected] | 40a47c16 | 2010-09-09 11:14:01 | [diff] [blame] | 112 | EXPECT_FALSE(obs.observer_fired()); |
[email protected] | 7aa0a96 | 2010-04-21 17:24:42 | [diff] [blame] | 113 | |
| 114 | // Clearing the pref should cause the pref to fire. |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 115 | obs.Reset(""); |
[email protected] | 7aa0a96 | 2010-04-21 17:24:42 | [diff] [blame] | 116 | prefs.ClearPref(pref_name); |
| 117 | EXPECT_TRUE(obs.observer_fired()); |
| 118 | |
| 119 | // Clearing the pref again should not cause the pref to fire. |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 120 | obs.Reset(""); |
[email protected] | 7aa0a96 | 2010-04-21 17:24:42 | [diff] [blame] | 121 | prefs.ClearPref(pref_name); |
[email protected] | 40a47c16 | 2010-09-09 11:14:01 | [diff] [blame] | 122 | EXPECT_FALSE(obs.observer_fired()); |
[email protected] | 7aa0a96 | 2010-04-21 17:24:42 | [diff] [blame] | 123 | } |
| 124 | |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 125 | TEST(PrefServiceTest, HasPrefPath) { |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 126 | TestingPrefService prefs; |
[email protected] | 7aa0a96 | 2010-04-21 17:24:42 | [diff] [blame] | 127 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 128 | const char path[] = "fake.path"; |
[email protected] | 7aa0a96 | 2010-04-21 17:24:42 | [diff] [blame] | 129 | |
| 130 | // Shouldn't initially have a path. |
| 131 | EXPECT_FALSE(prefs.HasPrefPath(path)); |
| 132 | |
| 133 | // Register the path. This doesn't set a value, so the path still shouldn't |
| 134 | // exist. |
[email protected] | 20ce516d | 2010-06-18 02:20:04 | [diff] [blame] | 135 | prefs.RegisterStringPref(path, std::string()); |
[email protected] | 7aa0a96 | 2010-04-21 17:24:42 | [diff] [blame] | 136 | EXPECT_FALSE(prefs.HasPrefPath(path)); |
| 137 | |
| 138 | // Set a value and make sure we have a path. |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 139 | prefs.SetString(path, "blah"); |
[email protected] | 7aa0a96 | 2010-04-21 17:24:42 | [diff] [blame] | 140 | EXPECT_TRUE(prefs.HasPrefPath(path)); |
| 141 | } |
| 142 | |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 143 | TEST(PrefServiceTest, Observers) { |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 144 | const char pref_name[] = "homepage"; |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 145 | |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 146 | TestingPrefService prefs; |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 147 | prefs.SetUserPref(pref_name, Value::CreateStringValue("http://www.cnn.com")); |
[email protected] | 20ce516d | 2010-06-18 02:20:04 | [diff] [blame] | 148 | prefs.RegisterStringPref(pref_name, ""); |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 149 | |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 150 | const std::string new_pref_value("http://www.google.com/"); |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 151 | TestPrefObserver obs(&prefs, pref_name, new_pref_value); |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame^] | 152 | PrefChangeRegistrar registrar; |
| 153 | registrar.Init(&prefs); |
| 154 | registrar.Add(pref_name, &obs); |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 155 | // This should fire the checks in TestPrefObserver::Observe. |
| 156 | prefs.SetString(pref_name, new_pref_value); |
| 157 | |
| 158 | // Make sure the tests were actually run. |
| 159 | EXPECT_TRUE(obs.observer_fired()); |
| 160 | |
| 161 | // Now try adding a second pref observer. |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 162 | const std::string new_pref_value2("http://www.youtube.com/"); |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 163 | obs.Reset(new_pref_value2); |
| 164 | TestPrefObserver obs2(&prefs, pref_name, new_pref_value2); |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame^] | 165 | registrar.Add(pref_name, &obs2); |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 166 | // This should fire the checks in obs and obs2. |
| 167 | prefs.SetString(pref_name, new_pref_value2); |
| 168 | EXPECT_TRUE(obs.observer_fired()); |
| 169 | EXPECT_TRUE(obs2.observer_fired()); |
| 170 | |
| 171 | // Make sure obs2 still works after removing obs. |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame^] | 172 | registrar.Remove(pref_name, &obs); |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 173 | obs.Reset(""); |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 174 | obs2.Reset(new_pref_value); |
| 175 | // This should only fire the observer in obs2. |
| 176 | prefs.SetString(pref_name, new_pref_value); |
| 177 | EXPECT_FALSE(obs.observer_fired()); |
| 178 | EXPECT_TRUE(obs2.observer_fired()); |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 179 | } |
| 180 | |
[email protected] | ecde274 | 2010-04-02 17:36:18 | [diff] [blame] | 181 | class PrefServiceSetValueTest : public testing::Test { |
| 182 | protected: |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 183 | static const char name_[]; |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 184 | static const char value_[]; |
[email protected] | ecde274 | 2010-04-02 17:36:18 | [diff] [blame] | 185 | |
| 186 | PrefServiceSetValueTest() |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 187 | : name_string_(name_), |
[email protected] | ecde274 | 2010-04-02 17:36:18 | [diff] [blame] | 188 | null_value_(Value::CreateNullValue()) {} |
| 189 | |
| 190 | void SetExpectNoNotification() { |
| 191 | EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); |
| 192 | } |
| 193 | |
| 194 | void SetExpectPrefChanged() { |
| 195 | EXPECT_CALL(observer_, |
| 196 | Observe(NotificationType(NotificationType::PREF_CHANGED), _, |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 197 | Property(&Details<std::string>::ptr, |
[email protected] | ecde274 | 2010-04-02 17:36:18 | [diff] [blame] | 198 | Pointee(name_string_)))); |
| 199 | } |
| 200 | |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 201 | TestingPrefService prefs_; |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 202 | std::string name_string_; |
[email protected] | ecde274 | 2010-04-02 17:36:18 | [diff] [blame] | 203 | scoped_ptr<Value> null_value_; |
| 204 | NotificationObserverMock observer_; |
| 205 | }; |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 206 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 207 | const char PrefServiceSetValueTest::name_[] = "name"; |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 208 | const char PrefServiceSetValueTest::value_[] = "value"; |
[email protected] | ecde274 | 2010-04-02 17:36:18 | [diff] [blame] | 209 | |
| 210 | TEST_F(PrefServiceSetValueTest, SetStringValue) { |
[email protected] | 20ce516d | 2010-06-18 02:20:04 | [diff] [blame] | 211 | const char default_string[] = "default"; |
[email protected] | ecde274 | 2010-04-02 17:36:18 | [diff] [blame] | 212 | scoped_ptr<Value> default_value(Value::CreateStringValue(default_string)); |
| 213 | prefs_.RegisterStringPref(name_, default_string); |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame^] | 214 | |
| 215 | PrefChangeRegistrar registrar; |
| 216 | registrar.Init(&prefs_); |
| 217 | registrar.Add(name_, &observer_); |
| 218 | |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 219 | // Changing the controlling store from default to user triggers notification. |
| 220 | SetExpectPrefChanged(); |
| 221 | prefs_.Set(name_, *default_value); |
| 222 | Mock::VerifyAndClearExpectations(&observer_); |
| 223 | |
[email protected] | 40a47c16 | 2010-09-09 11:14:01 | [diff] [blame] | 224 | SetExpectNoNotification(); |
[email protected] | ecde274 | 2010-04-02 17:36:18 | [diff] [blame] | 225 | prefs_.Set(name_, *default_value); |
| 226 | Mock::VerifyAndClearExpectations(&observer_); |
| 227 | |
| 228 | scoped_ptr<Value> new_value(Value::CreateStringValue(value_)); |
| 229 | SetExpectPrefChanged(); |
| 230 | prefs_.Set(name_, *new_value); |
| 231 | EXPECT_EQ(value_, prefs_.GetString(name_)); |
[email protected] | ecde274 | 2010-04-02 17:36:18 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | TEST_F(PrefServiceSetValueTest, SetDictionaryValue) { |
| 235 | prefs_.RegisterDictionaryPref(name_); |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame^] | 236 | PrefChangeRegistrar registrar; |
| 237 | registrar.Init(&prefs_); |
| 238 | registrar.Add(name_, &observer_); |
[email protected] | ecde274 | 2010-04-02 17:36:18 | [diff] [blame] | 239 | |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 240 | // Dictionary values are special: setting one to NULL is the same as clearing |
| 241 | // the user value, allowing the NULL default to take (or keep) control. |
[email protected] | ecde274 | 2010-04-02 17:36:18 | [diff] [blame] | 242 | SetExpectNoNotification(); |
| 243 | prefs_.Set(name_, *null_value_); |
| 244 | Mock::VerifyAndClearExpectations(&observer_); |
| 245 | |
| 246 | DictionaryValue new_value; |
| 247 | new_value.SetString(name_, value_); |
| 248 | SetExpectPrefChanged(); |
| 249 | prefs_.Set(name_, new_value); |
| 250 | Mock::VerifyAndClearExpectations(&observer_); |
| 251 | DictionaryValue* dict = prefs_.GetMutableDictionary(name_); |
| 252 | EXPECT_EQ(1U, dict->size()); |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 253 | std::string out_value; |
[email protected] | ecde274 | 2010-04-02 17:36:18 | [diff] [blame] | 254 | dict->GetString(name_, &out_value); |
| 255 | EXPECT_EQ(value_, out_value); |
| 256 | |
[email protected] | 40a47c16 | 2010-09-09 11:14:01 | [diff] [blame] | 257 | SetExpectNoNotification(); |
[email protected] | ecde274 | 2010-04-02 17:36:18 | [diff] [blame] | 258 | prefs_.Set(name_, new_value); |
| 259 | Mock::VerifyAndClearExpectations(&observer_); |
| 260 | |
| 261 | SetExpectPrefChanged(); |
| 262 | prefs_.Set(name_, *null_value_); |
| 263 | Mock::VerifyAndClearExpectations(&observer_); |
| 264 | dict = prefs_.GetMutableDictionary(name_); |
| 265 | EXPECT_EQ(0U, dict->size()); |
[email protected] | ecde274 | 2010-04-02 17:36:18 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | TEST_F(PrefServiceSetValueTest, SetListValue) { |
| 269 | prefs_.RegisterListPref(name_); |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame^] | 270 | PrefChangeRegistrar registrar; |
| 271 | registrar.Init(&prefs_); |
| 272 | registrar.Add(name_, &observer_); |
[email protected] | ecde274 | 2010-04-02 17:36:18 | [diff] [blame] | 273 | |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 274 | // List values are special: setting one to NULL is the same as clearing the |
| 275 | // user value, allowing the NULL default to take (or keep) control. |
[email protected] | ecde274 | 2010-04-02 17:36:18 | [diff] [blame] | 276 | SetExpectNoNotification(); |
| 277 | prefs_.Set(name_, *null_value_); |
| 278 | Mock::VerifyAndClearExpectations(&observer_); |
| 279 | |
| 280 | ListValue new_value; |
| 281 | new_value.Append(Value::CreateStringValue(value_)); |
| 282 | SetExpectPrefChanged(); |
| 283 | prefs_.Set(name_, new_value); |
| 284 | Mock::VerifyAndClearExpectations(&observer_); |
| 285 | ListValue* list = prefs_.GetMutableList(name_); |
| 286 | ASSERT_EQ(1U, list->GetSize()); |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 287 | std::string out_value; |
[email protected] | ecde274 | 2010-04-02 17:36:18 | [diff] [blame] | 288 | list->GetString(0, &out_value); |
| 289 | EXPECT_EQ(value_, out_value); |
| 290 | |
[email protected] | 40a47c16 | 2010-09-09 11:14:01 | [diff] [blame] | 291 | SetExpectNoNotification(); |
[email protected] | ecde274 | 2010-04-02 17:36:18 | [diff] [blame] | 292 | prefs_.Set(name_, new_value); |
| 293 | Mock::VerifyAndClearExpectations(&observer_); |
| 294 | |
| 295 | SetExpectPrefChanged(); |
| 296 | prefs_.Set(name_, *null_value_); |
| 297 | Mock::VerifyAndClearExpectations(&observer_); |
| 298 | list = prefs_.GetMutableList(name_); |
| 299 | EXPECT_EQ(0U, list->GetSize()); |
[email protected] | ecde274 | 2010-04-02 17:36:18 | [diff] [blame] | 300 | } |