| 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 "chrome/browser/extensions/extension_prefs_unittest.h" | 5 #include "chrome/browser/extensions/extension_prefs_unittest.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/prefs/mock_pref_change_callback.h" | 10 #include "base/prefs/mock_pref_change_callback.h" |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 AddPattern(&ehost_permissions_, "http://*.google.com/*"); | 215 AddPattern(&ehost_permissions_, "http://*.google.com/*"); |
| 216 AddPattern(&ehost_permissions_, "http://example.com/*"); | 216 AddPattern(&ehost_permissions_, "http://example.com/*"); |
| 217 AddPattern(&ehost_permissions_, "chrome://favicon/*"); | 217 AddPattern(&ehost_permissions_, "chrome://favicon/*"); |
| 218 AddPattern(&ehost_permissions_, "https://*.google.com/*"); | 218 AddPattern(&ehost_permissions_, "https://*.google.com/*"); |
| 219 | 219 |
| 220 AddPattern(&shost_permissions_, "http://reddit.com/r/test/*"); | 220 AddPattern(&shost_permissions_, "http://reddit.com/r/test/*"); |
| 221 AddPattern(&shost_permissions_, "http://somesite.com/*"); | 221 AddPattern(&shost_permissions_, "http://somesite.com/*"); |
| 222 AddPattern(&shost_permissions_, "http://example.com/*"); | 222 AddPattern(&shost_permissions_, "http://example.com/*"); |
| 223 | 223 |
| 224 APIPermissionSet empty_set; | 224 APIPermissionSet empty_set; |
| 225 ManifestPermissionSet empty_manifest_permissions; |
| 225 URLPatternSet empty_extent; | 226 URLPatternSet empty_extent; |
| 226 scoped_refptr<PermissionSet> permissions; | 227 scoped_refptr<PermissionSet> permissions; |
| 227 scoped_refptr<PermissionSet> granted_permissions; | 228 scoped_refptr<PermissionSet> granted_permissions; |
| 228 | 229 |
| 229 // Make sure both granted api and host permissions start empty. | 230 // Make sure both granted api and host permissions start empty. |
| 230 granted_permissions = | 231 granted_permissions = |
| 231 prefs()->GetGrantedPermissions(extension_id_); | 232 prefs()->GetGrantedPermissions(extension_id_); |
| 232 EXPECT_TRUE(granted_permissions->IsEmpty()); | 233 EXPECT_TRUE(granted_permissions->IsEmpty()); |
| 233 | 234 |
| 234 permissions = new PermissionSet( | 235 permissions = new PermissionSet( |
| 235 api_perm_set1_, empty_extent, empty_extent); | 236 api_perm_set1_, empty_manifest_permissions, empty_extent, empty_extent); |
| 236 | 237 |
| 237 // Add part of the api permissions. | 238 // Add part of the api permissions. |
| 238 prefs()->AddGrantedPermissions(extension_id_, permissions.get()); | 239 prefs()->AddGrantedPermissions(extension_id_, permissions.get()); |
| 239 granted_permissions = prefs()->GetGrantedPermissions(extension_id_); | 240 granted_permissions = prefs()->GetGrantedPermissions(extension_id_); |
| 240 EXPECT_TRUE(granted_permissions.get()); | 241 EXPECT_TRUE(granted_permissions.get()); |
| 241 EXPECT_FALSE(granted_permissions->IsEmpty()); | 242 EXPECT_FALSE(granted_permissions->IsEmpty()); |
| 242 EXPECT_EQ(expected_apis, granted_permissions->apis()); | 243 EXPECT_EQ(expected_apis, granted_permissions->apis()); |
| 243 EXPECT_TRUE(granted_permissions->effective_hosts().is_empty()); | 244 EXPECT_TRUE(granted_permissions->effective_hosts().is_empty()); |
| 244 EXPECT_FALSE(granted_permissions->HasEffectiveFullAccess()); | 245 EXPECT_FALSE(granted_permissions->HasEffectiveFullAccess()); |
| 245 granted_permissions = NULL; | 246 granted_permissions = NULL; |
| 246 | 247 |
| 247 // Add part of the explicit host permissions. | 248 // Add part of the explicit host permissions. |
| 248 permissions = new PermissionSet( | 249 permissions = new PermissionSet( |
| 249 empty_set, ehost_perm_set1_, empty_extent); | 250 empty_set, empty_manifest_permissions, ehost_perm_set1_, empty_extent); |
| 250 prefs()->AddGrantedPermissions(extension_id_, permissions.get()); | 251 prefs()->AddGrantedPermissions(extension_id_, permissions.get()); |
| 251 granted_permissions = prefs()->GetGrantedPermissions(extension_id_); | 252 granted_permissions = prefs()->GetGrantedPermissions(extension_id_); |
| 252 EXPECT_FALSE(granted_permissions->IsEmpty()); | 253 EXPECT_FALSE(granted_permissions->IsEmpty()); |
| 253 EXPECT_FALSE(granted_permissions->HasEffectiveFullAccess()); | 254 EXPECT_FALSE(granted_permissions->HasEffectiveFullAccess()); |
| 254 EXPECT_EQ(expected_apis, granted_permissions->apis()); | 255 EXPECT_EQ(expected_apis, granted_permissions->apis()); |
| 255 EXPECT_EQ(ehost_perm_set1_, | 256 EXPECT_EQ(ehost_perm_set1_, |
| 256 granted_permissions->explicit_hosts()); | 257 granted_permissions->explicit_hosts()); |
| 257 EXPECT_EQ(ehost_perm_set1_, | 258 EXPECT_EQ(ehost_perm_set1_, |
| 258 granted_permissions->effective_hosts()); | 259 granted_permissions->effective_hosts()); |
| 259 | 260 |
| 260 // Add part of the scriptable host permissions. | 261 // Add part of the scriptable host permissions. |
| 261 permissions = new PermissionSet( | 262 permissions = new PermissionSet( |
| 262 empty_set, empty_extent, shost_perm_set1_); | 263 empty_set, empty_manifest_permissions, empty_extent, shost_perm_set1_); |
| 263 prefs()->AddGrantedPermissions(extension_id_, permissions.get()); | 264 prefs()->AddGrantedPermissions(extension_id_, permissions.get()); |
| 264 granted_permissions = prefs()->GetGrantedPermissions(extension_id_); | 265 granted_permissions = prefs()->GetGrantedPermissions(extension_id_); |
| 265 EXPECT_FALSE(granted_permissions->IsEmpty()); | 266 EXPECT_FALSE(granted_permissions->IsEmpty()); |
| 266 EXPECT_FALSE(granted_permissions->HasEffectiveFullAccess()); | 267 EXPECT_FALSE(granted_permissions->HasEffectiveFullAccess()); |
| 267 EXPECT_EQ(expected_apis, granted_permissions->apis()); | 268 EXPECT_EQ(expected_apis, granted_permissions->apis()); |
| 268 EXPECT_EQ(ehost_perm_set1_, | 269 EXPECT_EQ(ehost_perm_set1_, |
| 269 granted_permissions->explicit_hosts()); | 270 granted_permissions->explicit_hosts()); |
| 270 EXPECT_EQ(shost_perm_set1_, | 271 EXPECT_EQ(shost_perm_set1_, |
| 271 granted_permissions->scriptable_hosts()); | 272 granted_permissions->scriptable_hosts()); |
| 272 | 273 |
| 273 URLPatternSet::CreateUnion(ehost_perm_set1_, shost_perm_set1_, | 274 URLPatternSet::CreateUnion(ehost_perm_set1_, shost_perm_set1_, |
| 274 &effective_permissions_); | 275 &effective_permissions_); |
| 275 EXPECT_EQ(effective_permissions_, granted_permissions->effective_hosts()); | 276 EXPECT_EQ(effective_permissions_, granted_permissions->effective_hosts()); |
| 276 | 277 |
| 277 // Add the rest of the permissions. | 278 // Add the rest of the permissions. |
| 278 permissions = new PermissionSet( | 279 permissions = new PermissionSet( |
| 279 api_perm_set2_, ehost_perm_set2_, shost_perm_set2_); | 280 api_perm_set2_, empty_manifest_permissions, |
| 281 ehost_perm_set2_, shost_perm_set2_); |
| 280 | 282 |
| 281 APIPermissionSet::Union(expected_apis, api_perm_set2_, &api_permissions_); | 283 APIPermissionSet::Union(expected_apis, api_perm_set2_, &api_permissions_); |
| 282 | 284 |
| 283 prefs()->AddGrantedPermissions(extension_id_, permissions.get()); | 285 prefs()->AddGrantedPermissions(extension_id_, permissions.get()); |
| 284 granted_permissions = prefs()->GetGrantedPermissions(extension_id_); | 286 granted_permissions = prefs()->GetGrantedPermissions(extension_id_); |
| 285 EXPECT_TRUE(granted_permissions.get()); | 287 EXPECT_TRUE(granted_permissions.get()); |
| 286 EXPECT_FALSE(granted_permissions->IsEmpty()); | 288 EXPECT_FALSE(granted_permissions->IsEmpty()); |
| 287 EXPECT_EQ(api_permissions_, granted_permissions->apis()); | 289 EXPECT_EQ(api_permissions_, granted_permissions->apis()); |
| 288 EXPECT_EQ(ehost_permissions_, | 290 EXPECT_EQ(ehost_permissions_, |
| 289 granted_permissions->explicit_hosts()); | 291 granted_permissions->explicit_hosts()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 class ExtensionPrefsActivePermissions : public ExtensionPrefsTest { | 329 class ExtensionPrefsActivePermissions : public ExtensionPrefsTest { |
| 328 public: | 330 public: |
| 329 virtual void Initialize() OVERRIDE { | 331 virtual void Initialize() OVERRIDE { |
| 330 extension_id_ = prefs_.AddExtensionAndReturnId("test"); | 332 extension_id_ = prefs_.AddExtensionAndReturnId("test"); |
| 331 | 333 |
| 332 APIPermissionSet api_perms; | 334 APIPermissionSet api_perms; |
| 333 api_perms.insert(APIPermission::kTab); | 335 api_perms.insert(APIPermission::kTab); |
| 334 api_perms.insert(APIPermission::kBookmark); | 336 api_perms.insert(APIPermission::kBookmark); |
| 335 api_perms.insert(APIPermission::kHistory); | 337 api_perms.insert(APIPermission::kHistory); |
| 336 | 338 |
| 339 ManifestPermissionSet empty_manifest_permissions; |
| 340 |
| 337 URLPatternSet ehosts; | 341 URLPatternSet ehosts; |
| 338 AddPattern(&ehosts, "http://*.google.com/*"); | 342 AddPattern(&ehosts, "http://*.google.com/*"); |
| 339 AddPattern(&ehosts, "http://example.com/*"); | 343 AddPattern(&ehosts, "http://example.com/*"); |
| 340 AddPattern(&ehosts, "chrome://favicon/*"); | 344 AddPattern(&ehosts, "chrome://favicon/*"); |
| 341 | 345 |
| 342 URLPatternSet shosts; | 346 URLPatternSet shosts; |
| 343 AddPattern(&shosts, "https://*.google.com/*"); | 347 AddPattern(&shosts, "https://*.google.com/*"); |
| 344 AddPattern(&shosts, "http://reddit.com/r/test/*"); | 348 AddPattern(&shosts, "http://reddit.com/r/test/*"); |
| 345 | 349 |
| 346 active_perms_ = new PermissionSet(api_perms, ehosts, shosts); | 350 active_perms_ = new PermissionSet( |
| 351 api_perms, empty_manifest_permissions, ehosts, shosts); |
| 347 | 352 |
| 348 // Make sure the active permissions start empty. | 353 // Make sure the active permissions start empty. |
| 349 scoped_refptr<PermissionSet> active( | 354 scoped_refptr<PermissionSet> active( |
| 350 prefs()->GetActivePermissions(extension_id_)); | 355 prefs()->GetActivePermissions(extension_id_)); |
| 351 EXPECT_TRUE(active->IsEmpty()); | 356 EXPECT_TRUE(active->IsEmpty()); |
| 352 | 357 |
| 353 // Set the active permissions. | 358 // Set the active permissions. |
| 354 prefs()->SetActivePermissions(extension_id_, active_perms_.get()); | 359 prefs()->SetActivePermissions(extension_id_, active_perms_.get()); |
| 355 active = prefs()->GetActivePermissions(extension_id_); | 360 active = prefs()->GetActivePermissions(extension_id_); |
| 356 EXPECT_EQ(active_perms_->apis(), active->apis()); | 361 EXPECT_EQ(active_perms_->apis(), active->apis()); |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 | 836 |
| 832 private: | 837 private: |
| 833 scoped_refptr<const Extension> extension_a_; | 838 scoped_refptr<const Extension> extension_a_; |
| 834 scoped_refptr<const Extension> extension_b_; | 839 scoped_refptr<const Extension> extension_b_; |
| 835 scoped_refptr<const Extension> extension_c_; | 840 scoped_refptr<const Extension> extension_c_; |
| 836 }; | 841 }; |
| 837 TEST_F(ExtensionPrefsBlacklistedExtensions, | 842 TEST_F(ExtensionPrefsBlacklistedExtensions, |
| 838 ExtensionPrefsBlacklistedExtensions) {} | 843 ExtensionPrefsBlacklistedExtensions) {} |
| 839 | 844 |
| 840 } // namespace extensions | 845 } // namespace extensions |
| OLD | NEW |