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

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

Issue 388963002: Get rid of the rest of CreateStringValue (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix bad rebase Created 6 years, 5 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/prefs/pref_value_map.h" 5 #include "base/prefs/pref_value_map.h"
6 #include "chrome/browser/extensions/external_policy_loader.h" 6 #include "chrome/browser/extensions/external_policy_loader.h"
7 #include "chrome/browser/extensions/policy_handlers.h" 7 #include "chrome/browser/extensions/policy_handlers.h"
8 #include "chrome/common/pref_names.h" 8 #include "chrome/common/pref_names.h"
9 #include "components/policy/core/browser/policy_error_map.h" 9 #include "components/policy/core/browser/policy_error_map.h"
10 #include "components/policy/core/common/policy_map.h" 10 #include "components/policy/core/common/policy_map.h"
(...skipping 14 matching lines...) Expand all
25 25
26 policy_map.Set(policy::key::kExtensionInstallBlacklist, 26 policy_map.Set(policy::key::kExtensionInstallBlacklist,
27 policy::POLICY_LEVEL_MANDATORY, 27 policy::POLICY_LEVEL_MANDATORY,
28 policy::POLICY_SCOPE_USER, 28 policy::POLICY_SCOPE_USER,
29 list.DeepCopy(), 29 list.DeepCopy(),
30 NULL); 30 NULL);
31 errors.Clear(); 31 errors.Clear();
32 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 32 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
33 EXPECT_TRUE(errors.empty()); 33 EXPECT_TRUE(errors.empty());
34 34
35 list.Append( 35 list.Append(new base::StringValue("abcdefghijklmnopabcdefghijklmnop"));
36 base::Value::CreateStringValue("abcdefghijklmnopabcdefghijklmnop"));
37 policy_map.Set(policy::key::kExtensionInstallBlacklist, 36 policy_map.Set(policy::key::kExtensionInstallBlacklist,
38 policy::POLICY_LEVEL_MANDATORY, 37 policy::POLICY_LEVEL_MANDATORY,
39 policy::POLICY_SCOPE_USER, 38 policy::POLICY_SCOPE_USER,
40 list.DeepCopy(), 39 list.DeepCopy(),
41 NULL); 40 NULL);
42 errors.Clear(); 41 errors.Clear();
43 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 42 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
44 EXPECT_TRUE(errors.empty()); 43 EXPECT_TRUE(errors.empty());
45 44
46 list.Append(base::Value::CreateStringValue("*")); 45 list.Append(new base::StringValue("*"));
47 policy_map.Set(policy::key::kExtensionInstallBlacklist, 46 policy_map.Set(policy::key::kExtensionInstallBlacklist,
48 policy::POLICY_LEVEL_MANDATORY, 47 policy::POLICY_LEVEL_MANDATORY,
49 policy::POLICY_SCOPE_USER, 48 policy::POLICY_SCOPE_USER,
50 list.DeepCopy(), 49 list.DeepCopy(),
51 NULL); 50 NULL);
52 errors.Clear(); 51 errors.Clear();
53 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 52 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
54 EXPECT_TRUE(errors.empty()); 53 EXPECT_TRUE(errors.empty());
55 54
56 list.Append(base::Value::CreateStringValue("invalid")); 55 list.Append(new base::StringValue("invalid"));
57 policy_map.Set(policy::key::kExtensionInstallBlacklist, 56 policy_map.Set(policy::key::kExtensionInstallBlacklist,
58 policy::POLICY_LEVEL_MANDATORY, 57 policy::POLICY_LEVEL_MANDATORY,
59 policy::POLICY_SCOPE_USER, 58 policy::POLICY_SCOPE_USER,
60 list.DeepCopy(), 59 list.DeepCopy(),
61 NULL); 60 NULL);
62 errors.Clear(); 61 errors.Clear();
63 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 62 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
64 EXPECT_FALSE(errors.empty()); 63 EXPECT_FALSE(errors.empty());
65 EXPECT_FALSE( 64 EXPECT_FALSE(
66 errors.GetErrors(policy::key::kExtensionInstallBlacklist).empty()); 65 errors.GetErrors(policy::key::kExtensionInstallBlacklist).empty());
67 } 66 }
68 67
69 TEST(ExtensionListPolicyHandlerTest, ApplyPolicySettings) { 68 TEST(ExtensionListPolicyHandlerTest, ApplyPolicySettings) {
70 base::ListValue policy; 69 base::ListValue policy;
71 base::ListValue expected; 70 base::ListValue expected;
72 policy::PolicyMap policy_map; 71 policy::PolicyMap policy_map;
73 PrefValueMap prefs; 72 PrefValueMap prefs;
74 base::Value* value = NULL; 73 base::Value* value = NULL;
75 ExtensionListPolicyHandler handler( 74 ExtensionListPolicyHandler handler(
76 policy::key::kExtensionInstallBlacklist, kTestPref, false); 75 policy::key::kExtensionInstallBlacklist, kTestPref, false);
77 76
78 policy.Append( 77 policy.Append(new base::StringValue("abcdefghijklmnopabcdefghijklmnop"));
79 base::Value::CreateStringValue("abcdefghijklmnopabcdefghijklmnop")); 78 expected.Append(new base::StringValue("abcdefghijklmnopabcdefghijklmnop"));
80 expected.Append(
81 base::Value::CreateStringValue("abcdefghijklmnopabcdefghijklmnop"));
82 79
83 policy_map.Set(policy::key::kExtensionInstallBlacklist, 80 policy_map.Set(policy::key::kExtensionInstallBlacklist,
84 policy::POLICY_LEVEL_MANDATORY, 81 policy::POLICY_LEVEL_MANDATORY,
85 policy::POLICY_SCOPE_USER, 82 policy::POLICY_SCOPE_USER,
86 policy.DeepCopy(), 83 policy.DeepCopy(),
87 NULL); 84 NULL);
88 handler.ApplyPolicySettings(policy_map, &prefs); 85 handler.ApplyPolicySettings(policy_map, &prefs);
89 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); 86 EXPECT_TRUE(prefs.GetValue(kTestPref, &value));
90 EXPECT_TRUE(base::Value::Equals(&expected, value)); 87 EXPECT_TRUE(base::Value::Equals(&expected, value));
91 88
92 policy.Append(base::Value::CreateStringValue("invalid")); 89 policy.Append(new base::StringValue("invalid"));
93 policy_map.Set(policy::key::kExtensionInstallBlacklist, 90 policy_map.Set(policy::key::kExtensionInstallBlacklist,
94 policy::POLICY_LEVEL_MANDATORY, 91 policy::POLICY_LEVEL_MANDATORY,
95 policy::POLICY_SCOPE_USER, 92 policy::POLICY_SCOPE_USER,
96 policy.DeepCopy(), 93 policy.DeepCopy(),
97 NULL); 94 NULL);
98 handler.ApplyPolicySettings(policy_map, &prefs); 95 handler.ApplyPolicySettings(policy_map, &prefs);
99 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); 96 EXPECT_TRUE(prefs.GetValue(kTestPref, &value));
100 EXPECT_TRUE(base::Value::Equals(&expected, value)); 97 EXPECT_TRUE(base::Value::Equals(&expected, value));
101 } 98 }
102 99
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 210
214 policy_map.Set(policy::key::kExtensionInstallSources, 211 policy_map.Set(policy::key::kExtensionInstallSources,
215 policy::POLICY_LEVEL_MANDATORY, 212 policy::POLICY_LEVEL_MANDATORY,
216 policy::POLICY_SCOPE_USER, 213 policy::POLICY_SCOPE_USER,
217 list.DeepCopy(), 214 list.DeepCopy(),
218 NULL); 215 NULL);
219 errors.Clear(); 216 errors.Clear();
220 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 217 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
221 EXPECT_TRUE(errors.empty()); 218 EXPECT_TRUE(errors.empty());
222 219
223 list.Append(base::Value::CreateStringValue("http://*.google.com/*")); 220 list.Append(new base::StringValue("http://*.google.com/*"));
224 policy_map.Set(policy::key::kExtensionInstallSources, 221 policy_map.Set(policy::key::kExtensionInstallSources,
225 policy::POLICY_LEVEL_MANDATORY, 222 policy::POLICY_LEVEL_MANDATORY,
226 policy::POLICY_SCOPE_USER, 223 policy::POLICY_SCOPE_USER,
227 list.DeepCopy(), 224 list.DeepCopy(),
228 NULL); 225 NULL);
229 errors.Clear(); 226 errors.Clear();
230 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 227 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
231 EXPECT_TRUE(errors.empty()); 228 EXPECT_TRUE(errors.empty());
232 229
233 list.Append(base::Value::CreateStringValue("<all_urls>")); 230 list.Append(new base::StringValue("<all_urls>"));
234 policy_map.Set(policy::key::kExtensionInstallSources, 231 policy_map.Set(policy::key::kExtensionInstallSources,
235 policy::POLICY_LEVEL_MANDATORY, 232 policy::POLICY_LEVEL_MANDATORY,
236 policy::POLICY_SCOPE_USER, 233 policy::POLICY_SCOPE_USER,
237 list.DeepCopy(), 234 list.DeepCopy(),
238 NULL); 235 NULL);
239 errors.Clear(); 236 errors.Clear();
240 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 237 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
241 EXPECT_TRUE(errors.empty()); 238 EXPECT_TRUE(errors.empty());
242 239
243 list.Append(base::Value::CreateStringValue("invalid")); 240 list.Append(new base::StringValue("invalid"));
244 policy_map.Set(policy::key::kExtensionInstallSources, 241 policy_map.Set(policy::key::kExtensionInstallSources,
245 policy::POLICY_LEVEL_MANDATORY, 242 policy::POLICY_LEVEL_MANDATORY,
246 policy::POLICY_SCOPE_USER, 243 policy::POLICY_SCOPE_USER,
247 list.DeepCopy(), 244 list.DeepCopy(),
248 NULL); 245 NULL);
249 errors.Clear(); 246 errors.Clear();
250 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); 247 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
251 EXPECT_FALSE(errors.empty()); 248 EXPECT_FALSE(errors.empty());
252 EXPECT_FALSE(errors.GetErrors(policy::key::kExtensionInstallSources).empty()); 249 EXPECT_FALSE(errors.GetErrors(policy::key::kExtensionInstallSources).empty());
253 250
254 // URLPattern syntax has a different way to express 'all urls'. Though '*' 251 // URLPattern syntax has a different way to express 'all urls'. Though '*'
255 // would be compatible today, it would be brittle, so we disallow. 252 // would be compatible today, it would be brittle, so we disallow.
256 list.Append(base::Value::CreateStringValue("*")); 253 list.Append(new base::StringValue("*"));
257 policy_map.Set(policy::key::kExtensionInstallSources, 254 policy_map.Set(policy::key::kExtensionInstallSources,
258 policy::POLICY_LEVEL_MANDATORY, 255 policy::POLICY_LEVEL_MANDATORY,
259 policy::POLICY_SCOPE_USER, 256 policy::POLICY_SCOPE_USER,
260 list.DeepCopy(), 257 list.DeepCopy(),
261 NULL); 258 NULL);
262 errors.Clear(); 259 errors.Clear();
263 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); 260 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
264 EXPECT_FALSE(errors.empty()); 261 EXPECT_FALSE(errors.empty());
265 EXPECT_FALSE(errors.GetErrors(policy::key::kExtensionInstallSources).empty()); 262 EXPECT_FALSE(errors.GetErrors(policy::key::kExtensionInstallSources).empty());
266 } 263 }
267 264
268 TEST(ExtensionURLPatternListPolicyHandlerTest, ApplyPolicySettings) { 265 TEST(ExtensionURLPatternListPolicyHandlerTest, ApplyPolicySettings) {
269 base::ListValue list; 266 base::ListValue list;
270 policy::PolicyMap policy_map; 267 policy::PolicyMap policy_map;
271 PrefValueMap prefs; 268 PrefValueMap prefs;
272 base::Value* value = NULL; 269 base::Value* value = NULL;
273 ExtensionURLPatternListPolicyHandler handler( 270 ExtensionURLPatternListPolicyHandler handler(
274 policy::key::kExtensionInstallSources, kTestPref); 271 policy::key::kExtensionInstallSources, kTestPref);
275 272
276 list.Append(base::Value::CreateStringValue("https://corp.monkey.net/*")); 273 list.Append(new base::StringValue("https://corp.monkey.net/*"));
277 policy_map.Set(policy::key::kExtensionInstallSources, 274 policy_map.Set(policy::key::kExtensionInstallSources,
278 policy::POLICY_LEVEL_MANDATORY, 275 policy::POLICY_LEVEL_MANDATORY,
279 policy::POLICY_SCOPE_USER, 276 policy::POLICY_SCOPE_USER,
280 list.DeepCopy(), 277 list.DeepCopy(),
281 NULL); 278 NULL);
282 handler.ApplyPolicySettings(policy_map, &prefs); 279 handler.ApplyPolicySettings(policy_map, &prefs);
283 ASSERT_TRUE(prefs.GetValue(kTestPref, &value)); 280 ASSERT_TRUE(prefs.GetValue(kTestPref, &value));
284 EXPECT_TRUE(base::Value::Equals(&list, value)); 281 EXPECT_TRUE(base::Value::Equals(&list, value));
285 } 282 }
286 283
287 } // namespace extensions 284 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698