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

Side by Side Diff: chrome/browser/policy/configuration_policy_handler_unittest.cc

Issue 11183029: Don't reject extension list policies with invalid entries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comment. Created 8 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/policy/configuration_policy_handler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/policy/configuration_policy_handler.h" 5 #include "chrome/browser/policy/configuration_policy_handler.h"
6 #include "chrome/browser/policy/policy_error_map.h" 6 #include "chrome/browser/policy/policy_error_map.h"
7 #include "chrome/browser/policy/policy_map.h" 7 #include "chrome/browser/policy/policy_map.h"
8 #include "chrome/browser/prefs/pref_value_map.h" 8 #include "chrome/browser/prefs/pref_value_map.h"
9 #include "chrome/common/pref_names.h" 9 #include "chrome/common/pref_names.h"
10 #include "policy/policy_constants.h" 10 #include "policy/policy_constants.h"
(...skipping 26 matching lines...) Expand all
37 policy_map.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, 37 policy_map.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY,
38 POLICY_SCOPE_USER, list.DeepCopy()); 38 POLICY_SCOPE_USER, list.DeepCopy());
39 errors.Clear(); 39 errors.Clear();
40 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 40 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
41 EXPECT_TRUE(errors.empty()); 41 EXPECT_TRUE(errors.empty());
42 42
43 list.Append(Value::CreateStringValue("invalid")); 43 list.Append(Value::CreateStringValue("invalid"));
44 policy_map.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, 44 policy_map.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY,
45 POLICY_SCOPE_USER, list.DeepCopy()); 45 POLICY_SCOPE_USER, list.DeepCopy());
46 errors.Clear(); 46 errors.Clear();
47 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); 47 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
48 EXPECT_FALSE(errors.empty()); 48 EXPECT_FALSE(errors.empty());
49 EXPECT_FALSE(errors.GetErrors(key::kExtensionInstallBlacklist).empty()); 49 EXPECT_FALSE(errors.GetErrors(key::kExtensionInstallBlacklist).empty());
50 } 50 }
51 51
52 TEST(ExtensionListPolicyHandlerTest, ApplyPolicySettings) { 52 TEST(ExtensionListPolicyHandlerTest, ApplyPolicySettings) {
53 base::ListValue list; 53 base::ListValue policy;
54 base::ListValue expected;
54 PolicyMap policy_map; 55 PolicyMap policy_map;
55 PrefValueMap prefs; 56 PrefValueMap prefs;
56 base::Value* value = NULL; 57 base::Value* value = NULL;
57 ExtensionListPolicyHandler handler(key::kExtensionInstallBlacklist, 58 ExtensionListPolicyHandler handler(key::kExtensionInstallBlacklist,
58 prefs::kExtensionInstallDenyList, 59 prefs::kExtensionInstallDenyList,
59 false); 60 false);
60 61
61 list.Append(Value::CreateStringValue("abcdefghijklmnopabcdefghijklmnop")); 62 policy.Append(Value::CreateStringValue("abcdefghijklmnopabcdefghijklmnop"));
63 expected.Append(Value::CreateStringValue("abcdefghijklmnopabcdefghijklmnop"));
64
62 policy_map.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, 65 policy_map.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY,
63 POLICY_SCOPE_USER, list.DeepCopy()); 66 POLICY_SCOPE_USER, policy.DeepCopy());
64 handler.ApplyPolicySettings(policy_map, &prefs); 67 handler.ApplyPolicySettings(policy_map, &prefs);
65 EXPECT_TRUE(prefs.GetValue(prefs::kExtensionInstallDenyList, &value)); 68 EXPECT_TRUE(prefs.GetValue(prefs::kExtensionInstallDenyList, &value));
66 EXPECT_TRUE(base::Value::Equals(&list, value)); 69 EXPECT_TRUE(base::Value::Equals(&expected, value));
70
71 policy.Append(Value::CreateStringValue("invalid"));
72 policy_map.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY,
73 POLICY_SCOPE_USER, policy.DeepCopy());
74 handler.ApplyPolicySettings(policy_map, &prefs);
75 EXPECT_TRUE(prefs.GetValue(prefs::kExtensionInstallDenyList, &value));
76 EXPECT_TRUE(base::Value::Equals(&expected, value));
67 } 77 }
68 78
69 TEST(ExtensionURLPatternListPolicyHandlerTest, CheckPolicySettings) { 79 TEST(ExtensionURLPatternListPolicyHandlerTest, CheckPolicySettings) {
70 base::ListValue list; 80 base::ListValue list;
71 PolicyMap policy_map; 81 PolicyMap policy_map;
72 PolicyErrorMap errors; 82 PolicyErrorMap errors;
73 ExtensionURLPatternListPolicyHandler handler( 83 ExtensionURLPatternListPolicyHandler handler(
74 key::kExtensionInstallSources, 84 key::kExtensionInstallSources,
75 prefs::kExtensionAllowedInstallSites); 85 prefs::kExtensionAllowedInstallSites);
76 86
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 ASSERT_TRUE(prefs.GetValue(prefs::kManagedDefaultCookiesSetting, &val)); 187 ASSERT_TRUE(prefs.GetValue(prefs::kManagedDefaultCookiesSetting, &val));
178 EXPECT_TRUE(base::FundamentalValue(CONTENT_SETTING_SESSION_ONLY).Equals(val)); 188 EXPECT_TRUE(base::FundamentalValue(CONTENT_SETTING_SESSION_ONLY).Equals(val));
179 189
180 policy_map.Clear(); 190 policy_map.Clear();
181 prefs.Clear(); 191 prefs.Clear();
182 handler.ApplyPolicySettings(policy_map, &prefs); 192 handler.ApplyPolicySettings(policy_map, &prefs);
183 EXPECT_FALSE(prefs.GetValue(prefs::kManagedDefaultCookiesSetting, &val)); 193 EXPECT_FALSE(prefs.GetValue(prefs::kManagedDefaultCookiesSetting, &val));
184 } 194 }
185 195
186 } // namespace policy 196 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/configuration_policy_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698