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 "components/prefs/overlay_user_pref_store.h" | 5 #include "components/prefs/overlay_user_pref_store.h" |
6 | 6 |
| 7 #include "base/memory/ptr_util.h" |
7 #include "base/values.h" | 8 #include "base/values.h" |
8 #include "components/prefs/pref_store_observer_mock.h" | 9 #include "components/prefs/pref_store_observer_mock.h" |
9 #include "components/prefs/testing_pref_store.h" | 10 #include "components/prefs/testing_pref_store.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
12 | 13 |
13 using ::testing::Mock; | 14 using ::testing::Mock; |
14 using ::testing::StrEq; | 15 using ::testing::StrEq; |
15 | 16 |
16 namespace base { | 17 namespace base { |
(...skipping 24 matching lines...) Expand all Loading... |
41 | 42 |
42 scoped_refptr<TestingPrefStore> underlay_; | 43 scoped_refptr<TestingPrefStore> underlay_; |
43 scoped_refptr<OverlayUserPrefStore> overlay_; | 44 scoped_refptr<OverlayUserPrefStore> overlay_; |
44 }; | 45 }; |
45 | 46 |
46 TEST_F(OverlayUserPrefStoreTest, Observer) { | 47 TEST_F(OverlayUserPrefStoreTest, Observer) { |
47 PrefStoreObserverMock obs; | 48 PrefStoreObserverMock obs; |
48 overlay_->AddObserver(&obs); | 49 overlay_->AddObserver(&obs); |
49 | 50 |
50 // Check that underlay first value is reported. | 51 // Check that underlay first value is reported. |
51 underlay_->SetValue(overlay_key, make_scoped_ptr(new FundamentalValue(42)), | 52 underlay_->SetValue(overlay_key, base::WrapUnique(new FundamentalValue(42)), |
52 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 53 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
53 obs.VerifyAndResetChangedKey(overlay_key); | 54 obs.VerifyAndResetChangedKey(overlay_key); |
54 | 55 |
55 // Check that underlay overwriting is reported. | 56 // Check that underlay overwriting is reported. |
56 underlay_->SetValue(overlay_key, make_scoped_ptr(new FundamentalValue(43)), | 57 underlay_->SetValue(overlay_key, base::WrapUnique(new FundamentalValue(43)), |
57 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 58 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
58 obs.VerifyAndResetChangedKey(overlay_key); | 59 obs.VerifyAndResetChangedKey(overlay_key); |
59 | 60 |
60 // Check that overwriting change in overlay is reported. | 61 // Check that overwriting change in overlay is reported. |
61 overlay_->SetValue(overlay_key, make_scoped_ptr(new FundamentalValue(44)), | 62 overlay_->SetValue(overlay_key, base::WrapUnique(new FundamentalValue(44)), |
62 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 63 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
63 obs.VerifyAndResetChangedKey(overlay_key); | 64 obs.VerifyAndResetChangedKey(overlay_key); |
64 | 65 |
65 // Check that hidden underlay change is not reported. | 66 // Check that hidden underlay change is not reported. |
66 underlay_->SetValue(overlay_key, make_scoped_ptr(new FundamentalValue(45)), | 67 underlay_->SetValue(overlay_key, base::WrapUnique(new FundamentalValue(45)), |
67 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 68 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
68 EXPECT_TRUE(obs.changed_keys.empty()); | 69 EXPECT_TRUE(obs.changed_keys.empty()); |
69 | 70 |
70 // Check that overlay remove is reported. | 71 // Check that overlay remove is reported. |
71 overlay_->RemoveValue(overlay_key, | 72 overlay_->RemoveValue(overlay_key, |
72 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 73 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
73 obs.VerifyAndResetChangedKey(overlay_key); | 74 obs.VerifyAndResetChangedKey(overlay_key); |
74 | 75 |
75 // Check that underlay remove is reported. | 76 // Check that underlay remove is reported. |
76 underlay_->RemoveValue(overlay_key, | 77 underlay_->RemoveValue(overlay_key, |
77 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 78 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
78 obs.VerifyAndResetChangedKey(overlay_key); | 79 obs.VerifyAndResetChangedKey(overlay_key); |
79 | 80 |
80 // Check respecting of silence. | 81 // Check respecting of silence. |
81 overlay_->SetValueSilently(overlay_key, | 82 overlay_->SetValueSilently(overlay_key, |
82 make_scoped_ptr(new FundamentalValue(46)), | 83 base::WrapUnique(new FundamentalValue(46)), |
83 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 84 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
84 EXPECT_TRUE(obs.changed_keys.empty()); | 85 EXPECT_TRUE(obs.changed_keys.empty()); |
85 | 86 |
86 overlay_->RemoveObserver(&obs); | 87 overlay_->RemoveObserver(&obs); |
87 | 88 |
88 // Check successful unsubscription. | 89 // Check successful unsubscription. |
89 underlay_->SetValue(overlay_key, make_scoped_ptr(new FundamentalValue(47)), | 90 underlay_->SetValue(overlay_key, base::WrapUnique(new FundamentalValue(47)), |
90 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 91 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
91 overlay_->SetValue(overlay_key, make_scoped_ptr(new FundamentalValue(48)), | 92 overlay_->SetValue(overlay_key, base::WrapUnique(new FundamentalValue(48)), |
92 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 93 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
93 EXPECT_TRUE(obs.changed_keys.empty()); | 94 EXPECT_TRUE(obs.changed_keys.empty()); |
94 } | 95 } |
95 | 96 |
96 TEST_F(OverlayUserPrefStoreTest, GetAndSet) { | 97 TEST_F(OverlayUserPrefStoreTest, GetAndSet) { |
97 const Value* value = NULL; | 98 const Value* value = NULL; |
98 EXPECT_FALSE(overlay_->GetValue(overlay_key, &value)); | 99 EXPECT_FALSE(overlay_->GetValue(overlay_key, &value)); |
99 EXPECT_FALSE(underlay_->GetValue(overlay_key, &value)); | 100 EXPECT_FALSE(underlay_->GetValue(overlay_key, &value)); |
100 | 101 |
101 underlay_->SetValue(overlay_key, make_scoped_ptr(new FundamentalValue(42)), | 102 underlay_->SetValue(overlay_key, base::WrapUnique(new FundamentalValue(42)), |
102 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 103 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
103 | 104 |
104 // Value shines through: | 105 // Value shines through: |
105 EXPECT_TRUE(overlay_->GetValue(overlay_key, &value)); | 106 EXPECT_TRUE(overlay_->GetValue(overlay_key, &value)); |
106 EXPECT_TRUE(base::FundamentalValue(42).Equals(value)); | 107 EXPECT_TRUE(base::FundamentalValue(42).Equals(value)); |
107 | 108 |
108 EXPECT_TRUE(underlay_->GetValue(overlay_key, &value)); | 109 EXPECT_TRUE(underlay_->GetValue(overlay_key, &value)); |
109 EXPECT_TRUE(base::FundamentalValue(42).Equals(value)); | 110 EXPECT_TRUE(base::FundamentalValue(42).Equals(value)); |
110 | 111 |
111 overlay_->SetValue(overlay_key, make_scoped_ptr(new FundamentalValue(43)), | 112 overlay_->SetValue(overlay_key, base::WrapUnique(new FundamentalValue(43)), |
112 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 113 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
113 | 114 |
114 EXPECT_TRUE(overlay_->GetValue(overlay_key, &value)); | 115 EXPECT_TRUE(overlay_->GetValue(overlay_key, &value)); |
115 EXPECT_TRUE(base::FundamentalValue(43).Equals(value)); | 116 EXPECT_TRUE(base::FundamentalValue(43).Equals(value)); |
116 | 117 |
117 EXPECT_TRUE(underlay_->GetValue(overlay_key, &value)); | 118 EXPECT_TRUE(underlay_->GetValue(overlay_key, &value)); |
118 EXPECT_TRUE(base::FundamentalValue(42).Equals(value)); | 119 EXPECT_TRUE(base::FundamentalValue(42).Equals(value)); |
119 | 120 |
120 overlay_->RemoveValue(overlay_key, | 121 overlay_->RemoveValue(overlay_key, |
121 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 122 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
122 | 123 |
123 // Value shines through: | 124 // Value shines through: |
124 EXPECT_TRUE(overlay_->GetValue(overlay_key, &value)); | 125 EXPECT_TRUE(overlay_->GetValue(overlay_key, &value)); |
125 EXPECT_TRUE(base::FundamentalValue(42).Equals(value)); | 126 EXPECT_TRUE(base::FundamentalValue(42).Equals(value)); |
126 | 127 |
127 EXPECT_TRUE(underlay_->GetValue(overlay_key, &value)); | 128 EXPECT_TRUE(underlay_->GetValue(overlay_key, &value)); |
128 EXPECT_TRUE(base::FundamentalValue(42).Equals(value)); | 129 EXPECT_TRUE(base::FundamentalValue(42).Equals(value)); |
129 } | 130 } |
130 | 131 |
131 // Check that GetMutableValue does not return the dictionary of the underlay. | 132 // Check that GetMutableValue does not return the dictionary of the underlay. |
132 TEST_F(OverlayUserPrefStoreTest, ModifyDictionaries) { | 133 TEST_F(OverlayUserPrefStoreTest, ModifyDictionaries) { |
133 underlay_->SetValue(overlay_key, make_scoped_ptr(new DictionaryValue), | 134 underlay_->SetValue(overlay_key, base::WrapUnique(new DictionaryValue), |
134 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 135 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
135 | 136 |
136 Value* modify = NULL; | 137 Value* modify = NULL; |
137 EXPECT_TRUE(overlay_->GetMutableValue(overlay_key, &modify)); | 138 EXPECT_TRUE(overlay_->GetMutableValue(overlay_key, &modify)); |
138 ASSERT_TRUE(modify); | 139 ASSERT_TRUE(modify); |
139 ASSERT_TRUE(modify->IsType(Value::TYPE_DICTIONARY)); | 140 ASSERT_TRUE(modify->IsType(Value::TYPE_DICTIONARY)); |
140 static_cast<DictionaryValue*>(modify)->SetInteger(overlay_key, 42); | 141 static_cast<DictionaryValue*>(modify)->SetInteger(overlay_key, 42); |
141 | 142 |
142 Value* original_in_underlay = NULL; | 143 Value* original_in_underlay = NULL; |
143 EXPECT_TRUE(underlay_->GetMutableValue(overlay_key, &original_in_underlay)); | 144 EXPECT_TRUE(underlay_->GetMutableValue(overlay_key, &original_in_underlay)); |
144 ASSERT_TRUE(original_in_underlay); | 145 ASSERT_TRUE(original_in_underlay); |
145 ASSERT_TRUE(original_in_underlay->IsType(Value::TYPE_DICTIONARY)); | 146 ASSERT_TRUE(original_in_underlay->IsType(Value::TYPE_DICTIONARY)); |
146 EXPECT_TRUE(static_cast<DictionaryValue*>(original_in_underlay)->empty()); | 147 EXPECT_TRUE(static_cast<DictionaryValue*>(original_in_underlay)->empty()); |
147 | 148 |
148 Value* modified = NULL; | 149 Value* modified = NULL; |
149 EXPECT_TRUE(overlay_->GetMutableValue(overlay_key, &modified)); | 150 EXPECT_TRUE(overlay_->GetMutableValue(overlay_key, &modified)); |
150 ASSERT_TRUE(modified); | 151 ASSERT_TRUE(modified); |
151 ASSERT_TRUE(modified->IsType(Value::TYPE_DICTIONARY)); | 152 ASSERT_TRUE(modified->IsType(Value::TYPE_DICTIONARY)); |
152 EXPECT_TRUE(Value::Equals(modify, static_cast<DictionaryValue*>(modified))); | 153 EXPECT_TRUE(Value::Equals(modify, static_cast<DictionaryValue*>(modified))); |
153 } | 154 } |
154 | 155 |
155 // Here we consider a global preference that is not overlayed. | 156 // Here we consider a global preference that is not overlayed. |
156 TEST_F(OverlayUserPrefStoreTest, GlobalPref) { | 157 TEST_F(OverlayUserPrefStoreTest, GlobalPref) { |
157 PrefStoreObserverMock obs; | 158 PrefStoreObserverMock obs; |
158 overlay_->AddObserver(&obs); | 159 overlay_->AddObserver(&obs); |
159 | 160 |
160 const Value* value = NULL; | 161 const Value* value = NULL; |
161 | 162 |
162 // Check that underlay first value is reported. | 163 // Check that underlay first value is reported. |
163 underlay_->SetValue(regular_key, make_scoped_ptr(new FundamentalValue(42)), | 164 underlay_->SetValue(regular_key, base::WrapUnique(new FundamentalValue(42)), |
164 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 165 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
165 obs.VerifyAndResetChangedKey(regular_key); | 166 obs.VerifyAndResetChangedKey(regular_key); |
166 | 167 |
167 // Check that underlay overwriting is reported. | 168 // Check that underlay overwriting is reported. |
168 underlay_->SetValue(regular_key, make_scoped_ptr(new FundamentalValue(43)), | 169 underlay_->SetValue(regular_key, base::WrapUnique(new FundamentalValue(43)), |
169 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 170 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
170 obs.VerifyAndResetChangedKey(regular_key); | 171 obs.VerifyAndResetChangedKey(regular_key); |
171 | 172 |
172 // Check that we get this value from the overlay | 173 // Check that we get this value from the overlay |
173 EXPECT_TRUE(overlay_->GetValue(regular_key, &value)); | 174 EXPECT_TRUE(overlay_->GetValue(regular_key, &value)); |
174 EXPECT_TRUE(base::FundamentalValue(43).Equals(value)); | 175 EXPECT_TRUE(base::FundamentalValue(43).Equals(value)); |
175 | 176 |
176 // Check that overwriting change in overlay is reported. | 177 // Check that overwriting change in overlay is reported. |
177 overlay_->SetValue(regular_key, make_scoped_ptr(new FundamentalValue(44)), | 178 overlay_->SetValue(regular_key, base::WrapUnique(new FundamentalValue(44)), |
178 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 179 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
179 obs.VerifyAndResetChangedKey(regular_key); | 180 obs.VerifyAndResetChangedKey(regular_key); |
180 | 181 |
181 // Check that we get this value from the overlay and the underlay. | 182 // Check that we get this value from the overlay and the underlay. |
182 EXPECT_TRUE(overlay_->GetValue(regular_key, &value)); | 183 EXPECT_TRUE(overlay_->GetValue(regular_key, &value)); |
183 EXPECT_TRUE(base::FundamentalValue(44).Equals(value)); | 184 EXPECT_TRUE(base::FundamentalValue(44).Equals(value)); |
184 EXPECT_TRUE(underlay_->GetValue(regular_key, &value)); | 185 EXPECT_TRUE(underlay_->GetValue(regular_key, &value)); |
185 EXPECT_TRUE(base::FundamentalValue(44).Equals(value)); | 186 EXPECT_TRUE(base::FundamentalValue(44).Equals(value)); |
186 | 187 |
187 // Check that overlay remove is reported. | 188 // Check that overlay remove is reported. |
188 overlay_->RemoveValue(regular_key, | 189 overlay_->RemoveValue(regular_key, |
189 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 190 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
190 obs.VerifyAndResetChangedKey(regular_key); | 191 obs.VerifyAndResetChangedKey(regular_key); |
191 | 192 |
192 // Check that value was removed from overlay and underlay | 193 // Check that value was removed from overlay and underlay |
193 EXPECT_FALSE(overlay_->GetValue(regular_key, &value)); | 194 EXPECT_FALSE(overlay_->GetValue(regular_key, &value)); |
194 EXPECT_FALSE(underlay_->GetValue(regular_key, &value)); | 195 EXPECT_FALSE(underlay_->GetValue(regular_key, &value)); |
195 | 196 |
196 // Check respecting of silence. | 197 // Check respecting of silence. |
197 overlay_->SetValueSilently(regular_key, | 198 overlay_->SetValueSilently(regular_key, |
198 make_scoped_ptr(new FundamentalValue(46)), | 199 base::WrapUnique(new FundamentalValue(46)), |
199 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 200 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
200 EXPECT_TRUE(obs.changed_keys.empty()); | 201 EXPECT_TRUE(obs.changed_keys.empty()); |
201 | 202 |
202 overlay_->RemoveObserver(&obs); | 203 overlay_->RemoveObserver(&obs); |
203 | 204 |
204 // Check successful unsubscription. | 205 // Check successful unsubscription. |
205 underlay_->SetValue(regular_key, make_scoped_ptr(new FundamentalValue(47)), | 206 underlay_->SetValue(regular_key, base::WrapUnique(new FundamentalValue(47)), |
206 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 207 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
207 overlay_->SetValue(regular_key, make_scoped_ptr(new FundamentalValue(48)), | 208 overlay_->SetValue(regular_key, base::WrapUnique(new FundamentalValue(48)), |
208 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 209 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
209 EXPECT_TRUE(obs.changed_keys.empty()); | 210 EXPECT_TRUE(obs.changed_keys.empty()); |
210 } | 211 } |
211 | 212 |
212 // Check that names mapping works correctly. | 213 // Check that names mapping works correctly. |
213 TEST_F(OverlayUserPrefStoreTest, NamesMapping) { | 214 TEST_F(OverlayUserPrefStoreTest, NamesMapping) { |
214 PrefStoreObserverMock obs; | 215 PrefStoreObserverMock obs; |
215 overlay_->AddObserver(&obs); | 216 overlay_->AddObserver(&obs); |
216 | 217 |
217 const Value* value = NULL; | 218 const Value* value = NULL; |
218 | 219 |
219 // Check that if there is no override in the overlay, changing underlay value | 220 // Check that if there is no override in the overlay, changing underlay value |
220 // is reported as changing an overlay value. | 221 // is reported as changing an overlay value. |
221 underlay_->SetValue(mapped_underlay_key, | 222 underlay_->SetValue(mapped_underlay_key, |
222 make_scoped_ptr(new FundamentalValue(42)), | 223 base::WrapUnique(new FundamentalValue(42)), |
223 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 224 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
224 obs.VerifyAndResetChangedKey(mapped_overlay_key); | 225 obs.VerifyAndResetChangedKey(mapped_overlay_key); |
225 | 226 |
226 // Check that underlay overwriting is reported. | 227 // Check that underlay overwriting is reported. |
227 underlay_->SetValue(mapped_underlay_key, | 228 underlay_->SetValue(mapped_underlay_key, |
228 make_scoped_ptr(new FundamentalValue(43)), | 229 base::WrapUnique(new FundamentalValue(43)), |
229 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 230 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
230 obs.VerifyAndResetChangedKey(mapped_overlay_key); | 231 obs.VerifyAndResetChangedKey(mapped_overlay_key); |
231 | 232 |
232 // Check that we get this value from the overlay with both keys | 233 // Check that we get this value from the overlay with both keys |
233 EXPECT_TRUE(overlay_->GetValue(mapped_overlay_key, &value)); | 234 EXPECT_TRUE(overlay_->GetValue(mapped_overlay_key, &value)); |
234 EXPECT_TRUE(base::FundamentalValue(43).Equals(value)); | 235 EXPECT_TRUE(base::FundamentalValue(43).Equals(value)); |
235 // In this case, overlay reads directly from the underlay. | 236 // In this case, overlay reads directly from the underlay. |
236 EXPECT_TRUE(overlay_->GetValue(mapped_underlay_key, &value)); | 237 EXPECT_TRUE(overlay_->GetValue(mapped_underlay_key, &value)); |
237 EXPECT_TRUE(base::FundamentalValue(43).Equals(value)); | 238 EXPECT_TRUE(base::FundamentalValue(43).Equals(value)); |
238 | 239 |
239 // Check that overwriting change in overlay is reported. | 240 // Check that overwriting change in overlay is reported. |
240 overlay_->SetValue(mapped_overlay_key, | 241 overlay_->SetValue(mapped_overlay_key, |
241 make_scoped_ptr(new FundamentalValue(44)), | 242 base::WrapUnique(new FundamentalValue(44)), |
242 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 243 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
243 obs.VerifyAndResetChangedKey(mapped_overlay_key); | 244 obs.VerifyAndResetChangedKey(mapped_overlay_key); |
244 | 245 |
245 // Check that we get an overriden value from overlay, while reading the | 246 // Check that we get an overriden value from overlay, while reading the |
246 // value from underlay still holds an old value. | 247 // value from underlay still holds an old value. |
247 EXPECT_TRUE(overlay_->GetValue(mapped_overlay_key, &value)); | 248 EXPECT_TRUE(overlay_->GetValue(mapped_overlay_key, &value)); |
248 EXPECT_TRUE(base::FundamentalValue(44).Equals(value)); | 249 EXPECT_TRUE(base::FundamentalValue(44).Equals(value)); |
249 EXPECT_TRUE(overlay_->GetValue(mapped_underlay_key, &value)); | 250 EXPECT_TRUE(overlay_->GetValue(mapped_underlay_key, &value)); |
250 EXPECT_TRUE(base::FundamentalValue(43).Equals(value)); | 251 EXPECT_TRUE(base::FundamentalValue(43).Equals(value)); |
251 EXPECT_TRUE(underlay_->GetValue(mapped_underlay_key, &value)); | 252 EXPECT_TRUE(underlay_->GetValue(mapped_underlay_key, &value)); |
252 EXPECT_TRUE(base::FundamentalValue(43).Equals(value)); | 253 EXPECT_TRUE(base::FundamentalValue(43).Equals(value)); |
253 | 254 |
254 // Check that hidden underlay change is not reported. | 255 // Check that hidden underlay change is not reported. |
255 underlay_->SetValue(mapped_underlay_key, | 256 underlay_->SetValue(mapped_underlay_key, |
256 make_scoped_ptr(new FundamentalValue(45)), | 257 base::WrapUnique(new FundamentalValue(45)), |
257 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 258 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
258 EXPECT_TRUE(obs.changed_keys.empty()); | 259 EXPECT_TRUE(obs.changed_keys.empty()); |
259 | 260 |
260 // Check that overlay remove is reported. | 261 // Check that overlay remove is reported. |
261 overlay_->RemoveValue(mapped_overlay_key, | 262 overlay_->RemoveValue(mapped_overlay_key, |
262 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 263 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
263 obs.VerifyAndResetChangedKey(mapped_overlay_key); | 264 obs.VerifyAndResetChangedKey(mapped_overlay_key); |
264 | 265 |
265 // Check that underlay remove is reported. | 266 // Check that underlay remove is reported. |
266 underlay_->RemoveValue(mapped_underlay_key, | 267 underlay_->RemoveValue(mapped_underlay_key, |
267 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 268 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
268 obs.VerifyAndResetChangedKey(mapped_overlay_key); | 269 obs.VerifyAndResetChangedKey(mapped_overlay_key); |
269 | 270 |
270 // Check that value was removed. | 271 // Check that value was removed. |
271 EXPECT_FALSE(overlay_->GetValue(mapped_overlay_key, &value)); | 272 EXPECT_FALSE(overlay_->GetValue(mapped_overlay_key, &value)); |
272 EXPECT_FALSE(overlay_->GetValue(mapped_underlay_key, &value)); | 273 EXPECT_FALSE(overlay_->GetValue(mapped_underlay_key, &value)); |
273 | 274 |
274 // Check respecting of silence. | 275 // Check respecting of silence. |
275 overlay_->SetValueSilently(mapped_overlay_key, | 276 overlay_->SetValueSilently(mapped_overlay_key, |
276 make_scoped_ptr(new FundamentalValue(46)), | 277 base::WrapUnique(new FundamentalValue(46)), |
277 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 278 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
278 EXPECT_TRUE(obs.changed_keys.empty()); | 279 EXPECT_TRUE(obs.changed_keys.empty()); |
279 | 280 |
280 overlay_->RemoveObserver(&obs); | 281 overlay_->RemoveObserver(&obs); |
281 | 282 |
282 // Check successful unsubscription. | 283 // Check successful unsubscription. |
283 underlay_->SetValue(mapped_underlay_key, | 284 underlay_->SetValue(mapped_underlay_key, |
284 make_scoped_ptr(new FundamentalValue(47)), | 285 base::WrapUnique(new FundamentalValue(47)), |
285 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 286 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
286 overlay_->SetValue(mapped_overlay_key, | 287 overlay_->SetValue(mapped_overlay_key, |
287 make_scoped_ptr(new FundamentalValue(48)), | 288 base::WrapUnique(new FundamentalValue(48)), |
288 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 289 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
289 EXPECT_TRUE(obs.changed_keys.empty()); | 290 EXPECT_TRUE(obs.changed_keys.empty()); |
290 } | 291 } |
291 | 292 |
292 // Check that mutable values are removed correctly. | 293 // Check that mutable values are removed correctly. |
293 TEST_F(OverlayUserPrefStoreTest, ClearMutableValues) { | 294 TEST_F(OverlayUserPrefStoreTest, ClearMutableValues) { |
294 // Set in overlay and underlay the same preference. | 295 // Set in overlay and underlay the same preference. |
295 underlay_->SetValue(overlay_key, make_scoped_ptr(new FundamentalValue(42)), | 296 underlay_->SetValue(overlay_key, base::WrapUnique(new FundamentalValue(42)), |
296 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 297 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
297 overlay_->SetValue(overlay_key, make_scoped_ptr(new FundamentalValue(43)), | 298 overlay_->SetValue(overlay_key, base::WrapUnique(new FundamentalValue(43)), |
298 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 299 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
299 | 300 |
300 const Value* value = nullptr; | 301 const Value* value = nullptr; |
301 // Check that an overlay preference is returned. | 302 // Check that an overlay preference is returned. |
302 EXPECT_TRUE(overlay_->GetValue(overlay_key, &value)); | 303 EXPECT_TRUE(overlay_->GetValue(overlay_key, &value)); |
303 EXPECT_TRUE(base::FundamentalValue(43).Equals(value)); | 304 EXPECT_TRUE(base::FundamentalValue(43).Equals(value)); |
304 overlay_->ClearMutableValues(); | 305 overlay_->ClearMutableValues(); |
305 | 306 |
306 // Check that an underlay preference is returned. | 307 // Check that an underlay preference is returned. |
307 EXPECT_TRUE(overlay_->GetValue(overlay_key, &value)); | 308 EXPECT_TRUE(overlay_->GetValue(overlay_key, &value)); |
308 EXPECT_TRUE(base::FundamentalValue(42).Equals(value)); | 309 EXPECT_TRUE(base::FundamentalValue(42).Equals(value)); |
309 } | 310 } |
310 | 311 |
311 } // namespace base | 312 } // namespace base |
OLD | NEW |