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

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: Answered PK's comments. Created 8 years 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 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 IN_PROC_BROWSER_TEST_F(PolicyTest, DefaultSearchProvider) { 617 IN_PROC_BROWSER_TEST_F(PolicyTest, DefaultSearchProvider) {
618 MakeRequestFail("search.example"); 618 MakeRequestFail("search.example");
619 619
620 // Verifies that a default search is made using the provider configured via 620 // Verifies that a default search is made using the provider configured via
621 // policy. Also checks that default search can be completely disabled. 621 // policy. Also checks that default search can be completely disabled.
622 const string16 kKeyword(ASCIIToUTF16("testsearch")); 622 const string16 kKeyword(ASCIIToUTF16("testsearch"));
623 const std::string kSearchURL("http://search.example/search?q={searchTerms}"); 623 const std::string kSearchURL("http://search.example/search?q={searchTerms}");
624 const std::string kAlternateURL0( 624 const std::string kAlternateURL0(
625 "http://search.example/search#q={searchTerms}"); 625 "http://search.example/search#q={searchTerms}");
626 const std::string kAlternateURL1("http://search.example/#q={searchTerms}"); 626 const std::string kAlternateURL1("http://search.example/#q={searchTerms}");
627 const std::string kSearchTermsReplacementKey("zekey");
627 628
628 TemplateURLService* service = TemplateURLServiceFactory::GetForProfile( 629 TemplateURLService* service = TemplateURLServiceFactory::GetForProfile(
629 browser()->profile()); 630 browser()->profile());
630 ui_test_utils::WaitForTemplateURLServiceToLoad(service); 631 ui_test_utils::WaitForTemplateURLServiceToLoad(service);
631 TemplateURL* default_search = service->GetDefaultSearchProvider(); 632 TemplateURL* default_search = service->GetDefaultSearchProvider();
632 ASSERT_TRUE(default_search); 633 ASSERT_TRUE(default_search);
633 EXPECT_NE(kKeyword, default_search->keyword()); 634 EXPECT_NE(kKeyword, default_search->keyword());
634 EXPECT_NE(kSearchURL, default_search->url()); 635 EXPECT_NE(kSearchURL, default_search->url());
635 EXPECT_FALSE( 636 EXPECT_FALSE(
636 default_search->alternate_urls().size() == 2 && 637 default_search->alternate_urls().size() == 2 &&
637 default_search->alternate_urls()[0] == kAlternateURL0 && 638 default_search->alternate_urls()[0] == kAlternateURL0 &&
638 default_search->alternate_urls()[1] == kAlternateURL1); 639 default_search->alternate_urls()[1] == kAlternateURL1 &&
640 default_search->search_terms_replacement_key() ==
641 kSearchTermsReplacementKey);
639 642
640 // Override the default search provider using policies. 643 // Override the default search provider using policies.
641 PolicyMap policies; 644 PolicyMap policies;
642 policies.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY, 645 policies.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY,
643 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); 646 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true));
644 policies.Set(key::kDefaultSearchProviderKeyword, POLICY_LEVEL_MANDATORY, 647 policies.Set(key::kDefaultSearchProviderKeyword, POLICY_LEVEL_MANDATORY,
645 POLICY_SCOPE_USER, base::Value::CreateStringValue(kKeyword)); 648 POLICY_SCOPE_USER, base::Value::CreateStringValue(kKeyword));
646 policies.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, 649 policies.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY,
647 POLICY_SCOPE_USER, base::Value::CreateStringValue(kSearchURL)); 650 POLICY_SCOPE_USER, base::Value::CreateStringValue(kSearchURL));
648 base::ListValue* alternate_urls = new base::ListValue(); 651 base::ListValue* alternate_urls = new base::ListValue();
649 alternate_urls->AppendString(kAlternateURL0); 652 alternate_urls->AppendString(kAlternateURL0);
650 alternate_urls->AppendString(kAlternateURL1); 653 alternate_urls->AppendString(kAlternateURL1);
651 policies.Set(key::kDefaultSearchProviderAlternateURLs, POLICY_LEVEL_MANDATORY, 654 policies.Set(key::kDefaultSearchProviderAlternateURLs, POLICY_LEVEL_MANDATORY,
652 POLICY_SCOPE_USER, alternate_urls); 655 POLICY_SCOPE_USER, alternate_urls);
656 policies.Set(key::kDefaultSearchProviderSearchTermsReplacementKey,
657 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
658 base::Value::CreateStringValue(kSearchTermsReplacementKey));
653 provider_.UpdateChromePolicy(policies); 659 provider_.UpdateChromePolicy(policies);
654 default_search = service->GetDefaultSearchProvider(); 660 default_search = service->GetDefaultSearchProvider();
655 ASSERT_TRUE(default_search); 661 ASSERT_TRUE(default_search);
656 EXPECT_EQ(kKeyword, default_search->keyword()); 662 EXPECT_EQ(kKeyword, default_search->keyword());
657 EXPECT_EQ(kSearchURL, default_search->url()); 663 EXPECT_EQ(kSearchURL, default_search->url());
658 EXPECT_EQ(2U, default_search->alternate_urls().size()); 664 EXPECT_EQ(2U, default_search->alternate_urls().size());
659 EXPECT_EQ(kAlternateURL0, default_search->alternate_urls()[0]); 665 EXPECT_EQ(kAlternateURL0, default_search->alternate_urls()[0]);
660 EXPECT_EQ(kAlternateURL1, default_search->alternate_urls()[1]); 666 EXPECT_EQ(kAlternateURL1, default_search->alternate_urls()[1]);
667 EXPECT_EQ(kSearchTermsReplacementKey,
668 default_search->search_terms_replacement_key());
661 669
662 // Verify that searching from the omnibox uses kSearchURL. 670 // Verify that searching from the omnibox uses kSearchURL.
663 chrome::FocusLocationBar(browser()); 671 chrome::FocusLocationBar(browser());
664 LocationBar* location_bar = browser()->window()->GetLocationBar(); 672 LocationBar* location_bar = browser()->window()->GetLocationBar();
665 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "stuff to search for"); 673 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "stuff to search for");
666 OmniboxEditModel* model = location_bar->GetLocationEntry()->model(); 674 OmniboxEditModel* model = location_bar->GetLocationEntry()->model();
667 EXPECT_TRUE(model->CurrentMatch().destination_url.is_valid()); 675 EXPECT_TRUE(model->CurrentMatch().destination_url.is_valid());
668 content::WebContents* web_contents = chrome::GetActiveWebContents(browser()); 676 content::WebContents* web_contents = chrome::GetActiveWebContents(browser());
669 GURL expected("http://search.example/search?q=stuff+to+search+for"); 677 GURL expected("http://search.example/search?q=stuff+to+search+for");
670 EXPECT_EQ(expected, web_contents->GetURL()); 678 EXPECT_EQ(expected, web_contents->GetURL());
(...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after
1696 EXPECT_EQ(kExpectedLabel, text.substr(0, kExpectedLabel.size())); 1704 EXPECT_EQ(kExpectedLabel, text.substr(0, kExpectedLabel.size()));
1697 // HomepageLocation has policy ID 1. 1705 // HomepageLocation has policy ID 1.
1698 EXPECT_NE(std::string::npos, text.find("<br>1 ---")); 1706 EXPECT_NE(std::string::npos, text.find("<br>1 ---"));
1699 // ShowHomeButton has policy ID 35. 1707 // ShowHomeButton has policy ID 35.
1700 EXPECT_NE(std::string::npos, text.find("<br>35 ---")); 1708 EXPECT_NE(std::string::npos, text.find("<br>35 ---"));
1701 // BookmarkBarEnabled has policy ID 82. 1709 // BookmarkBarEnabled has policy ID 82.
1702 EXPECT_NE(std::string::npos, text.find("<br>82 ---")); 1710 EXPECT_NE(std::string::npos, text.find("<br>82 ---"));
1703 } 1711 }
1704 1712
1705 } // namespace policy 1713 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698