OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "app/test/data/resource.h" | 7 #include "app/test/data/resource.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 11 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
12 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 12 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
13 #include "chrome/browser/prefs/browser_prefs.h" | 13 #include "chrome/browser/prefs/browser_prefs.h" |
14 #include "chrome/browser/prefs/command_line_pref_store.h" | 14 #include "chrome/browser/prefs/command_line_pref_store.h" |
15 #include "chrome/browser/prefs/default_pref_store.h" | 15 #include "chrome/browser/prefs/default_pref_store.h" |
16 #include "chrome/browser/prefs/dummy_pref_store.h" | 16 #include "chrome/browser/prefs/testing_pref_store.h" |
17 #include "chrome/browser/prefs/pref_change_registrar.h" | 17 #include "chrome/browser/prefs/pref_change_registrar.h" |
18 #include "chrome/browser/prefs/pref_value_store.h" | 18 #include "chrome/browser/prefs/pref_value_store.h" |
19 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
20 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
21 #include "chrome/common/notification_observer_mock.h" | 21 #include "chrome/common/notification_details.h" |
22 #include "chrome/common/notification_service.h" | 22 #include "chrome/common/notification_observer.h" |
23 #include "chrome/common/notification_source.h" | |
23 #include "chrome/common/notification_type.h" | 24 #include "chrome/common/notification_type.h" |
24 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
25 #include "chrome/test/testing_pref_service.h" | 26 #include "chrome/test/testing_pref_service.h" |
26 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
28 | 29 |
29 using testing::_; | 30 using testing::_; |
31 using testing::AllOf; | |
30 using testing::Mock; | 32 using testing::Mock; |
31 using testing::Pointee; | 33 using testing::Pointee; |
32 using testing::Property; | 34 using testing::Property; |
35 using testing::Truly; | |
33 | 36 |
34 namespace { | 37 namespace { |
35 | 38 |
39 MATCHER_P3(PrefValueMatches, prefs, pref_name, value, "") { | |
danno
2010/12/02 10:31:52
Add comment please.
Mattias Nissler (ping if slow)
2010/12/02 16:38:24
Done.
| |
40 const PrefService::Preference* pref = | |
41 prefs->FindPreference(pref_name.c_str()); | |
42 if (!pref) | |
43 return false; | |
44 | |
45 const Value* actual_value = pref->GetValue(); | |
46 if (!actual_value) | |
47 return value == NULL; | |
48 if (!value) | |
49 return actual_value == NULL; | |
50 return value->Equals(actual_value); | |
51 } | |
52 | |
36 class TestPrefObserver : public NotificationObserver { | 53 class TestPrefObserver : public NotificationObserver { |
37 public: | 54 public: |
38 TestPrefObserver(const PrefService* prefs, | 55 TestPrefObserver() {} |
39 const std::string& pref_name, | |
40 const std::string& new_pref_value) | |
41 : observer_fired_(false), | |
42 prefs_(prefs), | |
43 pref_name_(pref_name), | |
44 new_pref_value_(new_pref_value) {} | |
45 virtual ~TestPrefObserver() {} | 56 virtual ~TestPrefObserver() {} |
46 | 57 |
47 virtual void Observe(NotificationType type, | 58 MOCK_METHOD3(Observe, void(NotificationType type, |
48 const NotificationSource& source, | 59 const NotificationSource& source, |
49 const NotificationDetails& details) { | 60 const NotificationDetails& details)); |
50 EXPECT_EQ(type.value, NotificationType::PREF_CHANGED); | 61 |
51 const PrefService* prefs_in = Source<PrefService>(source).ptr(); | 62 void Expect(const PrefService* prefs, |
52 EXPECT_EQ(prefs_in, prefs_); | 63 const std::string& pref_name, |
53 const std::string* pref_name_in = Details<std::string>(details).ptr(); | 64 const Value* value) { |
54 EXPECT_EQ(*pref_name_in, pref_name_); | 65 EXPECT_CALL(*this, Observe(NotificationType(NotificationType::PREF_CHANGED), |
55 EXPECT_EQ(new_pref_value_, prefs_in->GetString("homepage")); | 66 Source<PrefService>(prefs), |
56 observer_fired_ = true; | 67 Property(&Details<std::string>::ptr, |
68 Pointee(pref_name)))) | |
69 .With(PrefValueMatches(prefs, pref_name, value)); | |
57 } | 70 } |
58 | |
59 bool observer_fired() { return observer_fired_; } | |
60 | |
61 void Reset(const std::string& new_pref_value) { | |
62 observer_fired_ = false; | |
63 new_pref_value_ = new_pref_value; | |
64 } | |
65 | |
66 private: | |
67 bool observer_fired_; | |
68 const PrefService* prefs_; | |
69 const std::string pref_name_; | |
70 std::string new_pref_value_; | |
71 }; | 71 }; |
72 | 72 |
73 } // namespace | 73 } // namespace |
74 | 74 |
75 // TODO(port): port this test to POSIX. | 75 // TODO(port): port this test to POSIX. |
76 #if defined(OS_WIN) | 76 #if defined(OS_WIN) |
77 TEST(PrefServiceTest, LocalizedPrefs) { | 77 TEST(PrefServiceTest, LocalizedPrefs) { |
78 TestingPrefService prefs; | 78 TestingPrefService prefs; |
79 const char kBoolean[] = "boolean"; | 79 const char kBoolean[] = "boolean"; |
80 const char kInteger[] = "integer"; | 80 const char kInteger[] = "integer"; |
(...skipping 15 matching lines...) Expand all Loading... | |
96 EXPECT_EQ("foo", prefs.GetString(kString)); | 96 EXPECT_EQ("foo", prefs.GetString(kString)); |
97 } | 97 } |
98 #endif | 98 #endif |
99 | 99 |
100 TEST(PrefServiceTest, NoObserverFire) { | 100 TEST(PrefServiceTest, NoObserverFire) { |
101 TestingPrefService prefs; | 101 TestingPrefService prefs; |
102 | 102 |
103 const char pref_name[] = "homepage"; | 103 const char pref_name[] = "homepage"; |
104 prefs.RegisterStringPref(pref_name, std::string()); | 104 prefs.RegisterStringPref(pref_name, std::string()); |
105 | 105 |
106 const std::string new_pref_value("http://www.google.com/"); | 106 const char new_pref_value[] = "http://www.google.com/"; |
107 TestPrefObserver obs(&prefs, pref_name, new_pref_value); | 107 TestPrefObserver obs; |
108 | |
109 PrefChangeRegistrar registrar; | 108 PrefChangeRegistrar registrar; |
110 registrar.Init(&prefs); | 109 registrar.Init(&prefs); |
111 registrar.Add(pref_name, &obs); | 110 registrar.Add(pref_name, &obs); |
111 | |
112 // This should fire the checks in TestPrefObserver::Observe. | 112 // This should fire the checks in TestPrefObserver::Observe. |
113 StringValue expected_value(new_pref_value); | |
114 obs.Expect(&prefs, pref_name, &expected_value); | |
113 prefs.SetString(pref_name, new_pref_value); | 115 prefs.SetString(pref_name, new_pref_value); |
114 | 116 Mock::VerifyAndClearExpectations(&obs); |
115 // Make sure the observer was actually fired. | |
116 EXPECT_TRUE(obs.observer_fired()); | |
117 | 117 |
118 // Setting the pref to the same value should not set the pref value a second | 118 // Setting the pref to the same value should not set the pref value a second |
119 // time. | 119 // time. |
120 obs.Reset(new_pref_value); | 120 EXPECT_CALL(obs, Observe(_, _, _)).Times(0); |
121 prefs.SetString(pref_name, new_pref_value); | 121 prefs.SetString(pref_name, new_pref_value); |
122 EXPECT_FALSE(obs.observer_fired()); | 122 Mock::VerifyAndClearExpectations(&obs); |
123 | 123 |
124 // Clearing the pref should cause the pref to fire. | 124 // Clearing the pref should cause the pref to fire. |
125 obs.Reset(std::string()); | 125 StringValue expected_default_value(""); |
126 obs.Expect(&prefs, pref_name, &expected_default_value); | |
126 prefs.ClearPref(pref_name); | 127 prefs.ClearPref(pref_name); |
127 EXPECT_TRUE(obs.observer_fired()); | 128 Mock::VerifyAndClearExpectations(&obs); |
128 | 129 |
129 // Clearing the pref again should not cause the pref to fire. | 130 // Clearing the pref again should not cause the pref to fire. |
130 obs.Reset(std::string()); | 131 EXPECT_CALL(obs, Observe(_, _, _)).Times(0); |
131 prefs.ClearPref(pref_name); | 132 prefs.ClearPref(pref_name); |
132 EXPECT_FALSE(obs.observer_fired()); | 133 Mock::VerifyAndClearExpectations(&obs); |
133 } | 134 } |
134 | 135 |
135 TEST(PrefServiceTest, HasPrefPath) { | 136 TEST(PrefServiceTest, HasPrefPath) { |
136 TestingPrefService prefs; | 137 TestingPrefService prefs; |
137 | 138 |
138 const char path[] = "fake.path"; | 139 const char path[] = "fake.path"; |
139 | 140 |
140 // Shouldn't initially have a path. | 141 // Shouldn't initially have a path. |
141 EXPECT_FALSE(prefs.HasPrefPath(path)); | 142 EXPECT_FALSE(prefs.HasPrefPath(path)); |
142 | 143 |
143 // Register the path. This doesn't set a value, so the path still shouldn't | 144 // Register the path. This doesn't set a value, so the path still shouldn't |
144 // exist. | 145 // exist. |
145 prefs.RegisterStringPref(path, std::string()); | 146 prefs.RegisterStringPref(path, std::string()); |
146 EXPECT_FALSE(prefs.HasPrefPath(path)); | 147 EXPECT_FALSE(prefs.HasPrefPath(path)); |
147 | 148 |
148 // Set a value and make sure we have a path. | 149 // Set a value and make sure we have a path. |
149 prefs.SetString(path, "blah"); | 150 prefs.SetString(path, "blah"); |
150 EXPECT_TRUE(prefs.HasPrefPath(path)); | 151 EXPECT_TRUE(prefs.HasPrefPath(path)); |
151 } | 152 } |
152 | 153 |
153 TEST(PrefServiceTest, Observers) { | 154 TEST(PrefServiceTest, Observers) { |
154 const char pref_name[] = "homepage"; | 155 const char pref_name[] = "homepage"; |
155 | 156 |
156 TestingPrefService prefs; | 157 TestingPrefService prefs; |
157 prefs.SetUserPref(pref_name, Value::CreateStringValue("http://www.cnn.com")); | 158 prefs.SetUserPref(pref_name, Value::CreateStringValue("http://www.cnn.com")); |
158 prefs.RegisterStringPref(pref_name, std::string()); | 159 prefs.RegisterStringPref(pref_name, std::string()); |
159 | 160 |
160 const std::string new_pref_value("http://www.google.com/"); | 161 const char new_pref_value[] = "http://www.google.com/"; |
161 TestPrefObserver obs(&prefs, pref_name, new_pref_value); | 162 StringValue expected_new_pref_value(new_pref_value); |
163 TestPrefObserver obs; | |
162 PrefChangeRegistrar registrar; | 164 PrefChangeRegistrar registrar; |
163 registrar.Init(&prefs); | 165 registrar.Init(&prefs); |
164 registrar.Add(pref_name, &obs); | 166 registrar.Add(pref_name, &obs); |
167 | |
165 // This should fire the checks in TestPrefObserver::Observe. | 168 // This should fire the checks in TestPrefObserver::Observe. |
169 obs.Expect(&prefs, pref_name, &expected_new_pref_value); | |
166 prefs.SetString(pref_name, new_pref_value); | 170 prefs.SetString(pref_name, new_pref_value); |
167 | 171 Mock::VerifyAndClearExpectations(&obs); |
168 // Make sure the tests were actually run. | |
169 EXPECT_TRUE(obs.observer_fired()); | |
170 | 172 |
171 // Now try adding a second pref observer. | 173 // Now try adding a second pref observer. |
172 const std::string new_pref_value2("http://www.youtube.com/"); | 174 const char new_pref_value2[] = "http://www.youtube.com/"; |
173 obs.Reset(new_pref_value2); | 175 StringValue expected_new_pref_value2(new_pref_value2); |
174 TestPrefObserver obs2(&prefs, pref_name, new_pref_value2); | 176 TestPrefObserver obs2; |
177 obs.Expect(&prefs, pref_name, &expected_new_pref_value2); | |
178 obs2.Expect(&prefs, pref_name, &expected_new_pref_value2); | |
175 registrar.Add(pref_name, &obs2); | 179 registrar.Add(pref_name, &obs2); |
176 // This should fire the checks in obs and obs2. | 180 // This should fire the checks in obs and obs2. |
177 prefs.SetString(pref_name, new_pref_value2); | 181 prefs.SetString(pref_name, new_pref_value2); |
178 EXPECT_TRUE(obs.observer_fired()); | 182 Mock::VerifyAndClearExpectations(&obs); |
179 EXPECT_TRUE(obs2.observer_fired()); | 183 Mock::VerifyAndClearExpectations(&obs2); |
180 | 184 |
181 // Make sure obs2 still works after removing obs. | 185 // Make sure obs2 still works after removing obs. |
182 registrar.Remove(pref_name, &obs); | 186 registrar.Remove(pref_name, &obs); |
183 obs.Reset(std::string()); | 187 EXPECT_CALL(obs, Observe(_, _, _)).Times(0); |
184 obs2.Reset(new_pref_value); | 188 obs2.Expect(&prefs, pref_name, &expected_new_pref_value); |
185 // This should only fire the observer in obs2. | 189 // This should only fire the observer in obs2. |
186 prefs.SetString(pref_name, new_pref_value); | 190 prefs.SetString(pref_name, new_pref_value); |
187 EXPECT_FALSE(obs.observer_fired()); | 191 Mock::VerifyAndClearExpectations(&obs); |
188 EXPECT_TRUE(obs2.observer_fired()); | 192 Mock::VerifyAndClearExpectations(&obs2); |
189 } | 193 } |
190 | 194 |
191 TEST(PrefServiceTest, ProxyFromCommandLineNotPolicy) { | 195 TEST(PrefServiceTest, ProxyFromCommandLineNotPolicy) { |
192 CommandLine command_line(CommandLine::NO_PROGRAM); | 196 CommandLine command_line(CommandLine::NO_PROGRAM); |
193 command_line.AppendSwitch(switches::kProxyAutoDetect); | 197 command_line.AppendSwitch(switches::kProxyAutoDetect); |
194 TestingPrefService prefs(NULL, NULL, &command_line); | 198 TestingPrefService prefs(NULL, NULL, &command_line); |
195 browser::RegisterUserPrefs(&prefs); | 199 browser::RegisterUserPrefs(&prefs); |
196 EXPECT_TRUE(prefs.GetBoolean(prefs::kProxyAutoDetect)); | 200 EXPECT_TRUE(prefs.GetBoolean(prefs::kProxyAutoDetect)); |
197 const PrefService::Preference* pref = | 201 const PrefService::Preference* pref = |
198 prefs.FindPreference(prefs::kProxyAutoDetect); | 202 prefs.FindPreference(prefs::kProxyAutoDetect); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
334 EXPECT_EQ(std::string(), prefs2.GetString(prefs::kProxyPacUrl)); | 338 EXPECT_EQ(std::string(), prefs2.GetString(prefs::kProxyPacUrl)); |
335 EXPECT_EQ(std::string(), prefs2.GetString(prefs::kProxyBypassList)); | 339 EXPECT_EQ(std::string(), prefs2.GetString(prefs::kProxyBypassList)); |
336 } | 340 } |
337 | 341 |
338 class PrefServiceSetValueTest : public testing::Test { | 342 class PrefServiceSetValueTest : public testing::Test { |
339 protected: | 343 protected: |
340 static const char kName[]; | 344 static const char kName[]; |
341 static const char kValue[]; | 345 static const char kValue[]; |
342 | 346 |
343 PrefServiceSetValueTest() | 347 PrefServiceSetValueTest() |
344 : name_string_(kName), | 348 : null_value_(Value::CreateNullValue()) {} |
345 null_value_(Value::CreateNullValue()) {} | |
346 | |
347 void SetExpectNoNotification() { | |
348 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); | |
349 } | |
350 | |
351 void SetExpectPrefChanged() { | |
352 EXPECT_CALL(observer_, | |
353 Observe(NotificationType(NotificationType::PREF_CHANGED), _, | |
354 Property(&Details<std::string>::ptr, | |
355 Pointee(name_string_)))); | |
356 } | |
357 | 349 |
358 TestingPrefService prefs_; | 350 TestingPrefService prefs_; |
359 std::string name_string_; | |
360 scoped_ptr<Value> null_value_; | 351 scoped_ptr<Value> null_value_; |
361 NotificationObserverMock observer_; | 352 TestPrefObserver observer_; |
362 }; | 353 }; |
363 | 354 |
364 const char PrefServiceSetValueTest::kName[] = "name"; | 355 const char PrefServiceSetValueTest::kName[] = "name"; |
365 const char PrefServiceSetValueTest::kValue[] = "value"; | 356 const char PrefServiceSetValueTest::kValue[] = "value"; |
366 | 357 |
367 TEST_F(PrefServiceSetValueTest, SetStringValue) { | 358 TEST_F(PrefServiceSetValueTest, SetStringValue) { |
368 const char default_string[] = "default"; | 359 const char default_string[] = "default"; |
369 const scoped_ptr<Value> default_value( | 360 StringValue default_value(default_string); |
370 Value::CreateStringValue(default_string)); | |
371 prefs_.RegisterStringPref(kName, default_string); | 361 prefs_.RegisterStringPref(kName, default_string); |
372 | 362 |
373 PrefChangeRegistrar registrar; | 363 PrefChangeRegistrar registrar; |
374 registrar.Init(&prefs_); | 364 registrar.Init(&prefs_); |
375 registrar.Add(kName, &observer_); | 365 registrar.Add(kName, &observer_); |
376 | 366 |
377 // Changing the controlling store from default to user triggers notification. | 367 // Changing the controlling store from default to user triggers notification. |
378 SetExpectPrefChanged(); | 368 observer_.Expect(&prefs_, kName, &default_value); |
379 prefs_.Set(kName, *default_value); | 369 prefs_.Set(kName, default_value); |
380 Mock::VerifyAndClearExpectations(&observer_); | 370 Mock::VerifyAndClearExpectations(&observer_); |
381 | 371 |
382 SetExpectNoNotification(); | 372 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); |
383 prefs_.Set(kName, *default_value); | 373 prefs_.Set(kName, default_value); |
384 Mock::VerifyAndClearExpectations(&observer_); | 374 Mock::VerifyAndClearExpectations(&observer_); |
385 | 375 |
386 const scoped_ptr<Value> new_value(Value::CreateStringValue(kValue)); | 376 StringValue new_value(kValue); |
387 SetExpectPrefChanged(); | 377 observer_.Expect(&prefs_, kName, &new_value); |
388 prefs_.Set(kName, *new_value); | 378 prefs_.Set(kName, new_value); |
389 EXPECT_EQ(kValue, prefs_.GetString(kName)); | 379 Mock::VerifyAndClearExpectations(&observer_); |
390 } | 380 } |
391 | 381 |
392 TEST_F(PrefServiceSetValueTest, SetDictionaryValue) { | 382 TEST_F(PrefServiceSetValueTest, SetDictionaryValue) { |
393 prefs_.RegisterDictionaryPref(kName); | 383 prefs_.RegisterDictionaryPref(kName); |
394 PrefChangeRegistrar registrar; | 384 PrefChangeRegistrar registrar; |
395 registrar.Init(&prefs_); | 385 registrar.Init(&prefs_); |
396 registrar.Add(kName, &observer_); | 386 registrar.Add(kName, &observer_); |
397 | 387 |
398 // Dictionary values are special: setting one to NULL is the same as clearing | 388 // Dictionary values are special: setting one to NULL is the same as clearing |
399 // the user value, allowing the NULL default to take (or keep) control. | 389 // the user value, allowing the NULL default to take (or keep) control. |
400 SetExpectNoNotification(); | 390 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); |
401 prefs_.Set(kName, *null_value_); | 391 prefs_.Set(kName, *null_value_); |
402 Mock::VerifyAndClearExpectations(&observer_); | 392 Mock::VerifyAndClearExpectations(&observer_); |
403 | 393 |
404 DictionaryValue new_value; | 394 DictionaryValue new_value; |
405 new_value.SetString(kName, kValue); | 395 new_value.SetString(kName, kValue); |
406 SetExpectPrefChanged(); | 396 observer_.Expect(&prefs_, kName, &new_value); |
407 prefs_.Set(kName, new_value); | |
408 Mock::VerifyAndClearExpectations(&observer_); | |
409 DictionaryValue* dict = prefs_.GetMutableDictionary(kName); | |
410 EXPECT_EQ(1U, dict->size()); | |
411 std::string out_value; | |
412 dict->GetString(kName, &out_value); | |
413 EXPECT_EQ(kValue, out_value); | |
414 | |
415 SetExpectNoNotification(); | |
416 prefs_.Set(kName, new_value); | 397 prefs_.Set(kName, new_value); |
417 Mock::VerifyAndClearExpectations(&observer_); | 398 Mock::VerifyAndClearExpectations(&observer_); |
418 | 399 |
419 SetExpectPrefChanged(); | 400 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); |
401 prefs_.Set(kName, new_value); | |
402 Mock::VerifyAndClearExpectations(&observer_); | |
403 | |
404 observer_.Expect(&prefs_, kName, null_value_.get()); | |
420 prefs_.Set(kName, *null_value_); | 405 prefs_.Set(kName, *null_value_); |
421 Mock::VerifyAndClearExpectations(&observer_); | 406 Mock::VerifyAndClearExpectations(&observer_); |
422 dict = prefs_.GetMutableDictionary(kName); | |
423 EXPECT_EQ(0U, dict->size()); | |
424 } | 407 } |
425 | 408 |
426 TEST_F(PrefServiceSetValueTest, SetListValue) { | 409 TEST_F(PrefServiceSetValueTest, SetListValue) { |
427 prefs_.RegisterListPref(kName); | 410 prefs_.RegisterListPref(kName); |
428 PrefChangeRegistrar registrar; | 411 PrefChangeRegistrar registrar; |
429 registrar.Init(&prefs_); | 412 registrar.Init(&prefs_); |
430 registrar.Add(kName, &observer_); | 413 registrar.Add(kName, &observer_); |
431 | 414 |
432 // List values are special: setting one to NULL is the same as clearing the | 415 // List values are special: setting one to NULL is the same as clearing the |
433 // user value, allowing the NULL default to take (or keep) control. | 416 // user value, allowing the NULL default to take (or keep) control. |
434 SetExpectNoNotification(); | 417 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); |
435 prefs_.Set(kName, *null_value_); | 418 prefs_.Set(kName, *null_value_); |
436 Mock::VerifyAndClearExpectations(&observer_); | 419 Mock::VerifyAndClearExpectations(&observer_); |
437 | 420 |
438 ListValue new_value; | 421 ListValue new_value; |
439 new_value.Append(Value::CreateStringValue(kValue)); | 422 new_value.Append(Value::CreateStringValue(kValue)); |
440 SetExpectPrefChanged(); | 423 observer_.Expect(&prefs_, kName, &new_value); |
441 prefs_.Set(kName, new_value); | |
442 Mock::VerifyAndClearExpectations(&observer_); | |
443 const ListValue* list = prefs_.GetMutableList(kName); | |
444 ASSERT_EQ(1U, list->GetSize()); | |
445 std::string out_value; | |
446 list->GetString(0, &out_value); | |
447 EXPECT_EQ(kValue, out_value); | |
448 | |
449 SetExpectNoNotification(); | |
450 prefs_.Set(kName, new_value); | 424 prefs_.Set(kName, new_value); |
451 Mock::VerifyAndClearExpectations(&observer_); | 425 Mock::VerifyAndClearExpectations(&observer_); |
452 | 426 |
453 SetExpectPrefChanged(); | 427 EXPECT_CALL(observer_, Observe(_, _, _)).Times(0); |
428 prefs_.Set(kName, new_value); | |
429 Mock::VerifyAndClearExpectations(&observer_); | |
430 | |
431 observer_.Expect(&prefs_, kName, null_value_.get()); | |
454 prefs_.Set(kName, *null_value_); | 432 prefs_.Set(kName, *null_value_); |
455 Mock::VerifyAndClearExpectations(&observer_); | 433 Mock::VerifyAndClearExpectations(&observer_); |
456 list = prefs_.GetMutableList(kName); | |
457 EXPECT_EQ(0U, list->GetSize()); | |
458 } | 434 } |
OLD | NEW |