| 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 "chrome/browser/extensions/extension_management.h" | 5 #include "chrome/browser/extensions/extension_management.h" |
| 6 | 6 |
| 7 #include <algorithm> | |
| 8 #include <memory> | 7 #include <memory> |
| 9 #include <string> | 8 #include <string> |
| 10 #include <vector> | 9 #include <vector> |
| 11 | 10 |
| 12 #include "base/json/json_parser.h" | 11 #include "base/json/json_parser.h" |
| 13 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/stl_util.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/extensions/extension_management_internal.h" | 15 #include "chrome/browser/extensions/extension_management_internal.h" |
| 16 #include "chrome/browser/extensions/extension_management_test_util.h" | 16 #include "chrome/browser/extensions/extension_management_test_util.h" |
| 17 #include "chrome/browser/extensions/external_policy_loader.h" | 17 #include "chrome/browser/extensions/external_policy_loader.h" |
| 18 #include "chrome/browser/extensions/standard_management_policy_provider.h" | 18 #include "chrome/browser/extensions/standard_management_policy_provider.h" |
| 19 #include "components/prefs/pref_registry_simple.h" | 19 #include "components/prefs/pref_registry_simple.h" |
| 20 #include "components/prefs/testing_pref_service.h" | 20 #include "components/prefs/testing_pref_service.h" |
| 21 #include "extensions/browser/pref_names.h" | 21 #include "extensions/browser/pref_names.h" |
| 22 #include "extensions/common/manifest.h" | 22 #include "extensions/common/manifest.h" |
| 23 #include "extensions/common/manifest_constants.h" | 23 #include "extensions/common/manifest_constants.h" |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 TEST_F(ExtensionManagementServiceTest, LegacyAllowedTypes) { | 362 TEST_F(ExtensionManagementServiceTest, LegacyAllowedTypes) { |
| 363 base::ListValue allowed_types_pref; | 363 base::ListValue allowed_types_pref; |
| 364 allowed_types_pref.AppendInteger(Manifest::TYPE_THEME); | 364 allowed_types_pref.AppendInteger(Manifest::TYPE_THEME); |
| 365 allowed_types_pref.AppendInteger(Manifest::TYPE_USER_SCRIPT); | 365 allowed_types_pref.AppendInteger(Manifest::TYPE_USER_SCRIPT); |
| 366 | 366 |
| 367 SetPref(true, pref_names::kAllowedTypes, allowed_types_pref.CreateDeepCopy()); | 367 SetPref(true, pref_names::kAllowedTypes, allowed_types_pref.CreateDeepCopy()); |
| 368 const std::vector<Manifest::Type>& allowed_types = | 368 const std::vector<Manifest::Type>& allowed_types = |
| 369 ReadGlobalSettings()->allowed_types; | 369 ReadGlobalSettings()->allowed_types; |
| 370 ASSERT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types); | 370 ASSERT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types); |
| 371 EXPECT_EQ(allowed_types.size(), 2u); | 371 EXPECT_EQ(allowed_types.size(), 2u); |
| 372 EXPECT_FALSE(std::find(allowed_types.begin(), | 372 EXPECT_FALSE(base::ContainsValue(allowed_types, Manifest::TYPE_EXTENSION)); |
| 373 allowed_types.end(), | 373 EXPECT_TRUE(base::ContainsValue(allowed_types, Manifest::TYPE_THEME)); |
| 374 Manifest::TYPE_EXTENSION) != allowed_types.end()); | 374 EXPECT_TRUE(base::ContainsValue(allowed_types, Manifest::TYPE_USER_SCRIPT)); |
| 375 EXPECT_TRUE(std::find(allowed_types.begin(), | |
| 376 allowed_types.end(), | |
| 377 Manifest::TYPE_THEME) != allowed_types.end()); | |
| 378 EXPECT_TRUE(std::find(allowed_types.begin(), | |
| 379 allowed_types.end(), | |
| 380 Manifest::TYPE_USER_SCRIPT) != allowed_types.end()); | |
| 381 } | 375 } |
| 382 | 376 |
| 383 // Verify that preference controlled by legacy ExtensionInstallBlacklist policy | 377 // Verify that preference controlled by legacy ExtensionInstallBlacklist policy |
| 384 // is handled well. | 378 // is handled well. |
| 385 TEST_F(ExtensionManagementServiceTest, LegacyInstallBlacklist) { | 379 TEST_F(ExtensionManagementServiceTest, LegacyInstallBlacklist) { |
| 386 base::ListValue denied_list_pref; | 380 base::ListValue denied_list_pref; |
| 387 denied_list_pref.AppendString(kTargetExtension); | 381 denied_list_pref.AppendString(kTargetExtension); |
| 388 | 382 |
| 389 SetPref(true, pref_names::kInstallDenyList, | 383 SetPref(true, pref_names::kInstallDenyList, |
| 390 denied_list_pref.CreateDeepCopy()); | 384 denied_list_pref.CreateDeepCopy()); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 EXPECT_EQ(allowed_sites.size(), 1u); | 471 EXPECT_EQ(allowed_sites.size(), 1u); |
| 478 EXPECT_TRUE(allowed_sites.MatchesURL(GURL("http://foo.com/entry"))); | 472 EXPECT_TRUE(allowed_sites.MatchesURL(GURL("http://foo.com/entry"))); |
| 479 EXPECT_FALSE(allowed_sites.MatchesURL(GURL("http://bar.com/entry"))); | 473 EXPECT_FALSE(allowed_sites.MatchesURL(GURL("http://bar.com/entry"))); |
| 480 EXPECT_TRUE(GetRuntimeBlockedHosts(kNonExistingExtension) | 474 EXPECT_TRUE(GetRuntimeBlockedHosts(kNonExistingExtension) |
| 481 .MatchesURL(GURL("http://example.com/default"))); | 475 .MatchesURL(GURL("http://example.com/default"))); |
| 482 | 476 |
| 483 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types); | 477 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types); |
| 484 const std::vector<Manifest::Type>& allowed_types = | 478 const std::vector<Manifest::Type>& allowed_types = |
| 485 ReadGlobalSettings()->allowed_types; | 479 ReadGlobalSettings()->allowed_types; |
| 486 EXPECT_EQ(allowed_types.size(), 2u); | 480 EXPECT_EQ(allowed_types.size(), 2u); |
| 487 EXPECT_TRUE(std::find(allowed_types.begin(), | 481 EXPECT_TRUE(base::ContainsValue(allowed_types, Manifest::TYPE_THEME)); |
| 488 allowed_types.end(), | 482 EXPECT_TRUE(base::ContainsValue(allowed_types, Manifest::TYPE_USER_SCRIPT)); |
| 489 Manifest::TYPE_THEME) != allowed_types.end()); | |
| 490 EXPECT_TRUE(std::find(allowed_types.begin(), | |
| 491 allowed_types.end(), | |
| 492 Manifest::TYPE_USER_SCRIPT) != allowed_types.end()); | |
| 493 | 483 |
| 494 // Verifies blocked permission list settings. | 484 // Verifies blocked permission list settings. |
| 495 APIPermissionSet api_permission_set; | 485 APIPermissionSet api_permission_set; |
| 496 api_permission_set.clear(); | 486 api_permission_set.clear(); |
| 497 api_permission_set.insert(APIPermission::kFileSystem); | 487 api_permission_set.insert(APIPermission::kFileSystem); |
| 498 api_permission_set.insert(APIPermission::kDownloads); | 488 api_permission_set.insert(APIPermission::kDownloads); |
| 499 EXPECT_EQ(api_permission_set, | 489 EXPECT_EQ(api_permission_set, |
| 500 GetBlockedAPIPermissionsById(kNonExistingExtension)); | 490 GetBlockedAPIPermissionsById(kNonExistingExtension)); |
| 501 | 491 |
| 502 api_permission_set.clear(); | 492 api_permission_set.clear(); |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 EXPECT_FALSE(error.empty()); | 926 EXPECT_FALSE(error.empty()); |
| 937 | 927 |
| 938 CreateExtension(Manifest::INTERNAL); | 928 CreateExtension(Manifest::INTERNAL); |
| 939 error.clear(); | 929 error.clear(); |
| 940 EXPECT_FALSE(MustRemainEnabled(extension_.get(), NULL)); | 930 EXPECT_FALSE(MustRemainEnabled(extension_.get(), NULL)); |
| 941 EXPECT_FALSE(MustRemainEnabled(extension_.get(), &error)); | 931 EXPECT_FALSE(MustRemainEnabled(extension_.get(), &error)); |
| 942 EXPECT_TRUE(error.empty()); | 932 EXPECT_TRUE(error.empty()); |
| 943 } | 933 } |
| 944 | 934 |
| 945 } // namespace extensions | 935 } // namespace extensions |
| OLD | NEW |