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

Side by Side Diff: chrome/browser/chromeos/policy/configuration_policy_handler_chromeos_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 (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/chromeos/policy/configuration_policy_handler_chromeos.h " 5 #include "chrome/browser/chromeos/policy/configuration_policy_handler_chromeos.h "
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/prefs/pref_value_map.h" 10 #include "base/prefs/pref_value_map.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" 12 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
13 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
14 #include "components/policy/core/browser/policy_error_map.h" 14 #include "components/policy/core/browser/policy_error_map.h"
15 #include "components/policy/core/common/external_data_fetcher.h" 15 #include "components/policy/core/common/external_data_fetcher.h"
16 #include "components/policy/core/common/policy_map.h" 16 #include "components/policy/core/common/policy_map.h"
17 #include "components/policy/core/common/policy_types.h"
17 #include "components/policy/core/common/schema.h" 18 #include "components/policy/core/common/schema.h"
18 #include "policy/policy_constants.h" 19 #include "policy/policy_constants.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 21
21 namespace policy { 22 namespace policy {
22 23
23 namespace { 24 namespace {
24 25
25 // Test cases for the screen magnifier type policy setting. 26 // Test cases for the screen magnifier type policy setting.
26 class ScreenMagnifierPolicyHandlerTest : public testing::Test { 27 class ScreenMagnifierPolicyHandlerTest : public testing::Test {
(...skipping 27 matching lines...) Expand all
54 handler_.ApplyPolicySettings(policy_, &prefs_); 55 handler_.ApplyPolicySettings(policy_, &prefs_);
55 EXPECT_FALSE( 56 EXPECT_FALSE(
56 prefs_.GetValue(prefs::kAccessibilityScreenMagnifierEnabled, NULL)); 57 prefs_.GetValue(prefs::kAccessibilityScreenMagnifierEnabled, NULL));
57 EXPECT_FALSE(prefs_.GetValue(prefs::kAccessibilityScreenMagnifierType, NULL)); 58 EXPECT_FALSE(prefs_.GetValue(prefs::kAccessibilityScreenMagnifierType, NULL));
58 } 59 }
59 60
60 TEST_F(ScreenMagnifierPolicyHandlerTest, Disabled) { 61 TEST_F(ScreenMagnifierPolicyHandlerTest, Disabled) {
61 policy_.Set(key::kScreenMagnifierType, 62 policy_.Set(key::kScreenMagnifierType,
62 POLICY_LEVEL_MANDATORY, 63 POLICY_LEVEL_MANDATORY,
63 POLICY_SCOPE_USER, 64 POLICY_SCOPE_USER,
65 POLICY_SOURCE_CLOUD,
64 new base::FundamentalValue(0), 66 new base::FundamentalValue(0),
65 NULL); 67 NULL);
66 handler_.ApplyPolicySettings(policy_, &prefs_); 68 handler_.ApplyPolicySettings(policy_, &prefs_);
67 69
68 const base::Value* enabled = NULL; 70 const base::Value* enabled = NULL;
69 EXPECT_TRUE( 71 EXPECT_TRUE(
70 prefs_.GetValue(prefs::kAccessibilityScreenMagnifierEnabled, &enabled)); 72 prefs_.GetValue(prefs::kAccessibilityScreenMagnifierEnabled, &enabled));
71 ASSERT_TRUE(enabled); 73 ASSERT_TRUE(enabled);
72 EXPECT_TRUE(base::FundamentalValue(false).Equals(enabled)); 74 EXPECT_TRUE(base::FundamentalValue(false).Equals(enabled));
73 75
74 const base::Value* type = NULL; 76 const base::Value* type = NULL;
75 EXPECT_TRUE(prefs_.GetValue(prefs::kAccessibilityScreenMagnifierType, &type)); 77 EXPECT_TRUE(prefs_.GetValue(prefs::kAccessibilityScreenMagnifierType, &type));
76 ASSERT_TRUE(type); 78 ASSERT_TRUE(type);
77 EXPECT_TRUE(base::FundamentalValue(0).Equals(type)); 79 EXPECT_TRUE(base::FundamentalValue(0).Equals(type));
78 } 80 }
79 81
80 TEST_F(ScreenMagnifierPolicyHandlerTest, Enabled) { 82 TEST_F(ScreenMagnifierPolicyHandlerTest, Enabled) {
81 policy_.Set(key::kScreenMagnifierType, 83 policy_.Set(key::kScreenMagnifierType,
82 POLICY_LEVEL_MANDATORY, 84 POLICY_LEVEL_MANDATORY,
83 POLICY_SCOPE_USER, 85 POLICY_SCOPE_USER,
86 POLICY_SOURCE_CLOUD,
84 new base::FundamentalValue(1), 87 new base::FundamentalValue(1),
85 NULL); 88 NULL);
86 handler_.ApplyPolicySettings(policy_, &prefs_); 89 handler_.ApplyPolicySettings(policy_, &prefs_);
87 90
88 const base::Value* enabled = NULL; 91 const base::Value* enabled = NULL;
89 EXPECT_TRUE( 92 EXPECT_TRUE(
90 prefs_.GetValue(prefs::kAccessibilityScreenMagnifierEnabled, &enabled)); 93 prefs_.GetValue(prefs::kAccessibilityScreenMagnifierEnabled, &enabled));
91 ASSERT_TRUE(enabled); 94 ASSERT_TRUE(enabled);
92 EXPECT_TRUE(base::FundamentalValue(true).Equals(enabled)); 95 EXPECT_TRUE(base::FundamentalValue(true).Equals(enabled));
93 96
94 const base::Value* type = NULL; 97 const base::Value* type = NULL;
95 EXPECT_TRUE(prefs_.GetValue(prefs::kAccessibilityScreenMagnifierType, &type)); 98 EXPECT_TRUE(prefs_.GetValue(prefs::kAccessibilityScreenMagnifierType, &type));
96 ASSERT_TRUE(type); 99 ASSERT_TRUE(type);
97 EXPECT_TRUE(base::FundamentalValue(1).Equals(type)); 100 EXPECT_TRUE(base::FundamentalValue(1).Equals(type));
98 } 101 }
99 102
100 TEST(ExternalDataPolicyHandlerTest, Empty) { 103 TEST(ExternalDataPolicyHandlerTest, Empty) {
101 PolicyErrorMap errors; 104 PolicyErrorMap errors;
102 EXPECT_TRUE(ExternalDataPolicyHandler(key::kUserAvatarImage) 105 EXPECT_TRUE(ExternalDataPolicyHandler(key::kUserAvatarImage)
103 .CheckPolicySettings(PolicyMap(), &errors)); 106 .CheckPolicySettings(PolicyMap(), &errors));
104 EXPECT_TRUE(errors.GetErrors(key::kUserAvatarImage).empty()); 107 EXPECT_TRUE(errors.GetErrors(key::kUserAvatarImage).empty());
105 } 108 }
106 109
107 TEST(ExternalDataPolicyHandlerTest, WrongType) { 110 TEST(ExternalDataPolicyHandlerTest, WrongType) {
108 PolicyMap policy_map; 111 PolicyMap policy_map;
109 policy_map.Set(key::kUserAvatarImage, 112 policy_map.Set(key::kUserAvatarImage,
110 POLICY_LEVEL_MANDATORY, 113 POLICY_LEVEL_MANDATORY,
111 POLICY_SCOPE_USER, 114 POLICY_SCOPE_USER,
115 POLICY_SOURCE_CLOUD,
112 new base::FundamentalValue(false), 116 new base::FundamentalValue(false),
113 NULL); 117 NULL);
114 PolicyErrorMap errors; 118 PolicyErrorMap errors;
115 EXPECT_FALSE(ExternalDataPolicyHandler(key::kUserAvatarImage) 119 EXPECT_FALSE(ExternalDataPolicyHandler(key::kUserAvatarImage)
116 .CheckPolicySettings(policy_map, &errors)); 120 .CheckPolicySettings(policy_map, &errors));
117 EXPECT_FALSE(errors.GetErrors(key::kUserAvatarImage).empty()); 121 EXPECT_FALSE(errors.GetErrors(key::kUserAvatarImage).empty());
118 } 122 }
119 123
120 TEST(ExternalDataPolicyHandlerTest, MissingURL) { 124 TEST(ExternalDataPolicyHandlerTest, MissingURL) {
121 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); 125 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
122 dict->SetString("hash", "1234567890123456789012345678901234567890"); 126 dict->SetString("hash", "1234567890123456789012345678901234567890");
123 PolicyMap policy_map; 127 PolicyMap policy_map;
124 policy_map.Set(key::kUserAvatarImage, 128 policy_map.Set(key::kUserAvatarImage,
125 POLICY_LEVEL_MANDATORY, 129 POLICY_LEVEL_MANDATORY,
126 POLICY_SCOPE_USER, 130 POLICY_SCOPE_USER,
131 POLICY_SOURCE_CLOUD,
127 dict.release(), 132 dict.release(),
128 NULL); 133 NULL);
129 PolicyErrorMap errors; 134 PolicyErrorMap errors;
130 EXPECT_FALSE(ExternalDataPolicyHandler(key::kUserAvatarImage) 135 EXPECT_FALSE(ExternalDataPolicyHandler(key::kUserAvatarImage)
131 .CheckPolicySettings(policy_map, &errors)); 136 .CheckPolicySettings(policy_map, &errors));
132 EXPECT_FALSE(errors.GetErrors(key::kUserAvatarImage).empty()); 137 EXPECT_FALSE(errors.GetErrors(key::kUserAvatarImage).empty());
133 } 138 }
134 139
135 TEST(ExternalDataPolicyHandlerTest, InvalidURL) { 140 TEST(ExternalDataPolicyHandlerTest, InvalidURL) {
136 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); 141 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
137 dict->SetString("url", "http://"); 142 dict->SetString("url", "http://");
138 dict->SetString("hash", "1234567890123456789012345678901234567890"); 143 dict->SetString("hash", "1234567890123456789012345678901234567890");
139 PolicyMap policy_map; 144 PolicyMap policy_map;
140 policy_map.Set(key::kUserAvatarImage, 145 policy_map.Set(key::kUserAvatarImage,
141 POLICY_LEVEL_MANDATORY, 146 POLICY_LEVEL_MANDATORY,
142 POLICY_SCOPE_USER, 147 POLICY_SCOPE_USER,
148 POLICY_SOURCE_CLOUD,
143 dict.release(), 149 dict.release(),
144 NULL); 150 NULL);
145 PolicyErrorMap errors; 151 PolicyErrorMap errors;
146 EXPECT_FALSE(ExternalDataPolicyHandler(key::kUserAvatarImage) 152 EXPECT_FALSE(ExternalDataPolicyHandler(key::kUserAvatarImage)
147 .CheckPolicySettings(policy_map, &errors)); 153 .CheckPolicySettings(policy_map, &errors));
148 EXPECT_FALSE(errors.GetErrors(key::kUserAvatarImage).empty()); 154 EXPECT_FALSE(errors.GetErrors(key::kUserAvatarImage).empty());
149 } 155 }
150 156
151 TEST(ExternalDataPolicyHandlerTest, MissingHash) { 157 TEST(ExternalDataPolicyHandlerTest, MissingHash) {
152 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); 158 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
153 dict->SetString("url", "http://localhost/"); 159 dict->SetString("url", "http://localhost/");
154 PolicyMap policy_map; 160 PolicyMap policy_map;
155 policy_map.Set(key::kUserAvatarImage, 161 policy_map.Set(key::kUserAvatarImage,
156 POLICY_LEVEL_MANDATORY, 162 POLICY_LEVEL_MANDATORY,
157 POLICY_SCOPE_USER, 163 POLICY_SCOPE_USER,
164 POLICY_SOURCE_CLOUD,
158 dict.release(), 165 dict.release(),
159 NULL); 166 NULL);
160 PolicyErrorMap errors; 167 PolicyErrorMap errors;
161 EXPECT_FALSE(ExternalDataPolicyHandler(key::kUserAvatarImage) 168 EXPECT_FALSE(ExternalDataPolicyHandler(key::kUserAvatarImage)
162 .CheckPolicySettings(policy_map, &errors)); 169 .CheckPolicySettings(policy_map, &errors));
163 EXPECT_FALSE(errors.GetErrors(key::kUserAvatarImage).empty()); 170 EXPECT_FALSE(errors.GetErrors(key::kUserAvatarImage).empty());
164 } 171 }
165 172
166 TEST(ExternalDataPolicyHandlerTest, InvalidHash) { 173 TEST(ExternalDataPolicyHandlerTest, InvalidHash) {
167 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); 174 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
168 dict->SetString("url", "http://localhost/"); 175 dict->SetString("url", "http://localhost/");
169 dict->SetString("hash", "1234"); 176 dict->SetString("hash", "1234");
170 PolicyMap policy_map; 177 PolicyMap policy_map;
171 policy_map.Set(key::kUserAvatarImage, 178 policy_map.Set(key::kUserAvatarImage,
172 POLICY_LEVEL_MANDATORY, 179 POLICY_LEVEL_MANDATORY,
173 POLICY_SCOPE_USER, 180 POLICY_SCOPE_USER,
181 POLICY_SOURCE_CLOUD,
174 dict.release(), 182 dict.release(),
175 NULL); 183 NULL);
176 PolicyErrorMap errors; 184 PolicyErrorMap errors;
177 EXPECT_FALSE(ExternalDataPolicyHandler(key::kUserAvatarImage) 185 EXPECT_FALSE(ExternalDataPolicyHandler(key::kUserAvatarImage)
178 .CheckPolicySettings(policy_map, &errors)); 186 .CheckPolicySettings(policy_map, &errors));
179 EXPECT_FALSE(errors.GetErrors(key::kUserAvatarImage).empty()); 187 EXPECT_FALSE(errors.GetErrors(key::kUserAvatarImage).empty());
180 } 188 }
181 189
182 TEST(ExternalDataPolicyHandlerTest, Valid) { 190 TEST(ExternalDataPolicyHandlerTest, Valid) {
183 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); 191 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
184 dict->SetString("url", "http://localhost/"); 192 dict->SetString("url", "http://localhost/");
185 dict->SetString( 193 dict->SetString(
186 "hash", 194 "hash",
187 "1234567890123456789012345678901234567890123456789012345678901234"); 195 "1234567890123456789012345678901234567890123456789012345678901234");
188 PolicyMap policy_map; 196 PolicyMap policy_map;
189 policy_map.Set(key::kUserAvatarImage, 197 policy_map.Set(key::kUserAvatarImage,
190 POLICY_LEVEL_MANDATORY, 198 POLICY_LEVEL_MANDATORY,
191 POLICY_SCOPE_USER, 199 POLICY_SCOPE_USER,
200 POLICY_SOURCE_CLOUD,
192 dict.release(), 201 dict.release(),
193 NULL); 202 NULL);
194 PolicyErrorMap errors; 203 PolicyErrorMap errors;
195 EXPECT_TRUE(ExternalDataPolicyHandler(key::kUserAvatarImage) 204 EXPECT_TRUE(ExternalDataPolicyHandler(key::kUserAvatarImage)
196 .CheckPolicySettings(policy_map, &errors)); 205 .CheckPolicySettings(policy_map, &errors));
197 EXPECT_TRUE(errors.GetErrors(key::kUserAvatarImage).empty()); 206 EXPECT_TRUE(errors.GetErrors(key::kUserAvatarImage).empty());
198 } 207 }
199 208
200 const char kLoginScreenPowerManagementPolicy[] = 209 const char kLoginScreenPowerManagementPolicy[] =
201 "{" 210 "{"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 " \"SSID\": \"ssid\"," 251 " \"SSID\": \"ssid\","
243 " \"Passphrase\": \"pass\"," 252 " \"Passphrase\": \"pass\","
244 " }" 253 " }"
245 " }]" 254 " }]"
246 "}"); 255 "}");
247 256
248 PolicyMap policy_map; 257 PolicyMap policy_map;
249 policy_map.Set(key::kOpenNetworkConfiguration, 258 policy_map.Set(key::kOpenNetworkConfiguration,
250 POLICY_LEVEL_MANDATORY, 259 POLICY_LEVEL_MANDATORY,
251 POLICY_SCOPE_USER, 260 POLICY_SCOPE_USER,
261 POLICY_SOURCE_CLOUD,
252 new base::StringValue(kTestONC), 262 new base::StringValue(kTestONC),
253 NULL); 263 NULL);
254 scoped_ptr<NetworkConfigurationPolicyHandler> handler( 264 scoped_ptr<NetworkConfigurationPolicyHandler> handler(
255 NetworkConfigurationPolicyHandler::CreateForUserPolicy()); 265 NetworkConfigurationPolicyHandler::CreateForUserPolicy());
256 PolicyErrorMap errors; 266 PolicyErrorMap errors;
257 EXPECT_TRUE(handler->CheckPolicySettings(policy_map, &errors)); 267 EXPECT_TRUE(handler->CheckPolicySettings(policy_map, &errors));
258 EXPECT_TRUE(errors.GetErrors(key::kOpenNetworkConfiguration).empty()); 268 EXPECT_TRUE(errors.GetErrors(key::kOpenNetworkConfiguration).empty());
259 } 269 }
260 270
261 TEST(NetworkConfigurationPolicyHandlerTest, WrongType) { 271 TEST(NetworkConfigurationPolicyHandlerTest, WrongType) {
262 PolicyMap policy_map; 272 PolicyMap policy_map;
263 policy_map.Set(key::kOpenNetworkConfiguration, 273 policy_map.Set(key::kOpenNetworkConfiguration,
264 POLICY_LEVEL_MANDATORY, 274 POLICY_LEVEL_MANDATORY,
265 POLICY_SCOPE_USER, 275 POLICY_SCOPE_USER,
276 POLICY_SOURCE_CLOUD,
266 new base::FundamentalValue(false), 277 new base::FundamentalValue(false),
267 NULL); 278 NULL);
268 scoped_ptr<NetworkConfigurationPolicyHandler> handler( 279 scoped_ptr<NetworkConfigurationPolicyHandler> handler(
269 NetworkConfigurationPolicyHandler::CreateForUserPolicy()); 280 NetworkConfigurationPolicyHandler::CreateForUserPolicy());
270 PolicyErrorMap errors; 281 PolicyErrorMap errors;
271 EXPECT_FALSE(handler->CheckPolicySettings(policy_map, &errors)); 282 EXPECT_FALSE(handler->CheckPolicySettings(policy_map, &errors));
272 EXPECT_FALSE(errors.GetErrors(key::kOpenNetworkConfiguration).empty()); 283 EXPECT_FALSE(errors.GetErrors(key::kOpenNetworkConfiguration).empty());
273 } 284 }
274 285
275 TEST(NetworkConfigurationPolicyHandlerTest, JSONParseError) { 286 TEST(NetworkConfigurationPolicyHandlerTest, JSONParseError) {
276 const std::string kTestONC("I'm not proper JSON!"); 287 const std::string kTestONC("I'm not proper JSON!");
277 PolicyMap policy_map; 288 PolicyMap policy_map;
278 policy_map.Set(key::kOpenNetworkConfiguration, 289 policy_map.Set(key::kOpenNetworkConfiguration,
279 POLICY_LEVEL_MANDATORY, 290 POLICY_LEVEL_MANDATORY,
280 POLICY_SCOPE_USER, 291 POLICY_SCOPE_USER,
292 POLICY_SOURCE_CLOUD,
281 new base::StringValue(kTestONC), 293 new base::StringValue(kTestONC),
282 NULL); 294 NULL);
283 scoped_ptr<NetworkConfigurationPolicyHandler> handler( 295 scoped_ptr<NetworkConfigurationPolicyHandler> handler(
284 NetworkConfigurationPolicyHandler::CreateForUserPolicy()); 296 NetworkConfigurationPolicyHandler::CreateForUserPolicy());
285 PolicyErrorMap errors; 297 PolicyErrorMap errors;
286 EXPECT_FALSE(handler->CheckPolicySettings(policy_map, &errors)); 298 EXPECT_FALSE(handler->CheckPolicySettings(policy_map, &errors));
287 EXPECT_FALSE(errors.GetErrors(key::kOpenNetworkConfiguration).empty()); 299 EXPECT_FALSE(errors.GetErrors(key::kOpenNetworkConfiguration).empty());
288 } 300 }
289 301
290 TEST(NetworkConfigurationPolicyHandlerTest, Sanitization) { 302 TEST(NetworkConfigurationPolicyHandlerTest, Sanitization) {
291 const std::string kTestONC( 303 const std::string kTestONC(
292 "{" 304 "{"
293 " \"NetworkConfigurations\": [{" 305 " \"NetworkConfigurations\": [{"
294 " \"GUID\": \"{485d6076-dd44-6b6d-69787465725f5045}\"," 306 " \"GUID\": \"{485d6076-dd44-6b6d-69787465725f5045}\","
295 " \"Type\": \"WiFi\"," 307 " \"Type\": \"WiFi\","
296 " \"Name\": \"some name\"," 308 " \"Name\": \"some name\","
297 " \"WiFi\": {" 309 " \"WiFi\": {"
298 " \"Security\": \"WEP-PSK\"," 310 " \"Security\": \"WEP-PSK\","
299 " \"SSID\": \"ssid\"," 311 " \"SSID\": \"ssid\","
300 " \"Passphrase\": \"pass\"," 312 " \"Passphrase\": \"pass\","
301 " }" 313 " }"
302 " }]" 314 " }]"
303 "}"); 315 "}");
304 316
305 PolicyMap policy_map; 317 PolicyMap policy_map;
306 policy_map.Set(key::kOpenNetworkConfiguration, 318 policy_map.Set(key::kOpenNetworkConfiguration,
307 POLICY_LEVEL_MANDATORY, 319 POLICY_LEVEL_MANDATORY,
308 POLICY_SCOPE_USER, 320 POLICY_SCOPE_USER,
321 POLICY_SOURCE_CLOUD,
309 new base::StringValue(kTestONC), 322 new base::StringValue(kTestONC),
310 NULL); 323 NULL);
311 scoped_ptr<NetworkConfigurationPolicyHandler> handler( 324 scoped_ptr<NetworkConfigurationPolicyHandler> handler(
312 NetworkConfigurationPolicyHandler::CreateForUserPolicy()); 325 NetworkConfigurationPolicyHandler::CreateForUserPolicy());
313 PolicyErrorMap errors; 326 PolicyErrorMap errors;
314 handler->PrepareForDisplaying(&policy_map); 327 handler->PrepareForDisplaying(&policy_map);
315 const base::Value* sanitized = 328 const base::Value* sanitized =
316 policy_map.GetValue(key::kOpenNetworkConfiguration); 329 policy_map.GetValue(key::kOpenNetworkConfiguration);
317 ASSERT_TRUE(sanitized); 330 ASSERT_TRUE(sanitized);
318 std::string sanitized_onc; 331 std::string sanitized_onc;
319 EXPECT_TRUE(sanitized->GetAsString(&sanitized_onc)); 332 EXPECT_TRUE(sanitized->GetAsString(&sanitized_onc));
320 EXPECT_FALSE(sanitized_onc.empty()); 333 EXPECT_FALSE(sanitized_onc.empty());
321 EXPECT_EQ(std::string::npos, sanitized_onc.find("pass")); 334 EXPECT_EQ(std::string::npos, sanitized_onc.find("pass"));
322 } 335 }
323 336
324 TEST(PinnedLauncherAppsPolicyHandler, PrefTranslation) { 337 TEST(PinnedLauncherAppsPolicyHandler, PrefTranslation) {
325 base::ListValue list; 338 base::ListValue list;
326 PolicyMap policy_map; 339 PolicyMap policy_map;
327 PrefValueMap prefs; 340 PrefValueMap prefs;
328 base::ListValue expected_pinned_apps; 341 base::ListValue expected_pinned_apps;
329 base::Value* value = NULL; 342 base::Value* value = NULL;
330 PinnedLauncherAppsPolicyHandler handler; 343 PinnedLauncherAppsPolicyHandler handler;
331 344
332 policy_map.Set(key::kPinnedLauncherApps, POLICY_LEVEL_MANDATORY, 345 policy_map.Set(key::kPinnedLauncherApps, POLICY_LEVEL_MANDATORY,
333 POLICY_SCOPE_USER, list.DeepCopy(), NULL); 346 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, list.DeepCopy(),
347 nullptr);
334 handler.ApplyPolicySettings(policy_map, &prefs); 348 handler.ApplyPolicySettings(policy_map, &prefs);
335 EXPECT_TRUE(prefs.GetValue(prefs::kPinnedLauncherApps, &value)); 349 EXPECT_TRUE(prefs.GetValue(prefs::kPinnedLauncherApps, &value));
336 EXPECT_TRUE(base::Value::Equals(&expected_pinned_apps, value)); 350 EXPECT_TRUE(base::Value::Equals(&expected_pinned_apps, value));
337 351
338 base::StringValue entry1("abcdefghijklmnopabcdefghijklmnop"); 352 base::StringValue entry1("abcdefghijklmnopabcdefghijklmnop");
339 base::DictionaryValue* entry1_dict = new base::DictionaryValue(); 353 base::DictionaryValue* entry1_dict = new base::DictionaryValue();
340 entry1_dict->Set(ash::kPinnedAppsPrefAppIDPath, entry1.DeepCopy()); 354 entry1_dict->Set(ash::kPinnedAppsPrefAppIDPath, entry1.DeepCopy());
341 expected_pinned_apps.Append(entry1_dict); 355 expected_pinned_apps.Append(entry1_dict);
342 list.Append(entry1.DeepCopy()); 356 list.Append(entry1.DeepCopy());
343 policy_map.Set(key::kPinnedLauncherApps, POLICY_LEVEL_MANDATORY, 357 policy_map.Set(key::kPinnedLauncherApps, POLICY_LEVEL_MANDATORY,
344 POLICY_SCOPE_USER, list.DeepCopy(), NULL); 358 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, list.DeepCopy(),
359 nullptr);
345 prefs.Clear(); 360 prefs.Clear();
346 handler.ApplyPolicySettings(policy_map, &prefs); 361 handler.ApplyPolicySettings(policy_map, &prefs);
347 EXPECT_TRUE(prefs.GetValue(prefs::kPinnedLauncherApps, &value)); 362 EXPECT_TRUE(prefs.GetValue(prefs::kPinnedLauncherApps, &value));
348 EXPECT_TRUE(base::Value::Equals(&expected_pinned_apps, value)); 363 EXPECT_TRUE(base::Value::Equals(&expected_pinned_apps, value));
349 } 364 }
350 365
351 TEST_F(LoginScreenPowerManagementPolicyHandlerTest, Empty) { 366 TEST_F(LoginScreenPowerManagementPolicyHandlerTest, Empty) {
352 PolicyMap policy_map; 367 PolicyMap policy_map;
353 LoginScreenPowerManagementPolicyHandler handler(chrome_schema_); 368 LoginScreenPowerManagementPolicyHandler handler(chrome_schema_);
354 PolicyErrorMap errors; 369 PolicyErrorMap errors;
355 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 370 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
356 EXPECT_TRUE(errors.GetErrors(key::kDeviceLoginScreenPowerManagement).empty()); 371 EXPECT_TRUE(errors.GetErrors(key::kDeviceLoginScreenPowerManagement).empty());
357 } 372 }
358 373
359 TEST_F(LoginScreenPowerManagementPolicyHandlerTest, ValidPolicy) { 374 TEST_F(LoginScreenPowerManagementPolicyHandlerTest, ValidPolicy) {
360 PolicyMap policy_map; 375 PolicyMap policy_map;
361 policy_map.Set( 376 policy_map.Set(
362 key::kDeviceLoginScreenPowerManagement, POLICY_LEVEL_MANDATORY, 377 key::kDeviceLoginScreenPowerManagement, POLICY_LEVEL_MANDATORY,
363 POLICY_SCOPE_USER, 378 POLICY_SCOPE_USER,
379 POLICY_SOURCE_CLOUD,
364 base::JSONReader::Read(kLoginScreenPowerManagementPolicy).release(), 380 base::JSONReader::Read(kLoginScreenPowerManagementPolicy).release(),
365 NULL); 381 NULL);
366 LoginScreenPowerManagementPolicyHandler handler(chrome_schema_); 382 LoginScreenPowerManagementPolicyHandler handler(chrome_schema_);
367 PolicyErrorMap errors; 383 PolicyErrorMap errors;
368 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 384 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
369 EXPECT_TRUE(errors.GetErrors(key::kDeviceLoginScreenPowerManagement).empty()); 385 EXPECT_TRUE(errors.GetErrors(key::kDeviceLoginScreenPowerManagement).empty());
370 } 386 }
371 387
372 TEST_F(LoginScreenPowerManagementPolicyHandlerTest, WrongType) { 388 TEST_F(LoginScreenPowerManagementPolicyHandlerTest, WrongType) {
373 PolicyMap policy_map; 389 PolicyMap policy_map;
374 policy_map.Set(key::kDeviceLoginScreenPowerManagement, 390 policy_map.Set(key::kDeviceLoginScreenPowerManagement,
375 POLICY_LEVEL_MANDATORY, 391 POLICY_LEVEL_MANDATORY,
376 POLICY_SCOPE_USER, 392 POLICY_SCOPE_USER,
393 POLICY_SOURCE_CLOUD,
377 new base::FundamentalValue(false), 394 new base::FundamentalValue(false),
378 NULL); 395 NULL);
379 LoginScreenPowerManagementPolicyHandler handler(chrome_schema_); 396 LoginScreenPowerManagementPolicyHandler handler(chrome_schema_);
380 PolicyErrorMap errors; 397 PolicyErrorMap errors;
381 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); 398 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
382 EXPECT_FALSE( 399 EXPECT_FALSE(
383 errors.GetErrors(key::kDeviceLoginScreenPowerManagement).empty()); 400 errors.GetErrors(key::kDeviceLoginScreenPowerManagement).empty());
384 } 401 }
385 402
386 } // namespace policy 403 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698