| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/prefs/pref_store_observer_mock.h" | 9 #include "base/prefs/pref_store_observer_mock.h" |
| 10 #include "chrome/browser/policy/configuration_policy_handler.h" | 10 #include "chrome/browser/policy/configuration_policy_handler.h" |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 default_alternate_urls_.AppendString( | 560 default_alternate_urls_.AppendString( |
| 561 "http://www.google.com/search#q={searchTerms}"); | 561 "http://www.google.com/search#q={searchTerms}"); |
| 562 } | 562 } |
| 563 | 563 |
| 564 protected: | 564 protected: |
| 565 static const char* const kSearchURL; | 565 static const char* const kSearchURL; |
| 566 static const char* const kSuggestURL; | 566 static const char* const kSuggestURL; |
| 567 static const char* const kIconURL; | 567 static const char* const kIconURL; |
| 568 static const char* const kName; | 568 static const char* const kName; |
| 569 static const char* const kKeyword; | 569 static const char* const kKeyword; |
| 570 static const char* const kReplacementKey; |
| 570 | 571 |
| 571 // Build a default search policy by setting search-related keys in |policy| to | 572 // Build a default search policy by setting search-related keys in |policy| to |
| 572 // reasonable values. You can update any of the keys after calling this | 573 // reasonable values. You can update any of the keys after calling this |
| 573 // method. | 574 // method. |
| 574 void BuildDefaultSearchPolicy(PolicyMap* policy); | 575 void BuildDefaultSearchPolicy(PolicyMap* policy); |
| 575 | 576 |
| 576 base::ListValue default_alternate_urls_; | 577 base::ListValue default_alternate_urls_; |
| 577 }; | 578 }; |
| 578 | 579 |
| 579 const char* const ConfigurationPolicyPrefStoreDefaultSearchTest::kSearchURL = | 580 const char* const ConfigurationPolicyPrefStoreDefaultSearchTest::kSearchURL = |
| 580 "http://test.com/search?t={searchTerms}"; | 581 "http://test.com/search?t={searchTerms}"; |
| 581 const char* const ConfigurationPolicyPrefStoreDefaultSearchTest::kSuggestURL = | 582 const char* const ConfigurationPolicyPrefStoreDefaultSearchTest::kSuggestURL = |
| 582 "http://test.com/sugg?={searchTerms}"; | 583 "http://test.com/sugg?={searchTerms}"; |
| 583 const char* const ConfigurationPolicyPrefStoreDefaultSearchTest::kIconURL = | 584 const char* const ConfigurationPolicyPrefStoreDefaultSearchTest::kIconURL = |
| 584 "http://test.com/icon.jpg"; | 585 "http://test.com/icon.jpg"; |
| 585 const char* const ConfigurationPolicyPrefStoreDefaultSearchTest::kName = | 586 const char* const ConfigurationPolicyPrefStoreDefaultSearchTest::kName = |
| 586 "MyName"; | 587 "MyName"; |
| 587 const char* const ConfigurationPolicyPrefStoreDefaultSearchTest::kKeyword = | 588 const char* const ConfigurationPolicyPrefStoreDefaultSearchTest::kKeyword = |
| 588 "MyKeyword"; | 589 "MyKeyword"; |
| 590 const char* const |
| 591 ConfigurationPolicyPrefStoreDefaultSearchTest::kReplacementKey = "espv"; |
| 589 | 592 |
| 590 void ConfigurationPolicyPrefStoreDefaultSearchTest:: | 593 void ConfigurationPolicyPrefStoreDefaultSearchTest:: |
| 591 BuildDefaultSearchPolicy(PolicyMap* policy) { | 594 BuildDefaultSearchPolicy(PolicyMap* policy) { |
| 592 base::ListValue* encodings = new base::ListValue(); | 595 base::ListValue* encodings = new base::ListValue(); |
| 593 encodings->AppendString("UTF-16"); | 596 encodings->AppendString("UTF-16"); |
| 594 encodings->AppendString("UTF-8"); | 597 encodings->AppendString("UTF-8"); |
| 595 policy->Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY, | 598 policy->Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY, |
| 596 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); | 599 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); |
| 597 policy->Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, | 600 policy->Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, |
| 598 POLICY_SCOPE_USER, base::Value::CreateStringValue(kSearchURL)); | 601 POLICY_SCOPE_USER, base::Value::CreateStringValue(kSearchURL)); |
| 599 policy->Set(key::kDefaultSearchProviderName, POLICY_LEVEL_MANDATORY, | 602 policy->Set(key::kDefaultSearchProviderName, POLICY_LEVEL_MANDATORY, |
| 600 POLICY_SCOPE_USER, base::Value::CreateStringValue(kName)); | 603 POLICY_SCOPE_USER, base::Value::CreateStringValue(kName)); |
| 601 policy->Set(key::kDefaultSearchProviderKeyword, POLICY_LEVEL_MANDATORY, | 604 policy->Set(key::kDefaultSearchProviderKeyword, POLICY_LEVEL_MANDATORY, |
| 602 POLICY_SCOPE_USER, base::Value::CreateStringValue(kKeyword)); | 605 POLICY_SCOPE_USER, base::Value::CreateStringValue(kKeyword)); |
| 603 policy->Set(key::kDefaultSearchProviderSuggestURL, POLICY_LEVEL_MANDATORY, | 606 policy->Set(key::kDefaultSearchProviderSuggestURL, POLICY_LEVEL_MANDATORY, |
| 604 POLICY_SCOPE_USER, base::Value::CreateStringValue(kSuggestURL)); | 607 POLICY_SCOPE_USER, base::Value::CreateStringValue(kSuggestURL)); |
| 605 policy->Set(key::kDefaultSearchProviderIconURL, POLICY_LEVEL_MANDATORY, | 608 policy->Set(key::kDefaultSearchProviderIconURL, POLICY_LEVEL_MANDATORY, |
| 606 POLICY_SCOPE_USER, base::Value::CreateStringValue(kIconURL)); | 609 POLICY_SCOPE_USER, base::Value::CreateStringValue(kIconURL)); |
| 607 policy->Set(key::kDefaultSearchProviderEncodings, POLICY_LEVEL_MANDATORY, | 610 policy->Set(key::kDefaultSearchProviderEncodings, POLICY_LEVEL_MANDATORY, |
| 608 POLICY_SCOPE_USER, encodings); | 611 POLICY_SCOPE_USER, encodings); |
| 609 policy->Set(key::kDefaultSearchProviderAlternateURLs, POLICY_LEVEL_MANDATORY, | 612 policy->Set(key::kDefaultSearchProviderAlternateURLs, POLICY_LEVEL_MANDATORY, |
| 610 POLICY_SCOPE_USER, default_alternate_urls_.DeepCopy()); | 613 POLICY_SCOPE_USER, default_alternate_urls_.DeepCopy()); |
| 614 policy->Set(key::kDefaultSearchProviderSearchTermsReplacementKey, |
| 615 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 616 base::Value::CreateStringValue(kReplacementKey)); |
| 611 } | 617 } |
| 612 | 618 |
| 613 // Checks that if the policy for default search is valid, i.e. there's a | 619 // Checks that if the policy for default search is valid, i.e. there's a |
| 614 // search URL, that all the elements have been given proper defaults. | 620 // search URL, that all the elements have been given proper defaults. |
| 615 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, MinimallyDefined) { | 621 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, MinimallyDefined) { |
| 616 PolicyMap policy; | 622 PolicyMap policy; |
| 617 policy.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY, | 623 policy.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY, |
| 618 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); | 624 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); |
| 619 policy.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, | 625 policy.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, |
| 620 POLICY_SCOPE_USER, base::Value::CreateStringValue(kSearchURL)); | 626 POLICY_SCOPE_USER, base::Value::CreateStringValue(kSearchURL)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 640 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderEncodings, &value)); | 646 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderEncodings, &value)); |
| 641 EXPECT_TRUE(base::StringValue(std::string()).Equals(value)); | 647 EXPECT_TRUE(base::StringValue(std::string()).Equals(value)); |
| 642 | 648 |
| 643 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderInstantURL, | 649 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderInstantURL, |
| 644 &value)); | 650 &value)); |
| 645 EXPECT_TRUE(base::StringValue(std::string()).Equals(value)); | 651 EXPECT_TRUE(base::StringValue(std::string()).Equals(value)); |
| 646 | 652 |
| 647 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderAlternateURLs, | 653 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderAlternateURLs, |
| 648 &value)); | 654 &value)); |
| 649 EXPECT_TRUE(base::ListValue().Equals(value)); | 655 EXPECT_TRUE(base::ListValue().Equals(value)); |
| 656 |
| 657 EXPECT_TRUE( |
| 658 store_->GetValue(prefs::kDefaultSearchProviderSearchTermsReplacementKey, |
| 659 &value)); |
| 660 EXPECT_TRUE(base::StringValue(std::string()).Equals(value)); |
| 650 } | 661 } |
| 651 | 662 |
| 652 // Checks that for a fully defined search policy, all elements have been | 663 // Checks that for a fully defined search policy, all elements have been |
| 653 // read properly. | 664 // read properly. |
| 654 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, FullyDefined) { | 665 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, FullyDefined) { |
| 655 PolicyMap policy; | 666 PolicyMap policy; |
| 656 BuildDefaultSearchPolicy(&policy); | 667 BuildDefaultSearchPolicy(&policy); |
| 657 provider_.UpdateChromePolicy(policy); | 668 provider_.UpdateChromePolicy(policy); |
| 658 | 669 |
| 659 const base::Value* value = NULL; | 670 const base::Value* value = NULL; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 672 | 683 |
| 673 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderIconURL, &value)); | 684 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderIconURL, &value)); |
| 674 EXPECT_TRUE(base::StringValue(kIconURL).Equals(value)); | 685 EXPECT_TRUE(base::StringValue(kIconURL).Equals(value)); |
| 675 | 686 |
| 676 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderEncodings, &value)); | 687 EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderEncodings, &value)); |
| 677 EXPECT_TRUE(base::StringValue("UTF-16;UTF-8").Equals(value)); | 688 EXPECT_TRUE(base::StringValue("UTF-16;UTF-8").Equals(value)); |
| 678 | 689 |
| 679 EXPECT_TRUE(store_->GetValue( | 690 EXPECT_TRUE(store_->GetValue( |
| 680 prefs::kDefaultSearchProviderAlternateURLs, &value)); | 691 prefs::kDefaultSearchProviderAlternateURLs, &value)); |
| 681 EXPECT_TRUE(default_alternate_urls_.Equals(value)); | 692 EXPECT_TRUE(default_alternate_urls_.Equals(value)); |
| 693 |
| 694 EXPECT_TRUE( |
| 695 store_->GetValue(prefs::kDefaultSearchProviderSearchTermsReplacementKey, |
| 696 &value)); |
| 697 EXPECT_TRUE(base::StringValue(kReplacementKey).Equals(value)); |
| 682 } | 698 } |
| 683 | 699 |
| 684 // Checks that if the default search policy is missing, that no elements of the | 700 // Checks that if the default search policy is missing, that no elements of the |
| 685 // default search policy will be present. | 701 // default search policy will be present. |
| 686 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, MissingUrl) { | 702 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, MissingUrl) { |
| 687 PolicyMap policy; | 703 PolicyMap policy; |
| 688 BuildDefaultSearchPolicy(&policy); | 704 BuildDefaultSearchPolicy(&policy); |
| 689 policy.Erase(key::kDefaultSearchProviderSearchURL); | 705 policy.Erase(key::kDefaultSearchProviderSearchURL); |
| 690 provider_.UpdateChromePolicy(policy); | 706 provider_.UpdateChromePolicy(policy); |
| 691 | 707 |
| 692 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderSearchURL, NULL)); | 708 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderSearchURL, NULL)); |
| 693 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderName, NULL)); | 709 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderName, NULL)); |
| 694 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderKeyword, NULL)); | 710 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderKeyword, NULL)); |
| 695 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderSuggestURL, NULL)); | 711 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderSuggestURL, NULL)); |
| 696 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderIconURL, NULL)); | 712 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderIconURL, NULL)); |
| 697 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderEncodings, NULL)); | 713 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderEncodings, NULL)); |
| 698 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderAlternateURLs, | 714 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderAlternateURLs, |
| 699 NULL)); | 715 NULL)); |
| 716 EXPECT_FALSE(store_->GetValue( |
| 717 prefs::kDefaultSearchProviderSearchTermsReplacementKey, NULL)); |
| 700 } | 718 } |
| 701 | 719 |
| 702 // Checks that if the default search policy is invalid, that no elements of the | 720 // Checks that if the default search policy is invalid, that no elements of the |
| 703 // default search policy will be present. | 721 // default search policy will be present. |
| 704 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, Invalid) { | 722 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, Invalid) { |
| 705 PolicyMap policy; | 723 PolicyMap policy; |
| 706 BuildDefaultSearchPolicy(&policy); | 724 BuildDefaultSearchPolicy(&policy); |
| 707 const char* const bad_search_url = "http://test.com/noSearchTerms"; | 725 const char* const bad_search_url = "http://test.com/noSearchTerms"; |
| 708 policy.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, | 726 policy.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, |
| 709 POLICY_SCOPE_USER, | 727 POLICY_SCOPE_USER, |
| 710 base::Value::CreateStringValue(bad_search_url)); | 728 base::Value::CreateStringValue(bad_search_url)); |
| 711 provider_.UpdateChromePolicy(policy); | 729 provider_.UpdateChromePolicy(policy); |
| 712 | 730 |
| 713 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderSearchURL, NULL)); | 731 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderSearchURL, NULL)); |
| 714 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderName, NULL)); | 732 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderName, NULL)); |
| 715 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderKeyword, NULL)); | 733 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderKeyword, NULL)); |
| 716 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderSuggestURL, NULL)); | 734 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderSuggestURL, NULL)); |
| 717 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderIconURL, NULL)); | 735 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderIconURL, NULL)); |
| 718 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderEncodings, NULL)); | 736 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderEncodings, NULL)); |
| 719 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderAlternateURLs, | 737 EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderAlternateURLs, |
| 720 NULL)); | 738 NULL)); |
| 739 EXPECT_FALSE(store_->GetValue( |
| 740 prefs::kDefaultSearchProviderSearchTermsReplacementKey, NULL)); |
| 721 } | 741 } |
| 722 | 742 |
| 723 // Checks that if the default search policy is invalid, that no elements of the | 743 // Checks that if the default search policy is invalid, that no elements of the |
| 724 // default search policy will be present. | 744 // default search policy will be present. |
| 725 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, Disabled) { | 745 TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, Disabled) { |
| 726 PolicyMap policy; | 746 PolicyMap policy; |
| 727 policy.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY, | 747 policy.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY, |
| 728 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false)); | 748 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false)); |
| 729 provider_.UpdateChromePolicy(policy); | 749 provider_.UpdateChromePolicy(policy); |
| 730 | 750 |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1040 policy.Set(key::kDefaultJavaScriptSetting, POLICY_LEVEL_MANDATORY, | 1060 policy.Set(key::kDefaultJavaScriptSetting, POLICY_LEVEL_MANDATORY, |
| 1041 POLICY_SCOPE_USER, | 1061 POLICY_SCOPE_USER, |
| 1042 base::Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); | 1062 base::Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); |
| 1043 provider_.UpdateChromePolicy(policy); | 1063 provider_.UpdateChromePolicy(policy); |
| 1044 EXPECT_TRUE(store_->GetValue(prefs::kManagedDefaultJavaScriptSetting, | 1064 EXPECT_TRUE(store_->GetValue(prefs::kManagedDefaultJavaScriptSetting, |
| 1045 &value)); | 1065 &value)); |
| 1046 EXPECT_TRUE(base::FundamentalValue(CONTENT_SETTING_ALLOW).Equals(value)); | 1066 EXPECT_TRUE(base::FundamentalValue(CONTENT_SETTING_ALLOW).Equals(value)); |
| 1047 } | 1067 } |
| 1048 | 1068 |
| 1049 } // namespace policy | 1069 } // namespace policy |
| OLD | NEW |