Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Side by Side Diff: chrome/browser/policy/policy_browsertest.cc

Issue 11552020: Add search_terms_replacement_key field to TemplateURL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments now describe a simpler behavior for the parameter. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 IN_PROC_BROWSER_TEST_F(PolicyTest, DefaultSearchProvider) { 648 IN_PROC_BROWSER_TEST_F(PolicyTest, DefaultSearchProvider) {
649 MakeRequestFail make_request_fail("search.example"); 649 MakeRequestFail make_request_fail("search.example");
650 650
651 // Verifies that a default search is made using the provider configured via 651 // Verifies that a default search is made using the provider configured via
652 // policy. Also checks that default search can be completely disabled. 652 // policy. Also checks that default search can be completely disabled.
653 const string16 kKeyword(ASCIIToUTF16("testsearch")); 653 const string16 kKeyword(ASCIIToUTF16("testsearch"));
654 const std::string kSearchURL("http://search.example/search?q={searchTerms}"); 654 const std::string kSearchURL("http://search.example/search?q={searchTerms}");
655 const std::string kAlternateURL0( 655 const std::string kAlternateURL0(
656 "http://search.example/search#q={searchTerms}"); 656 "http://search.example/search#q={searchTerms}");
657 const std::string kAlternateURL1("http://search.example/#q={searchTerms}"); 657 const std::string kAlternateURL1("http://search.example/#q={searchTerms}");
658 const std::string kSearchTermsReplacementKey("zekey");
658 659
659 TemplateURLService* service = TemplateURLServiceFactory::GetForProfile( 660 TemplateURLService* service = TemplateURLServiceFactory::GetForProfile(
660 browser()->profile()); 661 browser()->profile());
661 ui_test_utils::WaitForTemplateURLServiceToLoad(service); 662 ui_test_utils::WaitForTemplateURLServiceToLoad(service);
662 TemplateURL* default_search = service->GetDefaultSearchProvider(); 663 TemplateURL* default_search = service->GetDefaultSearchProvider();
663 ASSERT_TRUE(default_search); 664 ASSERT_TRUE(default_search);
664 EXPECT_NE(kKeyword, default_search->keyword()); 665 EXPECT_NE(kKeyword, default_search->keyword());
665 EXPECT_NE(kSearchURL, default_search->url()); 666 EXPECT_NE(kSearchURL, default_search->url());
666 EXPECT_FALSE( 667 EXPECT_FALSE(
667 default_search->alternate_urls().size() == 2 && 668 default_search->alternate_urls().size() == 2 &&
668 default_search->alternate_urls()[0] == kAlternateURL0 && 669 default_search->alternate_urls()[0] == kAlternateURL0 &&
669 default_search->alternate_urls()[1] == kAlternateURL1); 670 default_search->alternate_urls()[1] == kAlternateURL1 &&
671 default_search->search_terms_replacement_key() ==
672 kSearchTermsReplacementKey);
670 673
671 // Override the default search provider using policies. 674 // Override the default search provider using policies.
672 PolicyMap policies; 675 PolicyMap policies;
673 policies.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY, 676 policies.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY,
674 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); 677 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true));
675 policies.Set(key::kDefaultSearchProviderKeyword, POLICY_LEVEL_MANDATORY, 678 policies.Set(key::kDefaultSearchProviderKeyword, POLICY_LEVEL_MANDATORY,
676 POLICY_SCOPE_USER, base::Value::CreateStringValue(kKeyword)); 679 POLICY_SCOPE_USER, base::Value::CreateStringValue(kKeyword));
677 policies.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, 680 policies.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY,
678 POLICY_SCOPE_USER, base::Value::CreateStringValue(kSearchURL)); 681 POLICY_SCOPE_USER, base::Value::CreateStringValue(kSearchURL));
679 base::ListValue* alternate_urls = new base::ListValue(); 682 base::ListValue* alternate_urls = new base::ListValue();
680 alternate_urls->AppendString(kAlternateURL0); 683 alternate_urls->AppendString(kAlternateURL0);
681 alternate_urls->AppendString(kAlternateURL1); 684 alternate_urls->AppendString(kAlternateURL1);
682 policies.Set(key::kDefaultSearchProviderAlternateURLs, POLICY_LEVEL_MANDATORY, 685 policies.Set(key::kDefaultSearchProviderAlternateURLs, POLICY_LEVEL_MANDATORY,
683 POLICY_SCOPE_USER, alternate_urls); 686 POLICY_SCOPE_USER, alternate_urls);
687 policies.Set(key::kDefaultSearchProviderSearchTermsReplacementKey,
688 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
689 base::Value::CreateStringValue(kSearchTermsReplacementKey));
684 provider_.UpdateChromePolicy(policies); 690 provider_.UpdateChromePolicy(policies);
685 default_search = service->GetDefaultSearchProvider(); 691 default_search = service->GetDefaultSearchProvider();
686 ASSERT_TRUE(default_search); 692 ASSERT_TRUE(default_search);
687 EXPECT_EQ(kKeyword, default_search->keyword()); 693 EXPECT_EQ(kKeyword, default_search->keyword());
688 EXPECT_EQ(kSearchURL, default_search->url()); 694 EXPECT_EQ(kSearchURL, default_search->url());
689 EXPECT_EQ(2U, default_search->alternate_urls().size()); 695 EXPECT_EQ(2U, default_search->alternate_urls().size());
690 EXPECT_EQ(kAlternateURL0, default_search->alternate_urls()[0]); 696 EXPECT_EQ(kAlternateURL0, default_search->alternate_urls()[0]);
691 EXPECT_EQ(kAlternateURL1, default_search->alternate_urls()[1]); 697 EXPECT_EQ(kAlternateURL1, default_search->alternate_urls()[1]);
698 EXPECT_EQ(kSearchTermsReplacementKey,
699 default_search->search_terms_replacement_key());
692 700
693 // Verify that searching from the omnibox uses kSearchURL. 701 // Verify that searching from the omnibox uses kSearchURL.
694 chrome::FocusLocationBar(browser()); 702 chrome::FocusLocationBar(browser());
695 LocationBar* location_bar = browser()->window()->GetLocationBar(); 703 LocationBar* location_bar = browser()->window()->GetLocationBar();
696 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "stuff to search for"); 704 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "stuff to search for");
697 OmniboxEditModel* model = location_bar->GetLocationEntry()->model(); 705 OmniboxEditModel* model = location_bar->GetLocationEntry()->model();
698 EXPECT_TRUE(model->CurrentMatch().destination_url.is_valid()); 706 EXPECT_TRUE(model->CurrentMatch().destination_url.is_valid());
699 content::WebContents* web_contents = chrome::GetActiveWebContents(browser()); 707 content::WebContents* web_contents = chrome::GetActiveWebContents(browser());
700 GURL expected("http://search.example/search?q=stuff+to+search+for"); 708 GURL expected("http://search.example/search?q=stuff+to+search+for");
701 EXPECT_EQ(expected, web_contents->GetURL()); 709 EXPECT_EQ(expected, web_contents->GetURL());
(...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after
1731 EXPECT_EQ(kExpectedLabel, text.substr(0, kExpectedLabel.size())); 1739 EXPECT_EQ(kExpectedLabel, text.substr(0, kExpectedLabel.size()));
1732 // HomepageLocation has policy ID 1. 1740 // HomepageLocation has policy ID 1.
1733 EXPECT_NE(std::string::npos, text.find("<br>1 ---")); 1741 EXPECT_NE(std::string::npos, text.find("<br>1 ---"));
1734 // ShowHomeButton has policy ID 35. 1742 // ShowHomeButton has policy ID 35.
1735 EXPECT_NE(std::string::npos, text.find("<br>35 ---")); 1743 EXPECT_NE(std::string::npos, text.find("<br>35 ---"));
1736 // BookmarkBarEnabled has policy ID 82. 1744 // BookmarkBarEnabled has policy ID 82.
1737 EXPECT_NE(std::string::npos, text.find("<br>82 ---")); 1745 EXPECT_NE(std::string::npos, text.find("<br>82 ---"));
1738 } 1746 }
1739 1747
1740 } // namespace policy 1748 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698