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 "extension_prefs_unittest.h" | 5 #include "extension_prefs_unittest.h" |
6 | 6 |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/scoped_temp_dir.h" | 8 #include "base/scoped_temp_dir.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/extensions/extension_prefs.h" | 13 #include "chrome/browser/extensions/extension_prefs.h" |
14 #include "chrome/browser/extensions/extension_pref_value_map.h" | 14 #include "chrome/browser/extensions/extension_pref_value_map.h" |
15 #include "chrome/browser/prefs/pref_change_registrar.h" | 15 #include "chrome/browser/prefs/pref_change_registrar.h" |
16 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 16 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
17 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
18 #include "chrome/common/extensions/extension_manifest_constants.h" | 18 #include "chrome/common/extensions/extension_manifest_constants.h" |
19 #include "chrome/common/extensions/extension_permission_set.h" | 19 #include "chrome/common/extensions/permissions/permission_set.h" |
20 #include "chrome/common/string_ordinal.h" | 20 #include "chrome/common/string_ordinal.h" |
21 #include "content/public/browser/notification_details.h" | 21 #include "content/public/browser/notification_details.h" |
22 #include "content/public/browser/notification_source.h" | 22 #include "content/public/browser/notification_source.h" |
23 #include "content/public/test/mock_notification_observer.h" | 23 #include "content/public/test/mock_notification_observer.h" |
24 | 24 |
25 using base::Time; | 25 using base::Time; |
26 using base::TimeDelta; | 26 using base::TimeDelta; |
27 using content::BrowserThread; | 27 using content::BrowserThread; |
| 28 using extensions::APIPermission; |
| 29 using extensions::APIPermissionSet; |
28 using extensions::Extension; | 30 using extensions::Extension; |
29 using extensions::ExtensionList; | 31 using extensions::ExtensionList; |
| 32 using extensions::OAuth2Scopes; |
| 33 using extensions::PermissionSet; |
30 | 34 |
31 namespace { | 35 namespace { |
32 | 36 |
33 const char kPref1[] = "path1.subpath"; | 37 const char kPref1[] = "path1.subpath"; |
34 const char kPref2[] = "path2"; | 38 const char kPref2[] = "path2"; |
35 const char kPref3[] = "path3"; | 39 const char kPref3[] = "path3"; |
36 const char kPref4[] = "path4"; | 40 const char kPref4[] = "path4"; |
37 | 41 |
38 // Default values in case an extension pref value is not overridden. | 42 // Default values in case an extension pref value is not overridden. |
39 const char kDefaultPref1[] = "default pref 1"; | 43 const char kDefaultPref1[] = "default pref 1"; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 scoped_refptr<Extension> extension; | 165 scoped_refptr<Extension> extension; |
162 }; | 166 }; |
163 TEST_F(ExtensionPrefsEscalatePermissions, EscalatePermissions) {} | 167 TEST_F(ExtensionPrefsEscalatePermissions, EscalatePermissions) {} |
164 | 168 |
165 // Tests the AddGrantedPermissions / GetGrantedPermissions functions. | 169 // Tests the AddGrantedPermissions / GetGrantedPermissions functions. |
166 class ExtensionPrefsGrantedPermissions : public ExtensionPrefsTest { | 170 class ExtensionPrefsGrantedPermissions : public ExtensionPrefsTest { |
167 public: | 171 public: |
168 virtual void Initialize() { | 172 virtual void Initialize() { |
169 extension_id_ = prefs_.AddExtensionAndReturnId("test"); | 173 extension_id_ = prefs_.AddExtensionAndReturnId("test"); |
170 | 174 |
171 api_perm_set1_.insert(ExtensionAPIPermission::kTab); | 175 api_perm_set1_.insert(APIPermission::kTab); |
172 api_perm_set1_.insert(ExtensionAPIPermission::kBookmark); | 176 api_perm_set1_.insert(APIPermission::kBookmark); |
173 | 177 |
174 api_perm_set2_.insert(ExtensionAPIPermission::kHistory); | 178 api_perm_set2_.insert(APIPermission::kHistory); |
175 | 179 |
176 scopes_set1_.insert("scope1"); | 180 scopes_set1_.insert("scope1"); |
177 | 181 |
178 scopes_set2_.insert("scope1"); | 182 scopes_set2_.insert("scope1"); |
179 scopes_set2_.insert("scope2"); | 183 scopes_set2_.insert("scope2"); |
180 scopes_set2_.insert("scope3"); | 184 scopes_set2_.insert("scope3"); |
181 | 185 |
182 AddPattern(&ehost_perm_set1_, "http://*.google.com/*"); | 186 AddPattern(&ehost_perm_set1_, "http://*.google.com/*"); |
183 AddPattern(&ehost_perm_set1_, "http://example.com/*"); | 187 AddPattern(&ehost_perm_set1_, "http://example.com/*"); |
184 AddPattern(&ehost_perm_set1_, "chrome://favicon/*"); | 188 AddPattern(&ehost_perm_set1_, "chrome://favicon/*"); |
185 | 189 |
186 AddPattern(&ehost_perm_set2_, "https://*.google.com/*"); | 190 AddPattern(&ehost_perm_set2_, "https://*.google.com/*"); |
187 // with duplicate: | 191 // with duplicate: |
188 AddPattern(&ehost_perm_set2_, "http://*.google.com/*"); | 192 AddPattern(&ehost_perm_set2_, "http://*.google.com/*"); |
189 | 193 |
190 AddPattern(&shost_perm_set1_, "http://reddit.com/r/test/*"); | 194 AddPattern(&shost_perm_set1_, "http://reddit.com/r/test/*"); |
191 AddPattern(&shost_perm_set2_, "http://reddit.com/r/test/*"); | 195 AddPattern(&shost_perm_set2_, "http://reddit.com/r/test/*"); |
192 AddPattern(&shost_perm_set2_, "http://somesite.com/*"); | 196 AddPattern(&shost_perm_set2_, "http://somesite.com/*"); |
193 AddPattern(&shost_perm_set2_, "http://example.com/*"); | 197 AddPattern(&shost_perm_set2_, "http://example.com/*"); |
194 | 198 |
195 ExtensionAPIPermissionSet expected_apis = api_perm_set1_; | 199 APIPermissionSet expected_apis = api_perm_set1_; |
196 | 200 |
197 AddPattern(&ehost_permissions_, "http://*.google.com/*"); | 201 AddPattern(&ehost_permissions_, "http://*.google.com/*"); |
198 AddPattern(&ehost_permissions_, "http://example.com/*"); | 202 AddPattern(&ehost_permissions_, "http://example.com/*"); |
199 AddPattern(&ehost_permissions_, "chrome://favicon/*"); | 203 AddPattern(&ehost_permissions_, "chrome://favicon/*"); |
200 AddPattern(&ehost_permissions_, "https://*.google.com/*"); | 204 AddPattern(&ehost_permissions_, "https://*.google.com/*"); |
201 | 205 |
202 AddPattern(&shost_permissions_, "http://reddit.com/r/test/*"); | 206 AddPattern(&shost_permissions_, "http://reddit.com/r/test/*"); |
203 AddPattern(&shost_permissions_, "http://somesite.com/*"); | 207 AddPattern(&shost_permissions_, "http://somesite.com/*"); |
204 AddPattern(&shost_permissions_, "http://example.com/*"); | 208 AddPattern(&shost_permissions_, "http://example.com/*"); |
205 | 209 |
206 scope_permissions_.insert("scope1"); | 210 scope_permissions_.insert("scope1"); |
207 scope_permissions_.insert("scope2"); | 211 scope_permissions_.insert("scope2"); |
208 scope_permissions_.insert("scope3"); | 212 scope_permissions_.insert("scope3"); |
209 | 213 |
210 ExtensionAPIPermissionSet empty_set; | 214 APIPermissionSet empty_set; |
211 URLPatternSet empty_extent; | 215 URLPatternSet empty_extent; |
212 ExtensionOAuth2Scopes empty_scopes; | 216 OAuth2Scopes empty_scopes; |
213 scoped_refptr<ExtensionPermissionSet> permissions; | 217 scoped_refptr<PermissionSet> permissions; |
214 scoped_refptr<ExtensionPermissionSet> granted_permissions; | 218 scoped_refptr<PermissionSet> granted_permissions; |
215 | 219 |
216 // Make sure both granted api and host permissions start empty. | 220 // Make sure both granted api and host permissions start empty. |
217 granted_permissions = | 221 granted_permissions = |
218 prefs()->GetGrantedPermissions(extension_id_); | 222 prefs()->GetGrantedPermissions(extension_id_); |
219 EXPECT_TRUE(granted_permissions->IsEmpty()); | 223 EXPECT_TRUE(granted_permissions->IsEmpty()); |
220 | 224 |
221 permissions = new ExtensionPermissionSet( | 225 permissions = new PermissionSet( |
222 api_perm_set1_, empty_extent, empty_extent); | 226 api_perm_set1_, empty_extent, empty_extent); |
223 | 227 |
224 // Add part of the api permissions. | 228 // Add part of the api permissions. |
225 prefs()->AddGrantedPermissions(extension_id_, permissions.get()); | 229 prefs()->AddGrantedPermissions(extension_id_, permissions.get()); |
226 granted_permissions = prefs()->GetGrantedPermissions(extension_id_); | 230 granted_permissions = prefs()->GetGrantedPermissions(extension_id_); |
227 EXPECT_TRUE(granted_permissions.get()); | 231 EXPECT_TRUE(granted_permissions.get()); |
228 EXPECT_FALSE(granted_permissions->IsEmpty()); | 232 EXPECT_FALSE(granted_permissions->IsEmpty()); |
229 EXPECT_EQ(expected_apis, granted_permissions->apis()); | 233 EXPECT_EQ(expected_apis, granted_permissions->apis()); |
230 EXPECT_TRUE(granted_permissions->effective_hosts().is_empty()); | 234 EXPECT_TRUE(granted_permissions->effective_hosts().is_empty()); |
231 EXPECT_FALSE(granted_permissions->HasEffectiveFullAccess()); | 235 EXPECT_FALSE(granted_permissions->HasEffectiveFullAccess()); |
232 EXPECT_EQ(empty_scopes, granted_permissions->scopes()); | 236 EXPECT_EQ(empty_scopes, granted_permissions->scopes()); |
233 granted_permissions = NULL; | 237 granted_permissions = NULL; |
234 | 238 |
235 // Add part of the explicit host permissions. | 239 // Add part of the explicit host permissions. |
236 permissions = new ExtensionPermissionSet( | 240 permissions = new PermissionSet( |
237 empty_set, ehost_perm_set1_, empty_extent); | 241 empty_set, ehost_perm_set1_, empty_extent); |
238 prefs()->AddGrantedPermissions(extension_id_, permissions.get()); | 242 prefs()->AddGrantedPermissions(extension_id_, permissions.get()); |
239 granted_permissions = prefs()->GetGrantedPermissions(extension_id_); | 243 granted_permissions = prefs()->GetGrantedPermissions(extension_id_); |
240 EXPECT_FALSE(granted_permissions->IsEmpty()); | 244 EXPECT_FALSE(granted_permissions->IsEmpty()); |
241 EXPECT_FALSE(granted_permissions->HasEffectiveFullAccess()); | 245 EXPECT_FALSE(granted_permissions->HasEffectiveFullAccess()); |
242 EXPECT_EQ(expected_apis, granted_permissions->apis()); | 246 EXPECT_EQ(expected_apis, granted_permissions->apis()); |
243 EXPECT_EQ(ehost_perm_set1_, | 247 EXPECT_EQ(ehost_perm_set1_, |
244 granted_permissions->explicit_hosts()); | 248 granted_permissions->explicit_hosts()); |
245 EXPECT_EQ(ehost_perm_set1_, | 249 EXPECT_EQ(ehost_perm_set1_, |
246 granted_permissions->effective_hosts()); | 250 granted_permissions->effective_hosts()); |
247 EXPECT_EQ(empty_scopes, granted_permissions->scopes()); | 251 EXPECT_EQ(empty_scopes, granted_permissions->scopes()); |
248 | 252 |
249 // Add part of the scriptable host permissions. | 253 // Add part of the scriptable host permissions. |
250 permissions = new ExtensionPermissionSet( | 254 permissions = new PermissionSet( |
251 empty_set, empty_extent, shost_perm_set1_); | 255 empty_set, empty_extent, shost_perm_set1_); |
252 prefs()->AddGrantedPermissions(extension_id_, permissions.get()); | 256 prefs()->AddGrantedPermissions(extension_id_, permissions.get()); |
253 granted_permissions = prefs()->GetGrantedPermissions(extension_id_); | 257 granted_permissions = prefs()->GetGrantedPermissions(extension_id_); |
254 EXPECT_FALSE(granted_permissions->IsEmpty()); | 258 EXPECT_FALSE(granted_permissions->IsEmpty()); |
255 EXPECT_FALSE(granted_permissions->HasEffectiveFullAccess()); | 259 EXPECT_FALSE(granted_permissions->HasEffectiveFullAccess()); |
256 EXPECT_EQ(expected_apis, granted_permissions->apis()); | 260 EXPECT_EQ(expected_apis, granted_permissions->apis()); |
257 EXPECT_EQ(ehost_perm_set1_, | 261 EXPECT_EQ(ehost_perm_set1_, |
258 granted_permissions->explicit_hosts()); | 262 granted_permissions->explicit_hosts()); |
259 EXPECT_EQ(shost_perm_set1_, | 263 EXPECT_EQ(shost_perm_set1_, |
260 granted_permissions->scriptable_hosts()); | 264 granted_permissions->scriptable_hosts()); |
261 EXPECT_EQ(empty_scopes, granted_permissions->scopes()); | 265 EXPECT_EQ(empty_scopes, granted_permissions->scopes()); |
262 | 266 |
263 URLPatternSet::CreateUnion(ehost_perm_set1_, shost_perm_set1_, | 267 URLPatternSet::CreateUnion(ehost_perm_set1_, shost_perm_set1_, |
264 &effective_permissions_); | 268 &effective_permissions_); |
265 EXPECT_EQ(effective_permissions_, granted_permissions->effective_hosts()); | 269 EXPECT_EQ(effective_permissions_, granted_permissions->effective_hosts()); |
266 | 270 |
267 // Add part of the oauth2 scopes. | 271 // Add part of the oauth2 scopes. |
268 permissions = new ExtensionPermissionSet( | 272 permissions = new PermissionSet( |
269 empty_set, empty_extent, empty_extent, scopes_set1_); | 273 empty_set, empty_extent, empty_extent, scopes_set1_); |
270 prefs()->AddGrantedPermissions(extension_id_, permissions.get()); | 274 prefs()->AddGrantedPermissions(extension_id_, permissions.get()); |
271 granted_permissions = prefs()->GetGrantedPermissions(extension_id_); | 275 granted_permissions = prefs()->GetGrantedPermissions(extension_id_); |
272 EXPECT_FALSE(granted_permissions->IsEmpty()); | 276 EXPECT_FALSE(granted_permissions->IsEmpty()); |
273 EXPECT_FALSE(granted_permissions->HasEffectiveFullAccess()); | 277 EXPECT_FALSE(granted_permissions->HasEffectiveFullAccess()); |
274 EXPECT_EQ(expected_apis, granted_permissions->apis()); | 278 EXPECT_EQ(expected_apis, granted_permissions->apis()); |
275 EXPECT_EQ(ehost_perm_set1_, | 279 EXPECT_EQ(ehost_perm_set1_, |
276 granted_permissions->explicit_hosts()); | 280 granted_permissions->explicit_hosts()); |
277 EXPECT_EQ(shost_perm_set1_, | 281 EXPECT_EQ(shost_perm_set1_, |
278 granted_permissions->scriptable_hosts()); | 282 granted_permissions->scriptable_hosts()); |
279 EXPECT_EQ(scopes_set1_, granted_permissions->scopes()); | 283 EXPECT_EQ(scopes_set1_, granted_permissions->scopes()); |
280 | 284 |
281 // Add the rest of the permissions. | 285 // Add the rest of the permissions. |
282 permissions = new ExtensionPermissionSet( | 286 permissions = new PermissionSet( |
283 api_perm_set2_, ehost_perm_set2_, shost_perm_set2_, scopes_set2_); | 287 api_perm_set2_, ehost_perm_set2_, shost_perm_set2_, scopes_set2_); |
284 | 288 |
285 std::set_union(expected_apis.begin(), expected_apis.end(), | 289 std::set_union(expected_apis.begin(), expected_apis.end(), |
286 api_perm_set2_.begin(), api_perm_set2_.end(), | 290 api_perm_set2_.begin(), api_perm_set2_.end(), |
287 std::inserter(api_permissions_, api_permissions_.begin())); | 291 std::inserter(api_permissions_, api_permissions_.begin())); |
288 | 292 |
289 prefs()->AddGrantedPermissions(extension_id_, permissions.get()); | 293 prefs()->AddGrantedPermissions(extension_id_, permissions.get()); |
290 granted_permissions = prefs()->GetGrantedPermissions(extension_id_); | 294 granted_permissions = prefs()->GetGrantedPermissions(extension_id_); |
291 EXPECT_TRUE(granted_permissions.get()); | 295 EXPECT_TRUE(granted_permissions.get()); |
292 EXPECT_FALSE(granted_permissions->IsEmpty()); | 296 EXPECT_FALSE(granted_permissions->IsEmpty()); |
293 EXPECT_EQ(api_permissions_, granted_permissions->apis()); | 297 EXPECT_EQ(api_permissions_, granted_permissions->apis()); |
294 EXPECT_EQ(ehost_permissions_, | 298 EXPECT_EQ(ehost_permissions_, |
295 granted_permissions->explicit_hosts()); | 299 granted_permissions->explicit_hosts()); |
296 EXPECT_EQ(shost_permissions_, | 300 EXPECT_EQ(shost_permissions_, |
297 granted_permissions->scriptable_hosts()); | 301 granted_permissions->scriptable_hosts()); |
298 EXPECT_EQ(scope_permissions_, granted_permissions->scopes()); | 302 EXPECT_EQ(scope_permissions_, granted_permissions->scopes()); |
299 effective_permissions_.ClearPatterns(); | 303 effective_permissions_.ClearPatterns(); |
300 URLPatternSet::CreateUnion(ehost_permissions_, shost_permissions_, | 304 URLPatternSet::CreateUnion(ehost_permissions_, shost_permissions_, |
301 &effective_permissions_); | 305 &effective_permissions_); |
302 EXPECT_EQ(effective_permissions_, granted_permissions->effective_hosts()); | 306 EXPECT_EQ(effective_permissions_, granted_permissions->effective_hosts()); |
303 } | 307 } |
304 | 308 |
305 virtual void Verify() { | 309 virtual void Verify() { |
306 scoped_refptr<ExtensionPermissionSet> permissions( | 310 scoped_refptr<PermissionSet> permissions( |
307 prefs()->GetGrantedPermissions(extension_id_)); | 311 prefs()->GetGrantedPermissions(extension_id_)); |
308 EXPECT_TRUE(permissions.get()); | 312 EXPECT_TRUE(permissions.get()); |
309 EXPECT_FALSE(permissions->HasEffectiveFullAccess()); | 313 EXPECT_FALSE(permissions->HasEffectiveFullAccess()); |
310 EXPECT_EQ(api_permissions_, permissions->apis()); | 314 EXPECT_EQ(api_permissions_, permissions->apis()); |
311 EXPECT_EQ(ehost_permissions_, | 315 EXPECT_EQ(ehost_permissions_, |
312 permissions->explicit_hosts()); | 316 permissions->explicit_hosts()); |
313 EXPECT_EQ(shost_permissions_, | 317 EXPECT_EQ(shost_permissions_, |
314 permissions->scriptable_hosts()); | 318 permissions->scriptable_hosts()); |
315 EXPECT_EQ(scope_permissions_, | 319 EXPECT_EQ(scope_permissions_, |
316 permissions->scopes()); | 320 permissions->scopes()); |
317 } | 321 } |
318 | 322 |
319 private: | 323 private: |
320 std::string extension_id_; | 324 std::string extension_id_; |
321 ExtensionAPIPermissionSet api_perm_set1_; | 325 APIPermissionSet api_perm_set1_; |
322 ExtensionAPIPermissionSet api_perm_set2_; | 326 APIPermissionSet api_perm_set2_; |
323 URLPatternSet ehost_perm_set1_; | 327 URLPatternSet ehost_perm_set1_; |
324 URLPatternSet ehost_perm_set2_; | 328 URLPatternSet ehost_perm_set2_; |
325 URLPatternSet shost_perm_set1_; | 329 URLPatternSet shost_perm_set1_; |
326 URLPatternSet shost_perm_set2_; | 330 URLPatternSet shost_perm_set2_; |
327 ExtensionOAuth2Scopes scopes_set1_; | 331 OAuth2Scopes scopes_set1_; |
328 ExtensionOAuth2Scopes scopes_set2_; | 332 OAuth2Scopes scopes_set2_; |
329 | 333 |
330 ExtensionAPIPermissionSet api_permissions_; | 334 APIPermissionSet api_permissions_; |
331 URLPatternSet ehost_permissions_; | 335 URLPatternSet ehost_permissions_; |
332 URLPatternSet shost_permissions_; | 336 URLPatternSet shost_permissions_; |
333 ExtensionOAuth2Scopes scope_permissions_; | 337 OAuth2Scopes scope_permissions_; |
334 URLPatternSet effective_permissions_; | 338 URLPatternSet effective_permissions_; |
335 }; | 339 }; |
336 TEST_F(ExtensionPrefsGrantedPermissions, GrantedPermissions) {} | 340 TEST_F(ExtensionPrefsGrantedPermissions, GrantedPermissions) {} |
337 | 341 |
338 // Tests the SetActivePermissions / GetActivePermissions functions. | 342 // Tests the SetActivePermissions / GetActivePermissions functions. |
339 class ExtensionPrefsActivePermissions : public ExtensionPrefsTest { | 343 class ExtensionPrefsActivePermissions : public ExtensionPrefsTest { |
340 public: | 344 public: |
341 virtual void Initialize() { | 345 virtual void Initialize() { |
342 extension_id_ = prefs_.AddExtensionAndReturnId("test"); | 346 extension_id_ = prefs_.AddExtensionAndReturnId("test"); |
343 | 347 |
344 ExtensionAPIPermissionSet api_perms; | 348 APIPermissionSet api_perms; |
345 api_perms.insert(ExtensionAPIPermission::kTab); | 349 api_perms.insert(APIPermission::kTab); |
346 api_perms.insert(ExtensionAPIPermission::kBookmark); | 350 api_perms.insert(APIPermission::kBookmark); |
347 api_perms.insert(ExtensionAPIPermission::kHistory); | 351 api_perms.insert(APIPermission::kHistory); |
348 | 352 |
349 URLPatternSet ehosts; | 353 URLPatternSet ehosts; |
350 AddPattern(&ehosts, "http://*.google.com/*"); | 354 AddPattern(&ehosts, "http://*.google.com/*"); |
351 AddPattern(&ehosts, "http://example.com/*"); | 355 AddPattern(&ehosts, "http://example.com/*"); |
352 AddPattern(&ehosts, "chrome://favicon/*"); | 356 AddPattern(&ehosts, "chrome://favicon/*"); |
353 | 357 |
354 URLPatternSet shosts; | 358 URLPatternSet shosts; |
355 AddPattern(&shosts, "https://*.google.com/*"); | 359 AddPattern(&shosts, "https://*.google.com/*"); |
356 AddPattern(&shosts, "http://reddit.com/r/test/*"); | 360 AddPattern(&shosts, "http://reddit.com/r/test/*"); |
357 | 361 |
358 ExtensionOAuth2Scopes scopes; | 362 OAuth2Scopes scopes; |
359 scopes.insert("my-new-scope"); | 363 scopes.insert("my-new-scope"); |
360 | 364 |
361 active_perms_ = new ExtensionPermissionSet( | 365 active_perms_ = new PermissionSet( |
362 api_perms, ehosts, shosts, scopes); | 366 api_perms, ehosts, shosts, scopes); |
363 | 367 |
364 // Make sure the active permissions start empty. | 368 // Make sure the active permissions start empty. |
365 scoped_refptr<ExtensionPermissionSet> active( | 369 scoped_refptr<PermissionSet> active( |
366 prefs()->GetActivePermissions(extension_id_)); | 370 prefs()->GetActivePermissions(extension_id_)); |
367 EXPECT_TRUE(active->IsEmpty()); | 371 EXPECT_TRUE(active->IsEmpty()); |
368 | 372 |
369 // Set the active permissions. | 373 // Set the active permissions. |
370 prefs()->SetActivePermissions(extension_id_, active_perms_.get()); | 374 prefs()->SetActivePermissions(extension_id_, active_perms_.get()); |
371 active = prefs()->GetActivePermissions(extension_id_); | 375 active = prefs()->GetActivePermissions(extension_id_); |
372 EXPECT_EQ(active_perms_->apis(), active->apis()); | 376 EXPECT_EQ(active_perms_->apis(), active->apis()); |
373 EXPECT_EQ(active_perms_->explicit_hosts(), active->explicit_hosts()); | 377 EXPECT_EQ(active_perms_->explicit_hosts(), active->explicit_hosts()); |
374 EXPECT_EQ(active_perms_->scriptable_hosts(), active->scriptable_hosts()); | 378 EXPECT_EQ(active_perms_->scriptable_hosts(), active->scriptable_hosts()); |
375 EXPECT_EQ(active_perms_->scopes(), active->scopes()); | 379 EXPECT_EQ(active_perms_->scopes(), active->scopes()); |
376 EXPECT_EQ(*active_perms_, *active); | 380 EXPECT_EQ(*active_perms_, *active); |
377 } | 381 } |
378 | 382 |
379 virtual void Verify() { | 383 virtual void Verify() { |
380 scoped_refptr<ExtensionPermissionSet> permissions( | 384 scoped_refptr<PermissionSet> permissions( |
381 prefs()->GetActivePermissions(extension_id_)); | 385 prefs()->GetActivePermissions(extension_id_)); |
382 EXPECT_EQ(*active_perms_, *permissions); | 386 EXPECT_EQ(*active_perms_, *permissions); |
383 } | 387 } |
384 | 388 |
385 private: | 389 private: |
386 std::string extension_id_; | 390 std::string extension_id_; |
387 scoped_refptr<ExtensionPermissionSet> active_perms_; | 391 scoped_refptr<PermissionSet> active_perms_; |
388 }; | 392 }; |
389 TEST_F(ExtensionPrefsActivePermissions, SetAndGetActivePermissions) {} | 393 TEST_F(ExtensionPrefsActivePermissions, SetAndGetActivePermissions) {} |
390 | 394 |
391 // Tests the GetVersionString function. | 395 // Tests the GetVersionString function. |
392 class ExtensionPrefsVersionString : public ExtensionPrefsTest { | 396 class ExtensionPrefsVersionString : public ExtensionPrefsTest { |
393 public: | 397 public: |
394 virtual void Initialize() { | 398 virtual void Initialize() { |
395 extension = prefs_.AddExtension("test"); | 399 extension = prefs_.AddExtension("test"); |
396 EXPECT_EQ("0.1", prefs()->GetVersionString(extension->id())); | 400 EXPECT_EQ("0.1", prefs()->GetVersionString(extension->id())); |
397 prefs()->OnExtensionUninstalled(extension->id(), | 401 prefs()->OnExtensionUninstalled(extension->id(), |
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1198 string16 error16; | 1202 string16 error16; |
1199 EXPECT_TRUE(prefs()->UserMayLoad(extension_.get(), &error16)); | 1203 EXPECT_TRUE(prefs()->UserMayLoad(extension_.get(), &error16)); |
1200 EXPECT_EQ(string16(), error16); | 1204 EXPECT_EQ(string16(), error16); |
1201 EXPECT_TRUE(prefs()->UserMayModifySettings(extension_.get(), &error16)); | 1205 EXPECT_TRUE(prefs()->UserMayModifySettings(extension_.get(), &error16)); |
1202 EXPECT_EQ(string16(), error16); | 1206 EXPECT_EQ(string16(), error16); |
1203 EXPECT_FALSE(prefs()->MustRemainEnabled(extension_.get(), &error16)); | 1207 EXPECT_FALSE(prefs()->MustRemainEnabled(extension_.get(), &error16)); |
1204 EXPECT_EQ(string16(), error16); | 1208 EXPECT_EQ(string16(), error16); |
1205 } | 1209 } |
1206 }; | 1210 }; |
1207 TEST_F(ExtensionPrefsNotRequiredExtension, NotRequiredExtension) {} | 1211 TEST_F(ExtensionPrefsNotRequiredExtension, NotRequiredExtension) {} |
OLD | NEW |