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

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: Fixed NULL instead of false 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
2793 FilePath path = data_dir_.AppendASCII("good.crx");
2794
2795 const Extension* good = InstallCRX(path, INSTALL_NEW);
2796 EXPECT_EQ(good_crx, good->id());
2797 UpdateExtension(good_crx, path, FAILED_SILENTLY);
2798 EXPECT_EQ(1u, service_->extensions()->size());
2799
2800 base::ListValue whitelist;
2801 PrefService* prefs = service_->extension_prefs()->pref_service();
2802 whitelist.Append(base::Value::CreateStringValue(good_crx));
2803 prefs->Set(prefs::kExtensionInstallAllowList, whitelist);
2804
2805 std::vector<std::string> blacklist;
2806 blacklist.push_back(good_crx);
2807 service_->UpdateExtensionBlacklist(blacklist);
2808 // Make sure pref is updated
Mattias Nissler (ping if slow) 2012/08/08 08:08:37 Missing period. Also, pref read writes don't requi
qfel 2012/08/13 16:03:02 Uh, I was going to ask for the same, and forgot to
2809 loop_.RunAllPending();
2810
2811 // Now, the good_crx is blacklisted but whitelist negates it.
2812 ValidateBooleanPref(good_crx, "blacklist", true);
2813 EXPECT_EQ(1u, service_->extensions()->size());
2814
2815 whitelist.Clear();
2816 prefs->Set(prefs::kExtensionInstallAllowList, whitelist);
2817 loop_.RunAllPending();
2818
2819 // Now, the good_crx is blacklisted for good.
2820 ValidateBooleanPref(good_crx, "blacklist", true);
2821 EXPECT_EQ(0u, service_->extensions()->size());
2822 }
2823
2824 // Allow Google-blacklisted extension if policy explicitly allows it (blacklist
2825 // then set policy).
2826 TEST_F(ExtensionServiceTest, WhitelistGoogleBlacklistedExtension) {
2827 InitializeEmptyExtensionService();
2828
2829 std::vector<std::string> blacklist;
2830 blacklist.push_back(good_crx);
2831 EXPECT_FALSE(IsPrefExist(good_crx, "blacklist"));
2832 service_->UpdateExtensionBlacklist(blacklist);
2833 loop_.RunAllPending();
2834 EXPECT_TRUE(IsPrefExist(good_crx, "blacklist"));
2835
2836 PrefService* prefs = service_->extension_prefs()->pref_service();
2837 base::ListValue whitelist;
2838 whitelist.Append(base::Value::CreateStringValue(good_crx));
2839 prefs->Set(prefs::kExtensionInstallAllowList, whitelist);
2840 loop_.RunAllPending();
2841 EXPECT_FALSE(service_->extension_prefs()->IsExtensionBlacklisted(good_crx));
2842 }
2843
2844 // Allow Google-blacklisted extension if policy requires it (blacklist then set
2845 // policy).
2846 TEST_F(ExtensionServiceTest, ForcelistGoogleBlacklistedExtension) {
2847 InitializeEmptyExtensionService();
2848
2849 std::vector<std::string> blacklist;
2850 blacklist.push_back(good_crx);
2851 EXPECT_FALSE(IsPrefExist(good_crx, "blacklist"));
2852 service_->UpdateExtensionBlacklist(blacklist);
2853 loop_.RunAllPending();
2854 EXPECT_TRUE(IsPrefExist(good_crx, "blacklist"));
2855
2856 PrefService* prefs = service_->extension_prefs()->pref_service();
2857 base::ListValue forcelist;
2858 forcelist.Append(base::Value::CreateStringValue(good_crx));
2859 prefs->Set(prefs::kExtensionInstallForceList, forcelist);
2860 loop_.RunAllPending();
2861 EXPECT_FALSE(service_->extension_prefs()->IsExtensionBlacklisted(good_crx));
2862 }
2863
2864 // Allow Google-blacklisted extension if policy explicitly allows it (set policy
2865 // then blacklist).
Mattias Nissler (ping if slow) 2012/08/08 08:08:37 I'm not sure we really need to test different orde
qfel 2012/08/13 16:03:02 Considering you knowing the implementation, it's a
2866 TEST_F(ExtensionServiceTest, GoogleBlacklistWhitelistedExtension) {
2867 InitializeEmptyExtensionService();
2868
2869 PrefService* prefs = service_->extension_prefs()->pref_service();
2870 base::ListValue whitelist;
2871 whitelist.Append(base::Value::CreateStringValue(good_crx));
2872 prefs->Set(prefs::kExtensionInstallAllowList, whitelist);
2873 loop_.RunAllPending();
2874
2875 std::vector<std::string> blacklist;
2876 blacklist.push_back(good_crx);
2877 EXPECT_FALSE(IsPrefExist(good_crx, "blacklist"));
2878 service_->UpdateExtensionBlacklist(blacklist);
2879 loop_.RunAllPending();
2880 EXPECT_FALSE(service_->extension_prefs()->IsExtensionBlacklisted(good_crx));
2881 }
2882
2883 // Allow Google-blacklisted extension if policy requires it (set policy then
2884 // blacklist).
2885 TEST_F(ExtensionServiceTest, GoogleBlacklistForcelistedExtension) {
2886 InitializeEmptyExtensionService();
2887
2888 PrefService* prefs = service_->extension_prefs()->pref_service();
2889 base::ListValue forcelist;
2890 forcelist.Append(base::Value::CreateStringValue(good_crx));
2891 prefs->Set(prefs::kExtensionInstallForceList, forcelist);
2892 loop_.RunAllPending();
2893
2894 std::vector<std::string> blacklist;
2895 blacklist.push_back(good_crx);
2896 EXPECT_FALSE(IsPrefExist(good_crx, "blacklist"));
2897 service_->UpdateExtensionBlacklist(blacklist);
2898 loop_.RunAllPending();
2899 EXPECT_FALSE(service_->extension_prefs()->IsExtensionBlacklisted(good_crx));
2900 }
2901
2789 // Test loading extensions from the profile directory, except 2902 // Test loading extensions from the profile directory, except
2790 // blacklisted ones. 2903 // blacklisted ones.
2791 TEST_F(ExtensionServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) { 2904 TEST_F(ExtensionServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) {
2792 // Initialize the test dir with a good Preferences/extensions. 2905 // Initialize the test dir with a good Preferences/extensions.
2793 FilePath source_install_dir = data_dir_ 2906 FilePath source_install_dir = data_dir_
2794 .AppendASCII("good") 2907 .AppendASCII("good")
2795 .AppendASCII("Extensions"); 2908 .AppendASCII("Extensions");
2796 FilePath pref_path = source_install_dir 2909 FilePath pref_path = source_install_dir
2797 .DirName() 2910 .DirName()
2798 .AppendASCII("Preferences"); 2911 .AppendASCII("Preferences");
(...skipping 2447 matching lines...) Expand 10 before | Expand all | Expand 10 after
5246 // This should NOT trigger an alert. 5359 // This should NOT trigger an alert.
5247 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", 5360 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0",
5248 data_dir_.AppendASCII("hosted_app.crx")); 5361 data_dir_.AppendASCII("hosted_app.crx"));
5249 5362
5250 service_->CheckForExternalUpdates(); 5363 service_->CheckForExternalUpdates();
5251 loop_.RunAllPending(); 5364 loop_.RunAllPending();
5252 5365
5253 ASSERT_TRUE(service_->PopulateExtensionErrorUI(extension_error_ui.get())); 5366 ASSERT_TRUE(service_->PopulateExtensionErrorUI(extension_error_ui.get()));
5254 ASSERT_EQ(1u, extension_error_ui->get_external_extension_ids()->size()); 5367 ASSERT_EQ(1u, extension_error_ui->get_external_extension_ids()->size());
5255 } 5368 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698