| 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 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/json/json_parser.h" | 8 #include "base/json/json_parser.h" |
| 9 #include "base/memory/linked_ptr.h" |
| 9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/prefs/pref_registry_simple.h" | 11 #include "base/prefs/pref_registry_simple.h" |
| 11 #include "base/prefs/testing_pref_service.h" | 12 #include "base/prefs/testing_pref_service.h" |
| 12 #include "base/values.h" | 13 #include "base/values.h" |
| 13 #include "chrome/browser/extensions/extension_management.h" | 14 #include "chrome/browser/extensions/extension_management.h" |
| 15 #include "chrome/browser/extensions/extension_management_internal.h" |
| 14 #include "chrome/browser/extensions/extension_management_test_util.h" | 16 #include "chrome/browser/extensions/extension_management_test_util.h" |
| 15 #include "chrome/browser/extensions/external_policy_loader.h" | 17 #include "chrome/browser/extensions/external_policy_loader.h" |
| 16 #include "extensions/browser/pref_names.h" | 18 #include "extensions/browser/pref_names.h" |
| 17 #include "extensions/common/manifest.h" | 19 #include "extensions/common/manifest.h" |
| 18 #include "extensions/common/manifest_constants.h" | 20 #include "extensions/common/manifest_constants.h" |
| 19 #include "extensions/common/url_pattern.h" | 21 #include "extensions/common/url_pattern.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 22 | 24 |
| 23 namespace extensions { | 25 namespace extensions { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 pref_service_->SetUserPref(path, value); | 88 pref_service_->SetUserPref(path, value); |
| 87 } | 89 } |
| 88 | 90 |
| 89 void RemovePref(bool managed, const char* path) { | 91 void RemovePref(bool managed, const char* path) { |
| 90 if (managed) | 92 if (managed) |
| 91 pref_service_->RemoveManagedPref(path); | 93 pref_service_->RemoveManagedPref(path); |
| 92 else | 94 else |
| 93 pref_service_->RemoveUserPref(path); | 95 pref_service_->RemoveUserPref(path); |
| 94 } | 96 } |
| 95 | 97 |
| 98 linked_ptr<const internal::IndividualSettings> ReadById( |
| 99 const ExtensionId& id) { |
| 100 return extension_management_->ReadById(id); |
| 101 } |
| 102 |
| 103 linked_ptr<const internal::GlobalSettings> ReadGlobalSettings() { |
| 104 return extension_management_->ReadGlobalSettings(); |
| 105 } |
| 106 |
| 96 void SetExampleDictPref() { | 107 void SetExampleDictPref() { |
| 97 std::string error_msg; | 108 std::string error_msg; |
| 98 scoped_ptr<base::Value> parsed(base::JSONReader::ReadAndReturnError( | 109 scoped_ptr<base::Value> parsed(base::JSONReader::ReadAndReturnError( |
| 99 kExampleDictPreference, | 110 kExampleDictPreference, |
| 100 base::JSONParserOptions::JSON_ALLOW_TRAILING_COMMAS, | 111 base::JSONParserOptions::JSON_ALLOW_TRAILING_COMMAS, |
| 101 NULL, | 112 NULL, |
| 102 &error_msg)); | 113 &error_msg)); |
| 103 ASSERT_TRUE(parsed && parsed->IsType(base::Value::TYPE_DICTIONARY)) | 114 ASSERT_TRUE(parsed && parsed->IsType(base::Value::TYPE_DICTIONARY)) |
| 104 << error_msg; | 115 << error_msg; |
| 105 SetPref(true, pref_names::kExtensionManagement, parsed.release()); | 116 SetPref(true, pref_names::kExtensionManagement, parsed.release()); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 } | 206 } |
| 196 | 207 |
| 197 // Verify that preference controlled by legacy ExtensionInstallSources policy is | 208 // Verify that preference controlled by legacy ExtensionInstallSources policy is |
| 198 // handled well. | 209 // handled well. |
| 199 TEST_F(ExtensionManagementServiceTest, LegacyInstallSources) { | 210 TEST_F(ExtensionManagementServiceTest, LegacyInstallSources) { |
| 200 base::ListValue allowed_sites_pref; | 211 base::ListValue allowed_sites_pref; |
| 201 allowed_sites_pref.AppendString("https://www.example.com/foo"); | 212 allowed_sites_pref.AppendString("https://www.example.com/foo"); |
| 202 allowed_sites_pref.AppendString("https://corp.mycompany.com/*"); | 213 allowed_sites_pref.AppendString("https://corp.mycompany.com/*"); |
| 203 SetPref( | 214 SetPref( |
| 204 true, pref_names::kAllowedInstallSites, allowed_sites_pref.DeepCopy()); | 215 true, pref_names::kAllowedInstallSites, allowed_sites_pref.DeepCopy()); |
| 205 const URLPatternSet& allowed_sites = | 216 const URLPatternSet& allowed_sites = ReadGlobalSettings()->install_sources; |
| 206 extension_management_->ReadGlobalSettings().install_sources; | 217 ASSERT_TRUE(ReadGlobalSettings()->has_restricted_install_sources); |
| 207 ASSERT_TRUE(extension_management_->ReadGlobalSettings() | |
| 208 .has_restricted_install_sources); | |
| 209 EXPECT_FALSE(allowed_sites.is_empty()); | 218 EXPECT_FALSE(allowed_sites.is_empty()); |
| 210 EXPECT_TRUE(allowed_sites.MatchesURL(GURL("https://www.example.com/foo"))); | 219 EXPECT_TRUE(allowed_sites.MatchesURL(GURL("https://www.example.com/foo"))); |
| 211 EXPECT_FALSE(allowed_sites.MatchesURL(GURL("https://www.example.com/bar"))); | 220 EXPECT_FALSE(allowed_sites.MatchesURL(GURL("https://www.example.com/bar"))); |
| 212 EXPECT_TRUE( | 221 EXPECT_TRUE( |
| 213 allowed_sites.MatchesURL(GURL("https://corp.mycompany.com/entry"))); | 222 allowed_sites.MatchesURL(GURL("https://corp.mycompany.com/entry"))); |
| 214 EXPECT_FALSE( | 223 EXPECT_FALSE( |
| 215 allowed_sites.MatchesURL(GURL("https://www.mycompany.com/entry"))); | 224 allowed_sites.MatchesURL(GURL("https://www.mycompany.com/entry"))); |
| 216 } | 225 } |
| 217 | 226 |
| 218 // Verify that preference controlled by legacy ExtensionAllowedTypes policy is | 227 // Verify that preference controlled by legacy ExtensionAllowedTypes policy is |
| 219 // handled well. | 228 // handled well. |
| 220 TEST_F(ExtensionManagementServiceTest, LegacyAllowedTypes) { | 229 TEST_F(ExtensionManagementServiceTest, LegacyAllowedTypes) { |
| 221 base::ListValue allowed_types_pref; | 230 base::ListValue allowed_types_pref; |
| 222 allowed_types_pref.AppendInteger(Manifest::TYPE_THEME); | 231 allowed_types_pref.AppendInteger(Manifest::TYPE_THEME); |
| 223 allowed_types_pref.AppendInteger(Manifest::TYPE_USER_SCRIPT); | 232 allowed_types_pref.AppendInteger(Manifest::TYPE_USER_SCRIPT); |
| 224 | 233 |
| 225 SetPref(true, pref_names::kAllowedTypes, allowed_types_pref.DeepCopy()); | 234 SetPref(true, pref_names::kAllowedTypes, allowed_types_pref.DeepCopy()); |
| 226 const std::vector<Manifest::Type>& allowed_types = | 235 const std::vector<Manifest::Type>& allowed_types = |
| 227 extension_management_->ReadGlobalSettings().allowed_types; | 236 ReadGlobalSettings()->allowed_types; |
| 228 ASSERT_TRUE( | 237 ASSERT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types); |
| 229 extension_management_->ReadGlobalSettings().has_restricted_allowed_types); | |
| 230 EXPECT_TRUE(allowed_types.size() == 2); | 238 EXPECT_TRUE(allowed_types.size() == 2); |
| 231 EXPECT_FALSE(std::find(allowed_types.begin(), | 239 EXPECT_FALSE(std::find(allowed_types.begin(), |
| 232 allowed_types.end(), | 240 allowed_types.end(), |
| 233 Manifest::TYPE_EXTENSION) != allowed_types.end()); | 241 Manifest::TYPE_EXTENSION) != allowed_types.end()); |
| 234 EXPECT_TRUE(std::find(allowed_types.begin(), | 242 EXPECT_TRUE(std::find(allowed_types.begin(), |
| 235 allowed_types.end(), | 243 allowed_types.end(), |
| 236 Manifest::TYPE_THEME) != allowed_types.end()); | 244 Manifest::TYPE_THEME) != allowed_types.end()); |
| 237 EXPECT_TRUE(std::find(allowed_types.begin(), | 245 EXPECT_TRUE(std::find(allowed_types.begin(), |
| 238 allowed_types.end(), | 246 allowed_types.end(), |
| 239 Manifest::TYPE_USER_SCRIPT) != allowed_types.end()); | 247 Manifest::TYPE_USER_SCRIPT) != allowed_types.end()); |
| 240 } | 248 } |
| 241 | 249 |
| 242 // Verify that preference controlled by legacy ExtensionInstallBlacklist policy | 250 // Verify that preference controlled by legacy ExtensionInstallBlacklist policy |
| 243 // is handled well. | 251 // is handled well. |
| 244 TEST_F(ExtensionManagementServiceTest, LegacyInstallBlacklist) { | 252 TEST_F(ExtensionManagementServiceTest, LegacyInstallBlacklist) { |
| 245 base::ListValue denied_list_pref; | 253 base::ListValue denied_list_pref; |
| 246 denied_list_pref.AppendString(kTargetExtension); | 254 denied_list_pref.AppendString(kTargetExtension); |
| 247 | 255 |
| 248 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); | 256 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); |
| 249 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, | 257 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, |
| 250 ExtensionManagement::INSTALLATION_BLOCKED); | 258 ExtensionManagement::INSTALLATION_BLOCKED); |
| 251 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode, | 259 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, |
| 252 ExtensionManagement::INSTALLATION_ALLOWED); | 260 ExtensionManagement::INSTALLATION_ALLOWED); |
| 253 } | 261 } |
| 254 | 262 |
| 255 // Verify that preference controlled by legacy ExtensionInstallWhitelist policy | 263 // Verify that preference controlled by legacy ExtensionInstallWhitelist policy |
| 256 // is handled well. | 264 // is handled well. |
| 257 TEST_F(ExtensionManagementServiceTest, LegacyInstallWhitelist) { | 265 TEST_F(ExtensionManagementServiceTest, LegacyInstallWhitelist) { |
| 258 base::ListValue denied_list_pref; | 266 base::ListValue denied_list_pref; |
| 259 denied_list_pref.AppendString("*"); | 267 denied_list_pref.AppendString("*"); |
| 260 base::ListValue allowed_list_pref; | 268 base::ListValue allowed_list_pref; |
| 261 allowed_list_pref.AppendString(kTargetExtension); | 269 allowed_list_pref.AppendString(kTargetExtension); |
| 262 | 270 |
| 263 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); | 271 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); |
| 264 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); | 272 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); |
| 265 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, | 273 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, |
| 266 ExtensionManagement::INSTALLATION_ALLOWED); | 274 ExtensionManagement::INSTALLATION_ALLOWED); |
| 267 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode, | 275 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, |
| 268 ExtensionManagement::INSTALLATION_BLOCKED); | 276 ExtensionManagement::INSTALLATION_BLOCKED); |
| 269 | 277 |
| 270 // Verify that install whitelist preference set by user is ignored. | 278 // Verify that install whitelist preference set by user is ignored. |
| 271 RemovePref(true, pref_names::kInstallAllowList); | 279 RemovePref(true, pref_names::kInstallAllowList); |
| 272 SetPref(false, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); | 280 SetPref(false, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); |
| 273 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, | 281 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, |
| 274 ExtensionManagement::INSTALLATION_BLOCKED); | 282 ExtensionManagement::INSTALLATION_BLOCKED); |
| 275 } | 283 } |
| 276 | 284 |
| 277 // Verify that preference controlled by legacy ExtensionInstallForcelist policy | 285 // Verify that preference controlled by legacy ExtensionInstallForcelist policy |
| 278 // is handled well. | 286 // is handled well. |
| 279 TEST_F(ExtensionManagementServiceTest, LegacyInstallForcelist) { | 287 TEST_F(ExtensionManagementServiceTest, LegacyInstallForcelist) { |
| 280 base::DictionaryValue forced_list_pref; | 288 base::DictionaryValue forced_list_pref; |
| 281 ExternalPolicyLoader::AddExtension( | 289 ExternalPolicyLoader::AddExtension( |
| 282 &forced_list_pref, kTargetExtension, kExampleUpdateUrl); | 290 &forced_list_pref, kTargetExtension, kExampleUpdateUrl); |
| 283 | 291 |
| 284 SetPref(true, pref_names::kInstallForceList, forced_list_pref.DeepCopy()); | 292 SetPref(true, pref_names::kInstallForceList, forced_list_pref.DeepCopy()); |
| 285 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, | 293 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, |
| 286 ExtensionManagement::INSTALLATION_FORCED); | 294 ExtensionManagement::INSTALLATION_FORCED); |
| 287 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).update_url, | 295 EXPECT_EQ(ReadById(kTargetExtension)->update_url, |
| 288 kExampleUpdateUrl); | 296 kExampleUpdateUrl); |
| 289 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode, | 297 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, |
| 290 ExtensionManagement::INSTALLATION_ALLOWED); | 298 ExtensionManagement::INSTALLATION_ALLOWED); |
| 291 | 299 |
| 292 // Verify that install forcelist preference set by user is ignored. | 300 // Verify that install forcelist preference set by user is ignored. |
| 293 RemovePref(true, pref_names::kInstallForceList); | 301 RemovePref(true, pref_names::kInstallForceList); |
| 294 SetPref(false, pref_names::kInstallForceList, forced_list_pref.DeepCopy()); | 302 SetPref(false, pref_names::kInstallForceList, forced_list_pref.DeepCopy()); |
| 295 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, | 303 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, |
| 296 ExtensionManagement::INSTALLATION_ALLOWED); | 304 ExtensionManagement::INSTALLATION_ALLOWED); |
| 297 } | 305 } |
| 298 | 306 |
| 299 // Tests parsing of new dictionary preference. | 307 // Tests parsing of new dictionary preference. |
| 300 TEST_F(ExtensionManagementServiceTest, PreferenceParsing) { | 308 TEST_F(ExtensionManagementServiceTest, PreferenceParsing) { |
| 301 SetExampleDictPref(); | 309 SetExampleDictPref(); |
| 302 | 310 |
| 303 // Verifies the installation mode settings. | 311 // Verifies the installation mode settings. |
| 304 EXPECT_TRUE(extension_management_->BlacklistedByDefault()); | 312 EXPECT_TRUE(extension_management_->BlacklistedByDefault()); |
| 305 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, | 313 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, |
| 306 ExtensionManagement::INSTALLATION_ALLOWED); | 314 ExtensionManagement::INSTALLATION_ALLOWED); |
| 307 EXPECT_EQ( | 315 EXPECT_EQ(ReadById(kTargetExtension2)->installation_mode, |
| 308 extension_management_->ReadById(kTargetExtension2).installation_mode, | 316 ExtensionManagement::INSTALLATION_FORCED); |
| 309 ExtensionManagement::INSTALLATION_FORCED); | 317 EXPECT_EQ(ReadById(kTargetExtension2)->update_url, kExampleUpdateUrl); |
| 310 EXPECT_EQ(extension_management_->ReadById(kTargetExtension2).update_url, | 318 EXPECT_EQ(ReadById(kTargetExtension3)->installation_mode, |
| 311 kExampleUpdateUrl); | 319 ExtensionManagement::INSTALLATION_RECOMMENDED); |
| 312 EXPECT_EQ( | 320 EXPECT_EQ(ReadById(kTargetExtension3)->update_url, kExampleUpdateUrl); |
| 313 extension_management_->ReadById(kTargetExtension3).installation_mode, | 321 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, |
| 314 ExtensionManagement::INSTALLATION_RECOMMENDED); | |
| 315 EXPECT_EQ(extension_management_->ReadById(kTargetExtension3).update_url, | |
| 316 kExampleUpdateUrl); | |
| 317 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode, | |
| 318 ExtensionManagement::INSTALLATION_BLOCKED); | 322 ExtensionManagement::INSTALLATION_BLOCKED); |
| 319 | 323 |
| 320 // Verifies global settings. | 324 // Verifies global settings. |
| 321 EXPECT_TRUE(extension_management_->ReadGlobalSettings() | 325 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_install_sources); |
| 322 .has_restricted_install_sources); | 326 const URLPatternSet& allowed_sites = ReadGlobalSettings()->install_sources; |
| 323 const URLPatternSet& allowed_sites = | |
| 324 extension_management_->ReadGlobalSettings().install_sources; | |
| 325 EXPECT_EQ(allowed_sites.size(), 1u); | 327 EXPECT_EQ(allowed_sites.size(), 1u); |
| 326 EXPECT_TRUE(allowed_sites.MatchesURL(GURL("http://foo.com/entry"))); | 328 EXPECT_TRUE(allowed_sites.MatchesURL(GURL("http://foo.com/entry"))); |
| 327 EXPECT_FALSE(allowed_sites.MatchesURL(GURL("http://bar.com/entry"))); | 329 EXPECT_FALSE(allowed_sites.MatchesURL(GURL("http://bar.com/entry"))); |
| 328 | 330 |
| 329 EXPECT_TRUE( | 331 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types); |
| 330 extension_management_->ReadGlobalSettings().has_restricted_allowed_types); | |
| 331 const std::vector<Manifest::Type>& allowed_types = | 332 const std::vector<Manifest::Type>& allowed_types = |
| 332 extension_management_->ReadGlobalSettings().allowed_types; | 333 ReadGlobalSettings()->allowed_types; |
| 333 EXPECT_EQ(allowed_types.size(), 2u); | 334 EXPECT_EQ(allowed_types.size(), 2u); |
| 334 EXPECT_TRUE(std::find(allowed_types.begin(), | 335 EXPECT_TRUE(std::find(allowed_types.begin(), |
| 335 allowed_types.end(), | 336 allowed_types.end(), |
| 336 Manifest::TYPE_THEME) != allowed_types.end()); | 337 Manifest::TYPE_THEME) != allowed_types.end()); |
| 337 EXPECT_TRUE(std::find(allowed_types.begin(), | 338 EXPECT_TRUE(std::find(allowed_types.begin(), |
| 338 allowed_types.end(), | 339 allowed_types.end(), |
| 339 Manifest::TYPE_USER_SCRIPT) != allowed_types.end()); | 340 Manifest::TYPE_USER_SCRIPT) != allowed_types.end()); |
| 340 } | 341 } |
| 341 | 342 |
| 342 // Tests functionality of new preference as to deprecate legacy | 343 // Tests functionality of new preference as to deprecate legacy |
| 343 // ExtensionInstallSources policy. | 344 // ExtensionInstallSources policy. |
| 344 TEST_F(ExtensionManagementServiceTest, NewInstallSources) { | 345 TEST_F(ExtensionManagementServiceTest, NewInstallSources) { |
| 345 // Set the legacy preference, and verifies that it works. | 346 // Set the legacy preference, and verifies that it works. |
| 346 base::ListValue allowed_sites_pref; | 347 base::ListValue allowed_sites_pref; |
| 347 allowed_sites_pref.AppendString("https://www.example.com/foo"); | 348 allowed_sites_pref.AppendString("https://www.example.com/foo"); |
| 348 SetPref( | 349 SetPref( |
| 349 true, pref_names::kAllowedInstallSites, allowed_sites_pref.DeepCopy()); | 350 true, pref_names::kAllowedInstallSites, allowed_sites_pref.DeepCopy()); |
| 350 EXPECT_TRUE(extension_management_->ReadGlobalSettings() | 351 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_install_sources); |
| 351 .has_restricted_install_sources); | |
| 352 EXPECT_TRUE( | 352 EXPECT_TRUE( |
| 353 extension_management_->ReadGlobalSettings() | 353 ReadGlobalSettings() |
| 354 .install_sources.MatchesURL(GURL("https://www.example.com/foo"))); | 354 ->install_sources.MatchesURL(GURL("https://www.example.com/foo"))); |
| 355 | 355 |
| 356 // Set the new dictionary preference. | 356 // Set the new dictionary preference. |
| 357 { | 357 { |
| 358 PrefUpdater updater(pref_service_.get()); | 358 PrefUpdater updater(pref_service_.get()); |
| 359 updater.ClearInstallSources(); | 359 updater.ClearInstallSources(); |
| 360 } | 360 } |
| 361 // Verifies that the new one overrides the legacy ones. | 361 // Verifies that the new one overrides the legacy ones. |
| 362 EXPECT_TRUE(extension_management_->ReadGlobalSettings() | 362 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_install_sources); |
| 363 .has_restricted_install_sources); | |
| 364 EXPECT_FALSE( | 363 EXPECT_FALSE( |
| 365 extension_management_->ReadGlobalSettings() | 364 ReadGlobalSettings() |
| 366 .install_sources.MatchesURL(GURL("https://www.example.com/foo"))); | 365 ->install_sources.MatchesURL(GURL("https://www.example.com/foo"))); |
| 367 | 366 |
| 368 // Updates the new dictionary preference. | 367 // Updates the new dictionary preference. |
| 369 { | 368 { |
| 370 PrefUpdater updater(pref_service_.get()); | 369 PrefUpdater updater(pref_service_.get()); |
| 371 updater.AddInstallSource("https://corp.mycompany.com/*"); | 370 updater.AddInstallSource("https://corp.mycompany.com/*"); |
| 372 } | 371 } |
| 373 EXPECT_TRUE(extension_management_->ReadGlobalSettings() | 372 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_install_sources); |
| 374 .has_restricted_install_sources); | 373 EXPECT_TRUE(ReadGlobalSettings() |
| 375 EXPECT_TRUE(extension_management_->ReadGlobalSettings() | 374 ->install_sources.MatchesURL( |
| 376 .install_sources.MatchesURL( | |
| 377 GURL("https://corp.mycompany.com/entry"))); | 375 GURL("https://corp.mycompany.com/entry"))); |
| 378 } | 376 } |
| 379 | 377 |
| 380 // Tests functionality of new preference as to deprecate legacy | 378 // Tests functionality of new preference as to deprecate legacy |
| 381 // ExtensionAllowedTypes policy. | 379 // ExtensionAllowedTypes policy. |
| 382 TEST_F(ExtensionManagementServiceTest, NewAllowedTypes) { | 380 TEST_F(ExtensionManagementServiceTest, NewAllowedTypes) { |
| 383 // Set the legacy preference, and verifies that it works. | 381 // Set the legacy preference, and verifies that it works. |
| 384 base::ListValue allowed_types_pref; | 382 base::ListValue allowed_types_pref; |
| 385 allowed_types_pref.AppendInteger(Manifest::TYPE_USER_SCRIPT); | 383 allowed_types_pref.AppendInteger(Manifest::TYPE_USER_SCRIPT); |
| 386 SetPref(true, pref_names::kAllowedTypes, allowed_types_pref.DeepCopy()); | 384 SetPref(true, pref_names::kAllowedTypes, allowed_types_pref.DeepCopy()); |
| 387 EXPECT_TRUE( | 385 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types); |
| 388 extension_management_->ReadGlobalSettings().has_restricted_allowed_types); | 386 EXPECT_EQ(ReadGlobalSettings()->allowed_types.size(), 1u); |
| 389 EXPECT_EQ(extension_management_->ReadGlobalSettings().allowed_types.size(), | 387 EXPECT_EQ(ReadGlobalSettings()->allowed_types[0], Manifest::TYPE_USER_SCRIPT); |
| 390 1u); | |
| 391 EXPECT_EQ(extension_management_->ReadGlobalSettings().allowed_types[0], | |
| 392 Manifest::TYPE_USER_SCRIPT); | |
| 393 | 388 |
| 394 // Set the new dictionary preference. | 389 // Set the new dictionary preference. |
| 395 { | 390 { |
| 396 PrefUpdater updater(pref_service_.get()); | 391 PrefUpdater updater(pref_service_.get()); |
| 397 updater.ClearAllowedTypes(); | 392 updater.ClearAllowedTypes(); |
| 398 } | 393 } |
| 399 // Verifies that the new one overrides the legacy ones. | 394 // Verifies that the new one overrides the legacy ones. |
| 400 EXPECT_TRUE( | 395 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types); |
| 401 extension_management_->ReadGlobalSettings().has_restricted_allowed_types); | 396 EXPECT_EQ(ReadGlobalSettings()->allowed_types.size(), 0u); |
| 402 EXPECT_EQ(extension_management_->ReadGlobalSettings().allowed_types.size(), | |
| 403 0u); | |
| 404 | 397 |
| 405 // Updates the new dictionary preference. | 398 // Updates the new dictionary preference. |
| 406 { | 399 { |
| 407 PrefUpdater updater(pref_service_.get()); | 400 PrefUpdater updater(pref_service_.get()); |
| 408 updater.AddAllowedType("theme"); | 401 updater.AddAllowedType("theme"); |
| 409 } | 402 } |
| 410 EXPECT_TRUE( | 403 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types); |
| 411 extension_management_->ReadGlobalSettings().has_restricted_allowed_types); | 404 EXPECT_EQ(ReadGlobalSettings()->allowed_types.size(), 1u); |
| 412 EXPECT_EQ(extension_management_->ReadGlobalSettings().allowed_types.size(), | 405 EXPECT_EQ(ReadGlobalSettings()->allowed_types[0], Manifest::TYPE_THEME); |
| 413 1u); | |
| 414 EXPECT_EQ(extension_management_->ReadGlobalSettings().allowed_types[0], | |
| 415 Manifest::TYPE_THEME); | |
| 416 } | 406 } |
| 417 | 407 |
| 418 // Tests functionality of new preference as to deprecate legacy | 408 // Tests functionality of new preference as to deprecate legacy |
| 419 // ExtensionInstallBlacklist policy. | 409 // ExtensionInstallBlacklist policy. |
| 420 TEST_F(ExtensionManagementServiceTest, NewInstallBlacklist) { | 410 TEST_F(ExtensionManagementServiceTest, NewInstallBlacklist) { |
| 421 // Set the new dictionary preference. | 411 // Set the new dictionary preference. |
| 422 { | 412 { |
| 423 PrefUpdater updater(pref_service_.get()); | 413 PrefUpdater updater(pref_service_.get()); |
| 424 updater.SetBlacklistedByDefault(false); // Allowed by default. | 414 updater.SetBlacklistedByDefault(false); // Allowed by default. |
| 425 updater.SetIndividualExtensionInstallationAllowed(kTargetExtension, false); | 415 updater.SetIndividualExtensionInstallationAllowed(kTargetExtension, false); |
| 426 updater.ClearPerExtensionSettings(kTargetExtension2); | 416 updater.ClearPerExtensionSettings(kTargetExtension2); |
| 427 updater.ClearPerExtensionSettings(kOtherExtension); | 417 updater.ClearPerExtensionSettings(kOtherExtension); |
| 428 } | 418 } |
| 429 EXPECT_FALSE(extension_management_->BlacklistedByDefault()); | 419 EXPECT_FALSE(extension_management_->BlacklistedByDefault()); |
| 430 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, | 420 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, |
| 431 ExtensionManagement::INSTALLATION_BLOCKED); | 421 ExtensionManagement::INSTALLATION_BLOCKED); |
| 432 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode, | 422 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, |
| 433 ExtensionManagement::INSTALLATION_ALLOWED); | 423 ExtensionManagement::INSTALLATION_ALLOWED); |
| 434 | 424 |
| 435 // Set legacy preference. | 425 // Set legacy preference. |
| 436 base::ListValue denied_list_pref; | 426 base::ListValue denied_list_pref; |
| 437 denied_list_pref.AppendString("*"); | 427 denied_list_pref.AppendString("*"); |
| 438 denied_list_pref.AppendString(kTargetExtension2); | 428 denied_list_pref.AppendString(kTargetExtension2); |
| 439 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); | 429 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); |
| 440 | 430 |
| 441 base::ListValue allowed_list_pref; | 431 base::ListValue allowed_list_pref; |
| 442 allowed_list_pref.AppendString(kTargetExtension); | 432 allowed_list_pref.AppendString(kTargetExtension); |
| 443 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); | 433 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); |
| 444 | 434 |
| 445 // Verifies that the new one have higher priority over the legacy ones. | 435 // Verifies that the new one have higher priority over the legacy ones. |
| 446 EXPECT_FALSE(extension_management_->BlacklistedByDefault()); | 436 EXPECT_FALSE(extension_management_->BlacklistedByDefault()); |
| 447 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, | 437 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, |
| 448 ExtensionManagement::INSTALLATION_BLOCKED); | 438 ExtensionManagement::INSTALLATION_BLOCKED); |
| 449 EXPECT_EQ( | 439 EXPECT_EQ(ReadById(kTargetExtension2)->installation_mode, |
| 450 extension_management_->ReadById(kTargetExtension2).installation_mode, | 440 ExtensionManagement::INSTALLATION_BLOCKED); |
| 451 ExtensionManagement::INSTALLATION_BLOCKED); | 441 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, |
| 452 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode, | |
| 453 ExtensionManagement::INSTALLATION_ALLOWED); | 442 ExtensionManagement::INSTALLATION_ALLOWED); |
| 454 } | 443 } |
| 455 | 444 |
| 456 // Tests functionality of new preference as to deprecate legacy | 445 // Tests functionality of new preference as to deprecate legacy |
| 457 // ExtensionInstallWhitelist policy. | 446 // ExtensionInstallWhitelist policy. |
| 458 TEST_F(ExtensionManagementServiceTest, NewInstallWhitelist) { | 447 TEST_F(ExtensionManagementServiceTest, NewInstallWhitelist) { |
| 459 // Set the new dictionary preference. | 448 // Set the new dictionary preference. |
| 460 { | 449 { |
| 461 PrefUpdater updater(pref_service_.get()); | 450 PrefUpdater updater(pref_service_.get()); |
| 462 updater.SetBlacklistedByDefault(true); // Disallowed by default. | 451 updater.SetBlacklistedByDefault(true); // Disallowed by default. |
| 463 updater.SetIndividualExtensionInstallationAllowed(kTargetExtension, true); | 452 updater.SetIndividualExtensionInstallationAllowed(kTargetExtension, true); |
| 464 updater.ClearPerExtensionSettings(kTargetExtension2); | 453 updater.ClearPerExtensionSettings(kTargetExtension2); |
| 465 updater.ClearPerExtensionSettings(kOtherExtension); | 454 updater.ClearPerExtensionSettings(kOtherExtension); |
| 466 } | 455 } |
| 467 EXPECT_TRUE(extension_management_->BlacklistedByDefault()); | 456 EXPECT_TRUE(extension_management_->BlacklistedByDefault()); |
| 468 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, | 457 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, |
| 469 ExtensionManagement::INSTALLATION_ALLOWED); | 458 ExtensionManagement::INSTALLATION_ALLOWED); |
| 470 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode, | 459 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, |
| 471 ExtensionManagement::INSTALLATION_BLOCKED); | 460 ExtensionManagement::INSTALLATION_BLOCKED); |
| 472 | 461 |
| 473 // Set legacy preference. | 462 // Set legacy preference. |
| 474 base::ListValue denied_list_pref; | 463 base::ListValue denied_list_pref; |
| 475 denied_list_pref.AppendString(kTargetExtension); | 464 denied_list_pref.AppendString(kTargetExtension); |
| 476 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); | 465 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); |
| 477 | 466 |
| 478 base::ListValue allowed_list_pref; | 467 base::ListValue allowed_list_pref; |
| 479 allowed_list_pref.AppendString(kTargetExtension2); | 468 allowed_list_pref.AppendString(kTargetExtension2); |
| 480 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); | 469 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); |
| 481 | 470 |
| 482 // Verifies that the new one have higher priority over the legacy ones. | 471 // Verifies that the new one have higher priority over the legacy ones. |
| 483 EXPECT_TRUE(extension_management_->BlacklistedByDefault()); | 472 EXPECT_TRUE(extension_management_->BlacklistedByDefault()); |
| 484 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, | 473 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, |
| 485 ExtensionManagement::INSTALLATION_ALLOWED); | 474 ExtensionManagement::INSTALLATION_ALLOWED); |
| 486 EXPECT_EQ( | 475 EXPECT_EQ(ReadById(kTargetExtension2)->installation_mode, |
| 487 extension_management_->ReadById(kTargetExtension2).installation_mode, | 476 ExtensionManagement::INSTALLATION_ALLOWED); |
| 488 ExtensionManagement::INSTALLATION_ALLOWED); | 477 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, |
| 489 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode, | |
| 490 ExtensionManagement::INSTALLATION_BLOCKED); | 478 ExtensionManagement::INSTALLATION_BLOCKED); |
| 491 } | 479 } |
| 492 | 480 |
| 493 // Tests functionality of new preference as to deprecate legacy | 481 // Tests functionality of new preference as to deprecate legacy |
| 494 // ExtensionInstallForcelist policy. | 482 // ExtensionInstallForcelist policy. |
| 495 TEST_F(ExtensionManagementServiceTest, NewInstallForcelist) { | 483 TEST_F(ExtensionManagementServiceTest, NewInstallForcelist) { |
| 496 // Set some legacy preferences, to verify that the new one overrides the | 484 // Set some legacy preferences, to verify that the new one overrides the |
| 497 // legacy ones. | 485 // legacy ones. |
| 498 base::ListValue denied_list_pref; | 486 base::ListValue denied_list_pref; |
| 499 denied_list_pref.AppendString(kTargetExtension); | 487 denied_list_pref.AppendString(kTargetExtension); |
| 500 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); | 488 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); |
| 501 | 489 |
| 502 // Set the new dictionary preference. | 490 // Set the new dictionary preference. |
| 503 { | 491 { |
| 504 PrefUpdater updater(pref_service_.get()); | 492 PrefUpdater updater(pref_service_.get()); |
| 505 updater.SetIndividualExtensionAutoInstalled( | 493 updater.SetIndividualExtensionAutoInstalled( |
| 506 kTargetExtension, kExampleUpdateUrl, true); | 494 kTargetExtension, kExampleUpdateUrl, true); |
| 507 updater.ClearPerExtensionSettings(kOtherExtension); | 495 updater.ClearPerExtensionSettings(kOtherExtension); |
| 508 } | 496 } |
| 509 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, | 497 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, |
| 510 ExtensionManagement::INSTALLATION_FORCED); | 498 ExtensionManagement::INSTALLATION_FORCED); |
| 511 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).update_url, | 499 EXPECT_EQ(ReadById(kTargetExtension)->update_url, kExampleUpdateUrl); |
| 512 kExampleUpdateUrl); | 500 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, |
| 513 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode, | |
| 514 ExtensionManagement::INSTALLATION_ALLOWED); | 501 ExtensionManagement::INSTALLATION_ALLOWED); |
| 515 } | 502 } |
| 516 | 503 |
| 517 // Tests the flag value indicating that extensions are blacklisted by default. | 504 // Tests the flag value indicating that extensions are blacklisted by default. |
| 518 TEST_F(ExtensionAdminPolicyTest, BlacklistedByDefault) { | 505 TEST_F(ExtensionAdminPolicyTest, BlacklistedByDefault) { |
| 519 EXPECT_FALSE(BlacklistedByDefault(NULL)); | 506 EXPECT_FALSE(BlacklistedByDefault(NULL)); |
| 520 | 507 |
| 521 base::ListValue blacklist; | 508 base::ListValue blacklist; |
| 522 blacklist.Append(new base::StringValue(kOtherExtension)); | 509 blacklist.Append(new base::StringValue(kOtherExtension)); |
| 523 EXPECT_FALSE(BlacklistedByDefault(&blacklist)); | 510 EXPECT_FALSE(BlacklistedByDefault(&blacklist)); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 EXPECT_FALSE(error.empty()); | 643 EXPECT_FALSE(error.empty()); |
| 657 | 644 |
| 658 CreateExtension(Manifest::INTERNAL); | 645 CreateExtension(Manifest::INTERNAL); |
| 659 error.clear(); | 646 error.clear(); |
| 660 EXPECT_FALSE(MustRemainEnabled(extension_.get(), NULL)); | 647 EXPECT_FALSE(MustRemainEnabled(extension_.get(), NULL)); |
| 661 EXPECT_FALSE(MustRemainEnabled(extension_.get(), &error)); | 648 EXPECT_FALSE(MustRemainEnabled(extension_.get(), &error)); |
| 662 EXPECT_TRUE(error.empty()); | 649 EXPECT_TRUE(error.empty()); |
| 663 } | 650 } |
| 664 | 651 |
| 665 } // namespace extensions | 652 } // namespace extensions |
| OLD | NEW |