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

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

Issue 2664753002: Remove base::StringValue (Closed)
Patch Set: Rebase Created 3 years, 9 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_map.h" 5 #include "components/policy/core/common/policy_map.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 }; 52 };
53 53
54 std::unique_ptr<ExternalDataFetcher> PolicyMapTest::CreateExternalDataFetcher( 54 std::unique_ptr<ExternalDataFetcher> PolicyMapTest::CreateExternalDataFetcher(
55 const std::string& policy) const { 55 const std::string& policy) const {
56 return base::MakeUnique<ExternalDataFetcher>( 56 return base::MakeUnique<ExternalDataFetcher>(
57 base::WeakPtr<ExternalDataManager>(), policy); 57 base::WeakPtr<ExternalDataManager>(), policy);
58 } 58 }
59 59
60 TEST_F(PolicyMapTest, SetAndGet) { 60 TEST_F(PolicyMapTest, SetAndGet) {
61 PolicyMap map; 61 PolicyMap map;
62 SetPolicy(&map, kTestPolicyName1, base::MakeUnique<base::StringValue>("aaa")); 62 SetPolicy(&map, kTestPolicyName1, base::MakeUnique<base::Value>("aaa"));
63 base::StringValue expected("aaa"); 63 base::Value expected("aaa");
64 EXPECT_TRUE(expected.Equals(map.GetValue(kTestPolicyName1))); 64 EXPECT_TRUE(expected.Equals(map.GetValue(kTestPolicyName1)));
65 SetPolicy(&map, kTestPolicyName1, base::MakeUnique<base::StringValue>("bbb")); 65 SetPolicy(&map, kTestPolicyName1, base::MakeUnique<base::Value>("bbb"));
66 base::StringValue expected_b("bbb"); 66 base::Value expected_b("bbb");
67 EXPECT_TRUE(expected_b.Equals(map.GetValue(kTestPolicyName1))); 67 EXPECT_TRUE(expected_b.Equals(map.GetValue(kTestPolicyName1)));
68 SetPolicy(&map, kTestPolicyName1, CreateExternalDataFetcher("dummy")); 68 SetPolicy(&map, kTestPolicyName1, CreateExternalDataFetcher("dummy"));
69 EXPECT_FALSE(map.GetValue(kTestPolicyName1)); 69 EXPECT_FALSE(map.GetValue(kTestPolicyName1));
70 const PolicyMap::Entry* entry = map.Get(kTestPolicyName1); 70 const PolicyMap::Entry* entry = map.Get(kTestPolicyName1);
71 ASSERT_TRUE(entry != nullptr); 71 ASSERT_TRUE(entry != nullptr);
72 EXPECT_EQ(POLICY_LEVEL_MANDATORY, entry->level); 72 EXPECT_EQ(POLICY_LEVEL_MANDATORY, entry->level);
73 EXPECT_EQ(POLICY_SCOPE_USER, entry->scope); 73 EXPECT_EQ(POLICY_SCOPE_USER, entry->scope);
74 EXPECT_EQ(POLICY_SOURCE_CLOUD, entry->source); 74 EXPECT_EQ(POLICY_SOURCE_CLOUD, entry->source);
75 EXPECT_TRUE( 75 EXPECT_TRUE(
76 ExternalDataFetcher::Equals(entry->external_data_fetcher.get(), 76 ExternalDataFetcher::Equals(entry->external_data_fetcher.get(),
77 CreateExternalDataFetcher("dummy").get())); 77 CreateExternalDataFetcher("dummy").get()));
78 map.Set(kTestPolicyName1, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_MACHINE, 78 map.Set(kTestPolicyName1, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_MACHINE,
79 POLICY_SOURCE_ENTERPRISE_DEFAULT, nullptr, nullptr); 79 POLICY_SOURCE_ENTERPRISE_DEFAULT, nullptr, nullptr);
80 EXPECT_FALSE(map.GetValue(kTestPolicyName1)); 80 EXPECT_FALSE(map.GetValue(kTestPolicyName1));
81 entry = map.Get(kTestPolicyName1); 81 entry = map.Get(kTestPolicyName1);
82 ASSERT_TRUE(entry != nullptr); 82 ASSERT_TRUE(entry != nullptr);
83 EXPECT_EQ(POLICY_LEVEL_RECOMMENDED, entry->level); 83 EXPECT_EQ(POLICY_LEVEL_RECOMMENDED, entry->level);
84 EXPECT_EQ(POLICY_SCOPE_MACHINE, entry->scope); 84 EXPECT_EQ(POLICY_SCOPE_MACHINE, entry->scope);
85 EXPECT_EQ(POLICY_SOURCE_ENTERPRISE_DEFAULT, entry->source); 85 EXPECT_EQ(POLICY_SOURCE_ENTERPRISE_DEFAULT, entry->source);
86 EXPECT_FALSE(entry->external_data_fetcher); 86 EXPECT_FALSE(entry->external_data_fetcher);
87 } 87 }
88 88
89 TEST_F(PolicyMapTest, Equals) { 89 TEST_F(PolicyMapTest, Equals) {
90 PolicyMap a; 90 PolicyMap a;
91 SetPolicy(&a, kTestPolicyName1, base::MakeUnique<base::StringValue>("aaa")); 91 SetPolicy(&a, kTestPolicyName1, base::MakeUnique<base::Value>("aaa"));
92 PolicyMap a2; 92 PolicyMap a2;
93 SetPolicy(&a2, kTestPolicyName1, base::MakeUnique<base::StringValue>("aaa")); 93 SetPolicy(&a2, kTestPolicyName1, base::MakeUnique<base::Value>("aaa"));
94 PolicyMap b; 94 PolicyMap b;
95 SetPolicy(&b, kTestPolicyName1, base::MakeUnique<base::StringValue>("bbb")); 95 SetPolicy(&b, kTestPolicyName1, base::MakeUnique<base::Value>("bbb"));
96 PolicyMap c; 96 PolicyMap c;
97 SetPolicy(&c, kTestPolicyName1, base::MakeUnique<base::StringValue>("aaa")); 97 SetPolicy(&c, kTestPolicyName1, base::MakeUnique<base::Value>("aaa"));
98 SetPolicy(&c, kTestPolicyName2, base::MakeUnique<base::Value>(true)); 98 SetPolicy(&c, kTestPolicyName2, base::MakeUnique<base::Value>(true));
99 PolicyMap d; 99 PolicyMap d;
100 SetPolicy(&d, kTestPolicyName1, CreateExternalDataFetcher("ddd")); 100 SetPolicy(&d, kTestPolicyName1, CreateExternalDataFetcher("ddd"));
101 PolicyMap d2; 101 PolicyMap d2;
102 SetPolicy(&d2, kTestPolicyName1, CreateExternalDataFetcher("ddd")); 102 SetPolicy(&d2, kTestPolicyName1, CreateExternalDataFetcher("ddd"));
103 PolicyMap e; 103 PolicyMap e;
104 SetPolicy(&e, kTestPolicyName1, CreateExternalDataFetcher("eee")); 104 SetPolicy(&e, kTestPolicyName1, CreateExternalDataFetcher("eee"));
105 EXPECT_FALSE(a.Equals(b)); 105 EXPECT_FALSE(a.Equals(b));
106 EXPECT_FALSE(a.Equals(c)); 106 EXPECT_FALSE(a.Equals(c));
107 EXPECT_FALSE(a.Equals(d)); 107 EXPECT_FALSE(a.Equals(d));
(...skipping 21 matching lines...) Expand all
129 PolicyMap empty1; 129 PolicyMap empty1;
130 PolicyMap empty2; 130 PolicyMap empty2;
131 EXPECT_TRUE(empty1.Equals(empty2)); 131 EXPECT_TRUE(empty1.Equals(empty2));
132 EXPECT_TRUE(empty2.Equals(empty1)); 132 EXPECT_TRUE(empty2.Equals(empty1));
133 EXPECT_FALSE(empty1.Equals(a)); 133 EXPECT_FALSE(empty1.Equals(a));
134 EXPECT_FALSE(a.Equals(empty1)); 134 EXPECT_FALSE(a.Equals(empty1));
135 } 135 }
136 136
137 TEST_F(PolicyMapTest, Swap) { 137 TEST_F(PolicyMapTest, Swap) {
138 PolicyMap a; 138 PolicyMap a;
139 SetPolicy(&a, kTestPolicyName1, base::MakeUnique<base::StringValue>("aaa")); 139 SetPolicy(&a, kTestPolicyName1, base::MakeUnique<base::Value>("aaa"));
140 SetPolicy(&a, kTestPolicyName2, CreateExternalDataFetcher("dummy")); 140 SetPolicy(&a, kTestPolicyName2, CreateExternalDataFetcher("dummy"));
141 PolicyMap b; 141 PolicyMap b;
142 SetPolicy(&b, kTestPolicyName1, base::MakeUnique<base::StringValue>("bbb")); 142 SetPolicy(&b, kTestPolicyName1, base::MakeUnique<base::Value>("bbb"));
143 SetPolicy(&b, kTestPolicyName3, base::MakeUnique<base::Value>(true)); 143 SetPolicy(&b, kTestPolicyName3, base::MakeUnique<base::Value>(true));
144 144
145 a.Swap(&b); 145 a.Swap(&b);
146 base::StringValue expected("bbb"); 146 base::Value expected("bbb");
147 EXPECT_TRUE(expected.Equals(a.GetValue(kTestPolicyName1))); 147 EXPECT_TRUE(expected.Equals(a.GetValue(kTestPolicyName1)));
148 base::Value expected_bool(true); 148 base::Value expected_bool(true);
149 EXPECT_TRUE(expected_bool.Equals(a.GetValue(kTestPolicyName3))); 149 EXPECT_TRUE(expected_bool.Equals(a.GetValue(kTestPolicyName3)));
150 EXPECT_FALSE(a.GetValue(kTestPolicyName2)); 150 EXPECT_FALSE(a.GetValue(kTestPolicyName2));
151 EXPECT_FALSE(a.Get(kTestPolicyName2)); 151 EXPECT_FALSE(a.Get(kTestPolicyName2));
152 base::StringValue expected_a("aaa"); 152 base::Value expected_a("aaa");
153 EXPECT_TRUE(expected_a.Equals(b.GetValue(kTestPolicyName1))); 153 EXPECT_TRUE(expected_a.Equals(b.GetValue(kTestPolicyName1)));
154 EXPECT_FALSE(b.GetValue(kTestPolicyName3)); 154 EXPECT_FALSE(b.GetValue(kTestPolicyName3));
155 EXPECT_FALSE(a.GetValue(kTestPolicyName2)); 155 EXPECT_FALSE(a.GetValue(kTestPolicyName2));
156 const PolicyMap::Entry* entry = b.Get(kTestPolicyName2); 156 const PolicyMap::Entry* entry = b.Get(kTestPolicyName2);
157 ASSERT_TRUE(entry); 157 ASSERT_TRUE(entry);
158 EXPECT_TRUE( 158 EXPECT_TRUE(
159 ExternalDataFetcher::Equals(CreateExternalDataFetcher("dummy").get(), 159 ExternalDataFetcher::Equals(CreateExternalDataFetcher("dummy").get(),
160 entry->external_data_fetcher.get())); 160 entry->external_data_fetcher.get()));
161 161
162 b.Clear(); 162 b.Clear();
163 a.Swap(&b); 163 a.Swap(&b);
164 PolicyMap empty; 164 PolicyMap empty;
165 EXPECT_TRUE(a.Equals(empty)); 165 EXPECT_TRUE(a.Equals(empty));
166 EXPECT_FALSE(b.Equals(empty)); 166 EXPECT_FALSE(b.Equals(empty));
167 } 167 }
168 168
169 TEST_F(PolicyMapTest, MergeFrom) { 169 TEST_F(PolicyMapTest, MergeFrom) {
170 PolicyMap a; 170 PolicyMap a;
171 a.Set(kTestPolicyName1, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 171 a.Set(kTestPolicyName1, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
172 POLICY_SOURCE_CLOUD, base::MakeUnique<base::StringValue>("google.com"), 172 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>("google.com"),
173 nullptr); 173 nullptr);
174 a.Set(kTestPolicyName2, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 174 a.Set(kTestPolicyName2, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
175 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(true), nullptr); 175 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(true), nullptr);
176 a.Set(kTestPolicyName3, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 176 a.Set(kTestPolicyName3, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
177 POLICY_SOURCE_ENTERPRISE_DEFAULT, nullptr, 177 POLICY_SOURCE_ENTERPRISE_DEFAULT, nullptr,
178 CreateExternalDataFetcher("a")); 178 CreateExternalDataFetcher("a"));
179 a.Set(kTestPolicyName4, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER, 179 a.Set(kTestPolicyName4, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER,
180 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(false), nullptr); 180 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(false), nullptr);
181 a.Set(kTestPolicyName5, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_MACHINE, 181 a.Set(kTestPolicyName5, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_MACHINE,
182 POLICY_SOURCE_CLOUD, 182 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>("google.com/q={x}"),
183 base::MakeUnique<base::StringValue>("google.com/q={x}"), nullptr); 183 nullptr);
184 a.Set(kTestPolicyName7, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 184 a.Set(kTestPolicyName7, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
185 POLICY_SOURCE_ENTERPRISE_DEFAULT, base::MakeUnique<base::Value>(false), 185 POLICY_SOURCE_ENTERPRISE_DEFAULT, base::MakeUnique<base::Value>(false),
186 nullptr); 186 nullptr);
187 187
188 PolicyMap b; 188 PolicyMap b;
189 b.Set(kTestPolicyName1, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 189 b.Set(kTestPolicyName1, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
190 POLICY_SOURCE_CLOUD, 190 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>("chromium.org"),
191 base::MakeUnique<base::StringValue>("chromium.org"), nullptr); 191 nullptr);
192 b.Set(kTestPolicyName2, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 192 b.Set(kTestPolicyName2, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
193 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(false), nullptr); 193 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(false), nullptr);
194 b.Set(kTestPolicyName3, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 194 b.Set(kTestPolicyName3, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
195 POLICY_SOURCE_ENTERPRISE_DEFAULT, nullptr, 195 POLICY_SOURCE_ENTERPRISE_DEFAULT, nullptr,
196 CreateExternalDataFetcher("b")); 196 CreateExternalDataFetcher("b"));
197 b.Set(kTestPolicyName4, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_MACHINE, 197 b.Set(kTestPolicyName4, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_MACHINE,
198 POLICY_SOURCE_PUBLIC_SESSION_OVERRIDE, 198 POLICY_SOURCE_PUBLIC_SESSION_OVERRIDE,
199 base::MakeUnique<base::Value>(true), nullptr); 199 base::MakeUnique<base::Value>(true), nullptr);
200 b.Set(kTestPolicyName5, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 200 b.Set(kTestPolicyName5, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
201 POLICY_SOURCE_PLATFORM, 201 POLICY_SOURCE_PLATFORM, base::MakeUnique<base::Value>(std::string()),
202 base::MakeUnique<base::StringValue>(std::string()), nullptr); 202 nullptr);
203 b.Set(kTestPolicyName6, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER, 203 b.Set(kTestPolicyName6, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER,
204 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(true), nullptr); 204 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(true), nullptr);
205 b.Set(kTestPolicyName7, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 205 b.Set(kTestPolicyName7, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
206 POLICY_SOURCE_ACTIVE_DIRECTORY, base::MakeUnique<base::Value>(true), 206 POLICY_SOURCE_ACTIVE_DIRECTORY, base::MakeUnique<base::Value>(true),
207 nullptr); 207 nullptr);
208 208
209 a.MergeFrom(b); 209 a.MergeFrom(b);
210 210
211 PolicyMap c; 211 PolicyMap c;
212 // POLICY_SCOPE_MACHINE over POLICY_SCOPE_USER. 212 // POLICY_SCOPE_MACHINE over POLICY_SCOPE_USER.
213 c.Set(kTestPolicyName1, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 213 c.Set(kTestPolicyName1, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
214 POLICY_SOURCE_CLOUD, 214 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>("chromium.org"),
215 base::MakeUnique<base::StringValue>("chromium.org"), nullptr); 215 nullptr);
216 // |a| has precedence over |b|. 216 // |a| has precedence over |b|.
217 c.Set(kTestPolicyName2, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 217 c.Set(kTestPolicyName2, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
218 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(true), nullptr); 218 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(true), nullptr);
219 c.Set(kTestPolicyName3, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 219 c.Set(kTestPolicyName3, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
220 POLICY_SOURCE_ENTERPRISE_DEFAULT, nullptr, 220 POLICY_SOURCE_ENTERPRISE_DEFAULT, nullptr,
221 CreateExternalDataFetcher("a")); 221 CreateExternalDataFetcher("a"));
222 // POLICY_SCOPE_MACHINE over POLICY_SCOPE_USER for POLICY_LEVEL_RECOMMENDED. 222 // POLICY_SCOPE_MACHINE over POLICY_SCOPE_USER for POLICY_LEVEL_RECOMMENDED.
223 c.Set(kTestPolicyName4, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_MACHINE, 223 c.Set(kTestPolicyName4, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_MACHINE,
224 POLICY_SOURCE_PUBLIC_SESSION_OVERRIDE, 224 POLICY_SOURCE_PUBLIC_SESSION_OVERRIDE,
225 base::MakeUnique<base::Value>(true), nullptr); 225 base::MakeUnique<base::Value>(true), nullptr);
226 // POLICY_LEVEL_MANDATORY over POLICY_LEVEL_RECOMMENDED. 226 // POLICY_LEVEL_MANDATORY over POLICY_LEVEL_RECOMMENDED.
227 c.Set(kTestPolicyName5, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 227 c.Set(kTestPolicyName5, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
228 POLICY_SOURCE_PLATFORM, 228 POLICY_SOURCE_PLATFORM, base::MakeUnique<base::Value>(std::string()),
229 base::MakeUnique<base::StringValue>(std::string()), nullptr); 229 nullptr);
230 // Merge new ones. 230 // Merge new ones.
231 c.Set(kTestPolicyName6, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER, 231 c.Set(kTestPolicyName6, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER,
232 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(true), nullptr); 232 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(true), nullptr);
233 // POLICY_SOURCE_ACTIVE_DIRECTORY over POLICY_SOURCE_ENTERPRISE_DEFAULT. 233 // POLICY_SOURCE_ACTIVE_DIRECTORY over POLICY_SOURCE_ENTERPRISE_DEFAULT.
234 c.Set(kTestPolicyName7, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 234 c.Set(kTestPolicyName7, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
235 POLICY_SOURCE_ACTIVE_DIRECTORY, base::MakeUnique<base::Value>(true), 235 POLICY_SOURCE_ACTIVE_DIRECTORY, base::MakeUnique<base::Value>(true),
236 nullptr); 236 nullptr);
237 237
238 EXPECT_TRUE(a.Equals(c)); 238 EXPECT_TRUE(a.Equals(c));
239 } 239 }
240 240
241 TEST_F(PolicyMapTest, GetDifferingKeys) { 241 TEST_F(PolicyMapTest, GetDifferingKeys) {
242 PolicyMap a; 242 PolicyMap a;
243 a.Set(kTestPolicyName1, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 243 a.Set(kTestPolicyName1, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
244 POLICY_SOURCE_CLOUD, base::MakeUnique<base::StringValue>("google.com"), 244 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>("google.com"),
245 nullptr); 245 nullptr);
246 a.Set(kTestPolicyName2, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 246 a.Set(kTestPolicyName2, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
247 POLICY_SOURCE_CLOUD, nullptr, CreateExternalDataFetcher("dummy")); 247 POLICY_SOURCE_CLOUD, nullptr, CreateExternalDataFetcher("dummy"));
248 a.Set(kTestPolicyName3, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 248 a.Set(kTestPolicyName3, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
249 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(true), nullptr); 249 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(true), nullptr);
250 a.Set(kTestPolicyName4, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 250 a.Set(kTestPolicyName4, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
251 POLICY_SOURCE_CLOUD, nullptr, CreateExternalDataFetcher("a")); 251 POLICY_SOURCE_CLOUD, nullptr, CreateExternalDataFetcher("a"));
252 a.Set(kTestPolicyName5, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER, 252 a.Set(kTestPolicyName5, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER,
253 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(false), nullptr); 253 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(false), nullptr);
254 a.Set(kTestPolicyName6, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_MACHINE, 254 a.Set(kTestPolicyName6, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_MACHINE,
255 POLICY_SOURCE_CLOUD, 255 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>("google.com/q={x}"),
256 base::MakeUnique<base::StringValue>("google.com/q={x}"), nullptr); 256 nullptr);
257 a.Set(kTestPolicyName7, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 257 a.Set(kTestPolicyName7, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
258 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(true), nullptr); 258 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(true), nullptr);
259 259
260 PolicyMap b; 260 PolicyMap b;
261 b.Set(kTestPolicyName1, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 261 b.Set(kTestPolicyName1, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
262 POLICY_SOURCE_CLOUD, base::MakeUnique<base::StringValue>("google.com"), 262 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>("google.com"),
263 nullptr); 263 nullptr);
264 b.Set(kTestPolicyName2, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 264 b.Set(kTestPolicyName2, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
265 POLICY_SOURCE_CLOUD, nullptr, CreateExternalDataFetcher("dummy")); 265 POLICY_SOURCE_CLOUD, nullptr, CreateExternalDataFetcher("dummy"));
266 b.Set(kTestPolicyName3, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 266 b.Set(kTestPolicyName3, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
267 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(false), nullptr); 267 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(false), nullptr);
268 b.Set(kTestPolicyName4, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 268 b.Set(kTestPolicyName4, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
269 POLICY_SOURCE_CLOUD, nullptr, CreateExternalDataFetcher("b")); 269 POLICY_SOURCE_CLOUD, nullptr, CreateExternalDataFetcher("b"));
270 b.Set(kTestPolicyName5, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 270 b.Set(kTestPolicyName5, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
271 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(false), nullptr); 271 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(false), nullptr);
272 b.Set(kTestPolicyName6, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER, 272 b.Set(kTestPolicyName6, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER,
273 POLICY_SOURCE_CLOUD, 273 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>("google.com/q={x}"),
274 base::MakeUnique<base::StringValue>("google.com/q={x}"), nullptr); 274 nullptr);
275 b.Set(kTestPolicyName8, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER, 275 b.Set(kTestPolicyName8, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER,
276 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(true), nullptr); 276 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(true), nullptr);
277 277
278 std::set<std::string> diff; 278 std::set<std::string> diff;
279 std::set<std::string> diff2; 279 std::set<std::string> diff2;
280 a.GetDifferingKeys(b, &diff); 280 a.GetDifferingKeys(b, &diff);
281 b.GetDifferingKeys(a, &diff2); 281 b.GetDifferingKeys(a, &diff2);
282 // Order shouldn't matter. 282 // Order shouldn't matter.
283 EXPECT_EQ(diff, diff2); 283 EXPECT_EQ(diff, diff2);
284 // No change. 284 // No change.
(...skipping 23 matching lines...) Expand all
308 308
309 PolicyMap loaded; 309 PolicyMap loaded;
310 loaded.LoadFrom(&policies, 310 loaded.LoadFrom(&policies,
311 POLICY_LEVEL_MANDATORY, 311 POLICY_LEVEL_MANDATORY,
312 POLICY_SCOPE_USER, 312 POLICY_SCOPE_USER,
313 POLICY_SOURCE_PLATFORM); 313 POLICY_SOURCE_PLATFORM);
314 314
315 PolicyMap expected; 315 PolicyMap expected;
316 expected.Set("TestPolicy1", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 316 expected.Set("TestPolicy1", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
317 POLICY_SOURCE_PLATFORM, 317 POLICY_SOURCE_PLATFORM,
318 base::MakeUnique<base::StringValue>("google.com"), nullptr); 318 base::MakeUnique<base::Value>("google.com"), nullptr);
319 expected.Set("TestPolicy2", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 319 expected.Set("TestPolicy2", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
320 POLICY_SOURCE_PLATFORM, base::MakeUnique<base::Value>(true), 320 POLICY_SOURCE_PLATFORM, base::MakeUnique<base::Value>(true),
321 nullptr); 321 nullptr);
322 expected.Set("TestPolicy3", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 322 expected.Set("TestPolicy3", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
323 POLICY_SOURCE_PLATFORM, base::MakeUnique<base::Value>(-12321), 323 POLICY_SOURCE_PLATFORM, base::MakeUnique<base::Value>(-12321),
324 nullptr); 324 nullptr);
325 EXPECT_TRUE(loaded.Equals(expected)); 325 EXPECT_TRUE(loaded.Equals(expected));
326 } 326 }
327 327
328 bool IsMandatory(const PolicyMap::PolicyMapType::const_iterator iter) { 328 bool IsMandatory(const PolicyMap::PolicyMapType::const_iterator iter) {
329 return iter->second.level == POLICY_LEVEL_MANDATORY; 329 return iter->second.level == POLICY_LEVEL_MANDATORY;
330 } 330 }
331 331
332 TEST_F(PolicyMapTest, EraseNonmatching) { 332 TEST_F(PolicyMapTest, EraseNonmatching) {
333 PolicyMap a; 333 PolicyMap a;
334 a.Set(kTestPolicyName1, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 334 a.Set(kTestPolicyName1, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
335 POLICY_SOURCE_CLOUD, base::MakeUnique<base::StringValue>("google.com"), 335 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>("google.com"),
336 nullptr); 336 nullptr);
337 a.Set(kTestPolicyName2, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_MACHINE, 337 a.Set(kTestPolicyName2, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_MACHINE,
338 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(true), nullptr); 338 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(true), nullptr);
339 339
340 a.EraseNonmatching(base::Bind(&IsMandatory)); 340 a.EraseNonmatching(base::Bind(&IsMandatory));
341 341
342 PolicyMap b; 342 PolicyMap b;
343 b.Set(kTestPolicyName1, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 343 b.Set(kTestPolicyName1, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
344 POLICY_SOURCE_CLOUD, base::MakeUnique<base::StringValue>("google.com"), 344 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>("google.com"),
345 nullptr); 345 nullptr);
346 EXPECT_TRUE(a.Equals(b)); 346 EXPECT_TRUE(a.Equals(b));
347 } 347 }
348 348
349 } // namespace policy 349 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698