Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Side by Side Diff: chrome/browser/extensions/extension_service_unittest.cc

Issue 10854009: Extension white and force lists (set by policy) should have priority over auto-updated Google black… (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Refactored Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_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 2768 matching lines...) Expand 10 before | Expand all | Expand 10 after
2779 // Now, the good_crx is blacklisted. 2779 // Now, the good_crx is blacklisted.
2780 ValidateBooleanPref(good_crx, "blacklist", true); 2780 ValidateBooleanPref(good_crx, "blacklist", true);
2781 2781
2782 // We can not install good_crx. 2782 // We can not install good_crx.
2783 FilePath path = data_dir_.AppendASCII("good.crx"); 2783 FilePath path = data_dir_.AppendASCII("good.crx");
2784 InstallCRX(path, INSTALL_FAILED); 2784 InstallCRX(path, INSTALL_FAILED);
2785 EXPECT_EQ(0u, service_->extensions()->size()); 2785 EXPECT_EQ(0u, service_->extensions()->size());
2786 ValidateBooleanPref(good_crx, "blacklist", true); 2786 ValidateBooleanPref(good_crx, "blacklist", true);
2787 } 2787 }
2788 2788
2789 // Unload blacklisted extension on policy change.
2790 TEST_F(ExtensionServiceTest, UnloadBlacklistedExtensionPolicy) {
2791 InitializeEmptyExtensionService();
2792 FilePath path = data_dir_.AppendASCII("good.crx");
2793
2794 const Extension* good = InstallCRX(path, INSTALL_NEW);
2795 EXPECT_EQ(good_crx, good->id());
2796 UpdateExtension(good_crx, path, FAILED_SILENTLY);
2797 EXPECT_EQ(1u, service_->extensions()->size());
2798
2799 base::ListValue whitelist;
2800 PrefService* prefs = service_->extension_prefs()->pref_service();
2801 whitelist.Append(base::Value::CreateStringValue(good_crx));
2802 prefs->Set(prefs::kExtensionInstallAllowList, whitelist);
2803
2804 std::vector<std::string> blacklist;
2805 blacklist.push_back(good_crx);
2806 service_->UpdateExtensionBlacklist(blacklist);
2807 // Make sure pref is updated
2808 loop_.RunAllPending();
2809
2810 // Now, the good_crx is blacklisted but whitelist negates it.
2811 ValidateBooleanPref(good_crx, "blacklist", true);
2812 EXPECT_EQ(1u, service_->extensions()->size());
2813
2814 whitelist.Clear();
2815 prefs->Set(prefs::kExtensionInstallAllowList, whitelist);
2816 loop_.RunAllPending();
2817
2818 // Now, the good_crx is blacklisted for good.
2819 ValidateBooleanPref(good_crx, "blacklist", true);
2820 EXPECT_EQ(0u, service_->extensions()->size());
2821 }
2822
2823 // Allow Google-blacklisted extension if policy explicitly allows it (blacklist
2824 // then set policy).
2825 TEST_F(ExtensionServiceTest, WhitelistGoogleBlacklistedExtension) {
2826 InitializeEmptyExtensionService();
2827
2828 std::vector<std::string> blacklist;
2829 blacklist.push_back(good_crx);
2830 service_->UpdateExtensionBlacklist(blacklist);
2831 loop_.RunAllPending();
2832
2833 FilePath path = data_dir_.AppendASCII("good.crx");
2834 InstallCRX(path, INSTALL_FAILED);
2835
2836 base::ListValue whitelist;
2837 whitelist.Append(base::Value::CreateStringValue(good_crx));
2838 service_->extension_prefs()->pref_service()->Set(
2839 prefs::kExtensionInstallAllowList, whitelist);
2840 loop_.RunAllPending();
2841
2842 InstallCRX(path, INSTALL_NEW);
2843 }
2844
2845 // Allow Google-blacklisted extension if policy requires it (blacklist then set
2846 // policy).
2847 TEST_F(ExtensionServiceTest, ForcelistGoogleBlacklistedExtension) {
2848 InitializeEmptyExtensionService();
2849
2850 std::vector<std::string> blacklist;
2851 blacklist.push_back(good_crx);
2852 service_->UpdateExtensionBlacklist(blacklist);
2853 loop_.RunAllPending();
2854
2855 FilePath path = data_dir_.AppendASCII("good.crx");
2856 InstallCRX(path, INSTALL_FAILED);
2857
2858 base::ListValue forcelist;
2859 forcelist.Append(base::Value::CreateStringValue(good_crx));
2860 service_->extension_prefs()->pref_service()->Set(
2861 prefs::kExtensionInstallAllowList, forcelist);
2862 loop_.RunAllPending();
2863
2864 InstallCRX(path, INSTALL_NEW);
2865 }
2866
2867 // Allow Google-blacklisted extension if policy explicitly allows it (set policy
2868 // then blacklist).
2869 TEST_F(ExtensionServiceTest, GoogleBlacklistWhitelistedExtension) {
2870 InitializeEmptyExtensionService();
2871
2872 base::ListValue whitelist;
2873 whitelist.Append(base::Value::CreateStringValue(good_crx));
2874 service_->extension_prefs()->pref_service()->Set(
2875 prefs::kExtensionInstallAllowList, whitelist);
2876 loop_.RunAllPending();
2877
2878 std::vector<std::string> blacklist;
2879 blacklist.push_back(good_crx);
2880 service_->UpdateExtensionBlacklist(blacklist);
2881 loop_.RunAllPending();
2882
2883 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
2884 }
2885
2886 // Allow Google-blacklisted extension if policy requires it (set policy then
2887 // blacklist).
2888 TEST_F(ExtensionServiceTest, GoogleBlacklistForcelistedExtension) {
2889 InitializeEmptyExtensionService();
2890
2891 base::ListValue forcelist;
2892 forcelist.Append(base::Value::CreateStringValue(good_crx));
2893 service_->extension_prefs()->pref_service()->Set(
2894 prefs::kExtensionInstallAllowList, forcelist);
2895 loop_.RunAllPending();
2896
2897 std::vector<std::string> blacklist;
2898 blacklist.push_back(good_crx);
2899 service_->UpdateExtensionBlacklist(blacklist);
2900 loop_.RunAllPending();
2901
2902 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW);
2903 }
2904
2789 // Test loading extensions from the profile directory, except 2905 // Test loading extensions from the profile directory, except
2790 // blacklisted ones. 2906 // blacklisted ones.
2791 TEST_F(ExtensionServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) { 2907 TEST_F(ExtensionServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) {
2792 // Initialize the test dir with a good Preferences/extensions. 2908 // Initialize the test dir with a good Preferences/extensions.
2793 FilePath source_install_dir = data_dir_ 2909 FilePath source_install_dir = data_dir_
2794 .AppendASCII("good") 2910 .AppendASCII("good")
2795 .AppendASCII("Extensions"); 2911 .AppendASCII("Extensions");
2796 FilePath pref_path = source_install_dir 2912 FilePath pref_path = source_install_dir
2797 .DirName() 2913 .DirName()
2798 .AppendASCII("Preferences"); 2914 .AppendASCII("Preferences");
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
3060 InstallCRX(data_dir_.AppendASCII("page_action.crx"), INSTALL_NEW); 3176 InstallCRX(data_dir_.AppendASCII("page_action.crx"), INSTALL_NEW);
3061 EXPECT_EQ(2u, service_->extensions()->size()); 3177 EXPECT_EQ(2u, service_->extensions()->size());
3062 EXPECT_EQ(0u, service_->disabled_extensions()->size()); 3178 EXPECT_EQ(0u, service_->disabled_extensions()->size());
3063 3179
3064 management_policy_->UnregisterAllProviders(); 3180 management_policy_->UnregisterAllProviders();
3065 extensions::TestManagementPolicyProvider provider( 3181 extensions::TestManagementPolicyProvider provider(
3066 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD); 3182 extensions::TestManagementPolicyProvider::PROHIBIT_LOAD);
3067 management_policy_->RegisterProvider(&provider); 3183 management_policy_->RegisterProvider(&provider);
3068 3184
3069 // Run the policy check. 3185 // Run the policy check.
3070 service_->CheckAdminBlacklist(); 3186 service_->CheckManagementPolicy();
3071 EXPECT_EQ(0u, service_->extensions()->size()); 3187 EXPECT_EQ(0u, service_->extensions()->size());
3072 EXPECT_EQ(0u, service_->disabled_extensions()->size()); 3188 EXPECT_EQ(0u, service_->disabled_extensions()->size());
3073 } 3189 }
3074 3190
3075 // Tests that previously disabled extensions that are now required to be 3191 // Tests that previously disabled extensions that are now required to be
3076 // enabled are re-enabled on reinstall. 3192 // enabled are re-enabled on reinstall.
3077 TEST_F(ExtensionServiceTest, ManagementPolicyRequiresEnable) { 3193 TEST_F(ExtensionServiceTest, ManagementPolicyRequiresEnable) {
3078 InitializeEmptyExtensionService(); 3194 InitializeEmptyExtensionService();
3079 3195
3080 // Install, then disable, an extension. 3196 // Install, then disable, an extension.
(...skipping 2165 matching lines...) Expand 10 before | Expand all | Expand 10 after
5246 // This should NOT trigger an alert. 5362 // This should NOT trigger an alert.
5247 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", 5363 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0",
5248 data_dir_.AppendASCII("hosted_app.crx")); 5364 data_dir_.AppendASCII("hosted_app.crx"));
5249 5365
5250 service_->CheckForExternalUpdates(); 5366 service_->CheckForExternalUpdates();
5251 loop_.RunAllPending(); 5367 loop_.RunAllPending();
5252 5368
5253 ASSERT_TRUE(service_->PopulateExtensionErrorUI(extension_error_ui.get())); 5369 ASSERT_TRUE(service_->PopulateExtensionErrorUI(extension_error_ui.get()));
5254 ASSERT_EQ(1u, extension_error_ui->get_external_extension_ids()->size()); 5370 ASSERT_EQ(1u, extension_error_ui->get_external_extension_ids()->size());
5255 } 5371 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698