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

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

Issue 1870793002: Convert //chrome/browser/chromeos from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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>
8
7 #include "base/callback.h" 9 #include "base/callback.h"
8 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
9 #include "base/macros.h" 11 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/values.h" 12 #include "base/values.h"
12 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" 13 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
13 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
14 #include "components/policy/core/browser/policy_error_map.h" 15 #include "components/policy/core/browser/policy_error_map.h"
15 #include "components/policy/core/common/external_data_fetcher.h" 16 #include "components/policy/core/common/external_data_fetcher.h"
16 #include "components/policy/core/common/policy_map.h" 17 #include "components/policy/core/common/policy_map.h"
17 #include "components/policy/core/common/policy_types.h" 18 #include "components/policy/core/common/policy_types.h"
18 #include "components/policy/core/common/schema.h" 19 #include "components/policy/core/common/schema.h"
19 #include "components/prefs/pref_value_map.h" 20 #include "components/prefs/pref_value_map.h"
20 #include "policy/policy_constants.h" 21 #include "policy/policy_constants.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 POLICY_SOURCE_CLOUD, 117 POLICY_SOURCE_CLOUD,
117 new base::FundamentalValue(false), 118 new base::FundamentalValue(false),
118 NULL); 119 NULL);
119 PolicyErrorMap errors; 120 PolicyErrorMap errors;
120 EXPECT_FALSE(ExternalDataPolicyHandler(key::kUserAvatarImage) 121 EXPECT_FALSE(ExternalDataPolicyHandler(key::kUserAvatarImage)
121 .CheckPolicySettings(policy_map, &errors)); 122 .CheckPolicySettings(policy_map, &errors));
122 EXPECT_FALSE(errors.GetErrors(key::kUserAvatarImage).empty()); 123 EXPECT_FALSE(errors.GetErrors(key::kUserAvatarImage).empty());
123 } 124 }
124 125
125 TEST(ExternalDataPolicyHandlerTest, MissingURL) { 126 TEST(ExternalDataPolicyHandlerTest, MissingURL) {
126 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); 127 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
127 dict->SetString("hash", "1234567890123456789012345678901234567890"); 128 dict->SetString("hash", "1234567890123456789012345678901234567890");
128 PolicyMap policy_map; 129 PolicyMap policy_map;
129 policy_map.Set(key::kUserAvatarImage, 130 policy_map.Set(key::kUserAvatarImage,
130 POLICY_LEVEL_MANDATORY, 131 POLICY_LEVEL_MANDATORY,
131 POLICY_SCOPE_USER, 132 POLICY_SCOPE_USER,
132 POLICY_SOURCE_CLOUD, 133 POLICY_SOURCE_CLOUD,
133 dict.release(), 134 dict.release(),
134 NULL); 135 NULL);
135 PolicyErrorMap errors; 136 PolicyErrorMap errors;
136 EXPECT_FALSE(ExternalDataPolicyHandler(key::kUserAvatarImage) 137 EXPECT_FALSE(ExternalDataPolicyHandler(key::kUserAvatarImage)
137 .CheckPolicySettings(policy_map, &errors)); 138 .CheckPolicySettings(policy_map, &errors));
138 EXPECT_FALSE(errors.GetErrors(key::kUserAvatarImage).empty()); 139 EXPECT_FALSE(errors.GetErrors(key::kUserAvatarImage).empty());
139 } 140 }
140 141
141 TEST(ExternalDataPolicyHandlerTest, InvalidURL) { 142 TEST(ExternalDataPolicyHandlerTest, InvalidURL) {
142 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); 143 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
143 dict->SetString("url", "http://"); 144 dict->SetString("url", "http://");
144 dict->SetString("hash", "1234567890123456789012345678901234567890"); 145 dict->SetString("hash", "1234567890123456789012345678901234567890");
145 PolicyMap policy_map; 146 PolicyMap policy_map;
146 policy_map.Set(key::kUserAvatarImage, 147 policy_map.Set(key::kUserAvatarImage,
147 POLICY_LEVEL_MANDATORY, 148 POLICY_LEVEL_MANDATORY,
148 POLICY_SCOPE_USER, 149 POLICY_SCOPE_USER,
149 POLICY_SOURCE_CLOUD, 150 POLICY_SOURCE_CLOUD,
150 dict.release(), 151 dict.release(),
151 NULL); 152 NULL);
152 PolicyErrorMap errors; 153 PolicyErrorMap errors;
153 EXPECT_FALSE(ExternalDataPolicyHandler(key::kUserAvatarImage) 154 EXPECT_FALSE(ExternalDataPolicyHandler(key::kUserAvatarImage)
154 .CheckPolicySettings(policy_map, &errors)); 155 .CheckPolicySettings(policy_map, &errors));
155 EXPECT_FALSE(errors.GetErrors(key::kUserAvatarImage).empty()); 156 EXPECT_FALSE(errors.GetErrors(key::kUserAvatarImage).empty());
156 } 157 }
157 158
158 TEST(ExternalDataPolicyHandlerTest, MissingHash) { 159 TEST(ExternalDataPolicyHandlerTest, MissingHash) {
159 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); 160 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
160 dict->SetString("url", "http://localhost/"); 161 dict->SetString("url", "http://localhost/");
161 PolicyMap policy_map; 162 PolicyMap policy_map;
162 policy_map.Set(key::kUserAvatarImage, 163 policy_map.Set(key::kUserAvatarImage,
163 POLICY_LEVEL_MANDATORY, 164 POLICY_LEVEL_MANDATORY,
164 POLICY_SCOPE_USER, 165 POLICY_SCOPE_USER,
165 POLICY_SOURCE_CLOUD, 166 POLICY_SOURCE_CLOUD,
166 dict.release(), 167 dict.release(),
167 NULL); 168 NULL);
168 PolicyErrorMap errors; 169 PolicyErrorMap errors;
169 EXPECT_FALSE(ExternalDataPolicyHandler(key::kUserAvatarImage) 170 EXPECT_FALSE(ExternalDataPolicyHandler(key::kUserAvatarImage)
170 .CheckPolicySettings(policy_map, &errors)); 171 .CheckPolicySettings(policy_map, &errors));
171 EXPECT_FALSE(errors.GetErrors(key::kUserAvatarImage).empty()); 172 EXPECT_FALSE(errors.GetErrors(key::kUserAvatarImage).empty());
172 } 173 }
173 174
174 TEST(ExternalDataPolicyHandlerTest, InvalidHash) { 175 TEST(ExternalDataPolicyHandlerTest, InvalidHash) {
175 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); 176 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
176 dict->SetString("url", "http://localhost/"); 177 dict->SetString("url", "http://localhost/");
177 dict->SetString("hash", "1234"); 178 dict->SetString("hash", "1234");
178 PolicyMap policy_map; 179 PolicyMap policy_map;
179 policy_map.Set(key::kUserAvatarImage, 180 policy_map.Set(key::kUserAvatarImage,
180 POLICY_LEVEL_MANDATORY, 181 POLICY_LEVEL_MANDATORY,
181 POLICY_SCOPE_USER, 182 POLICY_SCOPE_USER,
182 POLICY_SOURCE_CLOUD, 183 POLICY_SOURCE_CLOUD,
183 dict.release(), 184 dict.release(),
184 NULL); 185 NULL);
185 PolicyErrorMap errors; 186 PolicyErrorMap errors;
186 EXPECT_FALSE(ExternalDataPolicyHandler(key::kUserAvatarImage) 187 EXPECT_FALSE(ExternalDataPolicyHandler(key::kUserAvatarImage)
187 .CheckPolicySettings(policy_map, &errors)); 188 .CheckPolicySettings(policy_map, &errors));
188 EXPECT_FALSE(errors.GetErrors(key::kUserAvatarImage).empty()); 189 EXPECT_FALSE(errors.GetErrors(key::kUserAvatarImage).empty());
189 } 190 }
190 191
191 TEST(ExternalDataPolicyHandlerTest, Valid) { 192 TEST(ExternalDataPolicyHandlerTest, Valid) {
192 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); 193 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
193 dict->SetString("url", "http://localhost/"); 194 dict->SetString("url", "http://localhost/");
194 dict->SetString( 195 dict->SetString(
195 "hash", 196 "hash",
196 "1234567890123456789012345678901234567890123456789012345678901234"); 197 "1234567890123456789012345678901234567890123456789012345678901234");
197 PolicyMap policy_map; 198 PolicyMap policy_map;
198 policy_map.Set(key::kUserAvatarImage, 199 policy_map.Set(key::kUserAvatarImage,
199 POLICY_LEVEL_MANDATORY, 200 POLICY_LEVEL_MANDATORY,
200 POLICY_SCOPE_USER, 201 POLICY_SCOPE_USER,
201 POLICY_SOURCE_CLOUD, 202 POLICY_SOURCE_CLOUD,
202 dict.release(), 203 dict.release(),
(...skipping 23 matching lines...) Expand all
226 " \"IdleAction\": \"DoNothing\"" 227 " \"IdleAction\": \"DoNothing\""
227 " }," 228 " },"
228 " \"LidCloseAction\": \"DoNothing\"," 229 " \"LidCloseAction\": \"DoNothing\","
229 " \"UserActivityScreenDimDelayScale\": 300" 230 " \"UserActivityScreenDimDelayScale\": 300"
230 "}"; 231 "}";
231 232
232 } // namespace 233 } // namespace
233 234
234 TEST(NetworkConfigurationPolicyHandlerTest, Empty) { 235 TEST(NetworkConfigurationPolicyHandlerTest, Empty) {
235 PolicyMap policy_map; 236 PolicyMap policy_map;
236 scoped_ptr<NetworkConfigurationPolicyHandler> handler( 237 std::unique_ptr<NetworkConfigurationPolicyHandler> handler(
237 NetworkConfigurationPolicyHandler::CreateForUserPolicy()); 238 NetworkConfigurationPolicyHandler::CreateForUserPolicy());
238 PolicyErrorMap errors; 239 PolicyErrorMap errors;
239 EXPECT_TRUE(handler->CheckPolicySettings(policy_map, &errors)); 240 EXPECT_TRUE(handler->CheckPolicySettings(policy_map, &errors));
240 EXPECT_TRUE(errors.GetErrors(key::kOpenNetworkConfiguration).empty()); 241 EXPECT_TRUE(errors.GetErrors(key::kOpenNetworkConfiguration).empty());
241 } 242 }
242 243
243 TEST(NetworkConfigurationPolicyHandlerTest, ValidONC) { 244 TEST(NetworkConfigurationPolicyHandlerTest, ValidONC) {
244 const std::string kTestONC( 245 const std::string kTestONC(
245 "{" 246 "{"
246 " \"NetworkConfigurations\": [{" 247 " \"NetworkConfigurations\": [{"
247 " \"GUID\": \"{485d6076-dd44-6b6d-69787465725f5045}\"," 248 " \"GUID\": \"{485d6076-dd44-6b6d-69787465725f5045}\","
248 " \"Type\": \"WiFi\"," 249 " \"Type\": \"WiFi\","
249 " \"Name\": \"some name\"," 250 " \"Name\": \"some name\","
250 " \"WiFi\": {" 251 " \"WiFi\": {"
251 " \"Security\": \"WEP-PSK\"," 252 " \"Security\": \"WEP-PSK\","
252 " \"SSID\": \"ssid\"," 253 " \"SSID\": \"ssid\","
253 " \"Passphrase\": \"pass\"," 254 " \"Passphrase\": \"pass\","
254 " }" 255 " }"
255 " }]" 256 " }]"
256 "}"); 257 "}");
257 258
258 PolicyMap policy_map; 259 PolicyMap policy_map;
259 policy_map.Set(key::kOpenNetworkConfiguration, 260 policy_map.Set(key::kOpenNetworkConfiguration,
260 POLICY_LEVEL_MANDATORY, 261 POLICY_LEVEL_MANDATORY,
261 POLICY_SCOPE_USER, 262 POLICY_SCOPE_USER,
262 POLICY_SOURCE_CLOUD, 263 POLICY_SOURCE_CLOUD,
263 new base::StringValue(kTestONC), 264 new base::StringValue(kTestONC),
264 NULL); 265 NULL);
265 scoped_ptr<NetworkConfigurationPolicyHandler> handler( 266 std::unique_ptr<NetworkConfigurationPolicyHandler> handler(
266 NetworkConfigurationPolicyHandler::CreateForUserPolicy()); 267 NetworkConfigurationPolicyHandler::CreateForUserPolicy());
267 PolicyErrorMap errors; 268 PolicyErrorMap errors;
268 EXPECT_TRUE(handler->CheckPolicySettings(policy_map, &errors)); 269 EXPECT_TRUE(handler->CheckPolicySettings(policy_map, &errors));
269 EXPECT_TRUE(errors.GetErrors(key::kOpenNetworkConfiguration).empty()); 270 EXPECT_TRUE(errors.GetErrors(key::kOpenNetworkConfiguration).empty());
270 } 271 }
271 272
272 TEST(NetworkConfigurationPolicyHandlerTest, WrongType) { 273 TEST(NetworkConfigurationPolicyHandlerTest, WrongType) {
273 PolicyMap policy_map; 274 PolicyMap policy_map;
274 policy_map.Set(key::kOpenNetworkConfiguration, 275 policy_map.Set(key::kOpenNetworkConfiguration,
275 POLICY_LEVEL_MANDATORY, 276 POLICY_LEVEL_MANDATORY,
276 POLICY_SCOPE_USER, 277 POLICY_SCOPE_USER,
277 POLICY_SOURCE_CLOUD, 278 POLICY_SOURCE_CLOUD,
278 new base::FundamentalValue(false), 279 new base::FundamentalValue(false),
279 NULL); 280 NULL);
280 scoped_ptr<NetworkConfigurationPolicyHandler> handler( 281 std::unique_ptr<NetworkConfigurationPolicyHandler> handler(
281 NetworkConfigurationPolicyHandler::CreateForUserPolicy()); 282 NetworkConfigurationPolicyHandler::CreateForUserPolicy());
282 PolicyErrorMap errors; 283 PolicyErrorMap errors;
283 EXPECT_FALSE(handler->CheckPolicySettings(policy_map, &errors)); 284 EXPECT_FALSE(handler->CheckPolicySettings(policy_map, &errors));
284 EXPECT_FALSE(errors.GetErrors(key::kOpenNetworkConfiguration).empty()); 285 EXPECT_FALSE(errors.GetErrors(key::kOpenNetworkConfiguration).empty());
285 } 286 }
286 287
287 TEST(NetworkConfigurationPolicyHandlerTest, JSONParseError) { 288 TEST(NetworkConfigurationPolicyHandlerTest, JSONParseError) {
288 const std::string kTestONC("I'm not proper JSON!"); 289 const std::string kTestONC("I'm not proper JSON!");
289 PolicyMap policy_map; 290 PolicyMap policy_map;
290 policy_map.Set(key::kOpenNetworkConfiguration, 291 policy_map.Set(key::kOpenNetworkConfiguration,
291 POLICY_LEVEL_MANDATORY, 292 POLICY_LEVEL_MANDATORY,
292 POLICY_SCOPE_USER, 293 POLICY_SCOPE_USER,
293 POLICY_SOURCE_CLOUD, 294 POLICY_SOURCE_CLOUD,
294 new base::StringValue(kTestONC), 295 new base::StringValue(kTestONC),
295 NULL); 296 NULL);
296 scoped_ptr<NetworkConfigurationPolicyHandler> handler( 297 std::unique_ptr<NetworkConfigurationPolicyHandler> handler(
297 NetworkConfigurationPolicyHandler::CreateForUserPolicy()); 298 NetworkConfigurationPolicyHandler::CreateForUserPolicy());
298 PolicyErrorMap errors; 299 PolicyErrorMap errors;
299 EXPECT_FALSE(handler->CheckPolicySettings(policy_map, &errors)); 300 EXPECT_FALSE(handler->CheckPolicySettings(policy_map, &errors));
300 EXPECT_FALSE(errors.GetErrors(key::kOpenNetworkConfiguration).empty()); 301 EXPECT_FALSE(errors.GetErrors(key::kOpenNetworkConfiguration).empty());
301 } 302 }
302 303
303 TEST(NetworkConfigurationPolicyHandlerTest, Sanitization) { 304 TEST(NetworkConfigurationPolicyHandlerTest, Sanitization) {
304 const std::string kTestONC( 305 const std::string kTestONC(
305 "{" 306 "{"
306 " \"NetworkConfigurations\": [{" 307 " \"NetworkConfigurations\": [{"
307 " \"GUID\": \"{485d6076-dd44-6b6d-69787465725f5045}\"," 308 " \"GUID\": \"{485d6076-dd44-6b6d-69787465725f5045}\","
308 " \"Type\": \"WiFi\"," 309 " \"Type\": \"WiFi\","
309 " \"Name\": \"some name\"," 310 " \"Name\": \"some name\","
310 " \"WiFi\": {" 311 " \"WiFi\": {"
311 " \"Security\": \"WEP-PSK\"," 312 " \"Security\": \"WEP-PSK\","
312 " \"SSID\": \"ssid\"," 313 " \"SSID\": \"ssid\","
313 " \"Passphrase\": \"pass\"," 314 " \"Passphrase\": \"pass\","
314 " }" 315 " }"
315 " }]" 316 " }]"
316 "}"); 317 "}");
317 318
318 PolicyMap policy_map; 319 PolicyMap policy_map;
319 policy_map.Set(key::kOpenNetworkConfiguration, 320 policy_map.Set(key::kOpenNetworkConfiguration,
320 POLICY_LEVEL_MANDATORY, 321 POLICY_LEVEL_MANDATORY,
321 POLICY_SCOPE_USER, 322 POLICY_SCOPE_USER,
322 POLICY_SOURCE_CLOUD, 323 POLICY_SOURCE_CLOUD,
323 new base::StringValue(kTestONC), 324 new base::StringValue(kTestONC),
324 NULL); 325 NULL);
325 scoped_ptr<NetworkConfigurationPolicyHandler> handler( 326 std::unique_ptr<NetworkConfigurationPolicyHandler> handler(
326 NetworkConfigurationPolicyHandler::CreateForUserPolicy()); 327 NetworkConfigurationPolicyHandler::CreateForUserPolicy());
327 PolicyErrorMap errors; 328 PolicyErrorMap errors;
328 handler->PrepareForDisplaying(&policy_map); 329 handler->PrepareForDisplaying(&policy_map);
329 const base::Value* sanitized = 330 const base::Value* sanitized =
330 policy_map.GetValue(key::kOpenNetworkConfiguration); 331 policy_map.GetValue(key::kOpenNetworkConfiguration);
331 ASSERT_TRUE(sanitized); 332 ASSERT_TRUE(sanitized);
332 std::string sanitized_onc; 333 std::string sanitized_onc;
333 EXPECT_TRUE(sanitized->GetAsString(&sanitized_onc)); 334 EXPECT_TRUE(sanitized->GetAsString(&sanitized_onc));
334 EXPECT_FALSE(sanitized_onc.empty()); 335 EXPECT_FALSE(sanitized_onc.empty());
335 EXPECT_EQ(std::string::npos, sanitized_onc.find("pass")); 336 EXPECT_EQ(std::string::npos, sanitized_onc.find("pass"));
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 new base::FundamentalValue(false), 396 new base::FundamentalValue(false),
396 NULL); 397 NULL);
397 LoginScreenPowerManagementPolicyHandler handler(chrome_schema_); 398 LoginScreenPowerManagementPolicyHandler handler(chrome_schema_);
398 PolicyErrorMap errors; 399 PolicyErrorMap errors;
399 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); 400 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
400 EXPECT_FALSE( 401 EXPECT_FALSE(
401 errors.GetErrors(key::kDeviceLoginScreenPowerManagement).empty()); 402 errors.GetErrors(key::kDeviceLoginScreenPowerManagement).empty());
402 } 403 }
403 404
404 } // namespace policy 405 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698