| 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 <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 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 EXPECT_EQ(kAlternateURL0, default_search->alternate_urls()[0]); | 772 EXPECT_EQ(kAlternateURL0, default_search->alternate_urls()[0]); |
| 773 EXPECT_EQ(kAlternateURL1, default_search->alternate_urls()[1]); | 773 EXPECT_EQ(kAlternateURL1, default_search->alternate_urls()[1]); |
| 774 EXPECT_EQ(kSearchTermsReplacementKey, | 774 EXPECT_EQ(kSearchTermsReplacementKey, |
| 775 default_search->search_terms_replacement_key()); | 775 default_search->search_terms_replacement_key()); |
| 776 | 776 |
| 777 // Verify that searching from the omnibox uses kSearchURL. | 777 // Verify that searching from the omnibox uses kSearchURL. |
| 778 chrome::FocusLocationBar(browser()); | 778 chrome::FocusLocationBar(browser()); |
| 779 LocationBar* location_bar = browser()->window()->GetLocationBar(); | 779 LocationBar* location_bar = browser()->window()->GetLocationBar(); |
| 780 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "stuff to search for"); | 780 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "stuff to search for"); |
| 781 OmniboxEditModel* model = location_bar->GetLocationEntry()->model(); | 781 OmniboxEditModel* model = location_bar->GetLocationEntry()->model(); |
| 782 EXPECT_TRUE(model->CurrentMatch().destination_url.is_valid()); | 782 EXPECT_TRUE(model->CurrentMatch(NULL).destination_url.is_valid()); |
| 783 content::WebContents* web_contents = | 783 content::WebContents* web_contents = |
| 784 browser()->tab_strip_model()->GetActiveWebContents(); | 784 browser()->tab_strip_model()->GetActiveWebContents(); |
| 785 GURL expected("http://search.example/search?q=stuff+to+search+for"); | 785 GURL expected("http://search.example/search?q=stuff+to+search+for"); |
| 786 EXPECT_EQ(expected, web_contents->GetURL()); | 786 EXPECT_EQ(expected, web_contents->GetURL()); |
| 787 | 787 |
| 788 // Verify that searching from the omnibox can be disabled. | 788 // Verify that searching from the omnibox can be disabled. |
| 789 ui_test_utils::NavigateToURL(browser(), GURL(content::kAboutBlankURL)); | 789 ui_test_utils::NavigateToURL(browser(), GURL(content::kAboutBlankURL)); |
| 790 policies.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY, | 790 policies.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY, |
| 791 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false)); | 791 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false)); |
| 792 EXPECT_TRUE(service->GetDefaultSearchProvider()); | 792 EXPECT_TRUE(service->GetDefaultSearchProvider()); |
| 793 UpdateProviderPolicy(policies); | 793 UpdateProviderPolicy(policies); |
| 794 EXPECT_FALSE(service->GetDefaultSearchProvider()); | 794 EXPECT_FALSE(service->GetDefaultSearchProvider()); |
| 795 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "should not work"); | 795 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "should not work"); |
| 796 // This means that submitting won't trigger any action. | 796 // This means that submitting won't trigger any action. |
| 797 EXPECT_FALSE(model->CurrentMatch().destination_url.is_valid()); | 797 EXPECT_FALSE(model->CurrentMatch(NULL).destination_url.is_valid()); |
| 798 EXPECT_EQ(GURL(content::kAboutBlankURL), web_contents->GetURL()); | 798 EXPECT_EQ(GURL(content::kAboutBlankURL), web_contents->GetURL()); |
| 799 } | 799 } |
| 800 | 800 |
| 801 IN_PROC_BROWSER_TEST_F(PolicyTest, ForceSafeSearch) { | 801 IN_PROC_BROWSER_TEST_F(PolicyTest, ForceSafeSearch) { |
| 802 // Makes the requests fail since all we want to check is that the redirection | 802 // Makes the requests fail since all we want to check is that the redirection |
| 803 // is done properly. | 803 // is done properly. |
| 804 MakeRequestFail make_request_fail("google.com"); | 804 MakeRequestFail make_request_fail("google.com"); |
| 805 | 805 |
| 806 // Verifies that requests to Google Search engine with the SafeSearch | 806 // Verifies that requests to Google Search engine with the SafeSearch |
| 807 // enabled set the safe=active&ssui=on parameters at the end of the query. | 807 // enabled set the safe=active&ssui=on parameters at the end of the query. |
| 808 TemplateURLService* service = TemplateURLServiceFactory::GetForProfile( | 808 TemplateURLService* service = TemplateURLServiceFactory::GetForProfile( |
| 809 browser()->profile()); | 809 browser()->profile()); |
| 810 ui_test_utils::WaitForTemplateURLServiceToLoad(service); | 810 ui_test_utils::WaitForTemplateURLServiceToLoad(service); |
| 811 | 811 |
| 812 // First check that nothing happens. | 812 // First check that nothing happens. |
| 813 content::TestNavigationObserver no_safesearch_observer( | 813 content::TestNavigationObserver no_safesearch_observer( |
| 814 browser()->tab_strip_model()->GetActiveWebContents()); | 814 browser()->tab_strip_model()->GetActiveWebContents()); |
| 815 chrome::FocusLocationBar(browser()); | 815 chrome::FocusLocationBar(browser()); |
| 816 LocationBar* location_bar = browser()->window()->GetLocationBar(); | 816 LocationBar* location_bar = browser()->window()->GetLocationBar(); |
| 817 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "http://google.com/"); | 817 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "http://google.com/"); |
| 818 OmniboxEditModel* model = location_bar->GetLocationEntry()->model(); | 818 OmniboxEditModel* model = location_bar->GetLocationEntry()->model(); |
| 819 no_safesearch_observer.Wait(); | 819 no_safesearch_observer.Wait(); |
| 820 EXPECT_TRUE(model->CurrentMatch().destination_url.is_valid()); | 820 EXPECT_TRUE(model->CurrentMatch(NULL).destination_url.is_valid()); |
| 821 content::WebContents* web_contents = | 821 content::WebContents* web_contents = |
| 822 browser()->tab_strip_model()->GetActiveWebContents(); | 822 browser()->tab_strip_model()->GetActiveWebContents(); |
| 823 GURL expected_without("http://google.com/"); | 823 GURL expected_without("http://google.com/"); |
| 824 EXPECT_EQ(expected_without, web_contents->GetURL()); | 824 EXPECT_EQ(expected_without, web_contents->GetURL()); |
| 825 | 825 |
| 826 PrefService* prefs = browser()->profile()->GetPrefs(); | 826 PrefService* prefs = browser()->profile()->GetPrefs(); |
| 827 EXPECT_FALSE(prefs->IsManagedPreference(prefs::kForceSafeSearch)); | 827 EXPECT_FALSE(prefs->IsManagedPreference(prefs::kForceSafeSearch)); |
| 828 EXPECT_FALSE(prefs->GetBoolean(prefs::kForceSafeSearch)); | 828 EXPECT_FALSE(prefs->GetBoolean(prefs::kForceSafeSearch)); |
| 829 | 829 |
| 830 // Override the default SafeSearch setting using policies. | 830 // Override the default SafeSearch setting using policies. |
| 831 PolicyMap policies; | 831 PolicyMap policies; |
| 832 policies.Set(key::kForceSafeSearch, POLICY_LEVEL_MANDATORY, | 832 policies.Set(key::kForceSafeSearch, POLICY_LEVEL_MANDATORY, |
| 833 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); | 833 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); |
| 834 UpdateProviderPolicy(policies); | 834 UpdateProviderPolicy(policies); |
| 835 | 835 |
| 836 EXPECT_TRUE(prefs->IsManagedPreference(prefs::kForceSafeSearch)); | 836 EXPECT_TRUE(prefs->IsManagedPreference(prefs::kForceSafeSearch)); |
| 837 EXPECT_TRUE(prefs->GetBoolean(prefs::kForceSafeSearch)); | 837 EXPECT_TRUE(prefs->GetBoolean(prefs::kForceSafeSearch)); |
| 838 | 838 |
| 839 content::TestNavigationObserver safesearch_observer( | 839 content::TestNavigationObserver safesearch_observer( |
| 840 browser()->tab_strip_model()->GetActiveWebContents()); | 840 browser()->tab_strip_model()->GetActiveWebContents()); |
| 841 | 841 |
| 842 // Verify that searching from google.com works. | 842 // Verify that searching from google.com works. |
| 843 chrome::FocusLocationBar(browser()); | 843 chrome::FocusLocationBar(browser()); |
| 844 location_bar = browser()->window()->GetLocationBar(); | 844 location_bar = browser()->window()->GetLocationBar(); |
| 845 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "http://google.com/"); | 845 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "http://google.com/"); |
| 846 safesearch_observer.Wait(); | 846 safesearch_observer.Wait(); |
| 847 model = location_bar->GetLocationEntry()->model(); | 847 model = location_bar->GetLocationEntry()->model(); |
| 848 EXPECT_TRUE(model->CurrentMatch().destination_url.is_valid()); | 848 EXPECT_TRUE(model->CurrentMatch(NULL).destination_url.is_valid()); |
| 849 web_contents = browser()->tab_strip_model()->GetActiveWebContents(); | 849 web_contents = browser()->tab_strip_model()->GetActiveWebContents(); |
| 850 std::string expected_url("http://google.com/?"); | 850 std::string expected_url("http://google.com/?"); |
| 851 expected_url += std::string(chrome::kSafeSearchSafeParameter) + "&" + | 851 expected_url += std::string(chrome::kSafeSearchSafeParameter) + "&" + |
| 852 chrome::kSafeSearchSsuiParameter; | 852 chrome::kSafeSearchSsuiParameter; |
| 853 GURL expected_with_parameters(expected_url); | 853 GURL expected_with_parameters(expected_url); |
| 854 EXPECT_EQ(expected_with_parameters, web_contents->GetURL()); | 854 EXPECT_EQ(expected_with_parameters, web_contents->GetURL()); |
| 855 } | 855 } |
| 856 | 856 |
| 857 IN_PROC_BROWSER_TEST_F(PolicyTest, ReplaceSearchTerms) { | 857 IN_PROC_BROWSER_TEST_F(PolicyTest, ReplaceSearchTerms) { |
| 858 MakeRequestFail make_request_fail("search.example"); | 858 MakeRequestFail make_request_fail("search.example"); |
| (...skipping 1606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2465 chrome_variations::VariationsService::GetVariationsServerURL( | 2465 chrome_variations::VariationsService::GetVariationsServerURL( |
| 2466 g_browser_process->local_state()); | 2466 g_browser_process->local_state()); |
| 2467 EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true)); | 2467 EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true)); |
| 2468 std::string value; | 2468 std::string value; |
| 2469 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); | 2469 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); |
| 2470 EXPECT_EQ("restricted", value); | 2470 EXPECT_EQ("restricted", value); |
| 2471 } | 2471 } |
| 2472 #endif | 2472 #endif |
| 2473 | 2473 |
| 2474 } // namespace policy | 2474 } // namespace policy |
| OLD | NEW |