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

Side by Side Diff: components/policy/core/common/policy_bundle_unittest.cc

Issue 1304843004: Add source column to chrome://policy showing the origins of policies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed another test. Created 5 years, 3 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 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 "components/policy/core/common/policy_bundle.h" 5 #include "components/policy/core/common/policy_bundle.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "components/policy/core/common/external_data_fetcher.h" 10 #include "components/policy/core/common/external_data_fetcher.h"
11 #include "components/policy/core/common/policy_map.h" 11 #include "components/policy/core/common/policy_map.h"
12 #include "components/policy/core/common/policy_types.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 namespace policy { 15 namespace policy {
15 16
16 namespace { 17 namespace {
17 18
18 const char kPolicyClashing0[] = "policy-clashing-0"; 19 const char kPolicyClashing0[] = "policy-clashing-0";
19 const char kPolicyClashing1[] = "policy-clashing-1"; 20 const char kPolicyClashing1[] = "policy-clashing-1";
20 const char kPolicy0[] = "policy-0"; 21 const char kPolicy0[] = "policy-0";
21 const char kPolicy1[] = "policy-1"; 22 const char kPolicy1[] = "policy-1";
22 const char kPolicy2[] = "policy-2"; 23 const char kPolicy2[] = "policy-2";
23 const char kExtension0[] = "extension-0"; 24 const char kExtension0[] = "extension-0";
24 const char kExtension1[] = "extension-1"; 25 const char kExtension1[] = "extension-1";
25 const char kExtension2[] = "extension-2"; 26 const char kExtension2[] = "extension-2";
26 const char kExtension3[] = "extension-3"; 27 const char kExtension3[] = "extension-3";
27 28
28 // Adds test policies to |policy|. 29 // Adds test policies to |policy|.
29 void AddTestPolicies(PolicyMap* policy) { 30 void AddTestPolicies(PolicyMap* policy) {
30 policy->Set("mandatory-user", 31 policy->Set("mandatory-user",
31 POLICY_LEVEL_MANDATORY, 32 POLICY_LEVEL_MANDATORY,
32 POLICY_SCOPE_USER, 33 POLICY_SCOPE_USER,
34 POLICY_SOURCE_CLOUD,
33 new base::FundamentalValue(123), 35 new base::FundamentalValue(123),
34 NULL); 36 NULL);
35 policy->Set("mandatory-machine", 37 policy->Set("mandatory-machine",
36 POLICY_LEVEL_MANDATORY, 38 POLICY_LEVEL_MANDATORY,
37 POLICY_SCOPE_MACHINE, 39 POLICY_SCOPE_MACHINE,
40 POLICY_SOURCE_CLOUD,
38 new base::StringValue("omg"), 41 new base::StringValue("omg"),
39 NULL); 42 NULL);
40 policy->Set("recommended-user", 43 policy->Set("recommended-user",
41 POLICY_LEVEL_RECOMMENDED, 44 POLICY_LEVEL_RECOMMENDED,
42 POLICY_SCOPE_USER, 45 POLICY_SCOPE_USER,
46 POLICY_SOURCE_CLOUD,
43 new base::FundamentalValue(true), 47 new base::FundamentalValue(true),
44 NULL); 48 NULL);
45 base::DictionaryValue* dict = new base::DictionaryValue(); 49 base::DictionaryValue* dict = new base::DictionaryValue();
46 dict->SetBoolean("false", false); 50 dict->SetBoolean("false", false);
47 dict->SetInteger("int", 456); 51 dict->SetInteger("int", 456);
48 dict->SetString("str", "bbq"); 52 dict->SetString("str", "bbq");
49 policy->Set("recommended-machine", POLICY_LEVEL_RECOMMENDED, 53 policy->Set("recommended-machine", POLICY_LEVEL_RECOMMENDED,
50 POLICY_SCOPE_MACHINE, dict, NULL); 54 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, dict, nullptr);
51 } 55 }
52 56
53 // Adds test policies to |policy| based on the parameters: 57 // Adds test policies to |policy| based on the parameters:
54 // - kPolicyClashing0 mapped to |value|, user mandatory 58 // - kPolicyClashing0 mapped to |value|, user mandatory
55 // - kPolicyClashing1 mapped to |value|, with |level| and |scope| 59 // - kPolicyClashing1 mapped to |value|, with |level| and |scope|
56 // - |name| mapped to |value|, user mandatory 60 // - |name| mapped to |value|, user mandatory
57 void AddTestPoliciesWithParams(PolicyMap *policy, 61 void AddTestPoliciesWithParams(PolicyMap *policy,
58 const char* name, 62 const char* name,
59 int value, 63 int value,
60 PolicyLevel level, 64 PolicyLevel level,
61 PolicyScope scope) { 65 PolicyScope scope) {
62 policy->Set(kPolicyClashing0, 66 policy->Set(kPolicyClashing0,
63 POLICY_LEVEL_MANDATORY, 67 POLICY_LEVEL_MANDATORY,
64 POLICY_SCOPE_USER, 68 POLICY_SCOPE_USER,
69 POLICY_SOURCE_CLOUD,
65 new base::FundamentalValue(value), 70 new base::FundamentalValue(value),
66 NULL); 71 NULL);
67 policy->Set( 72 policy->Set(kPolicyClashing1, level, scope, POLICY_SOURCE_CLOUD,
68 kPolicyClashing1, level, scope, new base::FundamentalValue(value), NULL); 73 new base::FundamentalValue(value), nullptr);
69 policy->Set(name, 74 policy->Set(name,
70 POLICY_LEVEL_MANDATORY, 75 POLICY_LEVEL_MANDATORY,
71 POLICY_SCOPE_USER, 76 POLICY_SCOPE_USER,
77 POLICY_SOURCE_CLOUD,
72 new base::FundamentalValue(value), 78 new base::FundamentalValue(value),
73 NULL); 79 NULL);
74 } 80 }
75 81
76 // Returns true if |bundle| is empty. 82 // Returns true if |bundle| is empty.
77 bool IsEmpty(const PolicyBundle& bundle) { 83 bool IsEmpty(const PolicyBundle& bundle) {
78 return bundle.begin() == bundle.end(); 84 return bundle.begin() == bundle.end();
79 } 85 }
80 86
81 } // namespace 87 } // namespace
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 199
194 // chrome and kExtension3 policies are merged: 200 // chrome and kExtension3 policies are merged:
195 // - kPolicyClashing0 comes from bundle0, which has the highest priority; 201 // - kPolicyClashing0 comes from bundle0, which has the highest priority;
196 // - kPolicyClashing1 comes from bundle1, which has the highest level/scope 202 // - kPolicyClashing1 comes from bundle1, which has the highest level/scope
197 // combination; 203 // combination;
198 // - kPolicyN are merged from each bundle. 204 // - kPolicyN are merged from each bundle.
199 PolicyMap expected; 205 PolicyMap expected;
200 expected.Set(kPolicyClashing0, 206 expected.Set(kPolicyClashing0,
201 POLICY_LEVEL_MANDATORY, 207 POLICY_LEVEL_MANDATORY,
202 POLICY_SCOPE_USER, 208 POLICY_SCOPE_USER,
209 POLICY_SOURCE_CLOUD,
203 new base::FundamentalValue(0), 210 new base::FundamentalValue(0),
204 NULL); 211 NULL);
205 expected.Set(kPolicyClashing1, 212 expected.Set(kPolicyClashing1,
206 POLICY_LEVEL_MANDATORY, 213 POLICY_LEVEL_MANDATORY,
207 POLICY_SCOPE_MACHINE, 214 POLICY_SCOPE_MACHINE,
215 POLICY_SOURCE_CLOUD,
208 new base::FundamentalValue(1), 216 new base::FundamentalValue(1),
209 NULL); 217 NULL);
210 expected.Set(kPolicy0, 218 expected.Set(kPolicy0,
211 POLICY_LEVEL_MANDATORY, 219 POLICY_LEVEL_MANDATORY,
212 POLICY_SCOPE_USER, 220 POLICY_SCOPE_USER,
221 POLICY_SOURCE_CLOUD,
213 new base::FundamentalValue(0), 222 new base::FundamentalValue(0),
214 NULL); 223 NULL);
215 expected.Set(kPolicy1, 224 expected.Set(kPolicy1,
216 POLICY_LEVEL_MANDATORY, 225 POLICY_LEVEL_MANDATORY,
217 POLICY_SCOPE_USER, 226 POLICY_SCOPE_USER,
227 POLICY_SOURCE_CLOUD,
218 new base::FundamentalValue(1), 228 new base::FundamentalValue(1),
219 NULL); 229 NULL);
220 expected.Set(kPolicy2, 230 expected.Set(kPolicy2,
221 POLICY_LEVEL_MANDATORY, 231 POLICY_LEVEL_MANDATORY,
222 POLICY_SCOPE_USER, 232 POLICY_SCOPE_USER,
233 POLICY_SOURCE_CLOUD,
223 new base::FundamentalValue(2), 234 new base::FundamentalValue(2),
224 NULL); 235 NULL);
225 EXPECT_TRUE(merged.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, 236 EXPECT_TRUE(merged.Get(PolicyNamespace(POLICY_DOMAIN_CHROME,
226 std::string())).Equals(expected)); 237 std::string())).Equals(expected));
227 EXPECT_TRUE(merged.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, 238 EXPECT_TRUE(merged.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS,
228 kExtension3)).Equals(expected)); 239 kExtension3)).Equals(expected));
229 // extension0 comes only from bundle0. 240 // extension0 comes only from bundle0.
230 EXPECT_TRUE(merged.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, 241 EXPECT_TRUE(merged.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS,
231 kExtension0)).Equals(policy0)); 242 kExtension0)).Equals(policy0));
232 // extension1 comes only from bundle1. 243 // extension1 comes only from bundle1.
(...skipping 23 matching lines...) Expand all
256 EXPECT_TRUE(bundle.Equals(other)); 267 EXPECT_TRUE(bundle.Equals(other));
257 AddTestPolicies(&other.Get( 268 AddTestPolicies(&other.Get(
258 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension2))); 269 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension2)));
259 EXPECT_FALSE(bundle.Equals(other)); 270 EXPECT_FALSE(bundle.Equals(other));
260 271
261 other.CopyFrom(bundle); 272 other.CopyFrom(bundle);
262 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 273 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
263 .Set(kPolicy0, 274 .Set(kPolicy0,
264 POLICY_LEVEL_MANDATORY, 275 POLICY_LEVEL_MANDATORY,
265 POLICY_SCOPE_USER, 276 POLICY_SCOPE_USER,
277 POLICY_SOURCE_CLOUD,
266 new base::FundamentalValue(123), 278 new base::FundamentalValue(123),
267 NULL); 279 NULL);
268 EXPECT_FALSE(bundle.Equals(other)); 280 EXPECT_FALSE(bundle.Equals(other));
269 other.CopyFrom(bundle); 281 other.CopyFrom(bundle);
270 EXPECT_TRUE(bundle.Equals(other)); 282 EXPECT_TRUE(bundle.Equals(other));
271 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 283 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
272 .Set(kPolicy0, 284 .Set(kPolicy0,
273 POLICY_LEVEL_MANDATORY, 285 POLICY_LEVEL_MANDATORY,
274 POLICY_SCOPE_MACHINE, 286 POLICY_SCOPE_MACHINE,
287 POLICY_SOURCE_CLOUD,
275 new base::FundamentalValue(123), 288 new base::FundamentalValue(123),
276 NULL); 289 NULL);
277 EXPECT_FALSE(bundle.Equals(other)); 290 EXPECT_FALSE(bundle.Equals(other));
278 291
279 // Test non-const Get(). 292 // Test non-const Get().
280 bundle.Clear(); 293 bundle.Clear();
281 other.Clear(); 294 other.Clear();
282 PolicyMap& policy_map = 295 PolicyMap& policy_map =
283 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); 296 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()));
284 EXPECT_TRUE(bundle.Equals(other)); 297 EXPECT_TRUE(bundle.Equals(other));
285 policy_map.Set(kPolicy0, 298 policy_map.Set(kPolicy0,
286 POLICY_LEVEL_MANDATORY, 299 POLICY_LEVEL_MANDATORY,
287 POLICY_SCOPE_USER, 300 POLICY_SCOPE_USER,
301 POLICY_SOURCE_CLOUD,
288 new base::FundamentalValue(123), 302 new base::FundamentalValue(123),
289 NULL); 303 NULL);
290 EXPECT_FALSE(bundle.Equals(other)); 304 EXPECT_FALSE(bundle.Equals(other));
291 } 305 }
292 306
293 } // namespace policy 307 } // namespace policy
OLDNEW
« no previous file with comments | « components/policy/core/common/generate_policy_source_unittest.cc ('k') | components/policy/core/common/policy_loader_ios.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698