Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/prefs/pref_registry_simple.h" | 8 #include "base/prefs/pref_registry_simple.h" |
| 9 #include "base/prefs/testing_pref_service.h" | 9 #include "base/prefs/testing_pref_service.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/extensions/extension_management.h" | 11 #include "chrome/browser/extensions/extension_management.h" |
| 12 #include "chrome/browser/extensions/external_policy_loader.h" | 12 #include "chrome/browser/extensions/external_policy_loader.h" |
| 13 #include "extensions/browser/pref_names.h" | 13 #include "extensions/browser/pref_names.h" |
| 14 #include "extensions/common/manifest_constants.h" | |
| 14 #include "extensions/common/url_pattern.h" | 15 #include "extensions/common/url_pattern.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 namespace extensions { | 18 namespace extensions { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 const char kTargetExtension[] = "abcdefghijklmnopabcdefghijklmnop"; | 21 const char kTargetExtension[] = "abcdefghijklmnopabcdefghijklmnop"; |
| 21 const char kOtherExtension[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 22 const char kOtherExtension[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 22 const char kExampleUpdateUrl[] = "http://example.com/update_url"; | 23 const char kExampleUpdateUrl[] = "http://example.com/update_url"; |
| 23 } // namespace | 24 } // namespace |
| 24 | 25 |
| 25 class ExtensionManagementTest : public testing::Test { | 26 class ExtensionManagementTest : public testing::Test { |
| 26 public: | 27 public: |
| 27 ExtensionManagementTest() {} | 28 ExtensionManagementTest() {} |
| 28 virtual ~ExtensionManagementTest() {} | 29 virtual ~ExtensionManagementTest() {} |
| 29 | 30 |
| 30 // testing::Test: | 31 // testing::Test: |
| 31 virtual void SetUp() OVERRIDE { | 32 virtual void SetUp() OVERRIDE { |
| 33 InitPrefService(); | |
| 34 } | |
| 35 | |
| 36 virtual void TearDown() OVERRIDE { | |
| 37 extension_management_.reset(); | |
| 38 pref_service_.reset(); | |
| 39 } | |
|
Joao da Silva
2014/09/04 10:17:46
This is not needed
binjin
2014/09/04 10:43:10
Done.
| |
| 40 | |
| 41 void InitPrefService() { | |
| 42 extension_management_.reset(); | |
| 32 pref_service_.reset(new TestingPrefServiceSimple()); | 43 pref_service_.reset(new TestingPrefServiceSimple()); |
| 33 pref_service_->registry()->RegisterListPref( | 44 pref_service_->registry()->RegisterListPref( |
| 34 pref_names::kAllowedInstallSites); | 45 pref_names::kAllowedInstallSites); |
| 35 pref_service_->registry()->RegisterListPref(pref_names::kAllowedTypes); | 46 pref_service_->registry()->RegisterListPref(pref_names::kAllowedTypes); |
| 36 pref_service_->registry()->RegisterListPref(pref_names::kInstallDenyList); | 47 pref_service_->registry()->RegisterListPref(pref_names::kInstallDenyList); |
| 37 pref_service_->registry()->RegisterListPref(pref_names::kInstallAllowList); | 48 pref_service_->registry()->RegisterListPref(pref_names::kInstallAllowList); |
| 38 pref_service_->registry()->RegisterDictionaryPref( | 49 pref_service_->registry()->RegisterDictionaryPref( |
| 39 pref_names::kInstallForceList); | 50 pref_names::kInstallForceList); |
| 40 extension_management_.reset(new ExtensionManagement(pref_service_.get())); | 51 extension_management_.reset(new ExtensionManagement(pref_service_.get())); |
| 41 } | 52 } |
| 42 | 53 |
| 43 void SetPref(bool managed, const char* path, base::Value* value) { | 54 void SetPref(bool managed, const char* path, base::Value* value) { |
| 44 if (managed) | 55 if (managed) |
| 45 pref_service_->SetManagedPref(path, value); | 56 pref_service_->SetManagedPref(path, value); |
| 46 else | 57 else |
| 47 pref_service_->SetUserPref(path, value); | 58 pref_service_->SetUserPref(path, value); |
| 48 } | 59 } |
| 49 | 60 |
| 50 void RemovePref(bool managed, const char* path) { | 61 void RemovePref(bool managed, const char* path) { |
| 51 if (managed) | 62 if (managed) |
| 52 pref_service_->RemoveManagedPref(path); | 63 pref_service_->RemoveManagedPref(path); |
| 53 else | 64 else |
| 54 pref_service_->RemoveUserPref(path); | 65 pref_service_->RemoveUserPref(path); |
| 55 } | 66 } |
| 56 | 67 |
| 57 void Refresh() { | |
| 58 extension_management_->Refresh(); | |
| 59 } | |
| 60 | |
| 61 protected: | 68 protected: |
| 62 scoped_ptr<TestingPrefServiceSimple> pref_service_; | 69 scoped_ptr<TestingPrefServiceSimple> pref_service_; |
| 63 scoped_ptr<ExtensionManagement> extension_management_; | 70 scoped_ptr<ExtensionManagement> extension_management_; |
| 64 }; | 71 }; |
| 65 | 72 |
| 73 class ExtensionAdminPolicyTest : public ExtensionManagementTest { | |
| 74 public: | |
| 75 ExtensionAdminPolicyTest() {} | |
| 76 virtual ~ExtensionAdminPolicyTest() {} | |
| 77 | |
| 78 void CreateExtension(Manifest::Location location) { | |
| 79 base::DictionaryValue values; | |
| 80 CreateExtensionFromValues(location, &values); | |
| 81 } | |
| 82 | |
| 83 void CreateHostedApp(Manifest::Location location) { | |
| 84 base::DictionaryValue values; | |
| 85 values.Set(extensions::manifest_keys::kWebURLs, new base::ListValue()); | |
| 86 values.SetString(extensions::manifest_keys::kLaunchWebURL, | |
| 87 "http://www.example.com"); | |
| 88 CreateExtensionFromValues(location, &values); | |
| 89 } | |
| 90 | |
| 91 void CreateExtensionFromValues(Manifest::Location location, | |
| 92 base::DictionaryValue* values) { | |
| 93 values->SetString(extensions::manifest_keys::kName, "test"); | |
| 94 values->SetString(extensions::manifest_keys::kVersion, "0.1"); | |
| 95 std::string error; | |
| 96 extension_ = Extension::Create(base::FilePath(), location, *values, | |
| 97 Extension::NO_FLAGS, &error); | |
| 98 ASSERT_TRUE(extension_.get()); | |
| 99 } | |
| 100 | |
| 101 // Wrappers for legacy admin policy functions, for testing purpose only. | |
| 102 bool BlacklistedByDefault(const base::ListValue* blacklist); | |
| 103 bool UserMayLoad(const base::ListValue* blacklist, | |
| 104 const base::ListValue* whitelist, | |
| 105 const base::DictionaryValue* forcelist, | |
| 106 const base::ListValue* allowed_types, | |
| 107 const Extension* extension, | |
| 108 base::string16* error); | |
| 109 bool UserMayModifySettings(const Extension* extension, base::string16* error); | |
| 110 bool MustRemainEnabled(const Extension* extension, base::string16* error); | |
| 111 | |
| 112 protected: | |
| 113 scoped_refptr<Extension> extension_; | |
| 114 }; | |
| 115 | |
| 116 bool ExtensionAdminPolicyTest::BlacklistedByDefault( | |
| 117 const base::ListValue* blacklist) { | |
| 118 InitPrefService(); | |
| 119 if (blacklist) | |
| 120 SetPref(true, pref_names::kInstallDenyList, blacklist->DeepCopy()); | |
| 121 return extension_management_->BlacklistedByDefault(); | |
| 122 } | |
| 123 | |
| 124 bool ExtensionAdminPolicyTest::UserMayLoad( | |
| 125 const base::ListValue* blacklist, | |
| 126 const base::ListValue* whitelist, | |
| 127 const base::DictionaryValue* forcelist, | |
| 128 const base::ListValue* allowed_types, | |
| 129 const Extension* extension, | |
| 130 base::string16* error) { | |
| 131 InitPrefService(); | |
| 132 if (blacklist) | |
| 133 SetPref(true, pref_names::kInstallDenyList, blacklist->DeepCopy()); | |
| 134 if (whitelist) | |
| 135 SetPref(true, pref_names::kInstallAllowList, whitelist->DeepCopy()); | |
| 136 if (forcelist) | |
| 137 SetPref(true, pref_names::kInstallForceList, forcelist->DeepCopy()); | |
| 138 if (allowed_types) | |
| 139 SetPref(true, pref_names::kAllowedTypes, allowed_types->DeepCopy()); | |
| 140 return extension_management_->GetProvider()->UserMayLoad(extension, error); | |
| 141 } | |
| 142 | |
| 143 bool ExtensionAdminPolicyTest::UserMayModifySettings(const Extension* extension, | |
| 144 base::string16* error) { | |
| 145 InitPrefService(); | |
| 146 return extension_management_->GetProvider()->UserMayModifySettings(extension, | |
| 147 error); | |
| 148 } | |
| 149 | |
| 150 bool ExtensionAdminPolicyTest::MustRemainEnabled(const Extension* extension, | |
| 151 base::string16* error) { | |
| 152 InitPrefService(); | |
| 153 return extension_management_->GetProvider()->MustRemainEnabled(extension, | |
| 154 error); | |
| 155 } | |
| 156 | |
| 66 // Verify that preference controlled by legacy ExtensionInstallSources policy is | 157 // Verify that preference controlled by legacy ExtensionInstallSources policy is |
| 67 // handled well. | 158 // handled well. |
| 68 TEST_F(ExtensionManagementTest, LegacyInstallSources) { | 159 TEST_F(ExtensionManagementTest, LegacyInstallSources) { |
| 69 base::ListValue allowed_sites_pref; | 160 base::ListValue allowed_sites_pref; |
| 70 allowed_sites_pref.AppendString("https://www.example.com/foo"); | 161 allowed_sites_pref.AppendString("https://www.example.com/foo"); |
| 71 allowed_sites_pref.AppendString("https://corp.mycompany.com/*"); | 162 allowed_sites_pref.AppendString("https://corp.mycompany.com/*"); |
| 72 SetPref( | 163 SetPref( |
| 73 true, pref_names::kAllowedInstallSites, allowed_sites_pref.DeepCopy()); | 164 true, pref_names::kAllowedInstallSites, allowed_sites_pref.DeepCopy()); |
| 74 Refresh(); | |
| 75 const URLPatternSet& allowed_sites = | 165 const URLPatternSet& allowed_sites = |
| 76 extension_management_->ReadGlobalSettings().install_sources; | 166 extension_management_->ReadGlobalSettings().install_sources; |
| 77 ASSERT_TRUE(extension_management_->ReadGlobalSettings() | 167 ASSERT_TRUE(extension_management_->ReadGlobalSettings() |
| 78 .has_restricted_install_sources); | 168 .has_restricted_install_sources); |
| 79 EXPECT_FALSE(allowed_sites.is_empty()); | 169 EXPECT_FALSE(allowed_sites.is_empty()); |
| 80 EXPECT_TRUE(allowed_sites.MatchesURL(GURL("https://www.example.com/foo"))); | 170 EXPECT_TRUE(allowed_sites.MatchesURL(GURL("https://www.example.com/foo"))); |
| 81 EXPECT_FALSE(allowed_sites.MatchesURL(GURL("https://www.example.com/bar"))); | 171 EXPECT_FALSE(allowed_sites.MatchesURL(GURL("https://www.example.com/bar"))); |
| 82 EXPECT_TRUE( | 172 EXPECT_TRUE( |
| 83 allowed_sites.MatchesURL(GURL("https://corp.mycompany.com/entry"))); | 173 allowed_sites.MatchesURL(GURL("https://corp.mycompany.com/entry"))); |
| 84 EXPECT_FALSE( | 174 EXPECT_FALSE( |
| 85 allowed_sites.MatchesURL(GURL("https://www.mycompany.com/entry"))); | 175 allowed_sites.MatchesURL(GURL("https://www.mycompany.com/entry"))); |
| 86 } | 176 } |
| 87 | 177 |
| 88 // Verify that preference controlled by legacy ExtensionAllowedTypes policy is | 178 // Verify that preference controlled by legacy ExtensionAllowedTypes policy is |
| 89 // handled well. | 179 // handled well. |
| 90 TEST_F(ExtensionManagementTest, LegacyAllowedTypes) { | 180 TEST_F(ExtensionManagementTest, LegacyAllowedTypes) { |
| 91 base::ListValue allowed_types_pref; | 181 base::ListValue allowed_types_pref; |
| 92 allowed_types_pref.AppendInteger(Manifest::TYPE_THEME); | 182 allowed_types_pref.AppendInteger(Manifest::TYPE_THEME); |
| 93 allowed_types_pref.AppendInteger(Manifest::TYPE_USER_SCRIPT); | 183 allowed_types_pref.AppendInteger(Manifest::TYPE_USER_SCRIPT); |
| 94 | 184 |
| 95 SetPref(true, pref_names::kAllowedTypes, allowed_types_pref.DeepCopy()); | 185 SetPref(true, pref_names::kAllowedTypes, allowed_types_pref.DeepCopy()); |
| 96 Refresh(); | |
| 97 const std::vector<Manifest::Type>& allowed_types = | 186 const std::vector<Manifest::Type>& allowed_types = |
| 98 extension_management_->ReadGlobalSettings().allowed_types; | 187 extension_management_->ReadGlobalSettings().allowed_types; |
| 99 ASSERT_TRUE( | 188 ASSERT_TRUE( |
| 100 extension_management_->ReadGlobalSettings().has_restricted_allowed_types); | 189 extension_management_->ReadGlobalSettings().has_restricted_allowed_types); |
| 101 EXPECT_TRUE(allowed_types.size() == 2); | 190 EXPECT_TRUE(allowed_types.size() == 2); |
| 102 EXPECT_FALSE(std::find(allowed_types.begin(), | 191 EXPECT_FALSE(std::find(allowed_types.begin(), |
| 103 allowed_types.end(), | 192 allowed_types.end(), |
| 104 Manifest::TYPE_EXTENSION) != allowed_types.end()); | 193 Manifest::TYPE_EXTENSION) != allowed_types.end()); |
| 105 EXPECT_TRUE(std::find(allowed_types.begin(), | 194 EXPECT_TRUE(std::find(allowed_types.begin(), |
| 106 allowed_types.end(), | 195 allowed_types.end(), |
| 107 Manifest::TYPE_THEME) != allowed_types.end()); | 196 Manifest::TYPE_THEME) != allowed_types.end()); |
| 108 EXPECT_TRUE(std::find(allowed_types.begin(), | 197 EXPECT_TRUE(std::find(allowed_types.begin(), |
| 109 allowed_types.end(), | 198 allowed_types.end(), |
| 110 Manifest::TYPE_USER_SCRIPT) != allowed_types.end()); | 199 Manifest::TYPE_USER_SCRIPT) != allowed_types.end()); |
| 111 } | 200 } |
| 112 | 201 |
| 113 // Verify that preference controlled by legacy ExtensionInstallBlacklist policy | 202 // Verify that preference controlled by legacy ExtensionInstallBlacklist policy |
| 114 // is handled well. | 203 // is handled well. |
| 115 TEST_F(ExtensionManagementTest, LegacyInstallBlacklist) { | 204 TEST_F(ExtensionManagementTest, LegacyInstallBlacklist) { |
| 116 base::ListValue denied_list_pref; | 205 base::ListValue denied_list_pref; |
| 117 denied_list_pref.AppendString(kTargetExtension); | 206 denied_list_pref.AppendString(kTargetExtension); |
| 118 | 207 |
| 119 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); | 208 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); |
| 120 Refresh(); | |
| 121 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, | 209 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, |
| 122 ExtensionManagement::INSTALLATION_BLOCKED); | 210 ExtensionManagement::INSTALLATION_BLOCKED); |
| 123 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode, | 211 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode, |
| 124 ExtensionManagement::INSTALLATION_ALLOWED); | 212 ExtensionManagement::INSTALLATION_ALLOWED); |
| 125 } | 213 } |
| 126 | 214 |
| 127 // Verify that preference controlled by legacy ExtensionInstallWhitelist policy | 215 // Verify that preference controlled by legacy ExtensionInstallWhitelist policy |
| 128 // is handled well. | 216 // is handled well. |
| 129 TEST_F(ExtensionManagementTest, LegacyInstallWhitelist) { | 217 TEST_F(ExtensionManagementTest, LegacyInstallWhitelist) { |
| 130 base::ListValue denied_list_pref; | 218 base::ListValue denied_list_pref; |
| 131 denied_list_pref.AppendString("*"); | 219 denied_list_pref.AppendString("*"); |
| 132 base::ListValue allowed_list_pref; | 220 base::ListValue allowed_list_pref; |
| 133 allowed_list_pref.AppendString(kTargetExtension); | 221 allowed_list_pref.AppendString(kTargetExtension); |
| 134 | 222 |
| 135 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); | 223 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); |
| 136 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); | 224 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); |
| 137 Refresh(); | |
| 138 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, | 225 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, |
| 139 ExtensionManagement::INSTALLATION_ALLOWED); | 226 ExtensionManagement::INSTALLATION_ALLOWED); |
| 140 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode, | 227 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode, |
| 141 ExtensionManagement::INSTALLATION_BLOCKED); | 228 ExtensionManagement::INSTALLATION_BLOCKED); |
| 142 | 229 |
| 143 // Verify that install whitelist preference set by user is ignored. | 230 // Verify that install whitelist preference set by user is ignored. |
| 144 RemovePref(true, pref_names::kInstallAllowList); | 231 RemovePref(true, pref_names::kInstallAllowList); |
| 145 SetPref(false, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); | 232 SetPref(false, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); |
| 146 Refresh(); | |
| 147 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, | 233 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, |
| 148 ExtensionManagement::INSTALLATION_BLOCKED); | 234 ExtensionManagement::INSTALLATION_BLOCKED); |
| 149 } | 235 } |
| 150 | 236 |
| 151 // Verify that preference controlled by legacy ExtensionInstallForcelist policy | 237 // Verify that preference controlled by legacy ExtensionInstallForcelist policy |
| 152 // is handled well. | 238 // is handled well. |
| 153 TEST_F(ExtensionManagementTest, LegacyInstallForcelist) { | 239 TEST_F(ExtensionManagementTest, LegacyInstallForcelist) { |
| 154 base::DictionaryValue forced_list_pref; | 240 base::DictionaryValue forced_list_pref; |
| 155 ExternalPolicyLoader::AddExtension( | 241 ExternalPolicyLoader::AddExtension( |
| 156 &forced_list_pref, kTargetExtension, kExampleUpdateUrl); | 242 &forced_list_pref, kTargetExtension, kExampleUpdateUrl); |
| 157 | 243 |
| 158 SetPref(true, pref_names::kInstallForceList, forced_list_pref.DeepCopy()); | 244 SetPref(true, pref_names::kInstallForceList, forced_list_pref.DeepCopy()); |
| 159 Refresh(); | |
| 160 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, | 245 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, |
| 161 ExtensionManagement::INSTALLATION_FORCED); | 246 ExtensionManagement::INSTALLATION_FORCED); |
| 162 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).update_url, | 247 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).update_url, |
| 163 kExampleUpdateUrl); | 248 kExampleUpdateUrl); |
| 164 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode, | 249 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode, |
| 165 ExtensionManagement::INSTALLATION_ALLOWED); | 250 ExtensionManagement::INSTALLATION_ALLOWED); |
| 166 | 251 |
| 167 // Verify that install forcelist preference set by user is ignored. | 252 // Verify that install forcelist preference set by user is ignored. |
| 168 RemovePref(true, pref_names::kInstallForceList); | 253 RemovePref(true, pref_names::kInstallForceList); |
| 169 SetPref(false, pref_names::kInstallForceList, forced_list_pref.DeepCopy()); | 254 SetPref(false, pref_names::kInstallForceList, forced_list_pref.DeepCopy()); |
| 170 Refresh(); | |
| 171 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, | 255 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, |
| 172 ExtensionManagement::INSTALLATION_ALLOWED); | 256 ExtensionManagement::INSTALLATION_ALLOWED); |
| 173 } | 257 } |
| 174 | 258 |
| 259 // Tests the flag value indicating that extensions are blacklisted by default. | |
| 260 TEST_F(ExtensionAdminPolicyTest, BlacklistedByDefault) { | |
| 261 EXPECT_FALSE(BlacklistedByDefault(NULL)); | |
| 262 | |
| 263 base::ListValue blacklist; | |
| 264 blacklist.Append(new base::StringValue(kOtherExtension)); | |
| 265 EXPECT_FALSE(BlacklistedByDefault(&blacklist)); | |
| 266 blacklist.Append(new base::StringValue("*")); | |
| 267 EXPECT_TRUE(BlacklistedByDefault(&blacklist)); | |
| 268 | |
| 269 blacklist.Clear(); | |
| 270 blacklist.Append(new base::StringValue("*")); | |
| 271 EXPECT_TRUE(BlacklistedByDefault(&blacklist)); | |
| 272 } | |
| 273 | |
| 274 // Tests UserMayLoad for required extensions. | |
| 275 TEST_F(ExtensionAdminPolicyTest, UserMayLoadRequired) { | |
| 276 CreateExtension(Manifest::COMPONENT); | |
| 277 EXPECT_TRUE(UserMayLoad(NULL, NULL, NULL, NULL, extension_.get(), NULL)); | |
| 278 base::string16 error; | |
| 279 EXPECT_TRUE(UserMayLoad(NULL, NULL, NULL, NULL, extension_.get(), &error)); | |
| 280 EXPECT_TRUE(error.empty()); | |
| 281 | |
| 282 // Required extensions may load even if they're on the blacklist. | |
| 283 base::ListValue blacklist; | |
| 284 blacklist.Append(new base::StringValue(extension_->id())); | |
| 285 EXPECT_TRUE( | |
| 286 UserMayLoad(&blacklist, NULL, NULL, NULL, extension_.get(), NULL)); | |
| 287 | |
| 288 blacklist.Append(new base::StringValue("*")); | |
| 289 EXPECT_TRUE( | |
| 290 UserMayLoad(&blacklist, NULL, NULL, NULL, extension_.get(), NULL)); | |
| 291 } | |
| 292 | |
| 293 // Tests UserMayLoad when no blacklist exists, or it's empty. | |
| 294 TEST_F(ExtensionAdminPolicyTest, UserMayLoadNoBlacklist) { | |
| 295 CreateExtension(Manifest::INTERNAL); | |
| 296 EXPECT_TRUE(UserMayLoad(NULL, NULL, NULL, NULL, extension_.get(), NULL)); | |
| 297 base::ListValue blacklist; | |
| 298 EXPECT_TRUE( | |
| 299 UserMayLoad(&blacklist, NULL, NULL, NULL, extension_.get(), NULL)); | |
| 300 base::string16 error; | |
| 301 EXPECT_TRUE( | |
| 302 UserMayLoad(&blacklist, NULL, NULL, NULL, extension_.get(), &error)); | |
| 303 EXPECT_TRUE(error.empty()); | |
| 304 } | |
| 305 | |
| 306 // Tests UserMayLoad for an extension on the whitelist. | |
| 307 TEST_F(ExtensionAdminPolicyTest, UserMayLoadWhitelisted) { | |
| 308 CreateExtension(Manifest::INTERNAL); | |
| 309 | |
| 310 base::ListValue whitelist; | |
| 311 whitelist.Append(new base::StringValue(extension_->id())); | |
| 312 EXPECT_TRUE( | |
| 313 UserMayLoad(NULL, &whitelist, NULL, NULL, extension_.get(), NULL)); | |
| 314 | |
| 315 base::ListValue blacklist; | |
| 316 blacklist.Append(new base::StringValue(extension_->id())); | |
| 317 EXPECT_TRUE( | |
| 318 UserMayLoad(NULL, &whitelist, NULL, NULL, extension_.get(), NULL)); | |
| 319 base::string16 error; | |
| 320 EXPECT_TRUE( | |
| 321 UserMayLoad(NULL, &whitelist, NULL, NULL, extension_.get(), &error)); | |
| 322 EXPECT_TRUE(error.empty()); | |
| 323 } | |
| 324 | |
| 325 // Tests UserMayLoad for an extension on the blacklist. | |
| 326 TEST_F(ExtensionAdminPolicyTest, UserMayLoadBlacklisted) { | |
| 327 CreateExtension(Manifest::INTERNAL); | |
| 328 | |
| 329 // Blacklisted by default. | |
| 330 base::ListValue blacklist; | |
| 331 blacklist.Append(new base::StringValue("*")); | |
| 332 EXPECT_FALSE( | |
| 333 UserMayLoad(&blacklist, NULL, NULL, NULL, extension_.get(), NULL)); | |
| 334 base::string16 error; | |
| 335 EXPECT_FALSE( | |
| 336 UserMayLoad(&blacklist, NULL, NULL, NULL, extension_.get(), &error)); | |
| 337 EXPECT_FALSE(error.empty()); | |
| 338 | |
| 339 // Extension on the blacklist, with and without wildcard. | |
| 340 blacklist.Append(new base::StringValue(extension_->id())); | |
| 341 EXPECT_FALSE( | |
| 342 UserMayLoad(&blacklist, NULL, NULL, NULL, extension_.get(), NULL)); | |
| 343 blacklist.Clear(); | |
| 344 blacklist.Append(new base::StringValue(extension_->id())); | |
| 345 EXPECT_FALSE( | |
| 346 UserMayLoad(&blacklist, NULL, NULL, NULL, extension_.get(), NULL)); | |
| 347 | |
| 348 // With a whitelist. There's no such thing as a whitelist wildcard. | |
| 349 base::ListValue whitelist; | |
| 350 whitelist.Append(new base::StringValue("behllobkkfkfnphdnhnkndlbkcpglgmj")); | |
| 351 EXPECT_FALSE( | |
| 352 UserMayLoad(&blacklist, &whitelist, NULL, NULL, extension_.get(), NULL)); | |
| 353 whitelist.Append(new base::StringValue("*")); | |
| 354 EXPECT_FALSE( | |
| 355 UserMayLoad(&blacklist, &whitelist, NULL, NULL, extension_.get(), NULL)); | |
| 356 } | |
| 357 | |
| 358 TEST_F(ExtensionAdminPolicyTest, UserMayLoadAllowedTypes) { | |
| 359 CreateExtension(Manifest::INTERNAL); | |
| 360 EXPECT_TRUE(UserMayLoad(NULL, NULL, NULL, NULL, extension_.get(), NULL)); | |
| 361 | |
| 362 base::ListValue allowed_types; | |
| 363 EXPECT_FALSE( | |
| 364 UserMayLoad(NULL, NULL, NULL, &allowed_types, extension_.get(), NULL)); | |
| 365 | |
| 366 allowed_types.AppendInteger(Manifest::TYPE_EXTENSION); | |
| 367 EXPECT_TRUE( | |
| 368 UserMayLoad(NULL, NULL, NULL, &allowed_types, extension_.get(), NULL)); | |
| 369 | |
| 370 CreateHostedApp(Manifest::INTERNAL); | |
| 371 EXPECT_FALSE( | |
| 372 UserMayLoad(NULL, NULL, NULL, &allowed_types, extension_.get(), NULL)); | |
| 373 | |
| 374 CreateHostedApp(Manifest::EXTERNAL_POLICY_DOWNLOAD); | |
| 375 EXPECT_FALSE( | |
| 376 UserMayLoad(NULL, NULL, NULL, &allowed_types, extension_.get(), NULL)); | |
| 377 } | |
| 378 | |
| 379 TEST_F(ExtensionAdminPolicyTest, UserMayModifySettings) { | |
| 380 CreateExtension(Manifest::INTERNAL); | |
| 381 EXPECT_TRUE(UserMayModifySettings(extension_.get(), NULL)); | |
| 382 base::string16 error; | |
| 383 EXPECT_TRUE(UserMayModifySettings(extension_.get(), &error)); | |
| 384 EXPECT_TRUE(error.empty()); | |
| 385 | |
| 386 CreateExtension(Manifest::EXTERNAL_POLICY_DOWNLOAD); | |
| 387 error.clear(); | |
| 388 EXPECT_FALSE(UserMayModifySettings(extension_.get(), NULL)); | |
| 389 EXPECT_FALSE(UserMayModifySettings(extension_.get(), &error)); | |
| 390 EXPECT_FALSE(error.empty()); | |
| 391 } | |
| 392 | |
| 393 TEST_F(ExtensionAdminPolicyTest, MustRemainEnabled) { | |
| 394 CreateExtension(Manifest::EXTERNAL_POLICY_DOWNLOAD); | |
| 395 EXPECT_TRUE(MustRemainEnabled(extension_.get(), NULL)); | |
| 396 base::string16 error; | |
| 397 EXPECT_TRUE(MustRemainEnabled(extension_.get(), &error)); | |
| 398 EXPECT_FALSE(error.empty()); | |
| 399 | |
| 400 CreateExtension(Manifest::INTERNAL); | |
| 401 error.clear(); | |
| 402 EXPECT_FALSE(MustRemainEnabled(extension_.get(), NULL)); | |
| 403 EXPECT_FALSE(MustRemainEnabled(extension_.get(), &error)); | |
| 404 EXPECT_TRUE(error.empty()); | |
| 405 } | |
| 406 | |
| 175 } // namespace extensions | 407 } // namespace extensions |
| OLD | NEW |