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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 } | 317 } |
320 | 318 |
321 void PreferencesBrowserTest::VerifySetPref(const std::string& name, | 319 void PreferencesBrowserTest::VerifySetPref(const std::string& name, |
322 const std::string& type, | 320 const std::string& type, |
323 const base::Value* value, | 321 const base::Value* value, |
324 bool commit) { | 322 bool commit) { |
325 if (commit) | 323 if (commit) |
326 ExpectSetCommit(name, value); | 324 ExpectSetCommit(name, value); |
327 else | 325 else |
328 ExpectNoCommit(name); | 326 ExpectNoCommit(name); |
329 scoped_ptr<base::Value> commit_ptr(base::Value::CreateBooleanValue(commit)); | 327 scoped_ptr<base::Value> commit_ptr(new base::FundamentalValue(commit)); |
330 std::string value_json; | 328 std::string value_json; |
331 std::string commit_json; | 329 std::string commit_json; |
332 base::JSONWriter::Write(value, &value_json); | 330 base::JSONWriter::Write(value, &value_json); |
333 base::JSONWriter::Write(commit_ptr.get(), &commit_json); | 331 base::JSONWriter::Write(commit_ptr.get(), &commit_json); |
334 std::wstringstream javascript; | 332 std::wstringstream javascript; |
335 javascript << "testEnv.runAndReply(function() {" | 333 javascript << "testEnv.runAndReply(function() {" |
336 << " Preferences.set" << type.c_str() << "Pref(" | 334 << " Preferences.set" << type.c_str() << "Pref(" |
337 << " '" << name.c_str() << "'," | 335 << " '" << name.c_str() << "'," |
338 << " " << value_json.c_str() << "," | 336 << " " << value_json.c_str() << "," |
339 << " " << commit_json.c_str() << ");});"; | 337 << " " << commit_json.c_str() << ");});"; |
340 std::string observed_json; | 338 std::string observed_json; |
341 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( | 339 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( |
342 render_view_host_, L"", javascript.str(), &observed_json)); | 340 render_view_host_, L"", javascript.str(), &observed_json)); |
343 VerifyObservedPref(observed_json, name, value, "", false, !commit); | 341 VerifyObservedPref(observed_json, name, value, "", false, !commit); |
344 VerifyAndClearExpectations(); | 342 VerifyAndClearExpectations(); |
345 } | 343 } |
346 | 344 |
347 void PreferencesBrowserTest::VerifyClearPref(const std::string& name, | 345 void PreferencesBrowserTest::VerifyClearPref(const std::string& name, |
348 const base::Value* value, | 346 const base::Value* value, |
349 bool commit) { | 347 bool commit) { |
350 if (commit) | 348 if (commit) |
351 ExpectClearCommit(name); | 349 ExpectClearCommit(name); |
352 else | 350 else |
353 ExpectNoCommit(name); | 351 ExpectNoCommit(name); |
354 scoped_ptr<base::Value> commit_ptr(base::Value::CreateBooleanValue(commit)); | 352 scoped_ptr<base::Value> commit_ptr(new base::FundamentalValue(commit)); |
355 std::string commit_json; | 353 std::string commit_json; |
356 base::JSONWriter::Write(commit_ptr.get(), &commit_json); | 354 base::JSONWriter::Write(commit_ptr.get(), &commit_json); |
357 std::wstringstream javascript; | 355 std::wstringstream javascript; |
358 javascript << "testEnv.runAndReply(function() {" | 356 javascript << "testEnv.runAndReply(function() {" |
359 << " Preferences.clearPref(" | 357 << " Preferences.clearPref(" |
360 << " '" << name.c_str() << "'," | 358 << " '" << name.c_str() << "'," |
361 << " " << commit_json.c_str() << ");});"; | 359 << " " << commit_json.c_str() << ");});"; |
362 std::string observed_json; | 360 std::string observed_json; |
363 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( | 361 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( |
364 render_view_host_, L"", javascript.str(), &observed_json)); | 362 render_view_host_, L"", javascript.str(), &observed_json)); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( | 415 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( |
418 render_view_host_, L"", L"testEnv.finishObservingAndReply();", | 416 render_view_host_, L"", L"testEnv.finishObservingAndReply();", |
419 observed_json)); | 417 observed_json)); |
420 } | 418 } |
421 | 419 |
422 void PreferencesBrowserTest::UseDefaultTestPrefs(bool includeListPref) { | 420 void PreferencesBrowserTest::UseDefaultTestPrefs(bool includeListPref) { |
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(new base::FundamentalValue(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(new base::FundamentalValue(4)); |
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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 | 633 |
636 // Verifies that initializing the JavaScript Preferences class fires the correct | 634 // Verifies that initializing the JavaScript Preferences class fires the correct |
637 // notifications in JavaScript for pref values handled by the | 635 // notifications in JavaScript for pref values handled by the |
638 // CoreChromeOSOptionsHandler class. | 636 // CoreChromeOSOptionsHandler class. |
639 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, ChromeOSDeviceFetchPrefs) { | 637 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, ChromeOSDeviceFetchPrefs) { |
640 std::vector<base::Value*> decorated_non_default_values; | 638 std::vector<base::Value*> decorated_non_default_values; |
641 std::string observed_json; | 639 std::string observed_json; |
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(new base::FundamentalValue(true)); |
646 non_default_values_.push_back(base::Value::CreateBooleanValue(false)); | 644 non_default_values_.push_back(new base::FundamentalValue(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 23 matching lines...) Expand all Loading... |
697 } | 694 } |
698 | 695 |
699 // Verifies that initializing the JavaScript Preferences class fires the correct | 696 // Verifies that initializing the JavaScript Preferences class fires the correct |
700 // notifications in JavaScript for pref values handled by the Chrome OS proxy | 697 // notifications in JavaScript for pref values handled by the Chrome OS proxy |
701 // settings parser. | 698 // settings parser. |
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(new base::FundamentalValue(false)); |
708 non_default_values_.push_back(base::Value::CreateBooleanValue(true)); | 705 non_default_values_.push_back(new base::FundamentalValue(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(new base::FundamentalValue(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 |