OLD | NEW |
---|---|
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 <iostream> | 7 #include <iostream> |
8 #include <sstream> | 8 #include <sstream> |
9 | 9 |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 policy_provider_.UpdateChromePolicy(empty_policy_map); | 194 policy_provider_.UpdateChromePolicy(empty_policy_map); |
195 } | 195 } |
196 | 196 |
197 void PreferencesBrowserTest::SetUserValues( | 197 void PreferencesBrowserTest::SetUserValues( |
198 const std::vector<std::string>& names, | 198 const std::vector<std::string>& names, |
199 const std::vector<base::Value*>& values) { | 199 const std::vector<base::Value*>& values) { |
200 for (size_t i = 0; i < names.size(); ++i) | 200 for (size_t i = 0; i < names.size(); ++i) |
201 pref_service_->Set(names[i].c_str(), *values[i]); | 201 pref_service_->Set(names[i].c_str(), *values[i]); |
202 } | 202 } |
203 | 203 |
204 void PreferencesBrowserTest::VerifyKeyValue(const base::DictionaryValue* dict, | 204 void PreferencesBrowserTest::VerifyKeyValue(const base::DictionaryValue& dict, |
205 const std::string& key, | 205 const std::string& key, |
206 base::Value* expected) { | 206 const base::Value& expected) { |
207 const base::Value* actual = NULL; | 207 const base::Value* actual = NULL; |
208 EXPECT_TRUE(dict->Get(key, &actual)) << "Was checking key: " << key; | 208 EXPECT_TRUE(dict.Get(key, &actual)) << "Was checking key: " << key; |
209 EXPECT_EQ(*expected, *actual) << "Was checking key: " << key; | 209 EXPECT_EQ(expected, *actual) << "Was checking key: " << key; |
210 delete expected; | |
211 } | 210 } |
212 | 211 |
213 void PreferencesBrowserTest::VerifyPref(const base::DictionaryValue* prefs, | 212 void PreferencesBrowserTest::VerifyPref(const base::DictionaryValue* prefs, |
214 const std::string& name, | 213 const std::string& name, |
215 const base::Value* value, | 214 const base::Value* value, |
216 const std::string& controlledBy, | 215 const std::string& controlledBy, |
217 bool disabled, | 216 bool disabled, |
218 bool uncommitted) { | 217 bool uncommitted) { |
219 const base::Value* pref; | 218 const base::Value* pref; |
220 const base::DictionaryValue* dict; | 219 const base::DictionaryValue* dict; |
221 ASSERT_TRUE(prefs->GetWithoutPathExpansion(name, &pref)); | 220 ASSERT_TRUE(prefs->GetWithoutPathExpansion(name, &pref)); |
222 ASSERT_TRUE(pref->GetAsDictionary(&dict)); | 221 ASSERT_TRUE(pref->GetAsDictionary(&dict)); |
223 VerifyKeyValue(dict, "value", value->DeepCopy()); | 222 VerifyKeyValue(*dict, "value", *value); |
224 if (!controlledBy.empty()) { | 223 if (!controlledBy.empty()) { |
225 VerifyKeyValue(dict, "controlledBy", | 224 VerifyKeyValue(*dict, "controlledBy", base::StringValue(controlledBy)); |
226 base::Value::CreateStringValue(controlledBy)); | |
227 } else { | 225 } else { |
228 EXPECT_FALSE(dict->HasKey("controlledBy")); | 226 EXPECT_FALSE(dict->HasKey("controlledBy")); |
229 } | 227 } |
230 if (disabled) | 228 if (disabled) |
231 VerifyKeyValue(dict, "disabled", base::Value::CreateBooleanValue(true)); | 229 VerifyKeyValue(*dict, "disabled", base::FundamentalValue(true)); |
232 else if (dict->HasKey("disabled")) | 230 else if (dict->HasKey("disabled")) |
233 VerifyKeyValue(dict, "disabled", base::Value::CreateBooleanValue(false)); | 231 VerifyKeyValue(*dict, "disabled", base::FundamentalValue(false)); |
234 if (uncommitted) | 232 if (uncommitted) |
235 VerifyKeyValue(dict, "uncommitted", base::Value::CreateBooleanValue(true)); | 233 VerifyKeyValue(*dict, "uncommitted", base::FundamentalValue(true)); |
236 else if (dict->HasKey("uncommitted")) | 234 else if (dict->HasKey("uncommitted")) |
237 VerifyKeyValue(dict, "uncommitted", base::Value::CreateBooleanValue(false)); | 235 VerifyKeyValue(*dict, "uncommitted", base::FundamentalValue(false)); |
238 } | 236 } |
239 | 237 |
240 void PreferencesBrowserTest::VerifyObservedPref(const std::string& json, | 238 void PreferencesBrowserTest::VerifyObservedPref(const std::string& json, |
241 const std::string& name, | 239 const std::string& name, |
242 const base::Value* value, | 240 const base::Value* value, |
243 const std::string& controlledBy, | 241 const std::string& controlledBy, |
244 bool disabled, | 242 bool disabled, |
245 bool uncommitted) { | 243 bool uncommitted) { |
246 scoped_ptr<base::Value> observed_value_ptr(base::JSONReader::Read(json)); | 244 scoped_ptr<base::Value> observed_value_ptr(base::JSONReader::Read(json)); |
247 const base::DictionaryValue* observed_dict; | 245 const base::DictionaryValue* observed_dict; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
423 // Boolean pref. | 421 // Boolean pref. |
424 types_.push_back("Boolean"); | 422 types_.push_back("Boolean"); |
425 pref_names_.push_back(prefs::kAlternateErrorPagesEnabled); | 423 pref_names_.push_back(prefs::kAlternateErrorPagesEnabled); |
426 policy_names_.push_back(policy::key::kAlternateErrorPagesEnabled); | 424 policy_names_.push_back(policy::key::kAlternateErrorPagesEnabled); |
427 non_default_values_.push_back(base::Value::CreateBooleanValue(false)); | 425 non_default_values_.push_back(base::Value::CreateBooleanValue(false)); |
428 | 426 |
429 // Integer pref. | 427 // Integer pref. |
430 types_.push_back("Integer"); | 428 types_.push_back("Integer"); |
431 pref_names_.push_back(prefs::kRestoreOnStartup); | 429 pref_names_.push_back(prefs::kRestoreOnStartup); |
432 policy_names_.push_back(policy::key::kRestoreOnStartup); | 430 policy_names_.push_back(policy::key::kRestoreOnStartup); |
433 non_default_values_.push_back(base::Value::CreateIntegerValue(4)); | 431 non_default_values_.push_back(base::Value::CreateIntegerValue(4)); |
Evan Stade
2012/11/30 22:47:00
still many Create* functions here.
tfarina
2012/11/30 23:07:31
Done.
| |
434 | 432 |
435 // String pref. | 433 // String pref. |
436 types_.push_back("String"); | 434 types_.push_back("String"); |
437 pref_names_.push_back(prefs::kEnterpriseWebStoreName); | 435 pref_names_.push_back(prefs::kEnterpriseWebStoreName); |
438 policy_names_.push_back(policy::key::kEnterpriseWebStoreName); | 436 policy_names_.push_back(policy::key::kEnterpriseWebStoreName); |
439 non_default_values_.push_back(base::Value::CreateStringValue("Store")); | 437 non_default_values_.push_back(new base::StringValue("Store")); |
440 | 438 |
441 // URL pref. | 439 // URL pref. |
442 types_.push_back("URL"); | 440 types_.push_back("URL"); |
443 pref_names_.push_back(prefs::kEnterpriseWebStoreURL); | 441 pref_names_.push_back(prefs::kEnterpriseWebStoreURL); |
444 policy_names_.push_back(policy::key::kEnterpriseWebStoreURL); | 442 policy_names_.push_back(policy::key::kEnterpriseWebStoreURL); |
445 non_default_values_.push_back( | 443 non_default_values_.push_back( |
446 base::Value::CreateStringValue("http://www.google.com/")); | 444 new base::StringValue("http://www.google.com/")); |
447 | 445 |
448 // List pref. | 446 // List pref. |
449 if (includeListPref) { | 447 if (includeListPref) { |
450 types_.push_back("List"); | 448 types_.push_back("List"); |
451 pref_names_.push_back(prefs::kURLsToRestoreOnStartup); | 449 pref_names_.push_back(prefs::kURLsToRestoreOnStartup); |
452 policy_names_.push_back(policy::key::kRestoreOnStartupURLs); | 450 policy_names_.push_back(policy::key::kRestoreOnStartupURLs); |
453 base::ListValue* list = new base::ListValue; | 451 base::ListValue* list = new base::ListValue; |
454 list->Append(base::Value::CreateStringValue("http://www.google.com")); | 452 list->Append(new base::StringValue("http://www.google.com")); |
455 list->Append(base::Value::CreateStringValue("http://example.com")); | 453 list->Append(new base::StringValue("http://example.com")); |
456 non_default_values_.push_back(list); | 454 non_default_values_.push_back(list); |
457 } | 455 } |
458 | 456 |
459 // Retrieve default values. | 457 // Retrieve default values. |
460 for (std::vector<std::string>::const_iterator name = pref_names_.begin(); | 458 for (std::vector<std::string>::const_iterator name = pref_names_.begin(); |
461 name != pref_names_.end(); ++name) { | 459 name != pref_names_.end(); ++name) { |
462 default_values_.push_back( | 460 default_values_.push_back( |
463 pref_service_->GetDefaultPrefValue(name->c_str())->DeepCopy()); | 461 pref_service_->GetDefaultPrefValue(name->c_str())->DeepCopy()); |
464 } | 462 } |
465 } | 463 } |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
642 | 640 |
643 // Boolean pref. | 641 // Boolean pref. |
644 pref_names_.push_back(chromeos::kAccountsPrefAllowGuest); | 642 pref_names_.push_back(chromeos::kAccountsPrefAllowGuest); |
645 default_values_.push_back(base::Value::CreateBooleanValue(true)); | 643 default_values_.push_back(base::Value::CreateBooleanValue(true)); |
646 non_default_values_.push_back(base::Value::CreateBooleanValue(false)); | 644 non_default_values_.push_back(base::Value::CreateBooleanValue(false)); |
647 decorated_non_default_values.push_back( | 645 decorated_non_default_values.push_back( |
648 non_default_values_.back()->DeepCopy()); | 646 non_default_values_.back()->DeepCopy()); |
649 | 647 |
650 // String pref. | 648 // String pref. |
651 pref_names_.push_back(chromeos::kReleaseChannel); | 649 pref_names_.push_back(chromeos::kReleaseChannel); |
652 default_values_.push_back(base::Value::CreateStringValue("")); | 650 default_values_.push_back(new base::StringValue("")); |
653 non_default_values_.push_back( | 651 non_default_values_.push_back(new base::StringValue("stable-channel")); |
654 base::Value::CreateStringValue("stable-channel")); | |
655 decorated_non_default_values.push_back( | 652 decorated_non_default_values.push_back( |
656 non_default_values_.back()->DeepCopy()); | 653 non_default_values_.back()->DeepCopy()); |
657 | 654 |
658 // List pref. | 655 // List pref. |
659 pref_names_.push_back(chromeos::kAccountsPrefUsers); | 656 pref_names_.push_back(chromeos::kAccountsPrefUsers); |
660 default_values_.push_back(new base::ListValue); | 657 default_values_.push_back(new base::ListValue); |
661 base::ListValue* list = new base::ListValue; | 658 base::ListValue* list = new base::ListValue; |
662 list->Append(base::Value::CreateStringValue("me@google.com")); | 659 list->Append(new base::StringValue("me@google.com")); |
663 list->Append(base::Value::CreateStringValue("you@google.com")); | 660 list->Append(new base::StringValue("you@google.com")); |
664 non_default_values_.push_back(list); | 661 non_default_values_.push_back(list); |
665 list = new base::ListValue; | 662 list = new base::ListValue; |
666 base::DictionaryValue* dict = new base::DictionaryValue; | 663 base::DictionaryValue* dict = new base::DictionaryValue; |
667 dict->SetString("username", "me@google.com"); | 664 dict->SetString("username", "me@google.com"); |
668 dict->SetString("name", "me@google.com"); | 665 dict->SetString("name", "me@google.com"); |
669 dict->SetString("email", ""); | 666 dict->SetString("email", ""); |
670 dict->SetBoolean("owner", false); | 667 dict->SetBoolean("owner", false); |
671 list->Append(dict); | 668 list->Append(dict); |
672 dict = new base::DictionaryValue; | 669 dict = new base::DictionaryValue; |
673 dict->SetString("username", "you@google.com"); | 670 dict->SetString("username", "you@google.com"); |
(...skipping 28 matching lines...) Expand all Loading... | |
702 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, ChromeOSProxyFetchPrefs) { | 699 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, ChromeOSProxyFetchPrefs) { |
703 std::string observed_json; | 700 std::string observed_json; |
704 | 701 |
705 // Boolean pref. | 702 // Boolean pref. |
706 pref_names_.push_back(chromeos::kProxySingle); | 703 pref_names_.push_back(chromeos::kProxySingle); |
707 default_values_.push_back(base::Value::CreateBooleanValue(false)); | 704 default_values_.push_back(base::Value::CreateBooleanValue(false)); |
708 non_default_values_.push_back(base::Value::CreateBooleanValue(true)); | 705 non_default_values_.push_back(base::Value::CreateBooleanValue(true)); |
709 | 706 |
710 // Integer pref. | 707 // Integer pref. |
711 pref_names_.push_back(chromeos::kProxySingleHttpPort); | 708 pref_names_.push_back(chromeos::kProxySingleHttpPort); |
712 default_values_.push_back(base::Value::CreateStringValue("")); | 709 default_values_.push_back(new base::StringValue("")); |
713 non_default_values_.push_back(base::Value::CreateIntegerValue(8080)); | 710 non_default_values_.push_back(base::Value::CreateIntegerValue(8080)); |
714 | 711 |
715 // String pref. | 712 // String pref. |
716 pref_names_.push_back(chromeos::kProxySingleHttp); | 713 pref_names_.push_back(chromeos::kProxySingleHttp); |
717 default_values_.push_back(base::Value::CreateStringValue("")); | 714 default_values_.push_back(new base::StringValue("")); |
718 non_default_values_.push_back(base::Value::CreateStringValue("127.0.0.1")); | 715 non_default_values_.push_back(new base::StringValue("127.0.0.1")); |
719 | 716 |
720 // List pref. | 717 // List pref. |
721 pref_names_.push_back(chromeos::kProxyIgnoreList); | 718 pref_names_.push_back(chromeos::kProxyIgnoreList); |
722 default_values_.push_back(new base::ListValue()); | 719 default_values_.push_back(new base::ListValue()); |
723 base::ListValue* list = new base::ListValue(); | 720 base::ListValue* list = new base::ListValue(); |
724 list->Append(base::Value::CreateStringValue("www.google.com")); | 721 list->Append(new base::StringValue("www.google.com")); |
725 list->Append(base::Value::CreateStringValue("example.com")); | 722 list->Append(new base::StringValue("example.com")); |
726 non_default_values_.push_back(list); | 723 non_default_values_.push_back(list); |
727 | 724 |
728 // Verify notifications when default values are in effect. | 725 // Verify notifications when default values are in effect. |
729 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); | 726 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); |
730 VerifyObservedPrefs(observed_json, pref_names_, default_values_, | 727 VerifyObservedPrefs(observed_json, pref_names_, default_values_, |
731 "", false, false); | 728 "", false, false); |
732 | 729 |
733 // Verify notifications when user-modified values are in effect. | 730 // Verify notifications when user-modified values are in effect. |
734 Profile* profile = browser()->profile(); | 731 Profile* profile = browser()->profile(); |
735 // Do not set the Boolean pref. It will toogle automatically. | 732 // Do not set the Boolean pref. It will toogle automatically. |
736 for (size_t i = 1; i < pref_names_.size(); ++i) | 733 for (size_t i = 1; i < pref_names_.size(); ++i) |
737 chromeos::proxy_cros_settings_parser::SetProxyPrefValue( | 734 chromeos::proxy_cros_settings_parser::SetProxyPrefValue( |
738 profile, pref_names_[i], non_default_values_[i]->DeepCopy()); | 735 profile, pref_names_[i], non_default_values_[i]->DeepCopy()); |
739 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); | 736 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); |
740 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_, | 737 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_, |
741 "", false, false); | 738 "", false, false); |
742 } | 739 } |
743 | 740 |
744 #endif | 741 #endif |
OLD | NEW |