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

Side by Side Diff: chrome/browser/chromeos/policy/configuration_policy_handler_chromeos_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698