Chromium Code Reviews| 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 base::Value* expected) { |
|
Evan Stade
2012/11/30 20:15:56
both |expected| and |dict| should be const ref
tfarina
2012/11/30 22:41:08
Done.
| |
| 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; | 210 delete expected; |
| 211 } | 211 } |
| 212 | 212 |
| 213 void PreferencesBrowserTest::VerifyPref(const base::DictionaryValue* prefs, | 213 void PreferencesBrowserTest::VerifyPref(const base::DictionaryValue* prefs, |
| 214 const std::string& name, | 214 const std::string& name, |
| 215 const base::Value* value, | 215 const base::Value* value, |
| 216 const std::string& controlledBy, | 216 const std::string& controlledBy, |
| 217 bool disabled, | 217 bool disabled, |
| 218 bool uncommitted) { | 218 bool uncommitted) { |
| 219 const base::Value* pref; | 219 const base::Value* pref; |
| 220 const base::DictionaryValue* dict; | 220 const base::DictionaryValue* dict; |
| 221 ASSERT_TRUE(prefs->GetWithoutPathExpansion(name, &pref)); | 221 ASSERT_TRUE(prefs->GetWithoutPathExpansion(name, &pref)); |
| 222 ASSERT_TRUE(pref->GetAsDictionary(&dict)); | 222 ASSERT_TRUE(pref->GetAsDictionary(&dict)); |
| 223 VerifyKeyValue(dict, "value", value->DeepCopy()); | 223 VerifyKeyValue(dict, "value", value->DeepCopy()); |
| 224 if (!controlledBy.empty()) { | 224 if (!controlledBy.empty()) { |
| 225 VerifyKeyValue(dict, "controlledBy", | 225 VerifyKeyValue(dict, "controlledBy", new base::StringValue(controlledBy)); |
| 226 base::Value::CreateStringValue(controlledBy)); | |
| 227 } else { | 226 } else { |
| 228 EXPECT_FALSE(dict->HasKey("controlledBy")); | 227 EXPECT_FALSE(dict->HasKey("controlledBy")); |
| 229 } | 228 } |
| 230 if (disabled) | 229 if (disabled) |
| 231 VerifyKeyValue(dict, "disabled", base::Value::CreateBooleanValue(true)); | 230 VerifyKeyValue(dict, "disabled", base::Value::CreateBooleanValue(true)); |
| 232 else if (dict->HasKey("disabled")) | 231 else if (dict->HasKey("disabled")) |
| 233 VerifyKeyValue(dict, "disabled", base::Value::CreateBooleanValue(false)); | 232 VerifyKeyValue(dict, "disabled", base::Value::CreateBooleanValue(false)); |
| 234 if (uncommitted) | 233 if (uncommitted) |
| 235 VerifyKeyValue(dict, "uncommitted", base::Value::CreateBooleanValue(true)); | 234 VerifyKeyValue(dict, "uncommitted", base::Value::CreateBooleanValue(true)); |
| 236 else if (dict->HasKey("uncommitted")) | 235 else if (dict->HasKey("uncommitted")) |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 // Integer pref. | 428 // Integer pref. |
| 430 types_.push_back("Integer"); | 429 types_.push_back("Integer"); |
| 431 pref_names_.push_back(prefs::kRestoreOnStartup); | 430 pref_names_.push_back(prefs::kRestoreOnStartup); |
| 432 policy_names_.push_back(policy::key::kRestoreOnStartup); | 431 policy_names_.push_back(policy::key::kRestoreOnStartup); |
| 433 non_default_values_.push_back(base::Value::CreateIntegerValue(4)); | 432 non_default_values_.push_back(base::Value::CreateIntegerValue(4)); |
| 434 | 433 |
| 435 // String pref. | 434 // String pref. |
| 436 types_.push_back("String"); | 435 types_.push_back("String"); |
| 437 pref_names_.push_back(prefs::kEnterpriseWebStoreName); | 436 pref_names_.push_back(prefs::kEnterpriseWebStoreName); |
| 438 policy_names_.push_back(policy::key::kEnterpriseWebStoreName); | 437 policy_names_.push_back(policy::key::kEnterpriseWebStoreName); |
| 439 non_default_values_.push_back(base::Value::CreateStringValue("Store")); | 438 non_default_values_.push_back(new base::StringValue("Store")); |
| 440 | 439 |
| 441 // URL pref. | 440 // URL pref. |
| 442 types_.push_back("URL"); | 441 types_.push_back("URL"); |
| 443 pref_names_.push_back(prefs::kEnterpriseWebStoreURL); | 442 pref_names_.push_back(prefs::kEnterpriseWebStoreURL); |
| 444 policy_names_.push_back(policy::key::kEnterpriseWebStoreURL); | 443 policy_names_.push_back(policy::key::kEnterpriseWebStoreURL); |
| 445 non_default_values_.push_back( | 444 non_default_values_.push_back( |
| 446 base::Value::CreateStringValue("http://www.google.com/")); | 445 new base::StringValue("http://www.google.com/")); |
| 447 | 446 |
| 448 // List pref. | 447 // List pref. |
| 449 if (includeListPref) { | 448 if (includeListPref) { |
| 450 types_.push_back("List"); | 449 types_.push_back("List"); |
| 451 pref_names_.push_back(prefs::kURLsToRestoreOnStartup); | 450 pref_names_.push_back(prefs::kURLsToRestoreOnStartup); |
| 452 policy_names_.push_back(policy::key::kRestoreOnStartupURLs); | 451 policy_names_.push_back(policy::key::kRestoreOnStartupURLs); |
| 453 base::ListValue* list = new base::ListValue; | 452 base::ListValue* list = new base::ListValue; |
| 454 list->Append(base::Value::CreateStringValue("http://www.google.com")); | 453 list->Append(new base::StringValue("http://www.google.com")); |
| 455 list->Append(base::Value::CreateStringValue("http://example.com")); | 454 list->Append(new base::StringValue("http://example.com")); |
| 456 non_default_values_.push_back(list); | 455 non_default_values_.push_back(list); |
| 457 } | 456 } |
| 458 | 457 |
| 459 // Retrieve default values. | 458 // Retrieve default values. |
| 460 for (std::vector<std::string>::const_iterator name = pref_names_.begin(); | 459 for (std::vector<std::string>::const_iterator name = pref_names_.begin(); |
| 461 name != pref_names_.end(); ++name) { | 460 name != pref_names_.end(); ++name) { |
| 462 default_values_.push_back( | 461 default_values_.push_back( |
| 463 pref_service_->GetDefaultPrefValue(name->c_str())->DeepCopy()); | 462 pref_service_->GetDefaultPrefValue(name->c_str())->DeepCopy()); |
| 464 } | 463 } |
| 465 } | 464 } |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 642 | 641 |
| 643 // Boolean pref. | 642 // Boolean pref. |
| 644 pref_names_.push_back(chromeos::kAccountsPrefAllowGuest); | 643 pref_names_.push_back(chromeos::kAccountsPrefAllowGuest); |
| 645 default_values_.push_back(base::Value::CreateBooleanValue(true)); | 644 default_values_.push_back(base::Value::CreateBooleanValue(true)); |
| 646 non_default_values_.push_back(base::Value::CreateBooleanValue(false)); | 645 non_default_values_.push_back(base::Value::CreateBooleanValue(false)); |
| 647 decorated_non_default_values.push_back( | 646 decorated_non_default_values.push_back( |
| 648 non_default_values_.back()->DeepCopy()); | 647 non_default_values_.back()->DeepCopy()); |
| 649 | 648 |
| 650 // String pref. | 649 // String pref. |
| 651 pref_names_.push_back(chromeos::kReleaseChannel); | 650 pref_names_.push_back(chromeos::kReleaseChannel); |
| 652 default_values_.push_back(base::Value::CreateStringValue("")); | 651 default_values_.push_back(new base::StringValue("")); |
| 653 non_default_values_.push_back( | 652 non_default_values_.push_back(new base::StringValue("stable-channel")); |
| 654 base::Value::CreateStringValue("stable-channel")); | |
| 655 decorated_non_default_values.push_back( | 653 decorated_non_default_values.push_back( |
| 656 non_default_values_.back()->DeepCopy()); | 654 non_default_values_.back()->DeepCopy()); |
| 657 | 655 |
| 658 // List pref. | 656 // List pref. |
| 659 pref_names_.push_back(chromeos::kAccountsPrefUsers); | 657 pref_names_.push_back(chromeos::kAccountsPrefUsers); |
| 660 default_values_.push_back(new base::ListValue); | 658 default_values_.push_back(new base::ListValue); |
| 661 base::ListValue* list = new base::ListValue; | 659 base::ListValue* list = new base::ListValue; |
| 662 list->Append(base::Value::CreateStringValue("me@google.com")); | 660 list->Append(new base::StringValue("me@google.com")); |
| 663 list->Append(base::Value::CreateStringValue("you@google.com")); | 661 list->Append(new base::StringValue("you@google.com")); |
| 664 non_default_values_.push_back(list); | 662 non_default_values_.push_back(list); |
| 665 list = new base::ListValue; | 663 list = new base::ListValue; |
| 666 base::DictionaryValue* dict = new base::DictionaryValue; | 664 base::DictionaryValue* dict = new base::DictionaryValue; |
| 667 dict->SetString("username", "me@google.com"); | 665 dict->SetString("username", "me@google.com"); |
| 668 dict->SetString("name", "me@google.com"); | 666 dict->SetString("name", "me@google.com"); |
| 669 dict->SetString("email", ""); | 667 dict->SetString("email", ""); |
| 670 dict->SetBoolean("owner", false); | 668 dict->SetBoolean("owner", false); |
| 671 list->Append(dict); | 669 list->Append(dict); |
| 672 dict = new base::DictionaryValue; | 670 dict = new base::DictionaryValue; |
| 673 dict->SetString("username", "you@google.com"); | 671 dict->SetString("username", "you@google.com"); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 702 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, ChromeOSProxyFetchPrefs) { | 700 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, ChromeOSProxyFetchPrefs) { |
| 703 std::string observed_json; | 701 std::string observed_json; |
| 704 | 702 |
| 705 // Boolean pref. | 703 // Boolean pref. |
| 706 pref_names_.push_back(chromeos::kProxySingle); | 704 pref_names_.push_back(chromeos::kProxySingle); |
| 707 default_values_.push_back(base::Value::CreateBooleanValue(false)); | 705 default_values_.push_back(base::Value::CreateBooleanValue(false)); |
| 708 non_default_values_.push_back(base::Value::CreateBooleanValue(true)); | 706 non_default_values_.push_back(base::Value::CreateBooleanValue(true)); |
| 709 | 707 |
| 710 // Integer pref. | 708 // Integer pref. |
| 711 pref_names_.push_back(chromeos::kProxySingleHttpPort); | 709 pref_names_.push_back(chromeos::kProxySingleHttpPort); |
| 712 default_values_.push_back(base::Value::CreateStringValue("")); | 710 default_values_.push_back(new base::StringValue("")); |
| 713 non_default_values_.push_back(base::Value::CreateIntegerValue(8080)); | 711 non_default_values_.push_back(base::Value::CreateIntegerValue(8080)); |
| 714 | 712 |
| 715 // String pref. | 713 // String pref. |
| 716 pref_names_.push_back(chromeos::kProxySingleHttp); | 714 pref_names_.push_back(chromeos::kProxySingleHttp); |
| 717 default_values_.push_back(base::Value::CreateStringValue("")); | 715 default_values_.push_back(new base::StringValue("")); |
| 718 non_default_values_.push_back(base::Value::CreateStringValue("127.0.0.1")); | 716 non_default_values_.push_back(new base::StringValue("127.0.0.1")); |
| 719 | 717 |
| 720 // List pref. | 718 // List pref. |
| 721 pref_names_.push_back(chromeos::kProxyIgnoreList); | 719 pref_names_.push_back(chromeos::kProxyIgnoreList); |
| 722 default_values_.push_back(new base::ListValue()); | 720 default_values_.push_back(new base::ListValue()); |
| 723 base::ListValue* list = new base::ListValue(); | 721 base::ListValue* list = new base::ListValue(); |
| 724 list->Append(base::Value::CreateStringValue("www.google.com")); | 722 list->Append(new base::StringValue("www.google.com")); |
| 725 list->Append(base::Value::CreateStringValue("example.com")); | 723 list->Append(new base::StringValue("example.com")); |
| 726 non_default_values_.push_back(list); | 724 non_default_values_.push_back(list); |
| 727 | 725 |
| 728 // Verify notifications when default values are in effect. | 726 // Verify notifications when default values are in effect. |
| 729 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); | 727 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); |
| 730 VerifyObservedPrefs(observed_json, pref_names_, default_values_, | 728 VerifyObservedPrefs(observed_json, pref_names_, default_values_, |
| 731 "", false, false); | 729 "", false, false); |
| 732 | 730 |
| 733 // Verify notifications when user-modified values are in effect. | 731 // Verify notifications when user-modified values are in effect. |
| 734 Profile* profile = browser()->profile(); | 732 Profile* profile = browser()->profile(); |
| 735 // Do not set the Boolean pref. It will toogle automatically. | 733 // Do not set the Boolean pref. It will toogle automatically. |
| 736 for (size_t i = 1; i < pref_names_.size(); ++i) | 734 for (size_t i = 1; i < pref_names_.size(); ++i) |
| 737 chromeos::proxy_cros_settings_parser::SetProxyPrefValue( | 735 chromeos::proxy_cros_settings_parser::SetProxyPrefValue( |
| 738 profile, pref_names_[i], non_default_values_[i]->DeepCopy()); | 736 profile, pref_names_[i], non_default_values_[i]->DeepCopy()); |
| 739 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); | 737 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); |
| 740 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_, | 738 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_, |
| 741 "", false, false); | 739 "", false, false); |
| 742 } | 740 } |
| 743 | 741 |
| 744 #endif | 742 #endif |
| OLD | NEW |