| 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/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 class ExtensionPrefsGrantedPermissions : public ExtensionPrefsTest { | 160 class ExtensionPrefsGrantedPermissions : public ExtensionPrefsTest { |
| 161 public: | 161 public: |
| 162 void Initialize() override { | 162 void Initialize() override { |
| 163 const APIPermissionInfo* permission_info = | 163 const APIPermissionInfo* permission_info = |
| 164 PermissionsInfo::GetInstance()->GetByID(APIPermission::kSocket); | 164 PermissionsInfo::GetInstance()->GetByID(APIPermission::kSocket); |
| 165 | 165 |
| 166 extension_id_ = prefs_.AddExtensionAndReturnId("test"); | 166 extension_id_ = prefs_.AddExtensionAndReturnId("test"); |
| 167 | 167 |
| 168 api_perm_set1_.insert(APIPermission::kTab); | 168 api_perm_set1_.insert(APIPermission::kTab); |
| 169 api_perm_set1_.insert(APIPermission::kBookmark); | 169 api_perm_set1_.insert(APIPermission::kBookmark); |
| 170 scoped_ptr<APIPermission> permission( | 170 std::unique_ptr<APIPermission> permission( |
| 171 permission_info->CreateAPIPermission()); | 171 permission_info->CreateAPIPermission()); |
| 172 { | 172 { |
| 173 scoped_ptr<base::ListValue> value(new base::ListValue()); | 173 std::unique_ptr<base::ListValue> value(new base::ListValue()); |
| 174 value->Append(new base::StringValue("tcp-connect:*.example.com:80")); | 174 value->Append(new base::StringValue("tcp-connect:*.example.com:80")); |
| 175 value->Append(new base::StringValue("udp-bind::8080")); | 175 value->Append(new base::StringValue("udp-bind::8080")); |
| 176 value->Append(new base::StringValue("udp-send-to::8888")); | 176 value->Append(new base::StringValue("udp-send-to::8888")); |
| 177 ASSERT_TRUE(permission->FromValue(value.get(), NULL, NULL)); | 177 ASSERT_TRUE(permission->FromValue(value.get(), NULL, NULL)); |
| 178 } | 178 } |
| 179 api_perm_set1_.insert(permission.release()); | 179 api_perm_set1_.insert(permission.release()); |
| 180 | 180 |
| 181 api_perm_set2_.insert(APIPermission::kHistory); | 181 api_perm_set2_.insert(APIPermission::kHistory); |
| 182 | 182 |
| 183 AddPattern(&ehost_perm_set1_, "http://*.google.com/*"); | 183 AddPattern(&ehost_perm_set1_, "http://*.google.com/*"); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 210 | 210 |
| 211 // Make sure both granted api and host permissions start empty. | 211 // Make sure both granted api and host permissions start empty. |
| 212 EXPECT_TRUE(prefs()->GetGrantedPermissions(extension_id_)->IsEmpty()); | 212 EXPECT_TRUE(prefs()->GetGrantedPermissions(extension_id_)->IsEmpty()); |
| 213 | 213 |
| 214 { | 214 { |
| 215 // Add part of the api permissions. | 215 // Add part of the api permissions. |
| 216 prefs()->AddGrantedPermissions( | 216 prefs()->AddGrantedPermissions( |
| 217 extension_id_, | 217 extension_id_, |
| 218 PermissionSet(api_perm_set1_, empty_manifest_permissions, | 218 PermissionSet(api_perm_set1_, empty_manifest_permissions, |
| 219 empty_extent, empty_extent)); | 219 empty_extent, empty_extent)); |
| 220 scoped_ptr<const PermissionSet> granted_permissions = | 220 std::unique_ptr<const PermissionSet> granted_permissions = |
| 221 prefs()->GetGrantedPermissions(extension_id_); | 221 prefs()->GetGrantedPermissions(extension_id_); |
| 222 EXPECT_TRUE(granted_permissions.get()); | 222 EXPECT_TRUE(granted_permissions.get()); |
| 223 EXPECT_FALSE(granted_permissions->IsEmpty()); | 223 EXPECT_FALSE(granted_permissions->IsEmpty()); |
| 224 EXPECT_EQ(expected_apis, granted_permissions->apis()); | 224 EXPECT_EQ(expected_apis, granted_permissions->apis()); |
| 225 EXPECT_TRUE(granted_permissions->effective_hosts().is_empty()); | 225 EXPECT_TRUE(granted_permissions->effective_hosts().is_empty()); |
| 226 EXPECT_FALSE(granted_permissions->HasEffectiveFullAccess()); | 226 EXPECT_FALSE(granted_permissions->HasEffectiveFullAccess()); |
| 227 } | 227 } |
| 228 | 228 |
| 229 { | 229 { |
| 230 // Add part of the explicit host permissions. | 230 // Add part of the explicit host permissions. |
| 231 prefs()->AddGrantedPermissions( | 231 prefs()->AddGrantedPermissions( |
| 232 extension_id_, PermissionSet(empty_set, empty_manifest_permissions, | 232 extension_id_, PermissionSet(empty_set, empty_manifest_permissions, |
| 233 ehost_perm_set1_, empty_extent)); | 233 ehost_perm_set1_, empty_extent)); |
| 234 scoped_ptr<const PermissionSet> granted_permissions = | 234 std::unique_ptr<const PermissionSet> granted_permissions = |
| 235 prefs()->GetGrantedPermissions(extension_id_); | 235 prefs()->GetGrantedPermissions(extension_id_); |
| 236 EXPECT_FALSE(granted_permissions->IsEmpty()); | 236 EXPECT_FALSE(granted_permissions->IsEmpty()); |
| 237 EXPECT_FALSE(granted_permissions->HasEffectiveFullAccess()); | 237 EXPECT_FALSE(granted_permissions->HasEffectiveFullAccess()); |
| 238 EXPECT_EQ(expected_apis, granted_permissions->apis()); | 238 EXPECT_EQ(expected_apis, granted_permissions->apis()); |
| 239 EXPECT_EQ(ehost_perm_set1_, granted_permissions->explicit_hosts()); | 239 EXPECT_EQ(ehost_perm_set1_, granted_permissions->explicit_hosts()); |
| 240 EXPECT_EQ(ehost_perm_set1_, granted_permissions->effective_hosts()); | 240 EXPECT_EQ(ehost_perm_set1_, granted_permissions->effective_hosts()); |
| 241 } | 241 } |
| 242 | 242 |
| 243 { | 243 { |
| 244 // Add part of the scriptable host permissions. | 244 // Add part of the scriptable host permissions. |
| 245 prefs()->AddGrantedPermissions( | 245 prefs()->AddGrantedPermissions( |
| 246 extension_id_, PermissionSet(empty_set, empty_manifest_permissions, | 246 extension_id_, PermissionSet(empty_set, empty_manifest_permissions, |
| 247 empty_extent, shost_perm_set1_)); | 247 empty_extent, shost_perm_set1_)); |
| 248 scoped_ptr<const PermissionSet> granted_permissions = | 248 std::unique_ptr<const PermissionSet> granted_permissions = |
| 249 prefs()->GetGrantedPermissions(extension_id_); | 249 prefs()->GetGrantedPermissions(extension_id_); |
| 250 EXPECT_FALSE(granted_permissions->IsEmpty()); | 250 EXPECT_FALSE(granted_permissions->IsEmpty()); |
| 251 EXPECT_FALSE(granted_permissions->HasEffectiveFullAccess()); | 251 EXPECT_FALSE(granted_permissions->HasEffectiveFullAccess()); |
| 252 EXPECT_EQ(expected_apis, granted_permissions->apis()); | 252 EXPECT_EQ(expected_apis, granted_permissions->apis()); |
| 253 EXPECT_EQ(ehost_perm_set1_, granted_permissions->explicit_hosts()); | 253 EXPECT_EQ(ehost_perm_set1_, granted_permissions->explicit_hosts()); |
| 254 EXPECT_EQ(shost_perm_set1_, granted_permissions->scriptable_hosts()); | 254 EXPECT_EQ(shost_perm_set1_, granted_permissions->scriptable_hosts()); |
| 255 | 255 |
| 256 effective_permissions_ = | 256 effective_permissions_ = |
| 257 URLPatternSet::CreateUnion(ehost_perm_set1_, shost_perm_set1_); | 257 URLPatternSet::CreateUnion(ehost_perm_set1_, shost_perm_set1_); |
| 258 EXPECT_EQ(effective_permissions_, granted_permissions->effective_hosts()); | 258 EXPECT_EQ(effective_permissions_, granted_permissions->effective_hosts()); |
| 259 } | 259 } |
| 260 | 260 |
| 261 { | 261 { |
| 262 // Add the rest of the permissions. | 262 // Add the rest of the permissions. |
| 263 APIPermissionSet::Union(expected_apis, api_perm_set2_, &api_permissions_); | 263 APIPermissionSet::Union(expected_apis, api_perm_set2_, &api_permissions_); |
| 264 prefs()->AddGrantedPermissions( | 264 prefs()->AddGrantedPermissions( |
| 265 extension_id_, | 265 extension_id_, |
| 266 PermissionSet(api_perm_set2_, empty_manifest_permissions, | 266 PermissionSet(api_perm_set2_, empty_manifest_permissions, |
| 267 ehost_perm_set2_, shost_perm_set2_)); | 267 ehost_perm_set2_, shost_perm_set2_)); |
| 268 | 268 |
| 269 scoped_ptr<const PermissionSet> granted_permissions = | 269 std::unique_ptr<const PermissionSet> granted_permissions = |
| 270 prefs()->GetGrantedPermissions(extension_id_); | 270 prefs()->GetGrantedPermissions(extension_id_); |
| 271 EXPECT_TRUE(granted_permissions.get()); | 271 EXPECT_TRUE(granted_permissions.get()); |
| 272 EXPECT_FALSE(granted_permissions->IsEmpty()); | 272 EXPECT_FALSE(granted_permissions->IsEmpty()); |
| 273 EXPECT_EQ(api_permissions_, granted_permissions->apis()); | 273 EXPECT_EQ(api_permissions_, granted_permissions->apis()); |
| 274 EXPECT_EQ(ehost_permissions_, granted_permissions->explicit_hosts()); | 274 EXPECT_EQ(ehost_permissions_, granted_permissions->explicit_hosts()); |
| 275 EXPECT_EQ(shost_permissions_, granted_permissions->scriptable_hosts()); | 275 EXPECT_EQ(shost_permissions_, granted_permissions->scriptable_hosts()); |
| 276 effective_permissions_ = | 276 effective_permissions_ = |
| 277 URLPatternSet::CreateUnion(ehost_permissions_, shost_permissions_); | 277 URLPatternSet::CreateUnion(ehost_permissions_, shost_permissions_); |
| 278 EXPECT_EQ(effective_permissions_, granted_permissions->effective_hosts()); | 278 EXPECT_EQ(effective_permissions_, granted_permissions->effective_hosts()); |
| 279 } | 279 } |
| 280 } | 280 } |
| 281 | 281 |
| 282 void Verify() override { | 282 void Verify() override { |
| 283 scoped_ptr<const PermissionSet> permissions = | 283 std::unique_ptr<const PermissionSet> permissions = |
| 284 prefs()->GetGrantedPermissions(extension_id_); | 284 prefs()->GetGrantedPermissions(extension_id_); |
| 285 EXPECT_TRUE(permissions.get()); | 285 EXPECT_TRUE(permissions.get()); |
| 286 EXPECT_FALSE(permissions->HasEffectiveFullAccess()); | 286 EXPECT_FALSE(permissions->HasEffectiveFullAccess()); |
| 287 EXPECT_EQ(api_permissions_, permissions->apis()); | 287 EXPECT_EQ(api_permissions_, permissions->apis()); |
| 288 EXPECT_EQ(ehost_permissions_, | 288 EXPECT_EQ(ehost_permissions_, |
| 289 permissions->explicit_hosts()); | 289 permissions->explicit_hosts()); |
| 290 EXPECT_EQ(shost_permissions_, | 290 EXPECT_EQ(shost_permissions_, |
| 291 permissions->scriptable_hosts()); | 291 permissions->scriptable_hosts()); |
| 292 } | 292 } |
| 293 | 293 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 AddPattern(&ehosts, "chrome://favicon/*"); | 326 AddPattern(&ehosts, "chrome://favicon/*"); |
| 327 | 327 |
| 328 URLPatternSet shosts; | 328 URLPatternSet shosts; |
| 329 AddPattern(&shosts, "https://*.google.com/*"); | 329 AddPattern(&shosts, "https://*.google.com/*"); |
| 330 AddPattern(&shosts, "http://reddit.com/r/test/*"); | 330 AddPattern(&shosts, "http://reddit.com/r/test/*"); |
| 331 | 331 |
| 332 active_perms_.reset(new PermissionSet(api_perms, empty_manifest_permissions, | 332 active_perms_.reset(new PermissionSet(api_perms, empty_manifest_permissions, |
| 333 ehosts, shosts)); | 333 ehosts, shosts)); |
| 334 | 334 |
| 335 // Make sure the active permissions start empty. | 335 // Make sure the active permissions start empty. |
| 336 scoped_ptr<const PermissionSet> active = | 336 std::unique_ptr<const PermissionSet> active = |
| 337 prefs()->GetActivePermissions(extension_id_); | 337 prefs()->GetActivePermissions(extension_id_); |
| 338 EXPECT_TRUE(active->IsEmpty()); | 338 EXPECT_TRUE(active->IsEmpty()); |
| 339 | 339 |
| 340 // Set the active permissions. | 340 // Set the active permissions. |
| 341 prefs()->SetActivePermissions(extension_id_, *active_perms_); | 341 prefs()->SetActivePermissions(extension_id_, *active_perms_); |
| 342 active = prefs()->GetActivePermissions(extension_id_); | 342 active = prefs()->GetActivePermissions(extension_id_); |
| 343 EXPECT_EQ(active_perms_->apis(), active->apis()); | 343 EXPECT_EQ(active_perms_->apis(), active->apis()); |
| 344 EXPECT_EQ(active_perms_->explicit_hosts(), active->explicit_hosts()); | 344 EXPECT_EQ(active_perms_->explicit_hosts(), active->explicit_hosts()); |
| 345 EXPECT_EQ(active_perms_->scriptable_hosts(), active->scriptable_hosts()); | 345 EXPECT_EQ(active_perms_->scriptable_hosts(), active->scriptable_hosts()); |
| 346 EXPECT_EQ(*active_perms_, *active); | 346 EXPECT_EQ(*active_perms_, *active); |
| 347 } | 347 } |
| 348 | 348 |
| 349 void Verify() override { | 349 void Verify() override { |
| 350 scoped_ptr<const PermissionSet> permissions = | 350 std::unique_ptr<const PermissionSet> permissions = |
| 351 prefs()->GetActivePermissions(extension_id_); | 351 prefs()->GetActivePermissions(extension_id_); |
| 352 EXPECT_EQ(*active_perms_, *permissions); | 352 EXPECT_EQ(*active_perms_, *permissions); |
| 353 } | 353 } |
| 354 | 354 |
| 355 private: | 355 private: |
| 356 std::string extension_id_; | 356 std::string extension_id_; |
| 357 scoped_ptr<const PermissionSet> active_perms_; | 357 std::unique_ptr<const PermissionSet> active_perms_; |
| 358 }; | 358 }; |
| 359 TEST_F(ExtensionPrefsActivePermissions, SetAndGetActivePermissions) {} | 359 TEST_F(ExtensionPrefsActivePermissions, SetAndGetActivePermissions) {} |
| 360 | 360 |
| 361 // Tests the GetVersionString function. | 361 // Tests the GetVersionString function. |
| 362 class ExtensionPrefsVersionString : public ExtensionPrefsTest { | 362 class ExtensionPrefsVersionString : public ExtensionPrefsTest { |
| 363 public: | 363 public: |
| 364 void Initialize() override { | 364 void Initialize() override { |
| 365 extension = prefs_.AddExtension("test"); | 365 extension = prefs_.AddExtension("test"); |
| 366 EXPECT_EQ("0.1", prefs()->GetVersionString(extension->id())); | 366 EXPECT_EQ("0.1", prefs()->GetVersionString(extension->id())); |
| 367 prefs()->OnExtensionUninstalled(extension->id(), | 367 prefs()->OnExtensionUninstalled(extension->id(), |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 Extension::ENABLED, | 459 Extension::ENABLED, |
| 460 kInstallFlagNone, | 460 kInstallFlagNone, |
| 461 ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE, | 461 ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE, |
| 462 syncer::StringOrdinal(), | 462 syncer::StringOrdinal(), |
| 463 std::string()); | 463 std::string()); |
| 464 } | 464 } |
| 465 | 465 |
| 466 // Verifies that we get back expected idle install information previously | 466 // Verifies that we get back expected idle install information previously |
| 467 // set by SetIdleInfo. | 467 // set by SetIdleInfo. |
| 468 void VerifyIdleInfo(const std::string& id, int num) { | 468 void VerifyIdleInfo(const std::string& id, int num) { |
| 469 scoped_ptr<ExtensionInfo> info(prefs()->GetDelayedInstallInfo(id)); | 469 std::unique_ptr<ExtensionInfo> info(prefs()->GetDelayedInstallInfo(id)); |
| 470 ASSERT_TRUE(info); | 470 ASSERT_TRUE(info); |
| 471 std::string version; | 471 std::string version; |
| 472 ASSERT_TRUE(info->extension_manifest->GetString("version", &version)); | 472 ASSERT_TRUE(info->extension_manifest->GetString("version", &version)); |
| 473 ASSERT_EQ("1." + base::IntToString(num), version); | 473 ASSERT_EQ("1." + base::IntToString(num), version); |
| 474 ASSERT_EQ(base::IntToString(num), | 474 ASSERT_EQ(base::IntToString(num), |
| 475 info->extension_path.BaseName().MaybeAsASCII()); | 475 info->extension_path.BaseName().MaybeAsASCII()); |
| 476 } | 476 } |
| 477 | 477 |
| 478 bool HasInfoForId(ExtensionPrefs::ExtensionsInfo* info, | 478 bool HasInfoForId(ExtensionPrefs::ExtensionsInfo* info, |
| 479 const std::string& id) { | 479 const std::string& id) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 490 id1_ = prefs_.AddExtensionAndReturnId("1"); | 490 id1_ = prefs_.AddExtensionAndReturnId("1"); |
| 491 id2_ = prefs_.AddExtensionAndReturnId("2"); | 491 id2_ = prefs_.AddExtensionAndReturnId("2"); |
| 492 id3_ = prefs_.AddExtensionAndReturnId("3"); | 492 id3_ = prefs_.AddExtensionAndReturnId("3"); |
| 493 id4_ = prefs_.AddExtensionAndReturnId("4"); | 493 id4_ = prefs_.AddExtensionAndReturnId("4"); |
| 494 | 494 |
| 495 // Set info for two extensions, then remove it. | 495 // Set info for two extensions, then remove it. |
| 496 SetIdleInfo(id1_, 1); | 496 SetIdleInfo(id1_, 1); |
| 497 SetIdleInfo(id2_, 2); | 497 SetIdleInfo(id2_, 2); |
| 498 VerifyIdleInfo(id1_, 1); | 498 VerifyIdleInfo(id1_, 1); |
| 499 VerifyIdleInfo(id2_, 2); | 499 VerifyIdleInfo(id2_, 2); |
| 500 scoped_ptr<ExtensionPrefs::ExtensionsInfo> info( | 500 std::unique_ptr<ExtensionPrefs::ExtensionsInfo> info( |
| 501 prefs()->GetAllDelayedInstallInfo()); | 501 prefs()->GetAllDelayedInstallInfo()); |
| 502 EXPECT_EQ(2u, info->size()); | 502 EXPECT_EQ(2u, info->size()); |
| 503 EXPECT_TRUE(HasInfoForId(info.get(), id1_)); | 503 EXPECT_TRUE(HasInfoForId(info.get(), id1_)); |
| 504 EXPECT_TRUE(HasInfoForId(info.get(), id2_)); | 504 EXPECT_TRUE(HasInfoForId(info.get(), id2_)); |
| 505 prefs()->RemoveDelayedInstallInfo(id1_); | 505 prefs()->RemoveDelayedInstallInfo(id1_); |
| 506 prefs()->RemoveDelayedInstallInfo(id2_); | 506 prefs()->RemoveDelayedInstallInfo(id2_); |
| 507 info = prefs()->GetAllDelayedInstallInfo(); | 507 info = prefs()->GetAllDelayedInstallInfo(); |
| 508 EXPECT_TRUE(info->empty()); | 508 EXPECT_TRUE(info->empty()); |
| 509 | 509 |
| 510 // Try getting/removing info for an id that used to have info set. | 510 // Try getting/removing info for an id that used to have info set. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 522 SetIdleInfo(id4_, 4); | 522 SetIdleInfo(id4_, 4); |
| 523 VerifyIdleInfo(id1_, 1); | 523 VerifyIdleInfo(id1_, 1); |
| 524 VerifyIdleInfo(id2_, 2); | 524 VerifyIdleInfo(id2_, 2); |
| 525 VerifyIdleInfo(id3_, 3); | 525 VerifyIdleInfo(id3_, 3); |
| 526 VerifyIdleInfo(id4_, 4); | 526 VerifyIdleInfo(id4_, 4); |
| 527 prefs()->RemoveDelayedInstallInfo(id3_); | 527 prefs()->RemoveDelayedInstallInfo(id3_); |
| 528 } | 528 } |
| 529 | 529 |
| 530 void Verify() override { | 530 void Verify() override { |
| 531 // Make sure the info for the 3 extensions we expect is present. | 531 // Make sure the info for the 3 extensions we expect is present. |
| 532 scoped_ptr<ExtensionPrefs::ExtensionsInfo> info( | 532 std::unique_ptr<ExtensionPrefs::ExtensionsInfo> info( |
| 533 prefs()->GetAllDelayedInstallInfo()); | 533 prefs()->GetAllDelayedInstallInfo()); |
| 534 EXPECT_EQ(3u, info->size()); | 534 EXPECT_EQ(3u, info->size()); |
| 535 EXPECT_TRUE(HasInfoForId(info.get(), id1_)); | 535 EXPECT_TRUE(HasInfoForId(info.get(), id1_)); |
| 536 EXPECT_TRUE(HasInfoForId(info.get(), id2_)); | 536 EXPECT_TRUE(HasInfoForId(info.get(), id2_)); |
| 537 EXPECT_TRUE(HasInfoForId(info.get(), id4_)); | 537 EXPECT_TRUE(HasInfoForId(info.get(), id4_)); |
| 538 VerifyIdleInfo(id1_, 1); | 538 VerifyIdleInfo(id1_, 1); |
| 539 VerifyIdleInfo(id2_, 2); | 539 VerifyIdleInfo(id2_, 2); |
| 540 VerifyIdleInfo(id4_, 4); | 540 VerifyIdleInfo(id4_, 4); |
| 541 | 541 |
| 542 // Make sure there isn't info the for the one extension id we removed. | 542 // Make sure there isn't info the for the one extension id we removed. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 563 dictionary.SetString(manifest_keys::kBackgroundPage, "background.html"); | 563 dictionary.SetString(manifest_keys::kBackgroundPage, "background.html"); |
| 564 scoped_refptr<Extension> extension = | 564 scoped_refptr<Extension> extension = |
| 565 prefs_.AddExtensionWithManifest(dictionary, Manifest::INTERNAL); | 565 prefs_.AddExtensionWithManifest(dictionary, Manifest::INTERNAL); |
| 566 id_ = extension->id(); | 566 id_ = extension->id(); |
| 567 | 567 |
| 568 | 568 |
| 569 // Set idle info | 569 // Set idle info |
| 570 base::DictionaryValue manifest; | 570 base::DictionaryValue manifest; |
| 571 manifest.SetString(manifest_keys::kName, "test"); | 571 manifest.SetString(manifest_keys::kName, "test"); |
| 572 manifest.SetString(manifest_keys::kVersion, "0.2"); | 572 manifest.SetString(manifest_keys::kVersion, "0.2"); |
| 573 scoped_ptr<base::ListValue> scripts(new base::ListValue); | 573 std::unique_ptr<base::ListValue> scripts(new base::ListValue); |
| 574 scripts->AppendString("test.js"); | 574 scripts->AppendString("test.js"); |
| 575 manifest.Set(manifest_keys::kBackgroundScripts, scripts.release()); | 575 manifest.Set(manifest_keys::kBackgroundScripts, scripts.release()); |
| 576 base::FilePath path = | 576 base::FilePath path = |
| 577 prefs_.extensions_dir().AppendASCII("test_0.2"); | 577 prefs_.extensions_dir().AppendASCII("test_0.2"); |
| 578 std::string errors; | 578 std::string errors; |
| 579 scoped_refptr<Extension> new_extension = Extension::Create( | 579 scoped_refptr<Extension> new_extension = Extension::Create( |
| 580 path, Manifest::INTERNAL, manifest, Extension::NO_FLAGS, id_, &errors); | 580 path, Manifest::INTERNAL, manifest, Extension::NO_FLAGS, id_, &errors); |
| 581 ASSERT_TRUE(new_extension.get()) << errors; | 581 ASSERT_TRUE(new_extension.get()) << errors; |
| 582 ASSERT_EQ(id_, new_extension->id()); | 582 ASSERT_EQ(id_, new_extension->id()); |
| 583 prefs()->SetDelayedInstallInfo(new_extension.get(), | 583 prefs()->SetDelayedInstallInfo(new_extension.get(), |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 956 active_perms_.reset(new PermissionSet(api_perms, empty_manifest_permissions, | 956 active_perms_.reset(new PermissionSet(api_perms, empty_manifest_permissions, |
| 957 ehosts, shosts)); | 957 ehosts, shosts)); |
| 958 // Set the active permissions. | 958 // Set the active permissions. |
| 959 prefs()->SetActivePermissions(component_extension_->id(), *active_perms_); | 959 prefs()->SetActivePermissions(component_extension_->id(), *active_perms_); |
| 960 prefs()->SetActivePermissions(no_component_extension_->id(), | 960 prefs()->SetActivePermissions(no_component_extension_->id(), |
| 961 *active_perms_); | 961 *active_perms_); |
| 962 } | 962 } |
| 963 | 963 |
| 964 void Verify() override { | 964 void Verify() override { |
| 965 // Component extension can access chrome://print/*. | 965 // Component extension can access chrome://print/*. |
| 966 scoped_ptr<const PermissionSet> component_permissions = | 966 std::unique_ptr<const PermissionSet> component_permissions = |
| 967 prefs()->GetActivePermissions(component_extension_->id()); | 967 prefs()->GetActivePermissions(component_extension_->id()); |
| 968 EXPECT_EQ(1u, component_permissions->scriptable_hosts().size()); | 968 EXPECT_EQ(1u, component_permissions->scriptable_hosts().size()); |
| 969 | 969 |
| 970 // Non Component extension can not access chrome://print/*. | 970 // Non Component extension can not access chrome://print/*. |
| 971 scoped_ptr<const PermissionSet> no_component_permissions = | 971 std::unique_ptr<const PermissionSet> no_component_permissions = |
| 972 prefs()->GetActivePermissions(no_component_extension_->id()); | 972 prefs()->GetActivePermissions(no_component_extension_->id()); |
| 973 EXPECT_EQ(0u, no_component_permissions->scriptable_hosts().size()); | 973 EXPECT_EQ(0u, no_component_permissions->scriptable_hosts().size()); |
| 974 | 974 |
| 975 // |URLPattern::SCHEME_CHROMEUI| scheme will be added in valid_schemes for | 975 // |URLPattern::SCHEME_CHROMEUI| scheme will be added in valid_schemes for |
| 976 // component extensions. | 976 // component extensions. |
| 977 URLPatternSet scriptable_hosts; | 977 URLPatternSet scriptable_hosts; |
| 978 std::string pref_key = "active_permissions.scriptable_host"; | 978 std::string pref_key = "active_permissions.scriptable_host"; |
| 979 int valid_schemes = URLPattern::SCHEME_ALL & ~URLPattern::SCHEME_CHROMEUI; | 979 int valid_schemes = URLPattern::SCHEME_ALL & ~URLPattern::SCHEME_CHROMEUI; |
| 980 | 980 |
| 981 EXPECT_TRUE(prefs()->ReadPrefAsURLPatternSet(component_extension_->id(), | 981 EXPECT_TRUE(prefs()->ReadPrefAsURLPatternSet(component_extension_->id(), |
| 982 pref_key, &scriptable_hosts, | 982 pref_key, &scriptable_hosts, |
| 983 valid_schemes)); | 983 valid_schemes)); |
| 984 | 984 |
| 985 EXPECT_FALSE(prefs()->ReadPrefAsURLPatternSet(no_component_extension_->id(), | 985 EXPECT_FALSE(prefs()->ReadPrefAsURLPatternSet(no_component_extension_->id(), |
| 986 pref_key, &scriptable_hosts, | 986 pref_key, &scriptable_hosts, |
| 987 valid_schemes)); | 987 valid_schemes)); |
| 988 } | 988 } |
| 989 | 989 |
| 990 private: | 990 private: |
| 991 scoped_ptr<const PermissionSet> active_perms_; | 991 std::unique_ptr<const PermissionSet> active_perms_; |
| 992 scoped_refptr<Extension> component_extension_; | 992 scoped_refptr<Extension> component_extension_; |
| 993 scoped_refptr<Extension> no_component_extension_; | 993 scoped_refptr<Extension> no_component_extension_; |
| 994 }; | 994 }; |
| 995 TEST_F(ExtensionPrefsComponentExtension, ExtensionPrefsComponentExtension) { | 995 TEST_F(ExtensionPrefsComponentExtension, ExtensionPrefsComponentExtension) { |
| 996 } | 996 } |
| 997 | 997 |
| 998 } // namespace extensions | 998 } // namespace extensions |
| OLD | NEW |