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

Side by Side Diff: chrome/browser/ui/webui/options/preferences_browsertest.cc

Issue 2606293002: Remove ScopedVector from chrome/browser/ui. (Closed)
Patch Set: view Created 3 years, 11 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/ui/webui/options/preferences_browsertest.h" 5 #include "chrome/browser/ui/webui/options/preferences_browsertest.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <iostream> 9 #include <iostream>
10 #include <memory> 10 #include <memory>
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 void PreferencesBrowserTest::SetUpInProcessBrowserTestFixture() { 208 void PreferencesBrowserTest::SetUpInProcessBrowserTestFixture() {
209 // Sets up a mock policy provider for user and device policies. 209 // Sets up a mock policy provider for user and device policies.
210 EXPECT_CALL(policy_provider_, IsInitializationComplete(_)) 210 EXPECT_CALL(policy_provider_, IsInitializationComplete(_))
211 .WillRepeatedly(Return(true)); 211 .WillRepeatedly(Return(true));
212 policy::BrowserPolicyConnector::SetPolicyProviderForTesting( 212 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(
213 &policy_provider_); 213 &policy_provider_);
214 } 214 }
215 215
216 void PreferencesBrowserTest::SetUserPolicies( 216 void PreferencesBrowserTest::SetUserPolicies(
217 const std::vector<std::string>& names, 217 const std::vector<std::string>& names,
218 const std::vector<base::Value*>& values, 218 const std::vector<std::unique_ptr<base::Value>>& values,
219 policy::PolicyLevel level) { 219 policy::PolicyLevel level) {
220 policy::PolicyMap map; 220 policy::PolicyMap map;
221 for (size_t i = 0; i < names.size(); ++i) { 221 for (size_t i = 0; i < names.size(); ++i) {
222 map.Set(names[i], level, policy::POLICY_SCOPE_USER, 222 map.Set(names[i], level, policy::POLICY_SCOPE_USER,
223 policy::POLICY_SOURCE_CLOUD, values[i]->CreateDeepCopy(), nullptr); 223 policy::POLICY_SOURCE_CLOUD, values[i]->CreateDeepCopy(), nullptr);
224 } 224 }
225 policy_provider_.UpdateChromePolicy(map); 225 policy_provider_.UpdateChromePolicy(map);
226 } 226 }
227 227
228 void PreferencesBrowserTest::ClearUserPolicies() { 228 void PreferencesBrowserTest::ClearUserPolicies() {
229 policy::PolicyMap empty_policy_map; 229 policy::PolicyMap empty_policy_map;
230 policy_provider_.UpdateChromePolicy(empty_policy_map); 230 policy_provider_.UpdateChromePolicy(empty_policy_map);
231 } 231 }
232 232
233 void PreferencesBrowserTest::SetUserValues( 233 void PreferencesBrowserTest::SetUserValues(
234 const std::vector<std::string>& names, 234 const std::vector<std::string>& names,
235 const std::vector<base::Value*>& values) { 235 const std::vector<std::unique_ptr<base::Value>>& values) {
236 for (size_t i = 0; i < names.size(); ++i) { 236 for (size_t i = 0; i < names.size(); ++i) {
237 pref_service()->Set(names[i].c_str(), *values[i]); 237 pref_service()->Set(names[i].c_str(), *values[i]);
238 } 238 }
239 } 239 }
240 240
241 void PreferencesBrowserTest::VerifyKeyValue(const base::DictionaryValue& dict, 241 void PreferencesBrowserTest::VerifyKeyValue(const base::DictionaryValue& dict,
242 const std::string& key, 242 const std::string& key,
243 const base::Value& expected) { 243 const base::Value& expected) {
244 const base::Value* actual = NULL; 244 const base::Value* actual = NULL;
245 EXPECT_TRUE(dict.Get(key, &actual)) << "Was checking key: " << key; 245 EXPECT_TRUE(dict.Get(key, &actual)) << "Was checking key: " << key;
246 if (actual) 246 if (actual)
247 EXPECT_EQ(expected, *actual) << "Was checking key: " << key; 247 EXPECT_EQ(expected, *actual) << "Was checking key: " << key;
248 } 248 }
249 249
250 void PreferencesBrowserTest::VerifyPref(const base::DictionaryValue* prefs, 250 void PreferencesBrowserTest::VerifyPref(
251 const std::string& name, 251 const base::DictionaryValue* prefs,
252 const base::Value* value, 252 const std::string& name,
253 const std::string& controlledBy, 253 const std::unique_ptr<base::Value>& value,
254 bool disabled, 254 const std::string& controlledBy,
255 bool uncommitted) { 255 bool disabled,
256 bool uncommitted) {
256 const base::Value* pref = NULL; 257 const base::Value* pref = NULL;
257 const base::DictionaryValue* dict = NULL; 258 const base::DictionaryValue* dict = NULL;
258 ASSERT_TRUE(prefs->GetWithoutPathExpansion(name, &pref)); 259 ASSERT_TRUE(prefs->GetWithoutPathExpansion(name, &pref));
259 ASSERT_TRUE(pref->GetAsDictionary(&dict)); 260 ASSERT_TRUE(pref->GetAsDictionary(&dict));
260 VerifyKeyValue(*dict, "value", *value); 261 VerifyKeyValue(*dict, "value", *value);
261 if (!controlledBy.empty()) 262 if (!controlledBy.empty())
262 VerifyKeyValue(*dict, "controlledBy", base::StringValue(controlledBy)); 263 VerifyKeyValue(*dict, "controlledBy", base::StringValue(controlledBy));
263 else 264 else
264 EXPECT_FALSE(dict->HasKey("controlledBy")); 265 EXPECT_FALSE(dict->HasKey("controlledBy"));
265 266
266 if (disabled) 267 if (disabled)
267 VerifyKeyValue(*dict, "disabled", base::FundamentalValue(true)); 268 VerifyKeyValue(*dict, "disabled", base::FundamentalValue(true));
268 else if (dict->HasKey("disabled")) 269 else if (dict->HasKey("disabled"))
269 VerifyKeyValue(*dict, "disabled", base::FundamentalValue(false)); 270 VerifyKeyValue(*dict, "disabled", base::FundamentalValue(false));
270 271
271 if (uncommitted) 272 if (uncommitted)
272 VerifyKeyValue(*dict, "uncommitted", base::FundamentalValue(true)); 273 VerifyKeyValue(*dict, "uncommitted", base::FundamentalValue(true));
273 else if (dict->HasKey("uncommitted")) 274 else if (dict->HasKey("uncommitted"))
274 VerifyKeyValue(*dict, "uncommitted", base::FundamentalValue(false)); 275 VerifyKeyValue(*dict, "uncommitted", base::FundamentalValue(false));
275 } 276 }
276 277
277 void PreferencesBrowserTest::VerifyObservedPref(const std::string& json, 278 void PreferencesBrowserTest::VerifyObservedPref(
278 const std::string& name, 279 const std::string& json,
279 const base::Value* value, 280 const std::string& name,
280 const std::string& controlledBy, 281 const std::unique_ptr<base::Value>& value,
281 bool disabled, 282 const std::string& controlledBy,
282 bool uncommitted) { 283 bool disabled,
284 bool uncommitted) {
283 std::unique_ptr<base::Value> observed_value_ptr = 285 std::unique_ptr<base::Value> observed_value_ptr =
284 base::JSONReader::Read(json); 286 base::JSONReader::Read(json);
285 const base::DictionaryValue* observed_dict; 287 const base::DictionaryValue* observed_dict;
286 ASSERT_TRUE(observed_value_ptr.get()); 288 ASSERT_TRUE(observed_value_ptr.get());
287 ASSERT_TRUE(observed_value_ptr->GetAsDictionary(&observed_dict)); 289 ASSERT_TRUE(observed_value_ptr->GetAsDictionary(&observed_dict));
288 VerifyPref(observed_dict, name, value, controlledBy, disabled, uncommitted); 290 VerifyPref(observed_dict, name, value, controlledBy, disabled, uncommitted);
289 } 291 }
290 292
291 void PreferencesBrowserTest::VerifyObservedPrefs( 293 void PreferencesBrowserTest::VerifyObservedPrefs(
292 const std::string& json, 294 const std::string& json,
293 const std::vector<std::string>& names, 295 const std::vector<std::string>& names,
294 const std::vector<base::Value*>& values, 296 const std::vector<std::unique_ptr<base::Value>>& values,
295 const std::string& controlledBy, 297 const std::string& controlledBy,
296 bool disabled, 298 bool disabled,
297 bool uncommitted) { 299 bool uncommitted) {
298 std::unique_ptr<base::Value> observed_value_ptr = 300 std::unique_ptr<base::Value> observed_value_ptr =
299 base::JSONReader::Read(json); 301 base::JSONReader::Read(json);
300 const base::DictionaryValue* observed_dict; 302 const base::DictionaryValue* observed_dict;
301 ASSERT_TRUE(observed_value_ptr.get()); 303 ASSERT_TRUE(observed_value_ptr.get());
302 ASSERT_TRUE(observed_value_ptr->GetAsDictionary(&observed_dict)); 304 ASSERT_TRUE(observed_value_ptr->GetAsDictionary(&observed_dict));
303 for (size_t i = 0; i < names.size(); ++i) { 305 for (size_t i = 0; i < names.size(); ++i) {
304 VerifyPref(observed_dict, names[i], values[i], controlledBy, disabled, 306 VerifyPref(observed_dict, names[i], values[i], controlledBy, disabled,
305 uncommitted); 307 uncommitted);
306 } 308 }
307 } 309 }
308 310
309 void PreferencesBrowserTest::ExpectNoCommit(const std::string& name) { 311 void PreferencesBrowserTest::ExpectNoCommit(const std::string& name) {
310 pref_change_registrar_->Add( 312 pref_change_registrar_->Add(
311 name.c_str(), 313 name.c_str(),
312 base::Bind(&PreferencesBrowserTest::OnPreferenceChanged, 314 base::Bind(&PreferencesBrowserTest::OnPreferenceChanged,
313 base::Unretained(this))); 315 base::Unretained(this)));
314 EXPECT_CALL(*this, OnCommit(Property(&PrefService::Preference::name, name))) 316 EXPECT_CALL(*this, OnCommit(Property(&PrefService::Preference::name, name)))
315 .Times(0); 317 .Times(0);
316 } 318 }
317 319
318 void PreferencesBrowserTest::ExpectSetCommit(const std::string& name, 320 void PreferencesBrowserTest::ExpectSetCommit(
319 const base::Value* value) { 321 const std::string& name,
322 const std::unique_ptr<base::Value>& value) {
320 pref_change_registrar_->Add( 323 pref_change_registrar_->Add(
321 name.c_str(), 324 name.c_str(),
322 base::Bind(&PreferencesBrowserTest::OnPreferenceChanged, 325 base::Bind(&PreferencesBrowserTest::OnPreferenceChanged,
323 base::Unretained(this))); 326 base::Unretained(this)));
324 EXPECT_CALL(*this, OnCommit(AllOf( 327 EXPECT_CALL(
325 Property(&PrefService::Preference::name, name), 328 *this,
326 Property(&PrefService::Preference::IsUserControlled, true), 329 OnCommit(AllOf(Property(&PrefService::Preference::name, name),
327 Property(&PrefService::Preference::GetValue, EqualsValue(value))))); 330 Property(&PrefService::Preference::IsUserControlled, true),
331 Property(&PrefService::Preference::GetValue,
332 EqualsValue(value.get())))));
328 } 333 }
329 334
330 void PreferencesBrowserTest::ExpectClearCommit(const std::string& name) { 335 void PreferencesBrowserTest::ExpectClearCommit(const std::string& name) {
331 pref_change_registrar_->Add( 336 pref_change_registrar_->Add(
332 name.c_str(), 337 name.c_str(),
333 base::Bind(&PreferencesBrowserTest::OnPreferenceChanged, 338 base::Bind(&PreferencesBrowserTest::OnPreferenceChanged,
334 base::Unretained(this))); 339 base::Unretained(this)));
335 EXPECT_CALL(*this, OnCommit(AllOf( 340 EXPECT_CALL(*this, OnCommit(AllOf(
336 Property(&PrefService::Preference::name, name), 341 Property(&PrefService::Preference::name, name),
337 Property(&PrefService::Preference::IsUserControlled, false)))); 342 Property(&PrefService::Preference::IsUserControlled, false))));
338 } 343 }
339 344
340 void PreferencesBrowserTest::VerifyAndClearExpectations() { 345 void PreferencesBrowserTest::VerifyAndClearExpectations() {
341 Mock::VerifyAndClearExpectations(this); 346 Mock::VerifyAndClearExpectations(this);
342 pref_change_registrar_->RemoveAll(); 347 pref_change_registrar_->RemoveAll();
343 } 348 }
344 349
345 void PreferencesBrowserTest::SetupJavaScriptTestEnvironment( 350 void PreferencesBrowserTest::SetupJavaScriptTestEnvironment(
346 const std::vector<std::string>& pref_names, 351 const std::vector<std::string>& pref_names,
347 std::string* observed_json) const { 352 std::string* observed_json) const {
348 std::stringstream javascript; 353 std::stringstream javascript;
349 javascript << "var testEnv = new TestEnv();"; 354 javascript << "var testEnv = new TestEnv();";
350 for (std::vector<std::string>::const_iterator name = pref_names.begin(); 355 for (auto name = pref_names.begin(); name != pref_names.end(); ++name) {
351 name != pref_names.end(); ++name) {
352 javascript << "testEnv.addPref('" << name->c_str() << "');"; 356 javascript << "testEnv.addPref('" << name->c_str() << "');";
353 } 357 }
354 javascript << "testEnv.setupAndReply();"; 358 javascript << "testEnv.setupAndReply();";
355 std::string temp_observed_json; 359 std::string temp_observed_json;
356 if (!observed_json) 360 if (!observed_json)
357 observed_json = &temp_observed_json; 361 observed_json = &temp_observed_json;
358 ASSERT_TRUE(content::ExecuteScriptAndExtractString( 362 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
359 render_view_host_, javascript.str(), observed_json)); 363 render_view_host_, javascript.str(), observed_json));
360 } 364 }
361 365
362 void PreferencesBrowserTest::SetPref(const std::string& name, 366 void PreferencesBrowserTest::SetPref(const std::string& name,
363 const std::string& type, 367 const std::string& type,
364 const base::Value* value, 368 const std::unique_ptr<base::Value>& value,
365 bool commit, 369 bool commit,
366 std::string* observed_json) { 370 std::string* observed_json) {
367 std::unique_ptr<base::Value> commit_ptr(new base::FundamentalValue(commit)); 371 std::unique_ptr<base::Value> commit_ptr(new base::FundamentalValue(commit));
368 std::stringstream javascript; 372 std::stringstream javascript;
369 javascript << "testEnv.runAndReply(function() {" 373 javascript << "testEnv.runAndReply(function() {"
370 << " Preferences.set" << type << "Pref(" 374 << " Preferences.set" << type << "Pref("
371 << " '" << name << "'," 375 << " '" << name << "',"
372 << " " << *value << "," 376 << " " << *value << ","
373 << " " << *commit_ptr << ");" 377 << " " << *commit_ptr << ");"
374 << "});"; 378 << "});";
375 ASSERT_TRUE(content::ExecuteScriptAndExtractString( 379 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
376 render_view_host_, javascript.str(), observed_json)); 380 render_view_host_, javascript.str(), observed_json));
377 } 381 }
378 382
379 void PreferencesBrowserTest::VerifySetPref(const std::string& name, 383 void PreferencesBrowserTest::VerifySetPref(
380 const std::string& type, 384 const std::string& name,
381 const base::Value* value, 385 const std::string& type,
382 bool commit) { 386 const std::unique_ptr<base::Value>& value,
387 bool commit) {
383 if (commit) 388 if (commit)
384 ExpectSetCommit(name, value); 389 ExpectSetCommit(name, value);
385 else 390 else
386 ExpectNoCommit(name); 391 ExpectNoCommit(name);
387 std::string observed_json; 392 std::string observed_json;
388 SetPref(name, type, value, commit, &observed_json); 393 SetPref(name, type, value, commit, &observed_json);
389 VerifyObservedPref(observed_json, name, value, std::string(), false, !commit); 394 VerifyObservedPref(observed_json, name, value, std::string(), false, !commit);
390 VerifyAndClearExpectations(); 395 VerifyAndClearExpectations();
391 } 396 }
392 397
393 void PreferencesBrowserTest::VerifyClearPref(const std::string& name, 398 void PreferencesBrowserTest::VerifyClearPref(
394 const base::Value* value, 399 const std::string& name,
395 bool commit) { 400 const std::unique_ptr<base::Value>& value,
401 bool commit) {
396 if (commit) 402 if (commit)
397 ExpectClearCommit(name); 403 ExpectClearCommit(name);
398 else 404 else
399 ExpectNoCommit(name); 405 ExpectNoCommit(name);
400 std::string commit_json; 406 std::string commit_json;
401 base::JSONWriter::Write(base::FundamentalValue(commit), &commit_json); 407 base::JSONWriter::Write(base::FundamentalValue(commit), &commit_json);
402 std::stringstream javascript; 408 std::stringstream javascript;
403 javascript << "testEnv.runAndReply(function() {" 409 javascript << "testEnv.runAndReply(function() {"
404 << " Preferences.clearPref(" 410 << " Preferences.clearPref("
405 << " '" << name.c_str() << "'," 411 << " '" << name.c_str() << "',"
406 << " " << commit_json.c_str() << ");});"; 412 << " " << commit_json.c_str() << ");});";
407 std::string observed_json; 413 std::string observed_json;
408 ASSERT_TRUE(content::ExecuteScriptAndExtractString( 414 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
409 render_view_host_, javascript.str(), &observed_json)); 415 render_view_host_, javascript.str(), &observed_json));
410 VerifyObservedPref(observed_json, name, value, "recommended", false, !commit); 416 VerifyObservedPref(observed_json, name, value, "recommended", false, !commit);
411 VerifyAndClearExpectations(); 417 VerifyAndClearExpectations();
412 } 418 }
413 419
414 void PreferencesBrowserTest::VerifyCommit(const std::string& name, 420 void PreferencesBrowserTest::VerifyCommit(
415 const base::Value* value, 421 const std::string& name,
416 const std::string& controlledBy) { 422 const std::unique_ptr<base::Value>& value,
423 const std::string& controlledBy) {
417 std::stringstream javascript; 424 std::stringstream javascript;
418 javascript << "testEnv.runAndReply(function() {" 425 javascript << "testEnv.runAndReply(function() {"
419 << " Preferences.getInstance().commitPref(" 426 << " Preferences.getInstance().commitPref("
420 << " '" << name.c_str() << "');});"; 427 << " '" << name.c_str() << "');});";
421 std::string observed_json; 428 std::string observed_json;
422 ASSERT_TRUE(content::ExecuteScriptAndExtractString( 429 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
423 render_view_host_, javascript.str(), &observed_json)); 430 render_view_host_, javascript.str(), &observed_json));
424 VerifyObservedPref(observed_json, name, value, controlledBy, false, false); 431 VerifyObservedPref(observed_json, name, value, controlledBy, false, false);
425 } 432 }
426 433
427 void PreferencesBrowserTest::VerifySetCommit(const std::string& name, 434 void PreferencesBrowserTest::VerifySetCommit(
428 const base::Value* value) { 435 const std::string& name,
436 const std::unique_ptr<base::Value>& value) {
429 ExpectSetCommit(name, value); 437 ExpectSetCommit(name, value);
430 VerifyCommit(name, value, std::string()); 438 VerifyCommit(name, value, std::string());
431 VerifyAndClearExpectations(); 439 VerifyAndClearExpectations();
432 } 440 }
433 441
434 void PreferencesBrowserTest::VerifyClearCommit(const std::string& name, 442 void PreferencesBrowserTest::VerifyClearCommit(
435 const base::Value* value) { 443 const std::string& name,
444 const std::unique_ptr<base::Value>& value) {
436 ExpectClearCommit(name); 445 ExpectClearCommit(name);
437 VerifyCommit(name, value, "recommended"); 446 VerifyCommit(name, value, "recommended");
438 VerifyAndClearExpectations(); 447 VerifyAndClearExpectations();
439 } 448 }
440 449
441 void PreferencesBrowserTest::VerifyRollback(const std::string& name, 450 void PreferencesBrowserTest::VerifyRollback(
442 const base::Value* value, 451 const std::string& name,
443 const std::string& controlledBy) { 452 const std::unique_ptr<base::Value>& value,
453 const std::string& controlledBy) {
444 ExpectNoCommit(name); 454 ExpectNoCommit(name);
445 std::stringstream javascript; 455 std::stringstream javascript;
446 javascript << "testEnv.runAndReply(function() {" 456 javascript << "testEnv.runAndReply(function() {"
447 << " Preferences.getInstance().rollbackPref(" 457 << " Preferences.getInstance().rollbackPref("
448 << " '" << name.c_str() << "');});"; 458 << " '" << name.c_str() << "');});";
449 std::string observed_json; 459 std::string observed_json;
450 ASSERT_TRUE(content::ExecuteScriptAndExtractString( 460 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
451 render_view_host_, javascript.str(), &observed_json)); 461 render_view_host_, javascript.str(), &observed_json));
452 VerifyObservedPref(observed_json, name, value, controlledBy, false, true); 462 VerifyObservedPref(observed_json, name, value, controlledBy, false, true);
453 VerifyAndClearExpectations(); 463 VerifyAndClearExpectations();
454 } 464 }
455 465
456 void PreferencesBrowserTest::StartObserving() { 466 void PreferencesBrowserTest::StartObserving() {
457 ASSERT_TRUE(content::ExecuteScript( 467 ASSERT_TRUE(content::ExecuteScript(
458 render_view_host_, "testEnv.startObserving();")); 468 render_view_host_, "testEnv.startObserving();"));
459 } 469 }
460 470
461 void PreferencesBrowserTest::FinishObserving(std::string* observed_json) { 471 void PreferencesBrowserTest::FinishObserving(std::string* observed_json) {
462 ASSERT_TRUE(content::ExecuteScriptAndExtractString( 472 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
463 render_view_host_, 473 render_view_host_,
464 "testEnv.finishObservingAndReply();", 474 "testEnv.finishObservingAndReply();",
465 observed_json)); 475 observed_json));
466 } 476 }
467 477
468 void PreferencesBrowserTest::UseDefaultTestPrefs(bool includeListPref) { 478 void PreferencesBrowserTest::UseDefaultTestPrefs(bool includeListPref) {
469 // Boolean pref. 479 // Boolean pref.
470 types_.push_back("Boolean"); 480 types_.push_back("Boolean");
471 pref_names_.push_back(prefs::kAlternateErrorPagesEnabled); 481 pref_names_.push_back(prefs::kAlternateErrorPagesEnabled);
472 policy_names_.push_back(policy::key::kAlternateErrorPagesEnabled); 482 policy_names_.push_back(policy::key::kAlternateErrorPagesEnabled);
473 non_default_values_.push_back(new base::FundamentalValue(false)); 483 non_default_values_.push_back(
484 base::MakeUnique<base::FundamentalValue>(false));
474 485
475 // Integer pref. 486 // Integer pref.
476 types_.push_back("Integer"); 487 types_.push_back("Integer");
477 pref_names_.push_back(prefs::kRestoreOnStartup); 488 pref_names_.push_back(prefs::kRestoreOnStartup);
478 policy_names_.push_back(policy::key::kRestoreOnStartup); 489 policy_names_.push_back(policy::key::kRestoreOnStartup);
479 non_default_values_.push_back(new base::FundamentalValue(4)); 490 non_default_values_.push_back(base::MakeUnique<base::FundamentalValue>(4));
480 491
481 // List pref. 492 // List pref.
482 if (includeListPref) { 493 if (includeListPref) {
483 types_.push_back("List"); 494 types_.push_back("List");
484 pref_names_.push_back(prefs::kURLsToRestoreOnStartup); 495 pref_names_.push_back(prefs::kURLsToRestoreOnStartup);
485 policy_names_.push_back(policy::key::kRestoreOnStartupURLs); 496 policy_names_.push_back(policy::key::kRestoreOnStartupURLs);
486 base::ListValue* list = new base::ListValue; 497 std::unique_ptr<base::ListValue> list = base::MakeUnique<base::ListValue>();
487 list->AppendString("http://www.example.com"); 498 list->AppendString("http://www.example.com");
488 list->AppendString("http://example.com"); 499 list->AppendString("http://example.com");
489 non_default_values_.push_back(list); 500 non_default_values_.push_back(std::move(list));
490 } 501 }
491 502
492 // Retrieve default values. 503 // Retrieve default values.
493 for (std::vector<std::string>::const_iterator name = pref_names_.begin(); 504 for (auto name = pref_names_.begin(); name != pref_names_.end(); ++name) {
494 name != pref_names_.end(); ++name) {
495 default_values_.push_back( 505 default_values_.push_back(
496 pref_service()->GetDefaultPrefValue(name->c_str())->DeepCopy()); 506 pref_service()->GetDefaultPrefValue(name->c_str())->CreateDeepCopy());
Nico 2017/01/03 18:12:35 The reasoning being "eh it's just a test" I assume
Avi (use Gerrit) 2017/01/03 22:54:53 I don't know what the ownership story of GetDefaul
497 } 507 }
498 } 508 }
499 509
500 // Verifies that initializing the JavaScript Preferences class fires the correct 510 // Verifies that initializing the JavaScript Preferences class fires the correct
501 // notifications in JavaScript. 511 // notifications in JavaScript.
502 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, FetchPrefs) { 512 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, FetchPrefs) {
503 UseDefaultTestPrefs(true); 513 UseDefaultTestPrefs(true);
504 std::string observed_json; 514 std::string observed_json;
505 515
506 // Verify notifications when default values are in effect. 516 // Verify notifications when default values are in effect.
507 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); 517 SetupJavaScriptTestEnvironment(pref_names_, &observed_json);
508 VerifyObservedPrefs( 518 VerifyObservedPrefs(observed_json, pref_names_, default_values_,
509 observed_json, pref_names_, default_values_.get(), 519 std::string(), false, false);
510 std::string(), false, false);
511 520
512 // Verify notifications when recommended values are in effect. 521 // Verify notifications when recommended values are in effect.
513 SetUserPolicies(policy_names_, non_default_values_.get(), 522 SetUserPolicies(policy_names_, non_default_values_,
514 policy::POLICY_LEVEL_RECOMMENDED); 523 policy::POLICY_LEVEL_RECOMMENDED);
515 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); 524 SetupJavaScriptTestEnvironment(pref_names_, &observed_json);
516 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_.get(), 525 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_,
517 "recommended", false, false); 526 "recommended", false, false);
518 527
519 // Verify notifications when mandatory values are in effect. 528 // Verify notifications when mandatory values are in effect.
520 SetUserPolicies(policy_names_, non_default_values_.get(), 529 SetUserPolicies(policy_names_, non_default_values_,
521 policy::POLICY_LEVEL_MANDATORY); 530 policy::POLICY_LEVEL_MANDATORY);
522 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); 531 SetupJavaScriptTestEnvironment(pref_names_, &observed_json);
523 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_.get(), 532 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_, "policy",
524 "policy", true, false); 533 true, false);
525 534
526 // Verify notifications when user-modified values are in effect. 535 // Verify notifications when user-modified values are in effect.
527 ClearUserPolicies(); 536 ClearUserPolicies();
528 SetUserValues(pref_names_, non_default_values_.get()); 537 SetUserValues(pref_names_, non_default_values_);
529 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); 538 SetupJavaScriptTestEnvironment(pref_names_, &observed_json);
530 VerifyObservedPrefs(observed_json, 539 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_,
531 pref_names_, 540 std::string(), false, false);
532 non_default_values_.get(),
533 std::string(),
534 false,
535 false);
536 } 541 }
537 542
538 // Verifies that setting a user-modified pref value through the JavaScript 543 // Verifies that setting a user-modified pref value through the JavaScript
539 // Preferences class fires the correct notification in JavaScript and causes the 544 // Preferences class fires the correct notification in JavaScript and causes the
540 // change to be committed to the C++ backend. 545 // change to be committed to the C++ backend.
541 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, SetPrefs) { 546 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, SetPrefs) {
542 UseDefaultTestPrefs(false); 547 UseDefaultTestPrefs(false);
543 548
544 ASSERT_NO_FATAL_FAILURE(SetupJavaScriptTestEnvironment(pref_names_, NULL)); 549 ASSERT_NO_FATAL_FAILURE(SetupJavaScriptTestEnvironment(pref_names_, NULL));
545 for (size_t i = 0; i < pref_names_.size(); ++i) { 550 for (size_t i = 0; i < pref_names_.size(); ++i) {
546 VerifySetPref(pref_names_[i], types_[i], non_default_values_[i], true); 551 VerifySetPref(pref_names_[i], types_[i], non_default_values_[i], true);
547 } 552 }
548 } 553 }
549 554
550 // Verifies that clearing a user-modified pref value through the JavaScript 555 // Verifies that clearing a user-modified pref value through the JavaScript
551 // Preferences class fires the correct notification in JavaScript and causes the 556 // Preferences class fires the correct notification in JavaScript and causes the
552 // change to be committed to the C++ backend. 557 // change to be committed to the C++ backend.
553 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, ClearPrefs) { 558 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, ClearPrefs) {
554 UseDefaultTestPrefs(false); 559 UseDefaultTestPrefs(false);
555 560
556 SetUserPolicies(policy_names_, default_values_.get(), 561 SetUserPolicies(policy_names_, default_values_,
557 policy::POLICY_LEVEL_RECOMMENDED); 562 policy::POLICY_LEVEL_RECOMMENDED);
558 SetUserValues(pref_names_, non_default_values_.get()); 563 SetUserValues(pref_names_, non_default_values_);
559 ASSERT_NO_FATAL_FAILURE(SetupJavaScriptTestEnvironment(pref_names_, NULL)); 564 ASSERT_NO_FATAL_FAILURE(SetupJavaScriptTestEnvironment(pref_names_, NULL));
560 for (size_t i = 0; i < pref_names_.size(); ++i) { 565 for (size_t i = 0; i < pref_names_.size(); ++i) {
561 VerifyClearPref(pref_names_[i], default_values_[i], true); 566 VerifyClearPref(pref_names_[i], default_values_[i], true);
562 } 567 }
563 } 568 }
564 569
565 // Verifies that when the user-modified value of a dialog pref is set and the 570 // Verifies that when the user-modified value of a dialog pref is set and the
566 // change then committed through the JavaScript Preferences class, the correct 571 // change then committed through the JavaScript Preferences class, the correct
567 // notifications fire and a commit to the C++ backend occurs in the latter step 572 // notifications fire and a commit to the C++ backend occurs in the latter step
568 // only. 573 // only.
(...skipping 14 matching lines...) Expand all
583 UseDefaultTestPrefs(false); 588 UseDefaultTestPrefs(false);
584 589
585 // Verify behavior when default values are in effect. 590 // Verify behavior when default values are in effect.
586 ASSERT_NO_FATAL_FAILURE(SetupJavaScriptTestEnvironment(pref_names_, NULL)); 591 ASSERT_NO_FATAL_FAILURE(SetupJavaScriptTestEnvironment(pref_names_, NULL));
587 for (size_t i = 0; i < pref_names_.size(); ++i) { 592 for (size_t i = 0; i < pref_names_.size(); ++i) {
588 VerifySetPref(pref_names_[i], types_[i], non_default_values_[i], false); 593 VerifySetPref(pref_names_[i], types_[i], non_default_values_[i], false);
589 VerifyRollback(pref_names_[i], default_values_[i], std::string()); 594 VerifyRollback(pref_names_[i], default_values_[i], std::string());
590 } 595 }
591 596
592 // Verify behavior when recommended values are in effect. 597 // Verify behavior when recommended values are in effect.
593 SetUserPolicies(policy_names_, default_values_.get(), 598 SetUserPolicies(policy_names_, default_values_,
594 policy::POLICY_LEVEL_RECOMMENDED); 599 policy::POLICY_LEVEL_RECOMMENDED);
595 ASSERT_NO_FATAL_FAILURE(SetupJavaScriptTestEnvironment(pref_names_, NULL)); 600 ASSERT_NO_FATAL_FAILURE(SetupJavaScriptTestEnvironment(pref_names_, NULL));
596 for (size_t i = 0; i < pref_names_.size(); ++i) { 601 for (size_t i = 0; i < pref_names_.size(); ++i) {
597 VerifySetPref(pref_names_[i], types_[i], non_default_values_[i], false); 602 VerifySetPref(pref_names_[i], types_[i], non_default_values_[i], false);
598 VerifyRollback(pref_names_[i], default_values_[i], "recommended"); 603 VerifyRollback(pref_names_[i], default_values_[i], "recommended");
599 } 604 }
600 } 605 }
601 606
602 // Verifies that when the user-modified value of a dialog pref is cleared and 607 // Verifies that when the user-modified value of a dialog pref is cleared and
603 // the change then committed through the JavaScript Preferences class, the 608 // the change then committed through the JavaScript Preferences class, the
604 // correct notifications fire and a commit to the C++ backend occurs in the 609 // correct notifications fire and a commit to the C++ backend occurs in the
605 // latter step only. 610 // latter step only.
606 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, DialogPrefsClearCommit) { 611 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, DialogPrefsClearCommit) {
607 UseDefaultTestPrefs(false); 612 UseDefaultTestPrefs(false);
608 613
609 SetUserPolicies(policy_names_, default_values_.get(), 614 SetUserPolicies(policy_names_, default_values_,
610 policy::POLICY_LEVEL_RECOMMENDED); 615 policy::POLICY_LEVEL_RECOMMENDED);
611 SetUserValues(pref_names_, non_default_values_.get()); 616 SetUserValues(pref_names_, non_default_values_);
612 ASSERT_NO_FATAL_FAILURE(SetupJavaScriptTestEnvironment(pref_names_, NULL)); 617 ASSERT_NO_FATAL_FAILURE(SetupJavaScriptTestEnvironment(pref_names_, NULL));
613 for (size_t i = 0; i < pref_names_.size(); ++i) { 618 for (size_t i = 0; i < pref_names_.size(); ++i) {
614 VerifyClearPref(pref_names_[i], default_values_[i], false); 619 VerifyClearPref(pref_names_[i], default_values_[i], false);
615 VerifyClearCommit(pref_names_[i], default_values_[i]); 620 VerifyClearCommit(pref_names_[i], default_values_[i]);
616 } 621 }
617 } 622 }
618 623
619 // Verifies that when the user-modified value of a dialog pref is cleared and 624 // Verifies that when the user-modified value of a dialog pref is cleared and
620 // the change then rolled back through the JavaScript Preferences class, the 625 // the change then rolled back through the JavaScript Preferences class, the
621 // correct notifications fire and no commit to the C++ backend occurs. 626 // correct notifications fire and no commit to the C++ backend occurs.
622 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, DialogPrefsClearRollback) { 627 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, DialogPrefsClearRollback) {
623 UseDefaultTestPrefs(false); 628 UseDefaultTestPrefs(false);
624 629
625 SetUserPolicies(policy_names_, default_values_.get(), 630 SetUserPolicies(policy_names_, default_values_,
626 policy::POLICY_LEVEL_RECOMMENDED); 631 policy::POLICY_LEVEL_RECOMMENDED);
627 SetUserValues(pref_names_, non_default_values_.get()); 632 SetUserValues(pref_names_, non_default_values_);
628 ASSERT_NO_FATAL_FAILURE(SetupJavaScriptTestEnvironment(pref_names_, NULL)); 633 ASSERT_NO_FATAL_FAILURE(SetupJavaScriptTestEnvironment(pref_names_, NULL));
629 for (size_t i = 0; i < pref_names_.size(); ++i) { 634 for (size_t i = 0; i < pref_names_.size(); ++i) {
630 VerifyClearPref(pref_names_[i], default_values_[i], false); 635 VerifyClearPref(pref_names_[i], default_values_[i], false);
631 VerifyRollback(pref_names_[i], non_default_values_[i], std::string()); 636 VerifyRollback(pref_names_[i], non_default_values_[i], std::string());
632 } 637 }
633 } 638 }
634 639
635 // Verifies that when preference values change in the C++ backend, the correct 640 // Verifies that when preference values change in the C++ backend, the correct
636 // notifications fire in JavaScript. 641 // notifications fire in JavaScript.
637 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, NotificationsOnBackendChanges) { 642 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, NotificationsOnBackendChanges) {
638 UseDefaultTestPrefs(false); 643 UseDefaultTestPrefs(false);
639 std::string observed_json; 644 std::string observed_json;
640 645
641 ASSERT_NO_FATAL_FAILURE(SetupJavaScriptTestEnvironment(pref_names_, NULL)); 646 ASSERT_NO_FATAL_FAILURE(SetupJavaScriptTestEnvironment(pref_names_, NULL));
642 647
643 // Verify notifications when recommended values come into effect. 648 // Verify notifications when recommended values come into effect.
644 StartObserving(); 649 StartObserving();
645 SetUserPolicies(policy_names_, non_default_values_.get(), 650 SetUserPolicies(policy_names_, non_default_values_,
646 policy::POLICY_LEVEL_RECOMMENDED); 651 policy::POLICY_LEVEL_RECOMMENDED);
647 FinishObserving(&observed_json); 652 FinishObserving(&observed_json);
648 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_.get(), 653 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_,
649 "recommended", false, false); 654 "recommended", false, false);
650 655
651 // Verify notifications when mandatory values come into effect. 656 // Verify notifications when mandatory values come into effect.
652 StartObserving(); 657 StartObserving();
653 SetUserPolicies(policy_names_, non_default_values_.get(), 658 SetUserPolicies(policy_names_, non_default_values_,
654 policy::POLICY_LEVEL_MANDATORY); 659 policy::POLICY_LEVEL_MANDATORY);
655 FinishObserving(&observed_json); 660 FinishObserving(&observed_json);
656 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_.get(), 661 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_, "policy",
657 "policy", true, false); 662 true, false);
658 663
659 // Verify notifications when default values come into effect. 664 // Verify notifications when default values come into effect.
660 StartObserving(); 665 StartObserving();
661 ClearUserPolicies(); 666 ClearUserPolicies();
662 FinishObserving(&observed_json); 667 FinishObserving(&observed_json);
663 VerifyObservedPrefs( 668 VerifyObservedPrefs(observed_json, pref_names_, default_values_,
664 observed_json, pref_names_, default_values_.get(), 669 std::string(), false, false);
665 std::string(), false, false);
666 670
667 // Verify notifications when user-modified values come into effect. 671 // Verify notifications when user-modified values come into effect.
668 StartObserving(); 672 StartObserving();
669 SetUserValues(pref_names_, non_default_values_.get()); 673 SetUserValues(pref_names_, non_default_values_);
670 FinishObserving(&observed_json); 674 FinishObserving(&observed_json);
671 VerifyObservedPrefs(observed_json, 675 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_,
672 pref_names_, 676 std::string(), false, false);
673 non_default_values_.get(),
674 std::string(),
675 false,
676 false);
677 } 677 }
678 678
679 #if defined(OS_CHROMEOS) 679 #if defined(OS_CHROMEOS)
680 680
681 // Verifies that initializing the JavaScript Preferences class fires the correct 681 // Verifies that initializing the JavaScript Preferences class fires the correct
682 // notifications in JavaScript for pref values handled by the 682 // notifications in JavaScript for pref values handled by the
683 // CoreChromeOSOptionsHandler class. 683 // CoreChromeOSOptionsHandler class.
684 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, ChromeOSDeviceFetchPrefs) { 684 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, ChromeOSDeviceFetchPrefs) {
685 std::string observed_json; 685 std::string observed_json;
686 686
687 // Boolean pref. 687 // Boolean pref.
688 pref_names_.push_back(chromeos::kAccountsPrefAllowGuest); 688 pref_names_.push_back(chromeos::kAccountsPrefAllowGuest);
689 default_values_.push_back(new base::FundamentalValue(true)); 689 default_values_.push_back(base::MakeUnique<base::FundamentalValue>(true));
690 690
691 // String pref. 691 // String pref.
692 pref_names_.push_back(chromeos::kReleaseChannel); 692 pref_names_.push_back(chromeos::kReleaseChannel);
693 default_values_.push_back(new base::StringValue("")); 693 default_values_.push_back(base::MakeUnique<base::StringValue>(""));
694 694
695 // List pref. 695 // List pref.
696 pref_names_.push_back(chromeos::kAccountsPrefUsers); 696 pref_names_.push_back(chromeos::kAccountsPrefUsers);
697 default_values_.push_back(new base::ListValue); 697 default_values_.push_back(base::MakeUnique<base::ListValue>());
698 698
699 // Verify notifications when default values are in effect. 699 // Verify notifications when default values are in effect.
700 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); 700 SetupJavaScriptTestEnvironment(pref_names_, &observed_json);
701 VerifyObservedPrefs(observed_json, pref_names_, default_values_.get(), 701 VerifyObservedPrefs(observed_json, pref_names_, default_values_, "owner",
702 "owner", true, false); 702 true, false);
703 } 703 }
704 704
705 // Verifies that initializing the JavaScript Preferences class fires the correct 705 // Verifies that initializing the JavaScript Preferences class fires the correct
706 // notifications in JavaScript for non-privileged pref values handled by the 706 // notifications in JavaScript for non-privileged pref values handled by the
707 // CoreChromeOSOptionsHandler class. 707 // CoreChromeOSOptionsHandler class.
708 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, 708 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest,
709 ChromeOSDeviceFetchNonPrivilegedPrefs) { 709 ChromeOSDeviceFetchNonPrivilegedPrefs) {
710 ScopedVector<base::Value> decorated_non_default_values; 710 std::vector<std::unique_ptr<base::Value>> decorated_non_default_values;
711 std::string observed_json; 711 std::string observed_json;
712 712
713 // Non-privileged string pref. 713 // Non-privileged string pref.
714 pref_names_.push_back(chromeos::kSystemTimezone); 714 pref_names_.push_back(chromeos::kSystemTimezone);
715 default_values_.push_back(new base::StringValue("America/Los_Angeles")); 715 default_values_.push_back(
716 non_default_values_.push_back(new base::StringValue("America/New_York")); 716 base::MakeUnique<base::StringValue>("America/Los_Angeles"));
717 non_default_values_.push_back(
718 base::MakeUnique<base::StringValue>("America/New_York"));
717 decorated_non_default_values.push_back( 719 decorated_non_default_values.push_back(
718 non_default_values_.back()->DeepCopy()); 720 non_default_values_.back()->CreateDeepCopy());
719 721
720 // Verify notifications when default values are in effect. 722 // Verify notifications when default values are in effect.
721 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); 723 SetupJavaScriptTestEnvironment(pref_names_, &observed_json);
722 VerifyObservedPrefs(observed_json, pref_names_, default_values_.get(), 724 VerifyObservedPrefs(observed_json, pref_names_, default_values_,
723 std::string(), false, false); 725 std::string(), false, false);
724 726
725 chromeos::CrosSettings* cros_settings = chromeos::CrosSettings::Get(); 727 chromeos::CrosSettings* cros_settings = chromeos::CrosSettings::Get();
726 cros_settings->Set(pref_names_[0], *non_default_values_[0]); 728 cros_settings->Set(pref_names_[0], *non_default_values_[0]);
727 729
728 // Verify notifications when non-default values are in effect. 730 // Verify notifications when non-default values are in effect.
729 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); 731 SetupJavaScriptTestEnvironment(pref_names_, &observed_json);
730 VerifyObservedPrefs(observed_json, pref_names_, 732 VerifyObservedPrefs(observed_json, pref_names_, decorated_non_default_values,
731 decorated_non_default_values.get(),
732 std::string(), false, false); 733 std::string(), false, false);
733 } 734 }
734 735
735 class ManagedPreferencesBrowserTest : public PreferencesBrowserTest { 736 class ManagedPreferencesBrowserTest : public PreferencesBrowserTest {
736 protected: 737 protected:
737 // PreferencesBrowserTest implementation: 738 // PreferencesBrowserTest implementation:
738 void SetUpInProcessBrowserTestFixture() override { 739 void SetUpInProcessBrowserTestFixture() override {
739 // Set up fake install attributes. 740 // Set up fake install attributes.
740 std::unique_ptr<chromeos::StubInstallAttributes> attributes = 741 std::unique_ptr<chromeos::StubInstallAttributes> attributes =
741 base::MakeUnique<chromeos::StubInstallAttributes>(); 742 base::MakeUnique<chromeos::StubInstallAttributes>();
742 attributes->SetEnterprise("example.com", "fake-id"); 743 attributes->SetEnterprise("example.com", "fake-id");
743 policy::BrowserPolicyConnectorChromeOS::SetInstallAttributesForTesting( 744 policy::BrowserPolicyConnectorChromeOS::SetInstallAttributesForTesting(
744 attributes.release()); 745 attributes.release());
745 746
746 PreferencesBrowserTest::SetUpInProcessBrowserTestFixture(); 747 PreferencesBrowserTest::SetUpInProcessBrowserTestFixture();
747 } 748 }
748 }; 749 };
749 750
750 // Verifies that initializing the JavaScript Preferences class fires the correct 751 // Verifies that initializing the JavaScript Preferences class fires the correct
751 // notifications in JavaScript for pref values handled by the 752 // notifications in JavaScript for pref values handled by the
752 // CoreChromeOSOptionsHandler class for a managed device. 753 // CoreChromeOSOptionsHandler class for a managed device.
753 IN_PROC_BROWSER_TEST_F(ManagedPreferencesBrowserTest, 754 IN_PROC_BROWSER_TEST_F(ManagedPreferencesBrowserTest,
754 ChromeOSDeviceFetchPrefs) { 755 ChromeOSDeviceFetchPrefs) {
755 ScopedVector<base::Value> decorated_non_default_values; 756 std::vector<std::unique_ptr<base::Value>> decorated_non_default_values;
756 std::string observed_json; 757 std::string observed_json;
757 758
758 // Boolean pref. 759 // Boolean pref.
759 pref_names_.push_back(chromeos::kAccountsPrefAllowGuest); 760 pref_names_.push_back(chromeos::kAccountsPrefAllowGuest);
760 non_default_values_.push_back(new base::FundamentalValue(false)); 761 non_default_values_.push_back(
762 base::MakeUnique<base::FundamentalValue>(false));
761 decorated_non_default_values.push_back( 763 decorated_non_default_values.push_back(
762 non_default_values_.back()->DeepCopy()); 764 non_default_values_.back()->CreateDeepCopy());
763 765
764 // String pref. 766 // String pref.
765 pref_names_.push_back(chromeos::kReleaseChannel); 767 pref_names_.push_back(chromeos::kReleaseChannel);
766 non_default_values_.push_back(new base::StringValue("stable-channel")); 768 non_default_values_.push_back(
769 base::MakeUnique<base::StringValue>("stable-channel"));
767 decorated_non_default_values.push_back( 770 decorated_non_default_values.push_back(
768 non_default_values_.back()->DeepCopy()); 771 non_default_values_.back()->CreateDeepCopy());
769 772
770 // List pref. 773 // List pref.
771 pref_names_.push_back(chromeos::kAccountsPrefUsers); 774 pref_names_.push_back(chromeos::kAccountsPrefUsers);
772 base::ListValue* list = new base::ListValue; 775 std::unique_ptr<base::ListValue> list = base::MakeUnique<base::ListValue>();
773 list->AppendString("me@google.com"); 776 list->AppendString("me@google.com");
774 list->AppendString("you@google.com"); 777 list->AppendString("you@google.com");
775 non_default_values_.push_back(list); 778 non_default_values_.push_back(std::move(list));
776 list = new base::ListValue; 779 list = base::MakeUnique<base::ListValue>();
777 auto dict = base::MakeUnique<base::DictionaryValue>(); 780 auto dict = base::MakeUnique<base::DictionaryValue>();
778 dict->SetString("username", "me@google.com"); 781 dict->SetString("username", "me@google.com");
779 dict->SetString("name", "me@google.com"); 782 dict->SetString("name", "me@google.com");
780 dict->SetString("email", ""); 783 dict->SetString("email", "");
781 dict->SetBoolean("owner", false); 784 dict->SetBoolean("owner", false);
782 list->Append(std::move(dict)); 785 list->Append(std::move(dict));
783 dict = base::MakeUnique<base::DictionaryValue>(); 786 dict = base::MakeUnique<base::DictionaryValue>();
784 dict->SetString("username", "you@google.com"); 787 dict->SetString("username", "you@google.com");
785 dict->SetString("name", "you@google.com"); 788 dict->SetString("name", "you@google.com");
786 dict->SetString("email", ""); 789 dict->SetString("email", "");
787 dict->SetBoolean("owner", false); 790 dict->SetBoolean("owner", false);
788 list->Append(std::move(dict)); 791 list->Append(std::move(dict));
789 decorated_non_default_values.push_back(list); 792 decorated_non_default_values.push_back(std::move(list));
790 793
791 chromeos::CrosSettings* cros_settings = chromeos::CrosSettings::Get(); 794 chromeos::CrosSettings* cros_settings = chromeos::CrosSettings::Get();
792 for (size_t i = 0; i < pref_names_.size(); ++i) { 795 for (size_t i = 0; i < pref_names_.size(); ++i) {
793 cros_settings->Set(pref_names_[i], *non_default_values_[i]); 796 cros_settings->Set(pref_names_[i], *non_default_values_[i]);
794 } 797 }
795 798
796 // Verify notifications when mandatory values are in effect. 799 // Verify notifications when mandatory values are in effect.
797 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); 800 SetupJavaScriptTestEnvironment(pref_names_, &observed_json);
798 VerifyObservedPrefs(observed_json, pref_names_, 801 VerifyObservedPrefs(observed_json, pref_names_, decorated_non_default_values,
799 decorated_non_default_values.get(),
800 "policy", true, false); 802 "policy", true, false);
801 } 803 }
802 804
803 // Verifies that initializing the JavaScript Preferences class fires the correct 805 // Verifies that initializing the JavaScript Preferences class fires the correct
804 // notifications in JavaScript for non-privileged pref values handled by the 806 // notifications in JavaScript for non-privileged pref values handled by the
805 // CoreChromeOSOptionsHandler class for a managed device. 807 // CoreChromeOSOptionsHandler class for a managed device.
806 IN_PROC_BROWSER_TEST_F(ManagedPreferencesBrowserTest, 808 IN_PROC_BROWSER_TEST_F(ManagedPreferencesBrowserTest,
807 ChromeOSDeviceFetchNonPrivilegedPrefs) { 809 ChromeOSDeviceFetchNonPrivilegedPrefs) {
808 ScopedVector<base::Value> decorated_non_default_values; 810 std::vector<std::unique_ptr<base::Value>> decorated_non_default_values;
809 std::string observed_json; 811 std::string observed_json;
810 812
811 // Non-privileged string pref. 813 // Non-privileged string pref.
812 pref_names_.push_back(chromeos::kSystemTimezone); 814 pref_names_.push_back(chromeos::kSystemTimezone);
813 non_default_values_.push_back(new base::StringValue("America/New_York")); 815 non_default_values_.push_back(
816 base::MakeUnique<base::StringValue>("America/New_York"));
814 decorated_non_default_values.push_back( 817 decorated_non_default_values.push_back(
815 non_default_values_.back()->DeepCopy()); 818 non_default_values_.back()->CreateDeepCopy());
816 819
817 // Verify notifications when mandatory values are in effect. 820 // Verify notifications when mandatory values are in effect.
818 chromeos::CrosSettings* cros_settings = chromeos::CrosSettings::Get(); 821 chromeos::CrosSettings* cros_settings = chromeos::CrosSettings::Get();
819 cros_settings->Set(pref_names_[0], *non_default_values_[0]); 822 cros_settings->Set(pref_names_[0], *non_default_values_[0]);
820 823
821 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); 824 SetupJavaScriptTestEnvironment(pref_names_, &observed_json);
822 VerifyObservedPrefs(observed_json, pref_names_, 825 VerifyObservedPrefs(observed_json, pref_names_, decorated_non_default_values,
823 decorated_non_default_values.get(),
824 std::string(), false, false); 826 std::string(), false, false);
825 } 827 }
826 828
827 namespace { 829 namespace {
828 830
829 const char* kUserProfilePath = "user_profile"; 831 const char* kUserProfilePath = "user_profile";
830 832
831 } // namespace 833 } // namespace
832 834
833 class ProxyPreferencesBrowserTest : public PreferencesBrowserTest { 835 class ProxyPreferencesBrowserTest : public PreferencesBrowserTest {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 type = "Integer"; 921 type = "Integer";
920 break; 922 break;
921 case base::Value::Type::STRING: 923 case base::Value::Type::STRING:
922 type = "String"; 924 type = "String";
923 break; 925 break;
924 default: 926 default:
925 ASSERT_TRUE(false); 927 ASSERT_TRUE(false);
926 } 928 }
927 929
928 std::string observed_json; 930 std::string observed_json;
929 SetPref(name, type, &value, true, &observed_json); 931 SetPref(name, type, value.CreateDeepCopy(), true, &observed_json);
930 } 932 }
931 933
932 void VerifyCurrentProxyServer(const std::string& expected_server, 934 void VerifyCurrentProxyServer(const std::string& expected_server,
933 onc::ONCSource expected_source) { 935 onc::ONCSource expected_source) {
934 const chromeos::NetworkState* network = GetDefaultNetwork(); 936 const chromeos::NetworkState* network = GetDefaultNetwork();
935 ASSERT_TRUE(network); 937 ASSERT_TRUE(network);
936 onc::ONCSource actual_source; 938 onc::ONCSource actual_source;
937 std::unique_ptr<ProxyConfigDictionary> proxy_dict = 939 std::unique_ptr<ProxyConfigDictionary> proxy_dict =
938 chromeos::proxy_config::GetProxyConfigForNetwork( 940 chromeos::proxy_config::GetProxyConfigForNetwork(
939 g_browser_process->local_state(), pref_service(), *network, 941 g_browser_process->local_state(), pref_service(), *network,
940 &actual_source); 942 &actual_source);
941 ASSERT_TRUE(proxy_dict); 943 ASSERT_TRUE(proxy_dict);
942 std::string actual_proxy_server; 944 std::string actual_proxy_server;
943 EXPECT_TRUE(proxy_dict->GetProxyServer(&actual_proxy_server)); 945 EXPECT_TRUE(proxy_dict->GetProxyServer(&actual_proxy_server));
944 EXPECT_EQ(expected_server, actual_proxy_server); 946 EXPECT_EQ(expected_server, actual_proxy_server);
945 EXPECT_EQ(expected_source, actual_source); 947 EXPECT_EQ(expected_source, actual_source);
946 } 948 }
947 }; 949 };
948 950
949 // Verifies that proxy settings are correctly pushed to JavaScript during 951 // Verifies that proxy settings are correctly pushed to JavaScript during
950 // initialization of the proxy settings page. 952 // initialization of the proxy settings page.
951 IN_PROC_BROWSER_TEST_F(ProxyPreferencesBrowserTest, ChromeOSInitializeProxy) { 953 IN_PROC_BROWSER_TEST_F(ProxyPreferencesBrowserTest, ChromeOSInitializeProxy) {
952 // Boolean pref. 954 // Boolean pref.
953 pref_names_.push_back(chromeos::proxy_cros_settings_parser::kProxySingle); 955 pref_names_.push_back(chromeos::proxy_cros_settings_parser::kProxySingle);
954 non_default_values_.push_back(new base::FundamentalValue(true)); 956 non_default_values_.push_back(base::MakeUnique<base::FundamentalValue>(true));
955 957
956 // Integer prefs. 958 // Integer prefs.
957 pref_names_.push_back( 959 pref_names_.push_back(
958 chromeos::proxy_cros_settings_parser::kProxySingleHttpPort); 960 chromeos::proxy_cros_settings_parser::kProxySingleHttpPort);
959 non_default_values_.push_back(new base::FundamentalValue(8080)); 961 non_default_values_.push_back(base::MakeUnique<base::FundamentalValue>(8080));
960 962
961 // String pref. 963 // String pref.
962 pref_names_.push_back(chromeos::proxy_cros_settings_parser::kProxySingleHttp); 964 pref_names_.push_back(chromeos::proxy_cros_settings_parser::kProxySingleHttp);
963 non_default_values_.push_back(new base::StringValue("127.0.0.1")); 965 non_default_values_.push_back(
966 base::MakeUnique<base::StringValue>("127.0.0.1"));
964 967
965 // List pref. 968 // List pref.
966 pref_names_.push_back(chromeos::proxy_cros_settings_parser::kProxyIgnoreList); 969 pref_names_.push_back(chromeos::proxy_cros_settings_parser::kProxyIgnoreList);
967 base::ListValue* list = new base::ListValue(); 970 std::unique_ptr<base::ListValue> list = base::MakeUnique<base::ListValue>();
968 list->AppendString("*.google.com"); 971 list->AppendString("*.google.com");
969 list->AppendString("1.2.3.4:22"); 972 list->AppendString("1.2.3.4:22");
970 non_default_values_.push_back(list); 973 non_default_values_.push_back(std::move(list));
971 974
972 // Verify that no policy is presented to the UI. This must be verified on the 975 // Verify that no policy is presented to the UI. This must be verified on the
973 // kProxyType and the kUseSharedProxies prefs. 976 // kProxyType and the kUseSharedProxies prefs.
974 pref_names_.push_back(chromeos::proxy_cros_settings_parser::kProxyType); 977 pref_names_.push_back(chromeos::proxy_cros_settings_parser::kProxyType);
975 non_default_values_.push_back(new base::FundamentalValue(2)); 978 non_default_values_.push_back(base::MakeUnique<base::FundamentalValue>(2));
976 979
977 pref_names_.push_back(proxy_config::prefs::kUseSharedProxies); 980 pref_names_.push_back(proxy_config::prefs::kUseSharedProxies);
978 non_default_values_.push_back(new base::FundamentalValue(false)); 981 non_default_values_.push_back(
982 base::MakeUnique<base::FundamentalValue>(false));
979 983
980 std::string observed_json; 984 std::string observed_json;
981 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); 985 SetupJavaScriptTestEnvironment(pref_names_, &observed_json);
982 VerifyObservedPrefs( 986 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_, "",
983 observed_json, pref_names_, non_default_values_.get(), "", false, false); 987 false, false);
984 } 988 }
985 989
986 IN_PROC_BROWSER_TEST_F(ProxyPreferencesBrowserTest, ONCPolicy) { 990 IN_PROC_BROWSER_TEST_F(ProxyPreferencesBrowserTest, ONCPolicy) {
987 SetONCPolicy(policy::key::kOpenNetworkConfiguration, 991 SetONCPolicy(policy::key::kOpenNetworkConfiguration,
988 policy::POLICY_SCOPE_USER); 992 policy::POLICY_SCOPE_USER);
989 993
990 // Verify that per-network policy is presented to the UI. This must be 994 // Verify that per-network policy is presented to the UI. This must be
991 // verified on the kProxyType. 995 // verified on the kProxyType.
992 pref_names_.push_back(chromeos::proxy_cros_settings_parser::kProxyType); 996 pref_names_.push_back(chromeos::proxy_cros_settings_parser::kProxyType);
993 non_default_values_.push_back(new base::FundamentalValue(3)); 997 non_default_values_.push_back(base::MakeUnique<base::FundamentalValue>(3));
994 998
995 std::string observed_json; 999 std::string observed_json;
996 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); 1000 SetupJavaScriptTestEnvironment(pref_names_, &observed_json);
997 VerifyObservedPrefs( 1001 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_, "policy",
998 observed_json, pref_names_, non_default_values_.get(), 1002 true, false);
999 "policy", true, false);
1000 1003
1001 // Verify that 'use-shared-proxies' is not affected by per-network policy. 1004 // Verify that 'use-shared-proxies' is not affected by per-network policy.
1002 pref_names_.clear(); 1005 pref_names_.clear();
1003 non_default_values_.clear(); 1006 non_default_values_.clear();
1004 pref_names_.push_back(proxy_config::prefs::kUseSharedProxies); 1007 pref_names_.push_back(proxy_config::prefs::kUseSharedProxies);
1005 non_default_values_.push_back(new base::FundamentalValue(false)); 1008 non_default_values_.push_back(
1009 base::MakeUnique<base::FundamentalValue>(false));
1006 1010
1007 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); 1011 SetupJavaScriptTestEnvironment(pref_names_, &observed_json);
1008 VerifyObservedPrefs( 1012 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_, "",
1009 observed_json, pref_names_, non_default_values_.get(), "", false, false); 1013 false, false);
1010 } 1014 }
1011 1015
1012 IN_PROC_BROWSER_TEST_F(ProxyPreferencesBrowserTest, DeviceONCPolicy) { 1016 IN_PROC_BROWSER_TEST_F(ProxyPreferencesBrowserTest, DeviceONCPolicy) {
1013 SetONCPolicy(policy::key::kDeviceOpenNetworkConfiguration, 1017 SetONCPolicy(policy::key::kDeviceOpenNetworkConfiguration,
1014 policy::POLICY_SCOPE_MACHINE); 1018 policy::POLICY_SCOPE_MACHINE);
1015 1019
1016 // Verify that the policy is presented to the UI. This verification must be 1020 // Verify that the policy is presented to the UI. This verification must be
1017 // done on the kProxyType pref. 1021 // done on the kProxyType pref.
1018 pref_names_.push_back(chromeos::proxy_cros_settings_parser::kProxyType); 1022 pref_names_.push_back(chromeos::proxy_cros_settings_parser::kProxyType);
1019 non_default_values_.push_back(new base::FundamentalValue(3)); 1023 non_default_values_.push_back(base::MakeUnique<base::FundamentalValue>(3));
1020 1024
1021 std::string observed_json; 1025 std::string observed_json;
1022 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); 1026 SetupJavaScriptTestEnvironment(pref_names_, &observed_json);
1023 VerifyObservedPrefs( 1027 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_, "policy",
1024 observed_json, pref_names_, non_default_values_.get(), 1028 true, false);
1025 "policy", true, false);
1026 1029
1027 // Verify that 'use-shared-proxies' is not affected by per-network policy. 1030 // Verify that 'use-shared-proxies' is not affected by per-network policy.
1028 pref_names_.clear(); 1031 pref_names_.clear();
1029 non_default_values_.clear(); 1032 non_default_values_.clear();
1030 pref_names_.push_back(proxy_config::prefs::kUseSharedProxies); 1033 pref_names_.push_back(proxy_config::prefs::kUseSharedProxies);
1031 non_default_values_.push_back(new base::FundamentalValue(false)); 1034 non_default_values_.push_back(
1035 base::MakeUnique<base::FundamentalValue>(false));
1032 1036
1033 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); 1037 SetupJavaScriptTestEnvironment(pref_names_, &observed_json);
1034 VerifyObservedPrefs( 1038 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_, "",
1035 observed_json, pref_names_, non_default_values_.get(), "", false, false); 1039 false, false);
1036 } 1040 }
1037 1041
1038 IN_PROC_BROWSER_TEST_F(ProxyPreferencesBrowserTest, UserProxyPolicy) { 1042 IN_PROC_BROWSER_TEST_F(ProxyPreferencesBrowserTest, UserProxyPolicy) {
1039 policy_names_.push_back(policy::key::kProxyMode); 1043 policy_names_.push_back(policy::key::kProxyMode);
1040 default_values_.push_back( 1044 default_values_.push_back(base::MakeUnique<base::StringValue>(
1041 new base::StringValue(ProxyPrefs::kAutoDetectProxyModeName)); 1045 ProxyPrefs::kAutoDetectProxyModeName));
1042 SetUserPolicies( 1046 SetUserPolicies(policy_names_, default_values_,
1043 policy_names_, default_values_.get(), policy::POLICY_LEVEL_MANDATORY); 1047 policy::POLICY_LEVEL_MANDATORY);
1044 content::RunAllPendingInMessageLoop(); 1048 content::RunAllPendingInMessageLoop();
1045 1049
1046 // Verify that the policy is presented to the UI. This verification must be 1050 // Verify that the policy is presented to the UI. This verification must be
1047 // done on the kProxyType pref. 1051 // done on the kProxyType pref.
1048 pref_names_.push_back(chromeos::proxy_cros_settings_parser::kProxyType); 1052 pref_names_.push_back(chromeos::proxy_cros_settings_parser::kProxyType);
1049 non_default_values_.push_back(new base::FundamentalValue(3)); 1053 non_default_values_.push_back(base::MakeUnique<base::FundamentalValue>(3));
1050 1054
1051 // Verify that 'use-shared-proxies' is controlled by the policy. 1055 // Verify that 'use-shared-proxies' is controlled by the policy.
1052 pref_names_.push_back(proxy_config::prefs::kUseSharedProxies); 1056 pref_names_.push_back(proxy_config::prefs::kUseSharedProxies);
1053 non_default_values_.push_back(new base::FundamentalValue(false)); 1057 non_default_values_.push_back(
1058 base::MakeUnique<base::FundamentalValue>(false));
1054 1059
1055 std::string observed_json; 1060 std::string observed_json;
1056 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); 1061 SetupJavaScriptTestEnvironment(pref_names_, &observed_json);
1057 VerifyObservedPrefs( 1062 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_, "policy",
1058 observed_json, pref_names_, non_default_values_.get(), 1063 true, false);
1059 "policy", true, false);
1060 } 1064 }
1061 1065
1062 // Verifies that modifications to the proxy settings are correctly pushed from 1066 // Verifies that modifications to the proxy settings are correctly pushed from
1063 // JavaScript to the ProxyConfig property stored in the network configuration. 1067 // JavaScript to the ProxyConfig property stored in the network configuration.
1064 IN_PROC_BROWSER_TEST_F(ProxyPreferencesBrowserTest, ChromeOSSetProxy) { 1068 IN_PROC_BROWSER_TEST_F(ProxyPreferencesBrowserTest, ChromeOSSetProxy) {
1065 ASSERT_NO_FATAL_FAILURE(SetupJavaScriptTestEnvironment(pref_names_, NULL)); 1069 ASSERT_NO_FATAL_FAILURE(SetupJavaScriptTestEnvironment(pref_names_, NULL));
1066 1070
1067 SetProxyPref(chromeos::proxy_cros_settings_parser::kProxySingleHttpPort, 1071 SetProxyPref(chromeos::proxy_cros_settings_parser::kProxySingleHttpPort,
1068 base::FundamentalValue(123)); 1072 base::FundamentalValue(123));
1069 SetProxyPref(chromeos::proxy_cros_settings_parser::kProxySingleHttp, 1073 SetProxyPref(chromeos::proxy_cros_settings_parser::kProxySingleHttp,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 base::FundamentalValue(3)); 1110 base::FundamentalValue(3));
1107 SetProxyPref(chromeos::proxy_cros_settings_parser::kProxySocksPort, 1111 SetProxyPref(chromeos::proxy_cros_settings_parser::kProxySocksPort,
1108 base::FundamentalValue(4)); 1112 base::FundamentalValue(4));
1109 1113
1110 VerifyCurrentProxyServer( 1114 VerifyCurrentProxyServer(
1111 "http=a.com:1;https=4.3.2.1:2;ftp=c.com:3;socks=socks4://d.com:4", 1115 "http=a.com:1;https=4.3.2.1:2;ftp=c.com:3;socks=socks4://d.com:4",
1112 onc::ONC_SOURCE_NONE); 1116 onc::ONC_SOURCE_NONE);
1113 } 1117 }
1114 1118
1115 #endif 1119 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698