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

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

Issue 12189011: Split up chrome/browser/policy subdirectory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, add chrome/browser/chromeos/policy/OWNERS Created 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/policy/configuration_policy_handler_chromeos.h"
6
7 #include "base/prefs/pref_value_map.h"
8 #include "chrome/browser/policy/policy_error_map.h"
9 #include "chrome/browser/policy/policy_map.h"
10 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
11 #include "chrome/common/pref_names.h"
12 #include "policy/policy_constants.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace policy {
16
17 TEST(NetworkConfigurationPolicyHandlerTest, Empty) {
18 PolicyMap policy_map;
19 NetworkConfigurationPolicyHandler handler(
20 key::kOpenNetworkConfiguration,
21 chromeos::onc::ONC_SOURCE_USER_POLICY);
22 PolicyErrorMap errors;
23 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
24 EXPECT_TRUE(errors.GetErrors(key::kOpenNetworkConfiguration).empty());
25 }
26
27 TEST(NetworkConfigurationPolicyHandlerTest, ValidONC) {
28 const std::string kTestONC(
29 "{"
30 " \"NetworkConfigurations\": [{"
31 " \"GUID\": \"{485d6076-dd44-6b6d-69787465725f5045}\","
32 " \"Type\": \"WiFi\","
33 " \"Name\": \"some name\","
34 " \"WiFi\": {"
35 " \"Security\": \"WEP-PSK\","
36 " \"SSID\": \"ssid\","
37 " \"Passphrase\": \"pass\","
38 " }"
39 " }]"
40 "}");
41
42 PolicyMap policy_map;
43 policy_map.Set(key::kOpenNetworkConfiguration,
44 POLICY_LEVEL_MANDATORY,
45 POLICY_SCOPE_USER,
46 Value::CreateStringValue(kTestONC));
47 NetworkConfigurationPolicyHandler handler(
48 key::kOpenNetworkConfiguration,
49 chromeos::onc::ONC_SOURCE_USER_POLICY);
50 PolicyErrorMap errors;
51 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
52 EXPECT_TRUE(errors.GetErrors(key::kOpenNetworkConfiguration).empty());
53 }
54
55 TEST(NetworkConfigurationPolicyHandlerTest, WrongType) {
56 PolicyMap policy_map;
57 policy_map.Set(key::kOpenNetworkConfiguration,
58 POLICY_LEVEL_MANDATORY,
59 POLICY_SCOPE_USER,
60 Value::CreateBooleanValue(false));
61 NetworkConfigurationPolicyHandler handler(
62 key::kOpenNetworkConfiguration,
63 chromeos::onc::ONC_SOURCE_USER_POLICY);
64 PolicyErrorMap errors;
65 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
66 EXPECT_FALSE(errors.GetErrors(key::kOpenNetworkConfiguration).empty());
67 }
68
69 TEST(NetworkConfigurationPolicyHandlerTest, JSONParseError) {
70 const std::string kTestONC("I'm not proper JSON!");
71 PolicyMap policy_map;
72 policy_map.Set(key::kOpenNetworkConfiguration,
73 POLICY_LEVEL_MANDATORY,
74 POLICY_SCOPE_USER,
75 Value::CreateStringValue(kTestONC));
76 NetworkConfigurationPolicyHandler handler(
77 key::kOpenNetworkConfiguration,
78 chromeos::onc::ONC_SOURCE_USER_POLICY);
79 PolicyErrorMap errors;
80 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
81 EXPECT_FALSE(errors.GetErrors(key::kOpenNetworkConfiguration).empty());
82 }
83
84 TEST(NetworkConfigurationPolicyHandlerTest, Sanitization) {
85 const std::string kTestONC(
86 "{"
87 " \"NetworkConfigurations\": [{"
88 " \"GUID\": \"{485d6076-dd44-6b6d-69787465725f5045}\","
89 " \"Type\": \"WiFi\","
90 " \"Name\": \"some name\","
91 " \"WiFi\": {"
92 " \"Security\": \"WEP-PSK\","
93 " \"SSID\": \"ssid\","
94 " \"Passphrase\": \"pass\","
95 " }"
96 " }]"
97 "}");
98
99 PolicyMap policy_map;
100 policy_map.Set(key::kOpenNetworkConfiguration,
101 POLICY_LEVEL_MANDATORY,
102 POLICY_SCOPE_USER,
103 Value::CreateStringValue(kTestONC));
104 NetworkConfigurationPolicyHandler handler(
105 key::kOpenNetworkConfiguration,
106 chromeos::onc::ONC_SOURCE_USER_POLICY);
107 PolicyErrorMap errors;
108 handler.PrepareForDisplaying(&policy_map);
109 const Value* sanitized = policy_map.GetValue(key::kOpenNetworkConfiguration);
110 ASSERT_TRUE(sanitized);
111 std::string sanitized_onc;
112 EXPECT_TRUE(sanitized->GetAsString(&sanitized_onc));
113 EXPECT_FALSE(sanitized_onc.empty());
114 EXPECT_EQ(std::string::npos, sanitized_onc.find("pass"));
115 }
116
117 TEST(PinnedLauncherAppsPolicyHandler, PrefTranslation) {
118 base::ListValue list;
119 PolicyMap policy_map;
120 PrefValueMap prefs;
121 base::ListValue expected_pinned_apps;
122 base::Value* value = NULL;
123 PinnedLauncherAppsPolicyHandler handler;
124
125 policy_map.Set(key::kPinnedLauncherApps, POLICY_LEVEL_MANDATORY,
126 POLICY_SCOPE_USER, list.DeepCopy());
127 handler.ApplyPolicySettings(policy_map, &prefs);
128 EXPECT_TRUE(prefs.GetValue(prefs::kPinnedLauncherApps, &value));
129 EXPECT_TRUE(base::Value::Equals(&expected_pinned_apps, value));
130
131 base::StringValue entry1("abcdefghijklmnopabcdefghijklmnop");
132 base::DictionaryValue* entry1_dict = new base::DictionaryValue();
133 entry1_dict->Set(ash::kPinnedAppsPrefAppIDPath, entry1.DeepCopy());
134 expected_pinned_apps.Append(entry1_dict);
135 list.Append(entry1.DeepCopy());
136 policy_map.Set(key::kPinnedLauncherApps, POLICY_LEVEL_MANDATORY,
137 POLICY_SCOPE_USER, list.DeepCopy());
138 prefs.Clear();
139 handler.ApplyPolicySettings(policy_map, &prefs);
140 EXPECT_TRUE(prefs.GetValue(prefs::kPinnedLauncherApps, &value));
141 EXPECT_TRUE(base::Value::Equals(&expected_pinned_apps, value));
142 }
143
144 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698