OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_service_unittest.h" | 5 #include "chrome/browser/extensions/extension_service_unittest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1094 void SetPrefInteg(const std::string& extension_id, | 1094 void SetPrefInteg(const std::string& extension_id, |
1095 const std::string& pref_path, | 1095 const std::string& pref_path, |
1096 int value) { | 1096 int value) { |
1097 std::string msg = " while setting: "; | 1097 std::string msg = " while setting: "; |
1098 msg += extension_id; | 1098 msg += extension_id; |
1099 msg += " "; | 1099 msg += " "; |
1100 msg += pref_path; | 1100 msg += pref_path; |
1101 msg += " = "; | 1101 msg += " = "; |
1102 msg += base::IntToString(value); | 1102 msg += base::IntToString(value); |
1103 | 1103 |
1104 SetPref(extension_id, pref_path, Value::CreateIntegerValue(value), msg); | 1104 SetPref(extension_id, pref_path, new base::FundamentalValue(value), msg); |
1105 } | 1105 } |
1106 | 1106 |
1107 void SetPrefBool(const std::string& extension_id, | 1107 void SetPrefBool(const std::string& extension_id, |
1108 const std::string& pref_path, | 1108 const std::string& pref_path, |
1109 bool value) { | 1109 bool value) { |
1110 std::string msg = " while setting: "; | 1110 std::string msg = " while setting: "; |
1111 msg += extension_id + " " + pref_path; | 1111 msg += extension_id + " " + pref_path; |
1112 msg += " = "; | 1112 msg += " = "; |
1113 msg += (value ? "true" : "false"); | 1113 msg += (value ? "true" : "false"); |
1114 | 1114 |
1115 SetPref(extension_id, pref_path, Value::CreateBooleanValue(value), msg); | 1115 SetPref(extension_id, pref_path, new base::FundamentalValue(value), msg); |
1116 } | 1116 } |
1117 | 1117 |
1118 void ClearPref(const std::string& extension_id, | 1118 void ClearPref(const std::string& extension_id, |
1119 const std::string& pref_path) { | 1119 const std::string& pref_path) { |
1120 std::string msg = " while clearing: "; | 1120 std::string msg = " while clearing: "; |
1121 msg += extension_id + " " + pref_path; | 1121 msg += extension_id + " " + pref_path; |
1122 | 1122 |
1123 DictionaryPrefUpdate update(profile_->GetPrefs(), "extensions.settings"); | 1123 DictionaryPrefUpdate update(profile_->GetPrefs(), "extensions.settings"); |
1124 DictionaryValue* dict = update.Get(); | 1124 DictionaryValue* dict = update.Get(); |
1125 ASSERT_TRUE(dict != NULL) << msg; | 1125 ASSERT_TRUE(dict != NULL) << msg; |
1126 DictionaryValue* pref = NULL; | 1126 DictionaryValue* pref = NULL; |
1127 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; | 1127 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; |
1128 EXPECT_TRUE(pref != NULL) << msg; | 1128 EXPECT_TRUE(pref != NULL) << msg; |
1129 pref->Remove(pref_path, NULL); | 1129 pref->Remove(pref_path, NULL); |
1130 } | 1130 } |
1131 | 1131 |
1132 void SetPrefStringSet(const std::string& extension_id, | 1132 void SetPrefStringSet(const std::string& extension_id, |
1133 const std::string& pref_path, | 1133 const std::string& pref_path, |
1134 const std::set<std::string>& value) { | 1134 const std::set<std::string>& value) { |
1135 std::string msg = " while setting: "; | 1135 std::string msg = " while setting: "; |
1136 msg += extension_id + " " + pref_path; | 1136 msg += extension_id + " " + pref_path; |
1137 | 1137 |
1138 ListValue* list_value = new ListValue(); | 1138 ListValue* list_value = new ListValue(); |
1139 for (std::set<std::string>::const_iterator iter = value.begin(); | 1139 for (std::set<std::string>::const_iterator iter = value.begin(); |
1140 iter != value.end(); ++iter) | 1140 iter != value.end(); ++iter) |
1141 list_value->Append(Value::CreateStringValue(*iter)); | 1141 list_value->Append(new base::StringValue(*iter)); |
1142 | 1142 |
1143 SetPref(extension_id, pref_path, list_value, msg); | 1143 SetPref(extension_id, pref_path, list_value, msg); |
1144 } | 1144 } |
1145 | 1145 |
1146 void InitPluginService() { | 1146 void InitPluginService() { |
1147 #if defined(ENABLE_PLUGINS) | 1147 #if defined(ENABLE_PLUGINS) |
1148 PluginService::GetInstance()->Init(); | 1148 PluginService::GetInstance()->Init(); |
1149 #endif | 1149 #endif |
1150 } | 1150 } |
1151 | 1151 |
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2096 // permissions). | 2096 // permissions). |
2097 host_permissions.clear(); | 2097 host_permissions.clear(); |
2098 current_perms = NULL; | 2098 current_perms = NULL; |
2099 | 2099 |
2100 host_permissions.insert("http://*.google.com/*"); | 2100 host_permissions.insert("http://*.google.com/*"); |
2101 host_permissions.insert("https://*.google.com/*"); | 2101 host_permissions.insert("https://*.google.com/*"); |
2102 host_permissions.insert("http://*.google.com.hk/*"); | 2102 host_permissions.insert("http://*.google.com.hk/*"); |
2103 | 2103 |
2104 ListValue* api_permissions = new ListValue(); | 2104 ListValue* api_permissions = new ListValue(); |
2105 api_permissions->Append( | 2105 api_permissions->Append( |
2106 Value::CreateStringValue("tabs")); | 2106 new base::StringValue("tabs")); |
2107 SetPref(extension_id, "granted_permissions.api", | 2107 SetPref(extension_id, "granted_permissions.api", |
2108 api_permissions, "granted_permissions.api"); | 2108 api_permissions, "granted_permissions.api"); |
2109 SetPrefStringSet( | 2109 SetPrefStringSet( |
2110 extension_id, "granted_permissions.scriptable_host", host_permissions); | 2110 extension_id, "granted_permissions.scriptable_host", host_permissions); |
2111 | 2111 |
2112 service_->ReloadExtensions(); | 2112 service_->ReloadExtensions(); |
2113 | 2113 |
2114 EXPECT_EQ(1u, service_->disabled_extensions()->size()); | 2114 EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
2115 extension = service_->disabled_extensions()->begin()->get(); | 2115 extension = service_->disabled_extensions()->begin()->get(); |
2116 | 2116 |
(...skipping 1231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3348 InitializeEmptyExtensionService(); | 3348 InitializeEmptyExtensionService(); |
3349 base::FilePath path = data_dir_.AppendASCII("good.crx"); | 3349 base::FilePath path = data_dir_.AppendASCII("good.crx"); |
3350 | 3350 |
3351 const Extension* good = InstallCRX(path, INSTALL_NEW); | 3351 const Extension* good = InstallCRX(path, INSTALL_NEW); |
3352 EXPECT_EQ(good_crx, good->id()); | 3352 EXPECT_EQ(good_crx, good->id()); |
3353 UpdateExtension(good_crx, path, FAILED_SILENTLY); | 3353 UpdateExtension(good_crx, path, FAILED_SILENTLY); |
3354 EXPECT_EQ(1u, service_->extensions()->size()); | 3354 EXPECT_EQ(1u, service_->extensions()->size()); |
3355 | 3355 |
3356 base::ListValue whitelist; | 3356 base::ListValue whitelist; |
3357 PrefService* prefs = service_->extension_prefs()->pref_service(); | 3357 PrefService* prefs = service_->extension_prefs()->pref_service(); |
3358 whitelist.Append(base::Value::CreateStringValue(good_crx)); | 3358 whitelist.Append(new base::StringValue(good_crx)); |
3359 prefs->Set(prefs::kExtensionInstallAllowList, whitelist); | 3359 prefs->Set(prefs::kExtensionInstallAllowList, whitelist); |
3360 | 3360 |
3361 std::vector<std::string> blacklist; | 3361 std::vector<std::string> blacklist; |
3362 blacklist.push_back(good_crx); | 3362 blacklist.push_back(good_crx); |
3363 ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist, | 3363 ExtensionSystem::Get(profile_.get())->blacklist()->SetFromUpdater(blacklist, |
3364 "v1"); | 3364 "v1"); |
3365 | 3365 |
3366 // Make sure pref is updated | 3366 // Make sure pref is updated |
3367 base::RunLoop().RunUntilIdle(); | 3367 base::RunLoop().RunUntilIdle(); |
3368 | 3368 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3412 | 3412 |
3413 // Will not install extension blacklisted by policy. | 3413 // Will not install extension blacklisted by policy. |
3414 TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) { | 3414 TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) { |
3415 InitializeEmptyExtensionService(); | 3415 InitializeEmptyExtensionService(); |
3416 | 3416 |
3417 // Blacklist everything. | 3417 // Blacklist everything. |
3418 { | 3418 { |
3419 ListPrefUpdate update(profile_->GetPrefs(), | 3419 ListPrefUpdate update(profile_->GetPrefs(), |
3420 prefs::kExtensionInstallDenyList); | 3420 prefs::kExtensionInstallDenyList); |
3421 ListValue* blacklist = update.Get(); | 3421 ListValue* blacklist = update.Get(); |
3422 blacklist->Append(Value::CreateStringValue("*")); | 3422 blacklist->Append(new base::StringValue("*")); |
3423 } | 3423 } |
3424 | 3424 |
3425 // Blacklist prevents us from installing good_crx. | 3425 // Blacklist prevents us from installing good_crx. |
3426 base::FilePath path = data_dir_.AppendASCII("good.crx"); | 3426 base::FilePath path = data_dir_.AppendASCII("good.crx"); |
3427 InstallCRX(path, INSTALL_FAILED); | 3427 InstallCRX(path, INSTALL_FAILED); |
3428 EXPECT_EQ(0u, service_->extensions()->size()); | 3428 EXPECT_EQ(0u, service_->extensions()->size()); |
3429 | 3429 |
3430 // Now whitelist this particular extension. | 3430 // Now whitelist this particular extension. |
3431 { | 3431 { |
3432 ListPrefUpdate update(profile_->GetPrefs(), | 3432 ListPrefUpdate update(profile_->GetPrefs(), |
3433 prefs::kExtensionInstallAllowList); | 3433 prefs::kExtensionInstallAllowList); |
3434 ListValue* whitelist = update.Get(); | 3434 ListValue* whitelist = update.Get(); |
3435 whitelist->Append(Value::CreateStringValue(good_crx)); | 3435 whitelist->Append(new base::StringValue(good_crx)); |
3436 } | 3436 } |
3437 | 3437 |
3438 // Ensure we can now install good_crx. | 3438 // Ensure we can now install good_crx. |
3439 InstallCRX(path, INSTALL_NEW); | 3439 InstallCRX(path, INSTALL_NEW); |
3440 EXPECT_EQ(1u, service_->extensions()->size()); | 3440 EXPECT_EQ(1u, service_->extensions()->size()); |
3441 } | 3441 } |
3442 | 3442 |
3443 // Extension blacklisted by policy get unloaded after installing. | 3443 // Extension blacklisted by policy get unloaded after installing. |
3444 TEST_F(ExtensionServiceTest, BlacklistedByPolicyRemovedIfRunning) { | 3444 TEST_F(ExtensionServiceTest, BlacklistedByPolicyRemovedIfRunning) { |
3445 InitializeEmptyExtensionService(); | 3445 InitializeEmptyExtensionService(); |
3446 | 3446 |
3447 // Install good_crx. | 3447 // Install good_crx. |
3448 base::FilePath path = data_dir_.AppendASCII("good.crx"); | 3448 base::FilePath path = data_dir_.AppendASCII("good.crx"); |
3449 InstallCRX(path, INSTALL_NEW); | 3449 InstallCRX(path, INSTALL_NEW); |
3450 EXPECT_EQ(1u, service_->extensions()->size()); | 3450 EXPECT_EQ(1u, service_->extensions()->size()); |
3451 | 3451 |
3452 { // Scope for pref update notification. | 3452 { // Scope for pref update notification. |
3453 PrefService* prefs = profile_->GetPrefs(); | 3453 PrefService* prefs = profile_->GetPrefs(); |
3454 ListPrefUpdate update(prefs, prefs::kExtensionInstallDenyList); | 3454 ListPrefUpdate update(prefs, prefs::kExtensionInstallDenyList); |
3455 ListValue* blacklist = update.Get(); | 3455 ListValue* blacklist = update.Get(); |
3456 ASSERT_TRUE(blacklist != NULL); | 3456 ASSERT_TRUE(blacklist != NULL); |
3457 | 3457 |
3458 // Blacklist this extension. | 3458 // Blacklist this extension. |
3459 blacklist->Append(Value::CreateStringValue(good_crx)); | 3459 blacklist->Append(new base::StringValue(good_crx)); |
3460 } | 3460 } |
3461 | 3461 |
3462 // Extension should not be running now. | 3462 // Extension should not be running now. |
3463 base::RunLoop().RunUntilIdle(); | 3463 base::RunLoop().RunUntilIdle(); |
3464 EXPECT_EQ(0u, service_->extensions()->size()); | 3464 EXPECT_EQ(0u, service_->extensions()->size()); |
3465 } | 3465 } |
3466 | 3466 |
3467 // Tests that component extensions are not blacklisted by policy. | 3467 // Tests that component extensions are not blacklisted by policy. |
3468 TEST_F(ExtensionServiceTest, ComponentExtensionWhitelisted) { | 3468 TEST_F(ExtensionServiceTest, ComponentExtensionWhitelisted) { |
3469 InitializeEmptyExtensionService(); | 3469 InitializeEmptyExtensionService(); |
3470 | 3470 |
3471 // Blacklist everything. | 3471 // Blacklist everything. |
3472 { | 3472 { |
3473 ListPrefUpdate update(profile_->GetPrefs(), | 3473 ListPrefUpdate update(profile_->GetPrefs(), |
3474 prefs::kExtensionInstallDenyList); | 3474 prefs::kExtensionInstallDenyList); |
3475 ListValue* blacklist = update.Get(); | 3475 ListValue* blacklist = update.Get(); |
3476 blacklist->Append(Value::CreateStringValue("*")); | 3476 blacklist->Append(new base::StringValue("*")); |
3477 } | 3477 } |
3478 | 3478 |
3479 // Install a component extension. | 3479 // Install a component extension. |
3480 base::FilePath path = data_dir_ | 3480 base::FilePath path = data_dir_ |
3481 .AppendASCII("good") | 3481 .AppendASCII("good") |
3482 .AppendASCII("Extensions") | 3482 .AppendASCII("Extensions") |
3483 .AppendASCII(good0) | 3483 .AppendASCII(good0) |
3484 .AppendASCII("1.0.0.0"); | 3484 .AppendASCII("1.0.0.0"); |
3485 std::string manifest; | 3485 std::string manifest; |
3486 ASSERT_TRUE(file_util::ReadFileToString( | 3486 ASSERT_TRUE(file_util::ReadFileToString( |
3487 path.Append(extensions::kManifestFilename), &manifest)); | 3487 path.Append(extensions::kManifestFilename), &manifest)); |
3488 service_->component_loader()->Add(manifest, path); | 3488 service_->component_loader()->Add(manifest, path); |
3489 service_->Init(); | 3489 service_->Init(); |
3490 | 3490 |
3491 // Extension should be installed despite blacklist. | 3491 // Extension should be installed despite blacklist. |
3492 ASSERT_EQ(1u, service_->extensions()->size()); | 3492 ASSERT_EQ(1u, service_->extensions()->size()); |
3493 EXPECT_TRUE(service_->GetExtensionById(good0, false)); | 3493 EXPECT_TRUE(service_->GetExtensionById(good0, false)); |
3494 | 3494 |
3495 // Poke external providers and make sure the extension is still present. | 3495 // Poke external providers and make sure the extension is still present. |
3496 service_->CheckForExternalUpdates(); | 3496 service_->CheckForExternalUpdates(); |
3497 ASSERT_EQ(1u, service_->extensions()->size()); | 3497 ASSERT_EQ(1u, service_->extensions()->size()); |
3498 EXPECT_TRUE(service_->GetExtensionById(good0, false)); | 3498 EXPECT_TRUE(service_->GetExtensionById(good0, false)); |
3499 | 3499 |
3500 // Extension should not be uninstalled on blacklist changes. | 3500 // Extension should not be uninstalled on blacklist changes. |
3501 { | 3501 { |
3502 ListPrefUpdate update(profile_->GetPrefs(), | 3502 ListPrefUpdate update(profile_->GetPrefs(), |
3503 prefs::kExtensionInstallDenyList); | 3503 prefs::kExtensionInstallDenyList); |
3504 ListValue* blacklist = update.Get(); | 3504 ListValue* blacklist = update.Get(); |
3505 blacklist->Append(Value::CreateStringValue(good0)); | 3505 blacklist->Append(new base::StringValue(good0)); |
3506 } | 3506 } |
3507 base::RunLoop().RunUntilIdle(); | 3507 base::RunLoop().RunUntilIdle(); |
3508 ASSERT_EQ(1u, service_->extensions()->size()); | 3508 ASSERT_EQ(1u, service_->extensions()->size()); |
3509 EXPECT_TRUE(service_->GetExtensionById(good0, false)); | 3509 EXPECT_TRUE(service_->GetExtensionById(good0, false)); |
3510 } | 3510 } |
3511 | 3511 |
3512 // Tests that policy-installed extensions are not blacklisted by policy. | 3512 // Tests that policy-installed extensions are not blacklisted by policy. |
3513 TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) { | 3513 TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) { |
3514 InitializeEmptyExtensionService(); | 3514 InitializeEmptyExtensionService(); |
3515 | 3515 |
(...skipping 28 matching lines...) Expand all Loading... |
3544 | 3544 |
3545 // Extension should be installed despite blacklist. | 3545 // Extension should be installed despite blacklist. |
3546 ASSERT_EQ(1u, service_->extensions()->size()); | 3546 ASSERT_EQ(1u, service_->extensions()->size()); |
3547 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); | 3547 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
3548 | 3548 |
3549 // Blacklist update should not uninstall the extension. | 3549 // Blacklist update should not uninstall the extension. |
3550 { | 3550 { |
3551 ListPrefUpdate update(profile_->GetPrefs(), | 3551 ListPrefUpdate update(profile_->GetPrefs(), |
3552 prefs::kExtensionInstallDenyList); | 3552 prefs::kExtensionInstallDenyList); |
3553 ListValue* blacklist = update.Get(); | 3553 ListValue* blacklist = update.Get(); |
3554 blacklist->Append(Value::CreateStringValue(good0)); | 3554 blacklist->Append(new base::StringValue(good0)); |
3555 } | 3555 } |
3556 base::RunLoop().RunUntilIdle(); | 3556 base::RunLoop().RunUntilIdle(); |
3557 ASSERT_EQ(1u, service_->extensions()->size()); | 3557 ASSERT_EQ(1u, service_->extensions()->size()); |
3558 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); | 3558 EXPECT_TRUE(service_->GetExtensionById(good_crx, false)); |
3559 } | 3559 } |
3560 | 3560 |
3561 // Tests that extensions cannot be installed if the policy provider prohibits | 3561 // Tests that extensions cannot be installed if the policy provider prohibits |
3562 // it. This functionality is implemented in CrxInstaller::ConfirmInstall(). | 3562 // it. This functionality is implemented in CrxInstaller::ConfirmInstall(). |
3563 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsInstall) { | 3563 TEST_F(ExtensionServiceTest, ManagementPolicyProhibitsInstall) { |
3564 InitializeEmptyExtensionService(); | 3564 InitializeEmptyExtensionService(); |
(...skipping 2806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6371 EXPECT_TRUE(notifications.CheckNotifications( | 6371 EXPECT_TRUE(notifications.CheckNotifications( |
6372 chrome::NOTIFICATION_EXTENSION_INSTALLED)); | 6372 chrome::NOTIFICATION_EXTENSION_INSTALLED)); |
6373 | 6373 |
6374 EXPECT_TRUE(service_->GetInstalledExtension(id)); | 6374 EXPECT_TRUE(service_->GetInstalledExtension(id)); |
6375 EXPECT_FALSE(service_->extensions()->Contains(id)); | 6375 EXPECT_FALSE(service_->extensions()->Contains(id)); |
6376 EXPECT_TRUE(service_->blacklisted_extensions()->Contains(id)); | 6376 EXPECT_TRUE(service_->blacklisted_extensions()->Contains(id)); |
6377 EXPECT_TRUE(service_->extension_prefs()->IsExtensionBlacklisted(id)); | 6377 EXPECT_TRUE(service_->extension_prefs()->IsExtensionBlacklisted(id)); |
6378 EXPECT_TRUE( | 6378 EXPECT_TRUE( |
6379 service_->extension_prefs()->IsBlacklistedExtensionAcknowledged(id)); | 6379 service_->extension_prefs()->IsBlacklistedExtensionAcknowledged(id)); |
6380 } | 6380 } |
OLD | NEW |