| 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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 base::JSONWriter::Write(commit_ptr.get(), &commit_json); | 336 base::JSONWriter::Write(commit_ptr.get(), &commit_json); |
| 337 std::stringstream javascript; | 337 std::stringstream javascript; |
| 338 javascript << "testEnv.runAndReply(function() {" | 338 javascript << "testEnv.runAndReply(function() {" |
| 339 << " Preferences.set" << type.c_str() << "Pref(" | 339 << " Preferences.set" << type.c_str() << "Pref(" |
| 340 << " '" << name.c_str() << "'," | 340 << " '" << name.c_str() << "'," |
| 341 << " " << value_json.c_str() << "," | 341 << " " << value_json.c_str() << "," |
| 342 << " " << commit_json.c_str() << ");});"; | 342 << " " << commit_json.c_str() << ");});"; |
| 343 std::string observed_json; | 343 std::string observed_json; |
| 344 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | 344 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 345 render_view_host_, javascript.str(), &observed_json)); | 345 render_view_host_, javascript.str(), &observed_json)); |
| 346 VerifyObservedPref(observed_json, name, value, "", false, !commit); | 346 VerifyObservedPref(observed_json, name, value, std::string(), false, !commit); |
| 347 VerifyAndClearExpectations(); | 347 VerifyAndClearExpectations(); |
| 348 } | 348 } |
| 349 | 349 |
| 350 void PreferencesBrowserTest::VerifyClearPref(const std::string& name, | 350 void PreferencesBrowserTest::VerifyClearPref(const std::string& name, |
| 351 const base::Value* value, | 351 const base::Value* value, |
| 352 bool commit) { | 352 bool commit) { |
| 353 if (commit) | 353 if (commit) |
| 354 ExpectClearCommit(name); | 354 ExpectClearCommit(name); |
| 355 else | 355 else |
| 356 ExpectNoCommit(name); | 356 ExpectNoCommit(name); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 378 << " '" << name.c_str() << "');});"; | 378 << " '" << name.c_str() << "');});"; |
| 379 std::string observed_json; | 379 std::string observed_json; |
| 380 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | 380 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 381 render_view_host_, javascript.str(), &observed_json)); | 381 render_view_host_, javascript.str(), &observed_json)); |
| 382 VerifyObservedPref(observed_json, name, value, controlledBy, false, false); | 382 VerifyObservedPref(observed_json, name, value, controlledBy, false, false); |
| 383 } | 383 } |
| 384 | 384 |
| 385 void PreferencesBrowserTest::VerifySetCommit(const std::string& name, | 385 void PreferencesBrowserTest::VerifySetCommit(const std::string& name, |
| 386 const base::Value* value) { | 386 const base::Value* value) { |
| 387 ExpectSetCommit(name, value); | 387 ExpectSetCommit(name, value); |
| 388 VerifyCommit(name, value, ""); | 388 VerifyCommit(name, value, std::string()); |
| 389 VerifyAndClearExpectations(); | 389 VerifyAndClearExpectations(); |
| 390 } | 390 } |
| 391 | 391 |
| 392 void PreferencesBrowserTest::VerifyClearCommit(const std::string& name, | 392 void PreferencesBrowserTest::VerifyClearCommit(const std::string& name, |
| 393 const base::Value* value) { | 393 const base::Value* value) { |
| 394 ExpectClearCommit(name); | 394 ExpectClearCommit(name); |
| 395 VerifyCommit(name, value, "recommended"); | 395 VerifyCommit(name, value, "recommended"); |
| 396 VerifyAndClearExpectations(); | 396 VerifyAndClearExpectations(); |
| 397 } | 397 } |
| 398 | 398 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 } | 469 } |
| 470 | 470 |
| 471 // Verifies that initializing the JavaScript Preferences class fires the correct | 471 // Verifies that initializing the JavaScript Preferences class fires the correct |
| 472 // notifications in JavaScript. | 472 // notifications in JavaScript. |
| 473 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, FetchPrefs) { | 473 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, FetchPrefs) { |
| 474 UseDefaultTestPrefs(true); | 474 UseDefaultTestPrefs(true); |
| 475 std::string observed_json; | 475 std::string observed_json; |
| 476 | 476 |
| 477 // Verify notifications when default values are in effect. | 477 // Verify notifications when default values are in effect. |
| 478 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); | 478 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); |
| 479 VerifyObservedPrefs(observed_json, pref_names_, default_values_, | 479 VerifyObservedPrefs( |
| 480 "", false, false); | 480 observed_json, pref_names_, default_values_, std::string(), false, false); |
| 481 | 481 |
| 482 // Verify notifications when recommended values are in effect. | 482 // Verify notifications when recommended values are in effect. |
| 483 SetUserPolicies(policy_names_, non_default_values_, | 483 SetUserPolicies(policy_names_, non_default_values_, |
| 484 policy::POLICY_LEVEL_RECOMMENDED); | 484 policy::POLICY_LEVEL_RECOMMENDED); |
| 485 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); | 485 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); |
| 486 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_, | 486 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_, |
| 487 "recommended", false, false); | 487 "recommended", false, false); |
| 488 | 488 |
| 489 // Verify notifications when mandatory values are in effect. | 489 // Verify notifications when mandatory values are in effect. |
| 490 SetUserPolicies(policy_names_, non_default_values_, | 490 SetUserPolicies(policy_names_, non_default_values_, |
| 491 policy::POLICY_LEVEL_MANDATORY); | 491 policy::POLICY_LEVEL_MANDATORY); |
| 492 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); | 492 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); |
| 493 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_, | 493 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_, |
| 494 "policy", true, false); | 494 "policy", true, false); |
| 495 | 495 |
| 496 // Verify notifications when user-modified values are in effect. | 496 // Verify notifications when user-modified values are in effect. |
| 497 ClearUserPolicies(); | 497 ClearUserPolicies(); |
| 498 SetUserValues(pref_names_, non_default_values_); | 498 SetUserValues(pref_names_, non_default_values_); |
| 499 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); | 499 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); |
| 500 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_, | 500 VerifyObservedPrefs(observed_json, |
| 501 "", false, false); | 501 pref_names_, |
| 502 non_default_values_, |
| 503 std::string(), |
| 504 false, |
| 505 false); |
| 502 } | 506 } |
| 503 | 507 |
| 504 // Verifies that setting a user-modified pref value through the JavaScript | 508 // Verifies that setting a user-modified pref value through the JavaScript |
| 505 // Preferences class fires the correct notification in JavaScript and causes the | 509 // Preferences class fires the correct notification in JavaScript and causes the |
| 506 // change to be committed to the C++ backend. | 510 // change to be committed to the C++ backend. |
| 507 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, SetPrefs) { | 511 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, SetPrefs) { |
| 508 UseDefaultTestPrefs(false); | 512 UseDefaultTestPrefs(false); |
| 509 | 513 |
| 510 ASSERT_NO_FATAL_FAILURE(SetupJavaScriptTestEnvironment(pref_names_, NULL)); | 514 ASSERT_NO_FATAL_FAILURE(SetupJavaScriptTestEnvironment(pref_names_, NULL)); |
| 511 for (size_t i = 0; i < pref_names_.size(); ++i) | 515 for (size_t i = 0; i < pref_names_.size(); ++i) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 // Verifies that when the user-modified value of a dialog pref is set and the | 547 // Verifies that when the user-modified value of a dialog pref is set and the |
| 544 // change then rolled back through the JavaScript Preferences class, the correct | 548 // change then rolled back through the JavaScript Preferences class, the correct |
| 545 // notifications fire and no commit to the C++ backend occurs. | 549 // notifications fire and no commit to the C++ backend occurs. |
| 546 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, DialogPrefsSetRollback) { | 550 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, DialogPrefsSetRollback) { |
| 547 UseDefaultTestPrefs(false); | 551 UseDefaultTestPrefs(false); |
| 548 | 552 |
| 549 // Verify behavior when default values are in effect. | 553 // Verify behavior when default values are in effect. |
| 550 ASSERT_NO_FATAL_FAILURE(SetupJavaScriptTestEnvironment(pref_names_, NULL)); | 554 ASSERT_NO_FATAL_FAILURE(SetupJavaScriptTestEnvironment(pref_names_, NULL)); |
| 551 for (size_t i = 0; i < pref_names_.size(); ++i) { | 555 for (size_t i = 0; i < pref_names_.size(); ++i) { |
| 552 VerifySetPref(pref_names_[i], types_[i], non_default_values_[i], false); | 556 VerifySetPref(pref_names_[i], types_[i], non_default_values_[i], false); |
| 553 VerifyRollback(pref_names_[i], default_values_[i], ""); | 557 VerifyRollback(pref_names_[i], default_values_[i], std::string()); |
| 554 } | 558 } |
| 555 | 559 |
| 556 // Verify behavior when recommended values are in effect. | 560 // Verify behavior when recommended values are in effect. |
| 557 SetUserPolicies(policy_names_, default_values_, | 561 SetUserPolicies(policy_names_, default_values_, |
| 558 policy::POLICY_LEVEL_RECOMMENDED); | 562 policy::POLICY_LEVEL_RECOMMENDED); |
| 559 ASSERT_NO_FATAL_FAILURE(SetupJavaScriptTestEnvironment(pref_names_, NULL)); | 563 ASSERT_NO_FATAL_FAILURE(SetupJavaScriptTestEnvironment(pref_names_, NULL)); |
| 560 for (size_t i = 0; i < pref_names_.size(); ++i) { | 564 for (size_t i = 0; i < pref_names_.size(); ++i) { |
| 561 VerifySetPref(pref_names_[i], types_[i], non_default_values_[i], false); | 565 VerifySetPref(pref_names_[i], types_[i], non_default_values_[i], false); |
| 562 VerifyRollback(pref_names_[i], default_values_[i], "recommended"); | 566 VerifyRollback(pref_names_[i], default_values_[i], "recommended"); |
| 563 } | 567 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 585 // correct notifications fire and no commit to the C++ backend occurs. | 589 // correct notifications fire and no commit to the C++ backend occurs. |
| 586 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, DialogPrefsClearRollback) { | 590 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, DialogPrefsClearRollback) { |
| 587 UseDefaultTestPrefs(false); | 591 UseDefaultTestPrefs(false); |
| 588 | 592 |
| 589 SetUserPolicies(policy_names_, default_values_, | 593 SetUserPolicies(policy_names_, default_values_, |
| 590 policy::POLICY_LEVEL_RECOMMENDED); | 594 policy::POLICY_LEVEL_RECOMMENDED); |
| 591 SetUserValues(pref_names_, non_default_values_); | 595 SetUserValues(pref_names_, non_default_values_); |
| 592 ASSERT_NO_FATAL_FAILURE(SetupJavaScriptTestEnvironment(pref_names_, NULL)); | 596 ASSERT_NO_FATAL_FAILURE(SetupJavaScriptTestEnvironment(pref_names_, NULL)); |
| 593 for (size_t i = 0; i < pref_names_.size(); ++i) { | 597 for (size_t i = 0; i < pref_names_.size(); ++i) { |
| 594 VerifyClearPref(pref_names_[i], default_values_[i], false); | 598 VerifyClearPref(pref_names_[i], default_values_[i], false); |
| 595 VerifyRollback(pref_names_[i], non_default_values_[i], ""); | 599 VerifyRollback(pref_names_[i], non_default_values_[i], std::string()); |
| 596 } | 600 } |
| 597 } | 601 } |
| 598 | 602 |
| 599 // Verifies that when preference values change in the C++ backend, the correct | 603 // Verifies that when preference values change in the C++ backend, the correct |
| 600 // notifications fire in JavaScript. | 604 // notifications fire in JavaScript. |
| 601 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, NotificationsOnBackendChanges) { | 605 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, NotificationsOnBackendChanges) { |
| 602 UseDefaultTestPrefs(false); | 606 UseDefaultTestPrefs(false); |
| 603 std::string observed_json; | 607 std::string observed_json; |
| 604 | 608 |
| 605 ASSERT_NO_FATAL_FAILURE(SetupJavaScriptTestEnvironment(pref_names_, NULL)); | 609 ASSERT_NO_FATAL_FAILURE(SetupJavaScriptTestEnvironment(pref_names_, NULL)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 617 SetUserPolicies(policy_names_, non_default_values_, | 621 SetUserPolicies(policy_names_, non_default_values_, |
| 618 policy::POLICY_LEVEL_MANDATORY); | 622 policy::POLICY_LEVEL_MANDATORY); |
| 619 FinishObserving(&observed_json); | 623 FinishObserving(&observed_json); |
| 620 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_, | 624 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_, |
| 621 "policy", true, false); | 625 "policy", true, false); |
| 622 | 626 |
| 623 // Verify notifications when default values come into effect. | 627 // Verify notifications when default values come into effect. |
| 624 StartObserving(); | 628 StartObserving(); |
| 625 ClearUserPolicies(); | 629 ClearUserPolicies(); |
| 626 FinishObserving(&observed_json); | 630 FinishObserving(&observed_json); |
| 627 VerifyObservedPrefs(observed_json, pref_names_, default_values_, | 631 VerifyObservedPrefs( |
| 628 "", false, false); | 632 observed_json, pref_names_, default_values_, std::string(), false, false); |
| 629 | 633 |
| 630 // Verify notifications when user-modified values come into effect. | 634 // Verify notifications when user-modified values come into effect. |
| 631 StartObserving(); | 635 StartObserving(); |
| 632 SetUserValues(pref_names_, non_default_values_); | 636 SetUserValues(pref_names_, non_default_values_); |
| 633 FinishObserving(&observed_json); | 637 FinishObserving(&observed_json); |
| 634 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_, | 638 VerifyObservedPrefs(observed_json, |
| 635 "", false, false); | 639 pref_names_, |
| 640 non_default_values_, |
| 641 std::string(), |
| 642 false, |
| 643 false); |
| 636 } | 644 } |
| 637 | 645 |
| 638 #if defined(OS_CHROMEOS) | 646 #if defined(OS_CHROMEOS) |
| 639 | 647 |
| 640 // Verifies that initializing the JavaScript Preferences class fires the correct | 648 // Verifies that initializing the JavaScript Preferences class fires the correct |
| 641 // notifications in JavaScript for pref values handled by the | 649 // notifications in JavaScript for pref values handled by the |
| 642 // CoreChromeOSOptionsHandler class. | 650 // CoreChromeOSOptionsHandler class. |
| 643 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, ChromeOSDeviceFetchPrefs) { | 651 IN_PROC_BROWSER_TEST_F(PreferencesBrowserTest, ChromeOSDeviceFetchPrefs) { |
| 644 std::vector<base::Value*> decorated_non_default_values; | 652 std::vector<base::Value*> decorated_non_default_values; |
| 645 std::string observed_json; | 653 std::string observed_json; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 // Do not set the Boolean pref. It will toogle automatically. | 746 // Do not set the Boolean pref. It will toogle automatically. |
| 739 for (size_t i = 1; i < pref_names_.size(); ++i) | 747 for (size_t i = 1; i < pref_names_.size(); ++i) |
| 740 chromeos::proxy_cros_settings_parser::SetProxyPrefValue( | 748 chromeos::proxy_cros_settings_parser::SetProxyPrefValue( |
| 741 profile, pref_names_[i], non_default_values_[i]->DeepCopy()); | 749 profile, pref_names_[i], non_default_values_[i]->DeepCopy()); |
| 742 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); | 750 SetupJavaScriptTestEnvironment(pref_names_, &observed_json); |
| 743 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_, | 751 VerifyObservedPrefs(observed_json, pref_names_, non_default_values_, |
| 744 "", false, false); | 752 "", false, false); |
| 745 } | 753 } |
| 746 | 754 |
| 747 #endif | 755 #endif |
| OLD | NEW |