Chromium Code Reviews

Side by Side Diff: chrome/browser/extensions/extension_pref_store_unittest.cc

Issue 4438001: First part to fix Bug 50726 "Save extension list and "winning" prefs from extensions" (Closed) Base URL: http://git.chromium.org/git/chromium.git/@trunk
Patch Set: whitespaces Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
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 #include <vector> 6 #include <vector>
7 7
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/scoped_temp_dir.h" 9 #include "base/scoped_temp_dir.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 51 matching lines...)
62 62
63 void SetPrefService(PrefService* pref_service) { 63 void SetPrefService(PrefService* pref_service) {
64 pref_service_ = pref_service; 64 pref_service_ = pref_service;
65 } 65 }
66 66
67 // Overridden from ExtensionPrefStore. 67 // Overridden from ExtensionPrefStore.
68 virtual PrefService* GetPrefService() { 68 virtual PrefService* GetPrefService() {
69 return pref_service_; 69 return pref_service_;
70 } 70 }
71 71
72 virtual void PersistExtensionPrecedences(
73 const std::vector<std::string>& precedence) {
74 precedence_ = precedence;
75 }
76
77 virtual void GetExtensionPrecedences(
78 std::vector<std::string>* precedence) const {
79 *precedence = precedence_;
80 }
81
72 // Weak references, for convenience. 82 // Weak references, for convenience.
73 Extension* ext1; 83 Extension* ext1;
74 Extension* ext2; 84 Extension* ext2;
75 Extension* ext3; 85 Extension* ext3;
76 86
77 private: 87 private:
78 ScopedTempDir temp_dir_; 88 ScopedTempDir temp_dir_;
79 89
80 scoped_refptr<Extension> ext1_scoped_; 90 scoped_refptr<Extension> ext1_scoped_;
81 scoped_refptr<Extension> ext2_scoped_; 91 scoped_refptr<Extension> ext2_scoped_;
82 scoped_refptr<Extension> ext3_scoped_; 92 scoped_refptr<Extension> ext3_scoped_;
83 93
84 // Weak reference. 94 // Weak reference.
85 PrefService* pref_service_; 95 PrefService* pref_service_;
96
97 std::vector<std::string> precedence_;
86 }; 98 };
87 99
88 // Mock PrefNotifier that allows the notifications to be tracked. 100 // Mock PrefNotifier that allows the notifications to be tracked.
89 class MockPrefNotifier : public PrefNotifier { 101 class MockPrefNotifier : public PrefNotifier {
90 public: 102 public:
91 MockPrefNotifier(PrefService* service, PrefValueStore* value_store) 103 MockPrefNotifier(PrefService* service, PrefValueStore* value_store)
92 : PrefNotifier(service, value_store) {} 104 : PrefNotifier(service, value_store) {}
93 105
94 virtual ~MockPrefNotifier() {} 106 virtual ~MockPrefNotifier() {}
95 107
(...skipping 20 matching lines...)
116 128
117 } // namespace 129 } // namespace
118 130
119 TEST(ExtensionPrefStoreTest, InstallOneExtension) { 131 TEST(ExtensionPrefStoreTest, InstallOneExtension) {
120 TestExtensionPrefStore eps; 132 TestExtensionPrefStore eps;
121 ASSERT_TRUE(eps.ext1 != NULL); 133 ASSERT_TRUE(eps.ext1 != NULL);
122 eps.InstallExtensionPref(eps.ext1, kPref1, Value::CreateStringValue("val1")); 134 eps.InstallExtensionPref(eps.ext1, kPref1, Value::CreateStringValue("val1"));
123 135
124 TestExtensionPrefStore::ExtensionIDs ids; 136 TestExtensionPrefStore::ExtensionIDs ids;
125 eps.GetExtensionIDList(&ids); 137 eps.GetExtensionIDList(&ids);
126 EXPECT_EQ(1u, ids.size()); 138 ASSERT_EQ(1u, ids.size());
127 EXPECT_EQ(eps.ext1->id(), ids[0]); 139 EXPECT_EQ(eps.ext1->id(), ids[0]);
128 140
129 DictionaryValue* prefs = eps.prefs(); 141 DictionaryValue* prefs = eps.prefs();
130 ASSERT_EQ(1u, prefs->size()); 142 ASSERT_EQ(1u, prefs->size());
131 std::string actual; 143 std::string actual;
132 ASSERT_TRUE(prefs->GetString(kPref1, &actual)); 144 ASSERT_TRUE(prefs->GetString(kPref1, &actual));
133 EXPECT_EQ("val1", actual); 145 EXPECT_EQ("val1", actual);
134 } 146 }
135 147
136 // Make sure the last-installed extension wins. 148 // Make sure the last-installed extension wins.
137 TEST(ExtensionPrefStoreTest, InstallMultipleExtensions) { 149 TEST(ExtensionPrefStoreTest, InstallMultipleExtensions) {
138 TestExtensionPrefStore eps; 150 TestExtensionPrefStore eps;
139 ASSERT_TRUE(eps.ext1 != NULL); 151 ASSERT_TRUE(eps.ext1 != NULL);
140 eps.InstallExtensionPref(eps.ext1, kPref1, Value::CreateStringValue("val1")); 152 eps.InstallExtensionPref(eps.ext1, kPref1, Value::CreateStringValue("val1"));
141 eps.InstallExtensionPref(eps.ext2, kPref1, Value::CreateStringValue("val2")); 153 eps.InstallExtensionPref(eps.ext2, kPref1, Value::CreateStringValue("val2"));
142 eps.InstallExtensionPref(eps.ext3, kPref1, Value::CreateStringValue("val3")); 154 eps.InstallExtensionPref(eps.ext3, kPref1, Value::CreateStringValue("val3"));
143 155
144 TestExtensionPrefStore::ExtensionIDs ids; 156 TestExtensionPrefStore::ExtensionIDs ids;
145 eps.GetExtensionIDList(&ids); 157 eps.GetExtensionIDList(&ids);
146 EXPECT_EQ(3u, ids.size()); 158 ASSERT_EQ(3u, ids.size());
147 EXPECT_EQ(eps.ext3->id(), ids[0]); 159 EXPECT_EQ(eps.ext3->id(), ids[0]);
148 EXPECT_EQ(eps.ext2->id(), ids[1]); 160 EXPECT_EQ(eps.ext2->id(), ids[1]);
149 EXPECT_EQ(eps.ext1->id(), ids[2]); 161 EXPECT_EQ(eps.ext1->id(), ids[2]);
150 162
163 std::vector<std::string> precedences;
164 eps.GetExtensionPrecedences(&precedences);
165 ASSERT_EQ(3u, precedences.size());
166 EXPECT_EQ(eps.ext1->id(), precedences[0]);
167 EXPECT_EQ(eps.ext2->id(), precedences[1]);
168 EXPECT_EQ(eps.ext3->id(), precedences[2]);
169
151 DictionaryValue* prefs = eps.prefs(); 170 DictionaryValue* prefs = eps.prefs();
152 ASSERT_EQ(1u, prefs->size()); 171 ASSERT_EQ(1u, prefs->size());
153 std::string actual; 172 std::string actual;
154 ASSERT_TRUE(prefs->GetString(kPref1, &actual)); 173 ASSERT_TRUE(prefs->GetString(kPref1, &actual));
155 EXPECT_EQ("val3", actual); 174 EXPECT_EQ("val3", actual);
156 } 175 }
157 176
158 // Make sure the last-installed extension wins for each preference. 177 // Make sure the last-installed extension wins for each preference.
159 TEST(ExtensionPrefStoreTest, InstallOverwrittenExtensions) { 178 TEST(ExtensionPrefStoreTest, InstallOverwrittenExtensions) {
160 TestExtensionPrefStore eps; 179 TestExtensionPrefStore eps;
161 ASSERT_TRUE(eps.ext1 != NULL); 180 ASSERT_TRUE(eps.ext1 != NULL);
162 eps.InstallExtensionPref(eps.ext1, kPref1, Value::CreateStringValue("val1")); 181 eps.InstallExtensionPref(eps.ext1, kPref1, Value::CreateStringValue("val1"));
163 eps.InstallExtensionPref(eps.ext2, kPref1, Value::CreateStringValue("val2")); 182 eps.InstallExtensionPref(eps.ext2, kPref1, Value::CreateStringValue("val2"));
164 eps.InstallExtensionPref(eps.ext3, kPref1, Value::CreateStringValue("val3")); 183 eps.InstallExtensionPref(eps.ext3, kPref1, Value::CreateStringValue("val3"));
165 184
166 eps.InstallExtensionPref(eps.ext1, kPref2, Value::CreateStringValue("val4")); 185 eps.InstallExtensionPref(eps.ext1, kPref2, Value::CreateStringValue("val4"));
167 eps.InstallExtensionPref(eps.ext2, kPref2, Value::CreateStringValue("val5")); 186 eps.InstallExtensionPref(eps.ext2, kPref2, Value::CreateStringValue("val5"));
168 187
169 eps.InstallExtensionPref(eps.ext1, kPref1, Value::CreateStringValue("val6")); 188 eps.InstallExtensionPref(eps.ext1, kPref1, Value::CreateStringValue("val6"));
170 eps.InstallExtensionPref(eps.ext1, kPref2, Value::CreateStringValue("val7")); 189 eps.InstallExtensionPref(eps.ext1, kPref2, Value::CreateStringValue("val7"));
171 eps.InstallExtensionPref(eps.ext1, kPref3, Value::CreateStringValue("val8")); 190 eps.InstallExtensionPref(eps.ext1, kPref3, Value::CreateStringValue("val8"));
172 191
173 TestExtensionPrefStore::ExtensionIDs ids; 192 TestExtensionPrefStore::ExtensionIDs ids;
174 eps.GetExtensionIDList(&ids); 193 eps.GetExtensionIDList(&ids);
175 EXPECT_EQ(3u, ids.size()); 194 ASSERT_EQ(3u, ids.size());
176 EXPECT_EQ(eps.ext3->id(), ids[0]); 195 EXPECT_EQ(eps.ext3->id(), ids[0]);
177 EXPECT_EQ(eps.ext2->id(), ids[1]); 196 EXPECT_EQ(eps.ext2->id(), ids[1]);
178 EXPECT_EQ(eps.ext1->id(), ids[2]); 197 EXPECT_EQ(eps.ext1->id(), ids[2]);
179 198
199 std::vector<std::string> precedences;
200 eps.GetExtensionPrecedences(&precedences);
201 ASSERT_EQ(3u, precedences.size());
202 EXPECT_EQ(eps.ext1->id(), precedences[0]);
203 EXPECT_EQ(eps.ext2->id(), precedences[1]);
204 EXPECT_EQ(eps.ext3->id(), precedences[2]);
205
180 DictionaryValue* prefs = eps.prefs(); 206 DictionaryValue* prefs = eps.prefs();
181 ASSERT_EQ(3u, prefs->size()); 207 ASSERT_EQ(3u, prefs->size());
182 std::string actual; 208 std::string actual;
183 EXPECT_TRUE(prefs->GetString(kPref1, &actual)); 209 EXPECT_TRUE(prefs->GetString(kPref1, &actual));
184 EXPECT_EQ("val3", actual); 210 EXPECT_EQ("val3", actual);
185 EXPECT_TRUE(prefs->GetString(kPref2, &actual)); 211 EXPECT_TRUE(prefs->GetString(kPref2, &actual));
186 EXPECT_EQ("val5", actual); 212 EXPECT_EQ("val5", actual);
187 EXPECT_TRUE(prefs->GetString(kPref3, &actual)); 213 EXPECT_TRUE(prefs->GetString(kPref3, &actual));
188 EXPECT_EQ("val8", actual); 214 EXPECT_EQ("val8", actual);
189 } 215 }
190 216
191 // Make sure the last-installed extension wins even if other extensions set 217 // Make sure the last-installed extension wins even if other extensions set
192 // the same or different preferences later. 218 // the same or different preferences later.
193 TEST(ExtensionPrefStoreTest, InstallInterleavedExtensions) { 219 TEST(ExtensionPrefStoreTest, InstallInterleavedExtensions) {
194 TestExtensionPrefStore eps; 220 TestExtensionPrefStore eps;
195 ASSERT_TRUE(eps.ext1 != NULL); 221 ASSERT_TRUE(eps.ext1 != NULL);
196 eps.InstallExtensionPref(eps.ext1, kPref1, Value::CreateStringValue("val1")); 222 eps.InstallExtensionPref(eps.ext1, kPref1, Value::CreateStringValue("val1"));
197 eps.InstallExtensionPref(eps.ext2, kPref2, Value::CreateStringValue("val2")); 223 eps.InstallExtensionPref(eps.ext2, kPref2, Value::CreateStringValue("val2"));
198 eps.InstallExtensionPref(eps.ext3, kPref3, Value::CreateStringValue("val3")); 224 eps.InstallExtensionPref(eps.ext3, kPref3, Value::CreateStringValue("val3"));
199 225
200 eps.InstallExtensionPref(eps.ext3, kPref3, Value::CreateStringValue("val4")); 226 eps.InstallExtensionPref(eps.ext3, kPref3, Value::CreateStringValue("val4"));
201 eps.InstallExtensionPref(eps.ext2, kPref3, Value::CreateStringValue("val5")); 227 eps.InstallExtensionPref(eps.ext2, kPref3, Value::CreateStringValue("val5"));
202 eps.InstallExtensionPref(eps.ext1, kPref3, Value::CreateStringValue("val6")); 228 eps.InstallExtensionPref(eps.ext1, kPref3, Value::CreateStringValue("val6"));
203 229
204 eps.InstallExtensionPref(eps.ext3, kPref1, Value::CreateStringValue("val7")); 230 eps.InstallExtensionPref(eps.ext3, kPref1, Value::CreateStringValue("val7"));
205 231
206 TestExtensionPrefStore::ExtensionIDs ids; 232 TestExtensionPrefStore::ExtensionIDs ids;
207 eps.GetExtensionIDList(&ids); 233 eps.GetExtensionIDList(&ids);
208 EXPECT_EQ(3u, ids.size()); 234 ASSERT_EQ(3u, ids.size());
209 EXPECT_EQ(eps.ext3->id(), ids[0]); 235 EXPECT_EQ(eps.ext3->id(), ids[0]);
210 EXPECT_EQ(eps.ext2->id(), ids[1]); 236 EXPECT_EQ(eps.ext2->id(), ids[1]);
211 EXPECT_EQ(eps.ext1->id(), ids[2]); 237 EXPECT_EQ(eps.ext1->id(), ids[2]);
212 238
239 std::vector<std::string> precedences;
240 eps.GetExtensionPrecedences(&precedences);
241 ASSERT_EQ(3u, precedences.size());
242 EXPECT_EQ(eps.ext1->id(), precedences[0]);
243 EXPECT_EQ(eps.ext2->id(), precedences[1]);
244 EXPECT_EQ(eps.ext3->id(), precedences[2]);
245
213 DictionaryValue* prefs = eps.prefs(); 246 DictionaryValue* prefs = eps.prefs();
214 ASSERT_EQ(3u, prefs->size()); 247 ASSERT_EQ(3u, prefs->size());
215 std::string actual; 248 std::string actual;
216 EXPECT_TRUE(prefs->GetString(kPref1, &actual)); 249 EXPECT_TRUE(prefs->GetString(kPref1, &actual));
217 EXPECT_EQ("val7", actual); 250 EXPECT_EQ("val7", actual);
218 EXPECT_TRUE(prefs->GetString(kPref2, &actual)); 251 EXPECT_TRUE(prefs->GetString(kPref2, &actual));
219 EXPECT_EQ("val2", actual); 252 EXPECT_EQ("val2", actual);
220 EXPECT_TRUE(prefs->GetString(kPref3, &actual)); 253 EXPECT_TRUE(prefs->GetString(kPref3, &actual));
221 EXPECT_EQ("val4", actual); 254 EXPECT_EQ("val4", actual);
222 } 255 }
223 256
224 TEST(ExtensionPrefStoreTest, UninstallOnlyExtension) { 257 TEST(ExtensionPrefStoreTest, UninstallOnlyExtension) {
225 TestExtensionPrefStore eps; 258 TestExtensionPrefStore eps;
226 ASSERT_TRUE(eps.ext1 != NULL); 259 ASSERT_TRUE(eps.ext1 != NULL);
227 eps.InstallExtensionPref(eps.ext1, kPref1, Value::CreateStringValue("val1")); 260 eps.InstallExtensionPref(eps.ext1, kPref1, Value::CreateStringValue("val1"));
228 eps.InstallExtensionPref(eps.ext1, kPref2, Value::CreateStringValue("val2")); 261 eps.InstallExtensionPref(eps.ext1, kPref2, Value::CreateStringValue("val2"));
229 262
230 // No need to check the state here; the Install* tests cover that. 263 // No need to check the state here; the Install* tests cover that.
231 eps.UninstallExtension(eps.ext1); 264 eps.UninstallExtension(eps.ext1);
232 265
233 TestExtensionPrefStore::ExtensionIDs ids; 266 TestExtensionPrefStore::ExtensionIDs ids;
234 eps.GetExtensionIDList(&ids); 267 eps.GetExtensionIDList(&ids);
235 EXPECT_EQ(0u, ids.size()); 268 EXPECT_EQ(0u, ids.size());
236 269
270 std::vector<std::string> precedences;
271 eps.GetExtensionPrecedences(&precedences);
272 EXPECT_EQ(0u, precedences.size());
273
237 DictionaryValue* prefs = eps.prefs(); 274 DictionaryValue* prefs = eps.prefs();
238 std::string actual; 275 std::string actual;
239 // "path1.name" has been removed, but an empty "path1" dictionary is still 276 // "path1.name" has been removed, but an empty "path1" dictionary is still
240 // present. 277 // present.
241 ASSERT_EQ(1u, prefs->size()); 278 ASSERT_EQ(1u, prefs->size());
242 EXPECT_FALSE(prefs->GetString(kPref1, &actual)); 279 EXPECT_FALSE(prefs->GetString(kPref1, &actual));
243 EXPECT_FALSE(prefs->GetString(kPref2, &actual)); 280 EXPECT_FALSE(prefs->GetString(kPref2, &actual));
244 } 281 }
245 282
246 // Tests uninstalling an extension that wasn't winning for any preferences. 283 // Tests uninstalling an extension that wasn't winning for any preferences.
247 TEST(ExtensionPrefStoreTest, UninstallIrrelevantExtension) { 284 TEST(ExtensionPrefStoreTest, UninstallIrrelevantExtension) {
248 TestExtensionPrefStore eps; 285 TestExtensionPrefStore eps;
249 ASSERT_TRUE(eps.ext1 != NULL); 286 ASSERT_TRUE(eps.ext1 != NULL);
250 eps.InstallExtensionPref(eps.ext1, kPref1, Value::CreateStringValue("val1")); 287 eps.InstallExtensionPref(eps.ext1, kPref1, Value::CreateStringValue("val1"));
251 eps.InstallExtensionPref(eps.ext2, kPref1, Value::CreateStringValue("val2")); 288 eps.InstallExtensionPref(eps.ext2, kPref1, Value::CreateStringValue("val2"));
252 289
253 eps.InstallExtensionPref(eps.ext1, kPref2, Value::CreateStringValue("val3")); 290 eps.InstallExtensionPref(eps.ext1, kPref2, Value::CreateStringValue("val3"));
254 eps.InstallExtensionPref(eps.ext2, kPref2, Value::CreateStringValue("val4")); 291 eps.InstallExtensionPref(eps.ext2, kPref2, Value::CreateStringValue("val4"));
255 292
256 eps.UninstallExtension(eps.ext1); 293 eps.UninstallExtension(eps.ext1);
257 294
258 TestExtensionPrefStore::ExtensionIDs ids; 295 TestExtensionPrefStore::ExtensionIDs ids;
259 eps.GetExtensionIDList(&ids); 296 eps.GetExtensionIDList(&ids);
260 EXPECT_EQ(1u, ids.size()); 297 ASSERT_EQ(1u, ids.size());
261 EXPECT_EQ(eps.ext2->id(), ids[0]); 298 EXPECT_EQ(eps.ext2->id(), ids[0]);
262 299
300 std::vector<std::string> precedences;
301 eps.GetExtensionPrecedences(&precedences);
302 ASSERT_EQ(1u, precedences.size());
303 EXPECT_EQ(eps.ext2->id(), precedences[0]);
304
263 DictionaryValue* prefs = eps.prefs(); 305 DictionaryValue* prefs = eps.prefs();
264 ASSERT_EQ(2u, prefs->size()); 306 ASSERT_EQ(2u, prefs->size());
265 std::string actual; 307 std::string actual;
266 EXPECT_TRUE(prefs->GetString(kPref1, &actual)); 308 EXPECT_TRUE(prefs->GetString(kPref1, &actual));
267 EXPECT_EQ("val2", actual); 309 EXPECT_EQ("val2", actual);
268 EXPECT_TRUE(prefs->GetString(kPref2, &actual)); 310 EXPECT_TRUE(prefs->GetString(kPref2, &actual));
269 EXPECT_EQ("val4", actual); 311 EXPECT_EQ("val4", actual);
270 } 312 }
271 313
272 // Tests uninstalling an extension that was winning for all preferences. 314 // Tests uninstalling an extension that was winning for all preferences.
273 TEST(ExtensionPrefStoreTest, UninstallExtensionFromTop) { 315 TEST(ExtensionPrefStoreTest, UninstallExtensionFromTop) {
274 TestExtensionPrefStore eps; 316 TestExtensionPrefStore eps;
275 ASSERT_TRUE(eps.ext1 != NULL); 317 ASSERT_TRUE(eps.ext1 != NULL);
276 eps.InstallExtensionPref(eps.ext1, kPref1, Value::CreateStringValue("val1")); 318 eps.InstallExtensionPref(eps.ext1, kPref1, Value::CreateStringValue("val1"));
277 eps.InstallExtensionPref(eps.ext2, kPref1, Value::CreateStringValue("val2")); 319 eps.InstallExtensionPref(eps.ext2, kPref1, Value::CreateStringValue("val2"));
278 eps.InstallExtensionPref(eps.ext3, kPref1, Value::CreateStringValue("val3")); 320 eps.InstallExtensionPref(eps.ext3, kPref1, Value::CreateStringValue("val3"));
279 321
280 eps.InstallExtensionPref(eps.ext1, kPref2, Value::CreateStringValue("val4")); 322 eps.InstallExtensionPref(eps.ext1, kPref2, Value::CreateStringValue("val4"));
281 eps.InstallExtensionPref(eps.ext3, kPref2, Value::CreateStringValue("val5")); 323 eps.InstallExtensionPref(eps.ext3, kPref2, Value::CreateStringValue("val5"));
282 324
283 eps.UninstallExtension(eps.ext3); 325 eps.UninstallExtension(eps.ext3);
284 326
285 TestExtensionPrefStore::ExtensionIDs ids; 327 TestExtensionPrefStore::ExtensionIDs ids;
286 eps.GetExtensionIDList(&ids); 328 eps.GetExtensionIDList(&ids);
287 EXPECT_EQ(2u, ids.size()); 329 ASSERT_EQ(2u, ids.size());
288 EXPECT_EQ(eps.ext2->id(), ids[0]); 330 EXPECT_EQ(eps.ext2->id(), ids[0]);
289 EXPECT_EQ(eps.ext1->id(), ids[1]); 331 EXPECT_EQ(eps.ext1->id(), ids[1]);
290 332
333 std::vector<std::string> precedences;
334 eps.GetExtensionPrecedences(&precedences);
335 ASSERT_EQ(2u, precedences.size());
336 EXPECT_EQ(eps.ext1->id(), precedences[0]);
337 EXPECT_EQ(eps.ext2->id(), precedences[1]);
338
291 DictionaryValue* prefs = eps.prefs(); 339 DictionaryValue* prefs = eps.prefs();
292 ASSERT_EQ(2u, prefs->size()); 340 ASSERT_EQ(2u, prefs->size());
293 std::string actual; 341 std::string actual;
294 EXPECT_TRUE(prefs->GetString(kPref1, &actual)); 342 EXPECT_TRUE(prefs->GetString(kPref1, &actual));
295 EXPECT_EQ("val2", actual); 343 EXPECT_EQ("val2", actual);
296 EXPECT_TRUE(prefs->GetString(kPref2, &actual)); 344 EXPECT_TRUE(prefs->GetString(kPref2, &actual));
297 EXPECT_EQ("val4", actual); 345 EXPECT_EQ("val4", actual);
298 } 346 }
299 347
300 // Tests uninstalling an extension that was winning for only some preferences. 348 // Tests uninstalling an extension that was winning for only some preferences.
301 TEST(ExtensionPrefStoreTest, UninstallExtensionFromMiddle) { 349 TEST(ExtensionPrefStoreTest, UninstallExtensionFromMiddle) {
302 TestExtensionPrefStore eps; 350 TestExtensionPrefStore eps;
303 ASSERT_TRUE(eps.ext1 != NULL); 351 ASSERT_TRUE(eps.ext1 != NULL);
304 eps.InstallExtensionPref(eps.ext1, kPref1, Value::CreateStringValue("val1")); 352 eps.InstallExtensionPref(eps.ext1, kPref1, Value::CreateStringValue("val1"));
305 eps.InstallExtensionPref(eps.ext2, kPref1, Value::CreateStringValue("val2")); 353 eps.InstallExtensionPref(eps.ext2, kPref1, Value::CreateStringValue("val2"));
306 eps.InstallExtensionPref(eps.ext3, kPref1, Value::CreateStringValue("val3")); 354 eps.InstallExtensionPref(eps.ext3, kPref1, Value::CreateStringValue("val3"));
307 355
308 eps.InstallExtensionPref(eps.ext1, kPref2, Value::CreateStringValue("val4")); 356 eps.InstallExtensionPref(eps.ext1, kPref2, Value::CreateStringValue("val4"));
309 eps.InstallExtensionPref(eps.ext2, kPref2, Value::CreateStringValue("val5")); 357 eps.InstallExtensionPref(eps.ext2, kPref2, Value::CreateStringValue("val5"));
310 358
311 eps.InstallExtensionPref(eps.ext1, kPref3, Value::CreateStringValue("val6")); 359 eps.InstallExtensionPref(eps.ext1, kPref3, Value::CreateStringValue("val6"));
312 360
313 eps.InstallExtensionPref(eps.ext2, kPref4, Value::CreateStringValue("val7")); 361 eps.InstallExtensionPref(eps.ext2, kPref4, Value::CreateStringValue("val7"));
314 362
315 eps.UninstallExtension(eps.ext2); 363 eps.UninstallExtension(eps.ext2);
316 364
317 TestExtensionPrefStore::ExtensionIDs ids; 365 TestExtensionPrefStore::ExtensionIDs ids;
318 eps.GetExtensionIDList(&ids); 366 eps.GetExtensionIDList(&ids);
319 EXPECT_EQ(2u, ids.size()); 367 ASSERT_EQ(2u, ids.size());
320 EXPECT_EQ(eps.ext3->id(), ids[0]); 368 EXPECT_EQ(eps.ext3->id(), ids[0]);
321 EXPECT_EQ(eps.ext1->id(), ids[1]); 369 EXPECT_EQ(eps.ext1->id(), ids[1]);
322 370
323 DictionaryValue* prefs = eps.prefs(); 371 DictionaryValue* prefs = eps.prefs();
324 ASSERT_EQ(3u, prefs->size()); 372 ASSERT_EQ(3u, prefs->size());
325 std::string actual; 373 std::string actual;
326 EXPECT_TRUE(prefs->GetString(kPref1, &actual)); 374 EXPECT_TRUE(prefs->GetString(kPref1, &actual));
327 EXPECT_EQ("val3", actual); 375 EXPECT_EQ("val3", actual);
328 EXPECT_TRUE(prefs->GetString(kPref2, &actual)); 376 EXPECT_TRUE(prefs->GetString(kPref2, &actual));
329 EXPECT_EQ("val4", actual); 377 EXPECT_EQ("val4", actual);
(...skipping 30 matching lines...)
360 EXPECT_CALL(*pref_notifier, FireObservers(kPref1)).Times(0); 408 EXPECT_CALL(*pref_notifier, FireObservers(kPref1)).Times(0);
361 eps->InstallExtensionPref(eps->ext1, kPref1, 409 eps->InstallExtensionPref(eps->ext1, kPref1,
362 Value::CreateStringValue("https://www.chromium.org")); 410 Value::CreateStringValue("https://www.chromium.org"));
363 Mock::VerifyAndClearExpectations(pref_notifier); 411 Mock::VerifyAndClearExpectations(pref_notifier);
364 412
365 EXPECT_CALL(*pref_notifier, FireObservers(kPref1)).Times(2); 413 EXPECT_CALL(*pref_notifier, FireObservers(kPref1)).Times(2);
366 eps->InstallExtensionPref(eps->ext1, kPref1, 414 eps->InstallExtensionPref(eps->ext1, kPref1,
367 Value::CreateStringValue("chrome://newtab")); 415 Value::CreateStringValue("chrome://newtab"));
368 eps->UninstallExtension(eps->ext1); 416 eps->UninstallExtension(eps->ext1);
369 } 417 }
418
419 // Make sure the precedence is respected when extensions are loaded
420 // and the precedence of extensions has been defined in the pref stores already.
421 TEST(ExtensionPrefStoreTest, InstallRegisteredExtensions) {
422 TestExtensionPrefStore eps;
423 ASSERT_TRUE(eps.ext1 != NULL);
424
425 std::vector<std::string> precedences;
426 precedences.push_back(eps.ext3->id());
427 precedences.push_back(eps.ext1->id());
428 precedences.push_back(eps.ext2->id());
429 eps.PersistExtensionPrecedences(precedences);
430
431 eps.InstallExtensionPref(eps.ext1, kPref1, Value::CreateStringValue("val1"));
432 {
433 DictionaryValue* prefs = eps.prefs();
434 ASSERT_EQ(1u, prefs->size());
435 std::string actual;
436 EXPECT_TRUE(prefs->GetString(kPref1, &actual));
437 EXPECT_EQ("val1", actual);
438 }
439
440 // ext2 has higher higher precedence --> override
441 eps.InstallExtensionPref(eps.ext2, kPref1, Value::CreateStringValue("val2"));
442 {
443 DictionaryValue* prefs = eps.prefs();
444 ASSERT_EQ(1u, prefs->size());
445 std::string actual;
446 EXPECT_TRUE(prefs->GetString(kPref1, &actual));
447 EXPECT_EQ("val2", actual);
448 }
449
450 // ext3 has lower precedence --> does not override
451 eps.InstallExtensionPref(eps.ext3, kPref1, Value::CreateStringValue("val3"));
452 {
453 DictionaryValue* prefs = eps.prefs();
454 ASSERT_EQ(1u, prefs->size());
455 std::string actual;
456 EXPECT_TRUE(prefs->GetString(kPref1, &actual));
457 EXPECT_EQ("val2", actual);
458 }
459
460 TestExtensionPrefStore::ExtensionIDs ids;
461 eps.GetExtensionIDList(&ids);
462 ASSERT_EQ(3u, ids.size());
463 EXPECT_EQ(eps.ext2->id(), ids[0]);
464 EXPECT_EQ(eps.ext1->id(), ids[1]);
465 EXPECT_EQ(eps.ext3->id(), ids[2]);
466
467 precedences.clear();
468 eps.GetExtensionPrecedences(&precedences);
469 ASSERT_EQ(3u, precedences.size());
470 EXPECT_EQ(eps.ext3->id(), precedences[0]);
471 EXPECT_EQ(eps.ext1->id(), precedences[1]);
472 EXPECT_EQ(eps.ext2->id(), precedences[2]);
473 }
474
475 // Make sure the precedence is respected when extensions are loaded and
476 // uninstalled later.
477 TEST(ExtensionPrefStoreTest, UninstallRegisteredExtensions) {
478 TestExtensionPrefStore eps;
479 ASSERT_TRUE(eps.ext1 != NULL);
480
481 std::vector<std::string> precedences;
482 precedences.push_back(eps.ext3->id());
483 precedences.push_back(eps.ext1->id());
484 precedences.push_back(eps.ext2->id());
485 eps.PersistExtensionPrecedences(precedences);
486
487 eps.InstallExtensionPref(eps.ext1, kPref1, Value::CreateStringValue("val1"));
488 eps.InstallExtensionPref(eps.ext2, kPref1, Value::CreateStringValue("val2"));
489 eps.InstallExtensionPref(eps.ext3, kPref1, Value::CreateStringValue("val3"));
490
491 // Correct state of this setup is ensured by InstallRegisteredExtensions test
492
493 eps.UninstallExtension(eps.ext2);
494 {
495 DictionaryValue* prefs = eps.prefs();
496 ASSERT_EQ(1u, prefs->size());
497 std::string actual;
498 EXPECT_TRUE(prefs->GetString(kPref1, &actual));
499 EXPECT_EQ("val1", actual);
500 }
501
502 TestExtensionPrefStore::ExtensionIDs ids;
503 eps.GetExtensionIDList(&ids);
504 ASSERT_EQ(2u, ids.size());
505 EXPECT_EQ(eps.ext1->id(), ids[0]);
506 EXPECT_EQ(eps.ext3->id(), ids[1]);
507
508 precedences.clear();
509 eps.GetExtensionPrecedences(&precedences);
510 ASSERT_EQ(2u, precedences.size());
511 EXPECT_EQ(eps.ext3->id(), precedences[0]);
512 EXPECT_EQ(eps.ext1->id(), precedences[1]);
513 }
514
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_pref_store.cc ('k') | chrome/browser/extensions/extension_prefs.h » ('j') | no next file with comments »

Powered by Google App Engine