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

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

Issue 397793002: Eliminate CreateBooleanValue from test files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix bad merge 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 "components/policy/core/common/policy_map.h" 5 #include "components/policy/core/common/policy_map.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "components/policy/core/common/external_data_manager.h" 9 #include "components/policy/core/common/external_data_manager.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 TEST_F(PolicyMapTest, Equals) { 79 TEST_F(PolicyMapTest, Equals) {
80 PolicyMap a; 80 PolicyMap a;
81 SetPolicy(&a, kTestPolicyName1, base::Value::CreateStringValue("aaa")); 81 SetPolicy(&a, kTestPolicyName1, base::Value::CreateStringValue("aaa"));
82 PolicyMap a2; 82 PolicyMap a2;
83 SetPolicy(&a2, kTestPolicyName1, base::Value::CreateStringValue("aaa")); 83 SetPolicy(&a2, kTestPolicyName1, base::Value::CreateStringValue("aaa"));
84 PolicyMap b; 84 PolicyMap b;
85 SetPolicy(&b, kTestPolicyName1, base::Value::CreateStringValue("bbb")); 85 SetPolicy(&b, kTestPolicyName1, base::Value::CreateStringValue("bbb"));
86 PolicyMap c; 86 PolicyMap c;
87 SetPolicy(&c, kTestPolicyName1, base::Value::CreateStringValue("aaa")); 87 SetPolicy(&c, kTestPolicyName1, base::Value::CreateStringValue("aaa"));
88 SetPolicy(&c, kTestPolicyName2, base::Value::CreateBooleanValue(true)); 88 SetPolicy(&c, kTestPolicyName2, new base::FundamentalValue(true));
89 PolicyMap d; 89 PolicyMap d;
90 SetPolicy(&d, kTestPolicyName1, 90 SetPolicy(&d, kTestPolicyName1,
91 CreateExternalDataFetcher("ddd").release()); 91 CreateExternalDataFetcher("ddd").release());
92 PolicyMap d2; 92 PolicyMap d2;
93 SetPolicy(&d2, kTestPolicyName1, 93 SetPolicy(&d2, kTestPolicyName1,
94 CreateExternalDataFetcher("ddd").release()); 94 CreateExternalDataFetcher("ddd").release());
95 PolicyMap e; 95 PolicyMap e;
96 SetPolicy(&e, kTestPolicyName1, 96 SetPolicy(&e, kTestPolicyName1,
97 CreateExternalDataFetcher("eee").release()); 97 CreateExternalDataFetcher("eee").release());
98 EXPECT_FALSE(a.Equals(b)); 98 EXPECT_FALSE(a.Equals(b));
(...skipping 28 matching lines...) Expand all
127 EXPECT_FALSE(a.Equals(empty1)); 127 EXPECT_FALSE(a.Equals(empty1));
128 } 128 }
129 129
130 TEST_F(PolicyMapTest, Swap) { 130 TEST_F(PolicyMapTest, Swap) {
131 PolicyMap a; 131 PolicyMap a;
132 SetPolicy(&a, kTestPolicyName1, base::Value::CreateStringValue("aaa")); 132 SetPolicy(&a, kTestPolicyName1, base::Value::CreateStringValue("aaa"));
133 SetPolicy(&a, kTestPolicyName2, 133 SetPolicy(&a, kTestPolicyName2,
134 CreateExternalDataFetcher("dummy").release()); 134 CreateExternalDataFetcher("dummy").release());
135 PolicyMap b; 135 PolicyMap b;
136 SetPolicy(&b, kTestPolicyName1, base::Value::CreateStringValue("bbb")); 136 SetPolicy(&b, kTestPolicyName1, base::Value::CreateStringValue("bbb"));
137 SetPolicy(&b, kTestPolicyName3, base::Value::CreateBooleanValue(true)); 137 SetPolicy(&b, kTestPolicyName3, new base::FundamentalValue(true));
138 138
139 a.Swap(&b); 139 a.Swap(&b);
140 base::StringValue expected("bbb"); 140 base::StringValue expected("bbb");
141 EXPECT_TRUE(expected.Equals(a.GetValue(kTestPolicyName1))); 141 EXPECT_TRUE(expected.Equals(a.GetValue(kTestPolicyName1)));
142 base::FundamentalValue expected_bool(true); 142 base::FundamentalValue expected_bool(true);
143 EXPECT_TRUE(expected_bool.Equals(a.GetValue(kTestPolicyName3))); 143 EXPECT_TRUE(expected_bool.Equals(a.GetValue(kTestPolicyName3)));
144 EXPECT_FALSE(a.GetValue(kTestPolicyName2)); 144 EXPECT_FALSE(a.GetValue(kTestPolicyName2));
145 EXPECT_FALSE(a.Get(kTestPolicyName2)); 145 EXPECT_FALSE(a.Get(kTestPolicyName2));
146 base::StringValue expected_a("aaa"); 146 base::StringValue expected_a("aaa");
147 EXPECT_TRUE(expected_a.Equals(b.GetValue(kTestPolicyName1))); 147 EXPECT_TRUE(expected_a.Equals(b.GetValue(kTestPolicyName1)));
148 EXPECT_FALSE(b.GetValue(kTestPolicyName3)); 148 EXPECT_FALSE(b.GetValue(kTestPolicyName3));
149 EXPECT_FALSE(a.GetValue(kTestPolicyName2)); 149 EXPECT_FALSE(a.GetValue(kTestPolicyName2));
150 const PolicyMap::Entry* entry = b.Get(kTestPolicyName2); 150 const PolicyMap::Entry* entry = b.Get(kTestPolicyName2);
151 ASSERT_TRUE(entry); 151 ASSERT_TRUE(entry);
152 EXPECT_TRUE(ExternalDataFetcher::Equals( 152 EXPECT_TRUE(ExternalDataFetcher::Equals(
153 CreateExternalDataFetcher("dummy").get(), entry->external_data_fetcher)); 153 CreateExternalDataFetcher("dummy").get(), entry->external_data_fetcher));
154 154
155 b.Clear(); 155 b.Clear();
156 a.Swap(&b); 156 a.Swap(&b);
157 PolicyMap empty; 157 PolicyMap empty;
158 EXPECT_TRUE(a.Equals(empty)); 158 EXPECT_TRUE(a.Equals(empty));
159 EXPECT_FALSE(b.Equals(empty)); 159 EXPECT_FALSE(b.Equals(empty));
160 } 160 }
161 161
162 TEST_F(PolicyMapTest, MergeFrom) { 162 TEST_F(PolicyMapTest, MergeFrom) {
163 PolicyMap a; 163 PolicyMap a;
164 a.Set(kTestPolicyName1, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 164 a.Set(kTestPolicyName1, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
165 base::Value::CreateStringValue("google.com"), NULL); 165 base::Value::CreateStringValue("google.com"), NULL);
166 a.Set(kTestPolicyName2, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 166 a.Set(kTestPolicyName2,
167 base::Value::CreateBooleanValue(true), NULL); 167 POLICY_LEVEL_MANDATORY,
168 POLICY_SCOPE_MACHINE,
169 new base::FundamentalValue(true),
170 NULL);
168 a.Set(kTestPolicyName3, 171 a.Set(kTestPolicyName3,
169 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 172 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
170 NULL, CreateExternalDataFetcher("a").release()); 173 NULL, CreateExternalDataFetcher("a").release());
171 a.Set(kTestPolicyName4, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER, 174 a.Set(kTestPolicyName4,
172 base::Value::CreateBooleanValue(false), NULL); 175 POLICY_LEVEL_RECOMMENDED,
176 POLICY_SCOPE_USER,
177 new base::FundamentalValue(false),
178 NULL);
173 a.Set(kTestPolicyName5, 179 a.Set(kTestPolicyName5,
174 POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_MACHINE, 180 POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_MACHINE,
175 base::Value::CreateStringValue("google.com/q={x}"), NULL); 181 base::Value::CreateStringValue("google.com/q={x}"), NULL);
176 182
177 PolicyMap b; 183 PolicyMap b;
178 b.Set(kTestPolicyName1, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 184 b.Set(kTestPolicyName1, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
179 base::Value::CreateStringValue("chromium.org"), NULL); 185 base::Value::CreateStringValue("chromium.org"), NULL);
180 b.Set(kTestPolicyName2, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 186 b.Set(kTestPolicyName2,
181 base::Value::CreateBooleanValue(false), NULL); 187 POLICY_LEVEL_MANDATORY,
188 POLICY_SCOPE_MACHINE,
189 new base::FundamentalValue(false),
190 NULL);
182 b.Set(kTestPolicyName3, 191 b.Set(kTestPolicyName3,
183 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 192 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
184 NULL, CreateExternalDataFetcher("b").release()); 193 NULL, CreateExternalDataFetcher("b").release());
185 b.Set(kTestPolicyName4, POLICY_LEVEL_RECOMMENDED, 194 b.Set(kTestPolicyName4,
186 POLICY_SCOPE_MACHINE, base::Value::CreateBooleanValue(true), NULL); 195 POLICY_LEVEL_RECOMMENDED,
196 POLICY_SCOPE_MACHINE,
197 new base::FundamentalValue(true),
198 NULL);
187 b.Set(kTestPolicyName5, 199 b.Set(kTestPolicyName5,
188 POLICY_LEVEL_MANDATORY, 200 POLICY_LEVEL_MANDATORY,
189 POLICY_SCOPE_MACHINE, 201 POLICY_SCOPE_MACHINE,
190 base::Value::CreateStringValue(std::string()), 202 base::Value::CreateStringValue(std::string()),
191 NULL); 203 NULL);
192 b.Set(kTestPolicyName6, 204 b.Set(kTestPolicyName6,
193 POLICY_LEVEL_RECOMMENDED, 205 POLICY_LEVEL_RECOMMENDED,
194 POLICY_SCOPE_USER, 206 POLICY_SCOPE_USER,
195 base::Value::CreateBooleanValue(true), 207 new base::FundamentalValue(true),
196 NULL); 208 NULL);
197 209
198 a.MergeFrom(b); 210 a.MergeFrom(b);
199 211
200 PolicyMap c; 212 PolicyMap c;
201 // POLICY_SCOPE_MACHINE over POLICY_SCOPE_USER. 213 // POLICY_SCOPE_MACHINE over POLICY_SCOPE_USER.
202 c.Set(kTestPolicyName1, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 214 c.Set(kTestPolicyName1, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
203 base::Value::CreateStringValue("chromium.org"), NULL); 215 base::Value::CreateStringValue("chromium.org"), NULL);
204 // |a| has precedence over |b|. 216 // |a| has precedence over |b|.
205 c.Set(kTestPolicyName2, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 217 c.Set(kTestPolicyName2,
206 base::Value::CreateBooleanValue(true), NULL); 218 POLICY_LEVEL_MANDATORY,
219 POLICY_SCOPE_MACHINE,
220 new base::FundamentalValue(true),
221 NULL);
207 c.Set(kTestPolicyName3, 222 c.Set(kTestPolicyName3,
208 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 223 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
209 NULL, CreateExternalDataFetcher("a").release()); 224 NULL, CreateExternalDataFetcher("a").release());
210 // POLICY_SCOPE_MACHINE over POLICY_SCOPE_USER for POLICY_LEVEL_RECOMMENDED. 225 // POLICY_SCOPE_MACHINE over POLICY_SCOPE_USER for POLICY_LEVEL_RECOMMENDED.
211 c.Set(kTestPolicyName4, POLICY_LEVEL_RECOMMENDED, 226 c.Set(kTestPolicyName4,
212 POLICY_SCOPE_MACHINE, base::Value::CreateBooleanValue(true), NULL); 227 POLICY_LEVEL_RECOMMENDED,
228 POLICY_SCOPE_MACHINE,
229 new base::FundamentalValue(true),
230 NULL);
213 // POLICY_LEVEL_MANDATORY over POLICY_LEVEL_RECOMMENDED. 231 // POLICY_LEVEL_MANDATORY over POLICY_LEVEL_RECOMMENDED.
214 c.Set(kTestPolicyName5, 232 c.Set(kTestPolicyName5,
215 POLICY_LEVEL_MANDATORY, 233 POLICY_LEVEL_MANDATORY,
216 POLICY_SCOPE_MACHINE, 234 POLICY_SCOPE_MACHINE,
217 base::Value::CreateStringValue(std::string()), 235 base::Value::CreateStringValue(std::string()),
218 NULL); 236 NULL);
219 // Merge new ones. 237 // Merge new ones.
220 c.Set(kTestPolicyName6, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER, 238 c.Set(kTestPolicyName6,
221 base::Value::CreateBooleanValue(true), NULL); 239 POLICY_LEVEL_RECOMMENDED,
240 POLICY_SCOPE_USER,
241 new base::FundamentalValue(true),
242 NULL);
222 243
223 EXPECT_TRUE(a.Equals(c)); 244 EXPECT_TRUE(a.Equals(c));
224 } 245 }
225 246
226 TEST_F(PolicyMapTest, GetDifferingKeys) { 247 TEST_F(PolicyMapTest, GetDifferingKeys) {
227 PolicyMap a; 248 PolicyMap a;
228 a.Set(kTestPolicyName1, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 249 a.Set(kTestPolicyName1, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
229 base::Value::CreateStringValue("google.com"), NULL); 250 base::Value::CreateStringValue("google.com"), NULL);
230 a.Set(kTestPolicyName2, 251 a.Set(kTestPolicyName2,
231 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 252 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
232 NULL, CreateExternalDataFetcher("dummy").release()); 253 NULL, CreateExternalDataFetcher("dummy").release());
233 a.Set(kTestPolicyName3, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 254 a.Set(kTestPolicyName3,
234 base::Value::CreateBooleanValue(true), NULL); 255 POLICY_LEVEL_MANDATORY,
256 POLICY_SCOPE_MACHINE,
257 new base::FundamentalValue(true),
258 NULL);
235 a.Set(kTestPolicyName4, 259 a.Set(kTestPolicyName4,
236 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 260 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
237 NULL, CreateExternalDataFetcher("a").release()); 261 NULL, CreateExternalDataFetcher("a").release());
238 a.Set(kTestPolicyName5, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER, 262 a.Set(kTestPolicyName5,
239 base::Value::CreateBooleanValue(false), NULL); 263 POLICY_LEVEL_RECOMMENDED,
264 POLICY_SCOPE_USER,
265 new base::FundamentalValue(false),
266 NULL);
240 a.Set(kTestPolicyName6, 267 a.Set(kTestPolicyName6,
241 POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_MACHINE, 268 POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_MACHINE,
242 base::Value::CreateStringValue("google.com/q={x}"), NULL); 269 base::Value::CreateStringValue("google.com/q={x}"), NULL);
243 a.Set(kTestPolicyName7, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 270 a.Set(kTestPolicyName7,
244 base::Value::CreateBooleanValue(true), NULL); 271 POLICY_LEVEL_MANDATORY,
272 POLICY_SCOPE_USER,
273 new base::FundamentalValue(true),
274 NULL);
245 275
246 PolicyMap b; 276 PolicyMap b;
247 b.Set(kTestPolicyName1, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 277 b.Set(kTestPolicyName1, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
248 base::Value::CreateStringValue("google.com"), NULL); 278 base::Value::CreateStringValue("google.com"), NULL);
249 b.Set(kTestPolicyName2, 279 b.Set(kTestPolicyName2,
250 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 280 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
251 NULL, CreateExternalDataFetcher("dummy").release()); 281 NULL, CreateExternalDataFetcher("dummy").release());
252 b.Set(kTestPolicyName3, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 282 b.Set(kTestPolicyName3,
253 base::Value::CreateBooleanValue(false), NULL); 283 POLICY_LEVEL_MANDATORY,
284 POLICY_SCOPE_MACHINE,
285 new base::FundamentalValue(false),
286 NULL);
254 b.Set(kTestPolicyName4, 287 b.Set(kTestPolicyName4,
255 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 288 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
256 NULL, CreateExternalDataFetcher("b").release()); 289 NULL, CreateExternalDataFetcher("b").release());
257 b.Set(kTestPolicyName5, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 290 b.Set(kTestPolicyName5,
258 base::Value::CreateBooleanValue(false), NULL); 291 POLICY_LEVEL_MANDATORY,
292 POLICY_SCOPE_USER,
293 new base::FundamentalValue(false),
294 NULL);
259 b.Set(kTestPolicyName6, POLICY_LEVEL_RECOMMENDED, 295 b.Set(kTestPolicyName6, POLICY_LEVEL_RECOMMENDED,
260 POLICY_SCOPE_USER, base::Value::CreateStringValue("google.com/q={x}"), 296 POLICY_SCOPE_USER, base::Value::CreateStringValue("google.com/q={x}"),
261 NULL); 297 NULL);
262 b.Set(kTestPolicyName8, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER, 298 b.Set(kTestPolicyName8,
263 base::Value::CreateBooleanValue(true), NULL); 299 POLICY_LEVEL_RECOMMENDED,
300 POLICY_SCOPE_USER,
301 new base::FundamentalValue(true),
302 NULL);
264 303
265 std::set<std::string> diff; 304 std::set<std::string> diff;
266 std::set<std::string> diff2; 305 std::set<std::string> diff2;
267 a.GetDifferingKeys(b, &diff); 306 a.GetDifferingKeys(b, &diff);
268 b.GetDifferingKeys(a, &diff2); 307 b.GetDifferingKeys(a, &diff2);
269 // Order shouldn't matter. 308 // Order shouldn't matter.
270 EXPECT_EQ(diff, diff2); 309 EXPECT_EQ(diff, diff2);
271 // No change. 310 // No change.
272 EXPECT_TRUE(diff.find(kTestPolicyName1) == diff.end()); 311 EXPECT_TRUE(diff.find(kTestPolicyName1) == diff.end());
273 EXPECT_TRUE(diff.find(kTestPolicyName2) == diff.end()); 312 EXPECT_TRUE(diff.find(kTestPolicyName2) == diff.end());
274 // Different values. 313 // Different values.
275 EXPECT_TRUE(diff.find(kTestPolicyName3) != diff.end()); 314 EXPECT_TRUE(diff.find(kTestPolicyName3) != diff.end());
276 // Different external data references. 315 // Different external data references.
277 EXPECT_TRUE(diff.find(kTestPolicyName4) != diff.end()); 316 EXPECT_TRUE(diff.find(kTestPolicyName4) != diff.end());
278 // Different levels. 317 // Different levels.
279 EXPECT_TRUE(diff.find(kTestPolicyName5) != diff.end()); 318 EXPECT_TRUE(diff.find(kTestPolicyName5) != diff.end());
280 // Different scopes. 319 // Different scopes.
281 EXPECT_TRUE(diff.find(kTestPolicyName6) != diff.end()); 320 EXPECT_TRUE(diff.find(kTestPolicyName6) != diff.end());
282 // Not in |a|. 321 // Not in |a|.
283 EXPECT_TRUE(diff.find(kTestPolicyName8) != diff.end()); 322 EXPECT_TRUE(diff.find(kTestPolicyName8) != diff.end());
284 // Not in |b|. 323 // Not in |b|.
285 EXPECT_TRUE(diff.find(kTestPolicyName7) != diff.end()); 324 EXPECT_TRUE(diff.find(kTestPolicyName7) != diff.end());
286 // No surprises. 325 // No surprises.
287 EXPECT_EQ(6u, diff.size()); 326 EXPECT_EQ(6u, diff.size());
288 } 327 }
289 328
290 } // namespace policy 329 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698