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

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

Issue 10908226: Introduces a search term extraction mechanism working for arbitrary search providers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Indent fix. Created 8 years, 2 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 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false)); 626 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false));
627 EXPECT_TRUE(service->GetDefaultSearchProvider()); 627 EXPECT_TRUE(service->GetDefaultSearchProvider());
628 provider_.UpdateChromePolicy(policies); 628 provider_.UpdateChromePolicy(policies);
629 EXPECT_FALSE(service->GetDefaultSearchProvider()); 629 EXPECT_FALSE(service->GetDefaultSearchProvider());
630 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "should not work"); 630 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "should not work");
631 // This means that submitting won't trigger any action. 631 // This means that submitting won't trigger any action.
632 EXPECT_FALSE(model->CurrentMatch().destination_url.is_valid()); 632 EXPECT_FALSE(model->CurrentMatch().destination_url.is_valid());
633 EXPECT_EQ(GURL(chrome::kAboutBlankURL), web_contents->GetURL()); 633 EXPECT_EQ(GURL(chrome::kAboutBlankURL), web_contents->GetURL());
634 } 634 }
635 635
636 IN_PROC_BROWSER_TEST_F(PolicyTest, ReplaceSearchTerms) {
637 CommandLine::ForCurrentProcess()->AppendSwitch(
638 switches::kEnableInstantExtendedAPI);
639
640 // Verifies that a default search is made using the provider configured via
641 // policy. Also checks that default search can be completely disabled.
642 const string16 kKeyword(ASCIIToUTF16("testsearch"));
643 const std::string kSearchURL("http://search.example/search?q={searchTerms}");
644 const std::string kAlternateURL0(
645 "http://search.example/search#q={searchTerms}");
646 const std::string kAlternateURL1("http://search.example/#q={searchTerms}");
647
648 TemplateURLService* service = TemplateURLServiceFactory::GetForProfile(
649 browser()->profile());
650 ui_test_utils::WaitForTemplateURLServiceToLoad(service);
651 TemplateURL* default_search = service->GetDefaultSearchProvider();
652 ASSERT_TRUE(default_search);
653 EXPECT_NE(kKeyword, default_search->keyword());
654 EXPECT_NE(kSearchURL, default_search->url());
655 EXPECT_NE(kAlternateURL0, default_search->alternate_urls()[0]);
656 EXPECT_NE(kAlternateURL1, default_search->alternate_urls()[1]);
657
658 // Override the default search provider using policies.
659 PolicyMap policies;
660 policies.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY,
661 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true));
662 policies.Set(key::kDefaultSearchProviderKeyword, POLICY_LEVEL_MANDATORY,
663 POLICY_SCOPE_USER, base::Value::CreateStringValue(kKeyword));
664 policies.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY,
665 POLICY_SCOPE_USER, base::Value::CreateStringValue(kSearchURL));
666 base::ListValue* alternate_urls = new base::ListValue();
667 alternate_urls->AppendString(kAlternateURL0);
668 alternate_urls->AppendString(kAlternateURL1);
669 policies.Set(key::kDefaultSearchProviderAlternateURLs, POLICY_LEVEL_MANDATORY,
670 POLICY_SCOPE_USER, alternate_urls);
671 provider_.UpdateChromePolicy(policies);
672 default_search = service->GetDefaultSearchProvider();
673 ASSERT_TRUE(default_search);
674 EXPECT_EQ(kKeyword, default_search->keyword());
675 EXPECT_EQ(kSearchURL, default_search->url());
676 EXPECT_EQ(kAlternateURL0, default_search->alternate_urls()[0]);
677 EXPECT_EQ(kAlternateURL1, default_search->alternate_urls()[1]);
678
679 // Verify that searching from the omnibox does search term replacement with
680 // first URL pattern.
681 chrome::FocusLocationBar(browser());
682 LocationBar* location_bar = browser()->window()->GetLocationBar();
683 ui_test_utils::SendToOmniboxAndSubmit(location_bar,
684 "http://search.example/#q=foobar");
685 OmniboxEditModel* model = location_bar->GetLocationEntry()->model();
686 EXPECT_TRUE(model->CurrentMatch().destination_url.is_valid());
687 EXPECT_EQ(ASCIIToUTF16("foobar"), model->CurrentMatch().contents);
688
689 // Verify that searching from the omnibox does search term replacement with
690 // second URL pattern.
691 chrome::FocusLocationBar(browser());
692 ui_test_utils::SendToOmniboxAndSubmit(location_bar,
693 "http://search.example/search#q=banana");
694 model = location_bar->GetLocationEntry()->model();
695 EXPECT_TRUE(model->CurrentMatch().destination_url.is_valid());
696 EXPECT_EQ(ASCIIToUTF16("banana"), model->CurrentMatch().contents);
697
698 // Verify that searching from the omnibox does search term replacement with
699 // standard search URL pattern.
700 chrome::FocusLocationBar(browser());
701 ui_test_utils::SendToOmniboxAndSubmit(location_bar,
702 "http://search.example/search?q=tractor+parts");
703 model = location_bar->GetLocationEntry()->model();
704 EXPECT_TRUE(model->CurrentMatch().destination_url.is_valid());
705 EXPECT_EQ(ASCIIToUTF16("tractor parts"), model->CurrentMatch().contents);
706
707 // Verify that searching from the omnibox prioritizes hash over query.
708 chrome::FocusLocationBar(browser());
709 ui_test_utils::SendToOmniboxAndSubmit(location_bar,
710 "http://search.example/search?q=tractor+parts#q=foobar");
711 model = location_bar->GetLocationEntry()->model();
712 EXPECT_TRUE(model->CurrentMatch().destination_url.is_valid());
713 EXPECT_EQ(ASCIIToUTF16("foobar"), model->CurrentMatch().contents);
714 }
715
636 // The linux and win bots can't create a GL context. http://crbug.com/103379 716 // The linux and win bots can't create a GL context. http://crbug.com/103379
637 #if defined(OS_MACOSX) 717 #if defined(OS_MACOSX)
638 IN_PROC_BROWSER_TEST_F(PolicyTest, Disable3DAPIs) { 718 IN_PROC_BROWSER_TEST_F(PolicyTest, Disable3DAPIs) {
639 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); 719 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL));
640 // WebGL is enabled by default. 720 // WebGL is enabled by default.
641 content::WebContents* contents = chrome::GetActiveWebContents(browser()); 721 content::WebContents* contents = chrome::GetActiveWebContents(browser());
642 EXPECT_TRUE(IsWebGLEnabled(contents)); 722 EXPECT_TRUE(IsWebGLEnabled(contents));
643 // Disable with a policy. 723 // Disable with a policy.
644 PolicyMap policies; 724 PolicyMap policies;
645 policies.Set(key::kDisable3DAPIs, POLICY_LEVEL_MANDATORY, 725 policies.Set(key::kDisable3DAPIs, POLICY_LEVEL_MANDATORY,
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 INSTANTIATE_TEST_CASE_P( 1577 INSTANTIATE_TEST_CASE_P(
1498 RestoreOnStartupPolicyTestInstance, 1578 RestoreOnStartupPolicyTestInstance,
1499 RestoreOnStartupPolicyTest, 1579 RestoreOnStartupPolicyTest,
1500 testing::Values(&RestoreOnStartupPolicyTest::HomepageIsNotNTP, 1580 testing::Values(&RestoreOnStartupPolicyTest::HomepageIsNotNTP,
1501 &RestoreOnStartupPolicyTest::HomepageIsNTP, 1581 &RestoreOnStartupPolicyTest::HomepageIsNTP,
1502 &RestoreOnStartupPolicyTest::ListOfURLs, 1582 &RestoreOnStartupPolicyTest::ListOfURLs,
1503 &RestoreOnStartupPolicyTest::NTP, 1583 &RestoreOnStartupPolicyTest::NTP,
1504 &RestoreOnStartupPolicyTest::Last)); 1584 &RestoreOnStartupPolicyTest::Last));
1505 1585
1506 } // namespace policy 1586 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698