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

Side by Side Diff: chrome/browser/chromeos/policy/configuration_policy_handler_chromeos_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 (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 <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 " \"Security\": \"WEP-PSK\"," 230 " \"Security\": \"WEP-PSK\","
231 " \"SSID\": \"ssid\"," 231 " \"SSID\": \"ssid\","
232 " \"Passphrase\": \"pass\"," 232 " \"Passphrase\": \"pass\","
233 " }" 233 " }"
234 " }]" 234 " }]"
235 "}"); 235 "}");
236 236
237 PolicyMap policy_map; 237 PolicyMap policy_map;
238 policy_map.Set(key::kOpenNetworkConfiguration, POLICY_LEVEL_MANDATORY, 238 policy_map.Set(key::kOpenNetworkConfiguration, POLICY_LEVEL_MANDATORY,
239 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, 239 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
240 base::MakeUnique<base::StringValue>(kTestONC), nullptr); 240 base::MakeUnique<base::Value>(kTestONC), nullptr);
241 std::unique_ptr<NetworkConfigurationPolicyHandler> handler( 241 std::unique_ptr<NetworkConfigurationPolicyHandler> handler(
242 NetworkConfigurationPolicyHandler::CreateForUserPolicy()); 242 NetworkConfigurationPolicyHandler::CreateForUserPolicy());
243 PolicyErrorMap errors; 243 PolicyErrorMap errors;
244 EXPECT_TRUE(handler->CheckPolicySettings(policy_map, &errors)); 244 EXPECT_TRUE(handler->CheckPolicySettings(policy_map, &errors));
245 EXPECT_TRUE(errors.GetErrors(key::kOpenNetworkConfiguration).empty()); 245 EXPECT_TRUE(errors.GetErrors(key::kOpenNetworkConfiguration).empty());
246 } 246 }
247 247
248 TEST(NetworkConfigurationPolicyHandlerTest, WrongType) { 248 TEST(NetworkConfigurationPolicyHandlerTest, WrongType) {
249 PolicyMap policy_map; 249 PolicyMap policy_map;
250 policy_map.Set(key::kOpenNetworkConfiguration, POLICY_LEVEL_MANDATORY, 250 policy_map.Set(key::kOpenNetworkConfiguration, POLICY_LEVEL_MANDATORY,
251 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, 251 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
252 base::MakeUnique<base::Value>(false), nullptr); 252 base::MakeUnique<base::Value>(false), nullptr);
253 std::unique_ptr<NetworkConfigurationPolicyHandler> handler( 253 std::unique_ptr<NetworkConfigurationPolicyHandler> handler(
254 NetworkConfigurationPolicyHandler::CreateForUserPolicy()); 254 NetworkConfigurationPolicyHandler::CreateForUserPolicy());
255 PolicyErrorMap errors; 255 PolicyErrorMap errors;
256 EXPECT_FALSE(handler->CheckPolicySettings(policy_map, &errors)); 256 EXPECT_FALSE(handler->CheckPolicySettings(policy_map, &errors));
257 EXPECT_FALSE(errors.GetErrors(key::kOpenNetworkConfiguration).empty()); 257 EXPECT_FALSE(errors.GetErrors(key::kOpenNetworkConfiguration).empty());
258 } 258 }
259 259
260 TEST(NetworkConfigurationPolicyHandlerTest, JSONParseError) { 260 TEST(NetworkConfigurationPolicyHandlerTest, JSONParseError) {
261 const std::string kTestONC("I'm not proper JSON!"); 261 const std::string kTestONC("I'm not proper JSON!");
262 PolicyMap policy_map; 262 PolicyMap policy_map;
263 policy_map.Set(key::kOpenNetworkConfiguration, POLICY_LEVEL_MANDATORY, 263 policy_map.Set(key::kOpenNetworkConfiguration, POLICY_LEVEL_MANDATORY,
264 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, 264 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
265 base::MakeUnique<base::StringValue>(kTestONC), nullptr); 265 base::MakeUnique<base::Value>(kTestONC), nullptr);
266 std::unique_ptr<NetworkConfigurationPolicyHandler> handler( 266 std::unique_ptr<NetworkConfigurationPolicyHandler> handler(
267 NetworkConfigurationPolicyHandler::CreateForUserPolicy()); 267 NetworkConfigurationPolicyHandler::CreateForUserPolicy());
268 PolicyErrorMap errors; 268 PolicyErrorMap errors;
269 EXPECT_FALSE(handler->CheckPolicySettings(policy_map, &errors)); 269 EXPECT_FALSE(handler->CheckPolicySettings(policy_map, &errors));
270 EXPECT_FALSE(errors.GetErrors(key::kOpenNetworkConfiguration).empty()); 270 EXPECT_FALSE(errors.GetErrors(key::kOpenNetworkConfiguration).empty());
271 } 271 }
272 272
273 TEST(NetworkConfigurationPolicyHandlerTest, Sanitization) { 273 TEST(NetworkConfigurationPolicyHandlerTest, Sanitization) {
274 const std::string kTestONC( 274 const std::string kTestONC(
275 "{" 275 "{"
276 " \"NetworkConfigurations\": [{" 276 " \"NetworkConfigurations\": [{"
277 " \"GUID\": \"{485d6076-dd44-6b6d-69787465725f5045}\"," 277 " \"GUID\": \"{485d6076-dd44-6b6d-69787465725f5045}\","
278 " \"Type\": \"WiFi\"," 278 " \"Type\": \"WiFi\","
279 " \"Name\": \"some name\"," 279 " \"Name\": \"some name\","
280 " \"WiFi\": {" 280 " \"WiFi\": {"
281 " \"Security\": \"WEP-PSK\"," 281 " \"Security\": \"WEP-PSK\","
282 " \"SSID\": \"ssid\"," 282 " \"SSID\": \"ssid\","
283 " \"Passphrase\": \"pass\"," 283 " \"Passphrase\": \"pass\","
284 " }" 284 " }"
285 " }]" 285 " }]"
286 "}"); 286 "}");
287 287
288 PolicyMap policy_map; 288 PolicyMap policy_map;
289 policy_map.Set(key::kOpenNetworkConfiguration, POLICY_LEVEL_MANDATORY, 289 policy_map.Set(key::kOpenNetworkConfiguration, POLICY_LEVEL_MANDATORY,
290 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, 290 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
291 base::MakeUnique<base::StringValue>(kTestONC), nullptr); 291 base::MakeUnique<base::Value>(kTestONC), nullptr);
292 std::unique_ptr<NetworkConfigurationPolicyHandler> handler( 292 std::unique_ptr<NetworkConfigurationPolicyHandler> handler(
293 NetworkConfigurationPolicyHandler::CreateForUserPolicy()); 293 NetworkConfigurationPolicyHandler::CreateForUserPolicy());
294 PolicyErrorMap errors; 294 PolicyErrorMap errors;
295 handler->PrepareForDisplaying(&policy_map); 295 handler->PrepareForDisplaying(&policy_map);
296 const base::Value* sanitized = 296 const base::Value* sanitized =
297 policy_map.GetValue(key::kOpenNetworkConfiguration); 297 policy_map.GetValue(key::kOpenNetworkConfiguration);
298 ASSERT_TRUE(sanitized); 298 ASSERT_TRUE(sanitized);
299 std::string sanitized_onc; 299 std::string sanitized_onc;
300 EXPECT_TRUE(sanitized->GetAsString(&sanitized_onc)); 300 EXPECT_TRUE(sanitized->GetAsString(&sanitized_onc));
301 EXPECT_FALSE(sanitized_onc.empty()); 301 EXPECT_FALSE(sanitized_onc.empty());
302 EXPECT_EQ(std::string::npos, sanitized_onc.find("pass")); 302 EXPECT_EQ(std::string::npos, sanitized_onc.find("pass"));
303 } 303 }
304 304
305 TEST(PinnedLauncherAppsPolicyHandler, PrefTranslation) { 305 TEST(PinnedLauncherAppsPolicyHandler, PrefTranslation) {
306 base::ListValue list; 306 base::ListValue list;
307 PolicyMap policy_map; 307 PolicyMap policy_map;
308 PrefValueMap prefs; 308 PrefValueMap prefs;
309 base::ListValue expected_pinned_apps; 309 base::ListValue expected_pinned_apps;
310 base::Value* value = NULL; 310 base::Value* value = NULL;
311 PinnedLauncherAppsPolicyHandler handler; 311 PinnedLauncherAppsPolicyHandler handler;
312 312
313 policy_map.Set(key::kPinnedLauncherApps, POLICY_LEVEL_MANDATORY, 313 policy_map.Set(key::kPinnedLauncherApps, POLICY_LEVEL_MANDATORY,
314 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, list.CreateDeepCopy(), 314 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, list.CreateDeepCopy(),
315 nullptr); 315 nullptr);
316 handler.ApplyPolicySettings(policy_map, &prefs); 316 handler.ApplyPolicySettings(policy_map, &prefs);
317 EXPECT_TRUE(prefs.GetValue(prefs::kPolicyPinnedLauncherApps, &value)); 317 EXPECT_TRUE(prefs.GetValue(prefs::kPolicyPinnedLauncherApps, &value));
318 EXPECT_TRUE(base::Value::Equals(&expected_pinned_apps, value)); 318 EXPECT_TRUE(base::Value::Equals(&expected_pinned_apps, value));
319 319
320 base::StringValue entry1("abcdefghijklmnopabcdefghijklmnop"); 320 base::Value entry1("abcdefghijklmnopabcdefghijklmnop");
321 auto entry1_dict = base::MakeUnique<base::DictionaryValue>(); 321 auto entry1_dict = base::MakeUnique<base::DictionaryValue>();
322 entry1_dict->Set(ash::launcher::kPinnedAppsPrefAppIDPath, entry1.DeepCopy()); 322 entry1_dict->Set(ash::launcher::kPinnedAppsPrefAppIDPath, entry1.DeepCopy());
323 expected_pinned_apps.Append(std::move(entry1_dict)); 323 expected_pinned_apps.Append(std::move(entry1_dict));
324 list.Append(entry1.CreateDeepCopy()); 324 list.Append(entry1.CreateDeepCopy());
325 policy_map.Set(key::kPinnedLauncherApps, POLICY_LEVEL_MANDATORY, 325 policy_map.Set(key::kPinnedLauncherApps, POLICY_LEVEL_MANDATORY,
326 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, list.CreateDeepCopy(), 326 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, list.CreateDeepCopy(),
327 nullptr); 327 nullptr);
328 prefs.Clear(); 328 prefs.Clear();
329 handler.ApplyPolicySettings(policy_map, &prefs); 329 handler.ApplyPolicySettings(policy_map, &prefs);
330 EXPECT_TRUE(prefs.GetValue(prefs::kPolicyPinnedLauncherApps, &value)); 330 EXPECT_TRUE(prefs.GetValue(prefs::kPolicyPinnedLauncherApps, &value));
(...skipping 26 matching lines...) Expand all
357 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, 357 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
358 base::MakeUnique<base::Value>(false), nullptr); 358 base::MakeUnique<base::Value>(false), nullptr);
359 LoginScreenPowerManagementPolicyHandler handler(chrome_schema_); 359 LoginScreenPowerManagementPolicyHandler handler(chrome_schema_);
360 PolicyErrorMap errors; 360 PolicyErrorMap errors;
361 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); 361 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
362 EXPECT_FALSE( 362 EXPECT_FALSE(
363 errors.GetErrors(key::kDeviceLoginScreenPowerManagement).empty()); 363 errors.GetErrors(key::kDeviceLoginScreenPowerManagement).empty());
364 } 364 }
365 365
366 } // namespace policy 366 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698