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 13 matching lines...) Expand all Loading... |
24 #include "chrome/app/chrome_command_ids.h" | 24 #include "chrome/app/chrome_command_ids.h" |
25 #include "chrome/browser/api/infobars/infobar_service.h" | 25 #include "chrome/browser/api/infobars/infobar_service.h" |
26 #include "chrome/browser/autocomplete/autocomplete_controller.h" | 26 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
27 #include "chrome/browser/browser_process.h" | 27 #include "chrome/browser/browser_process.h" |
28 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 28 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
29 #include "chrome/browser/devtools/devtools_window.h" | 29 #include "chrome/browser/devtools/devtools_window.h" |
30 #include "chrome/browser/download/download_prefs.h" | 30 #include "chrome/browser/download/download_prefs.h" |
31 #include "chrome/browser/extensions/crx_installer.h" | 31 #include "chrome/browser/extensions/crx_installer.h" |
32 #include "chrome/browser/extensions/extension_service.h" | 32 #include "chrome/browser/extensions/extension_service.h" |
33 #include "chrome/browser/extensions/extension_system.h" | 33 #include "chrome/browser/extensions/extension_system.h" |
| 34 #include "chrome/browser/instant/instant_service.h" |
| 35 #include "chrome/browser/instant/instant_service_factory.h" |
34 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 36 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
35 #include "chrome/browser/media/media_stream_devices_controller.h" | 37 #include "chrome/browser/media/media_stream_devices_controller.h" |
36 #include "chrome/browser/net/url_request_mock_util.h" | 38 #include "chrome/browser/net/url_request_mock_util.h" |
37 #include "chrome/browser/plugins/plugin_prefs.h" | 39 #include "chrome/browser/plugins/plugin_prefs.h" |
38 #include "chrome/browser/policy/browser_policy_connector.h" | 40 #include "chrome/browser/policy/browser_policy_connector.h" |
39 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 41 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
40 #include "chrome/browser/policy/policy_map.h" | 42 #include "chrome/browser/policy/policy_map.h" |
41 #include "chrome/browser/prefs/session_startup_pref.h" | 43 #include "chrome/browser/prefs/session_startup_pref.h" |
42 #include "chrome/browser/profiles/profile.h" | 44 #include "chrome/browser/profiles/profile.h" |
43 #include "chrome/browser/search_engines/template_url.h" | 45 #include "chrome/browser/search_engines/template_url.h" |
(...skipping 25 matching lines...) Expand all Loading... |
69 #include "content/public/browser/browser_child_process_host_iterator.h" | 71 #include "content/public/browser/browser_child_process_host_iterator.h" |
70 #include "content/public/browser/browser_context.h" | 72 #include "content/public/browser/browser_context.h" |
71 #include "content/public/browser/browser_thread.h" | 73 #include "content/public/browser/browser_thread.h" |
72 #include "content/public/browser/child_process_data.h" | 74 #include "content/public/browser/child_process_data.h" |
73 #include "content/public/browser/download_item.h" | 75 #include "content/public/browser/download_item.h" |
74 #include "content/public/browser/download_manager.h" | 76 #include "content/public/browser/download_manager.h" |
75 #include "content/public/browser/notification_service.h" | 77 #include "content/public/browser/notification_service.h" |
76 #include "content/public/browser/notification_source.h" | 78 #include "content/public/browser/notification_source.h" |
77 #include "content/public/browser/notification_types.h" | 79 #include "content/public/browser/notification_types.h" |
78 #include "content/public/browser/plugin_service.h" | 80 #include "content/public/browser/plugin_service.h" |
| 81 #include "content/public/browser/render_process_host.h" |
79 #include "content/public/browser/render_view_host.h" | 82 #include "content/public/browser/render_view_host.h" |
80 #include "content/public/browser/web_contents.h" | 83 #include "content/public/browser/web_contents.h" |
81 #include "content/public/common/content_paths.h" | 84 #include "content/public/common/content_paths.h" |
82 #include "content/public/common/page_transition_types.h" | 85 #include "content/public/common/page_transition_types.h" |
83 #include "content/public/common/process_type.h" | 86 #include "content/public/common/process_type.h" |
84 #include "content/public/common/url_constants.h" | 87 #include "content/public/common/url_constants.h" |
85 #include "content/public/test/browser_test_utils.h" | 88 #include "content/public/test/browser_test_utils.h" |
86 #include "content/public/test/download_test_observer.h" | 89 #include "content/public/test/download_test_observer.h" |
87 #include "content/public/test/test_navigation_observer.h" | 90 #include "content/public/test/test_navigation_observer.h" |
88 #include "content/public/test/test_utils.h" | 91 #include "content/public/test/test_utils.h" |
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 std::string expected_url("http://google.com/?"); | 787 std::string expected_url("http://google.com/?"); |
785 expected_url += std::string(chrome::kSafeSearchSafeParameter) + "&" + | 788 expected_url += std::string(chrome::kSafeSearchSafeParameter) + "&" + |
786 chrome::kSafeSearchSsuiParameter; | 789 chrome::kSafeSearchSsuiParameter; |
787 GURL expected_with_parameters(expected_url); | 790 GURL expected_with_parameters(expected_url); |
788 EXPECT_EQ(expected_with_parameters, web_contents->GetURL()); | 791 EXPECT_EQ(expected_with_parameters, web_contents->GetURL()); |
789 } | 792 } |
790 | 793 |
791 IN_PROC_BROWSER_TEST_F(PolicyTest, ReplaceSearchTerms) { | 794 IN_PROC_BROWSER_TEST_F(PolicyTest, ReplaceSearchTerms) { |
792 MakeRequestFail make_request_fail("search.example"); | 795 MakeRequestFail make_request_fail("search.example"); |
793 | 796 |
794 chrome::search::EnableInstantExtendedAPIForTesting(); | 797 chrome::search::EnableQueryExtractionForTesting(); |
795 | 798 |
796 // Verifies that a default search is made using the provider configured via | 799 // Verifies that a default search is made using the provider configured via |
797 // policy. Also checks that default search can be completely disabled. | 800 // policy. Also checks that default search can be completely disabled. |
798 const string16 kKeyword(ASCIIToUTF16("testsearch")); | 801 const string16 kKeyword(ASCIIToUTF16("testsearch")); |
799 const std::string kSearchURL("https://www.google.com/search?q={searchTerms}"); | 802 const std::string kSearchURL("https://www.google.com/search?q={searchTerms}"); |
| 803 const std::string kInstantURL("http://does/not/exist"); |
800 const std::string kAlternateURL0( | 804 const std::string kAlternateURL0( |
801 "https://www.google.com/search#q={searchTerms}"); | 805 "https://www.google.com/search#q={searchTerms}"); |
802 const std::string kAlternateURL1("https://www.google.com/#q={searchTerms}"); | 806 const std::string kAlternateURL1("https://www.google.com/#q={searchTerms}"); |
803 const std::string kSearchTermsReplacementKey( | 807 const std::string kSearchTermsReplacementKey( |
804 "{google:instantExtendedEnabledKey}"); | 808 "{google:instantExtendedEnabledKey}"); |
805 | 809 |
806 TemplateURLService* service = TemplateURLServiceFactory::GetForProfile( | 810 TemplateURLService* service = TemplateURLServiceFactory::GetForProfile( |
807 browser()->profile()); | 811 browser()->profile()); |
808 ui_test_utils::WaitForTemplateURLServiceToLoad(service); | 812 ui_test_utils::WaitForTemplateURLServiceToLoad(service); |
809 TemplateURL* default_search = service->GetDefaultSearchProvider(); | 813 TemplateURL* default_search = service->GetDefaultSearchProvider(); |
810 ASSERT_TRUE(default_search); | 814 ASSERT_TRUE(default_search); |
811 EXPECT_NE(kKeyword, default_search->keyword()); | 815 EXPECT_NE(kKeyword, default_search->keyword()); |
812 EXPECT_NE(kSearchURL, default_search->url()); | 816 EXPECT_NE(kSearchURL, default_search->url()); |
| 817 EXPECT_NE(kInstantURL, default_search->instant_url()); |
813 EXPECT_FALSE( | 818 EXPECT_FALSE( |
814 default_search->alternate_urls().size() == 2 && | 819 default_search->alternate_urls().size() == 2 && |
815 default_search->alternate_urls()[0] == kAlternateURL0 && | 820 default_search->alternate_urls()[0] == kAlternateURL0 && |
816 default_search->alternate_urls()[1] == kAlternateURL1); | 821 default_search->alternate_urls()[1] == kAlternateURL1); |
817 | 822 |
818 // Override the default search provider using policies. | 823 // Override the default search provider using policies. |
819 PolicyMap policies; | 824 PolicyMap policies; |
820 policies.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY, | 825 policies.Set(key::kDefaultSearchProviderEnabled, POLICY_LEVEL_MANDATORY, |
821 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); | 826 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); |
822 policies.Set(key::kDefaultSearchProviderKeyword, POLICY_LEVEL_MANDATORY, | 827 policies.Set(key::kDefaultSearchProviderKeyword, POLICY_LEVEL_MANDATORY, |
823 POLICY_SCOPE_USER, base::Value::CreateStringValue(kKeyword)); | 828 POLICY_SCOPE_USER, base::Value::CreateStringValue(kKeyword)); |
824 policies.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, | 829 policies.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY, |
825 POLICY_SCOPE_USER, base::Value::CreateStringValue(kSearchURL)); | 830 POLICY_SCOPE_USER, base::Value::CreateStringValue(kSearchURL)); |
| 831 policies.Set(key::kDefaultSearchProviderInstantURL, POLICY_LEVEL_MANDATORY, |
| 832 POLICY_SCOPE_USER, base::Value::CreateStringValue(kInstantURL)); |
826 base::ListValue* alternate_urls = new base::ListValue(); | 833 base::ListValue* alternate_urls = new base::ListValue(); |
827 alternate_urls->AppendString(kAlternateURL0); | 834 alternate_urls->AppendString(kAlternateURL0); |
828 alternate_urls->AppendString(kAlternateURL1); | 835 alternate_urls->AppendString(kAlternateURL1); |
829 policies.Set(key::kDefaultSearchProviderAlternateURLs, POLICY_LEVEL_MANDATORY, | 836 policies.Set(key::kDefaultSearchProviderAlternateURLs, POLICY_LEVEL_MANDATORY, |
830 POLICY_SCOPE_USER, alternate_urls); | 837 POLICY_SCOPE_USER, alternate_urls); |
831 policies.Set(key::kDefaultSearchProviderSearchTermsReplacementKey, | 838 policies.Set(key::kDefaultSearchProviderSearchTermsReplacementKey, |
832 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 839 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
833 base::Value::CreateStringValue(kSearchTermsReplacementKey)); | 840 base::Value::CreateStringValue(kSearchTermsReplacementKey)); |
834 UpdateProviderPolicy(policies); | 841 UpdateProviderPolicy(policies); |
835 default_search = service->GetDefaultSearchProvider(); | 842 default_search = service->GetDefaultSearchProvider(); |
836 ASSERT_TRUE(default_search); | 843 ASSERT_TRUE(default_search); |
837 EXPECT_EQ(kKeyword, default_search->keyword()); | 844 EXPECT_EQ(kKeyword, default_search->keyword()); |
838 EXPECT_EQ(kSearchURL, default_search->url()); | 845 EXPECT_EQ(kSearchURL, default_search->url()); |
| 846 EXPECT_EQ(kInstantURL, default_search->instant_url()); |
839 EXPECT_EQ(2U, default_search->alternate_urls().size()); | 847 EXPECT_EQ(2U, default_search->alternate_urls().size()); |
840 EXPECT_EQ(kAlternateURL0, default_search->alternate_urls()[0]); | 848 EXPECT_EQ(kAlternateURL0, default_search->alternate_urls()[0]); |
841 EXPECT_EQ(kAlternateURL1, default_search->alternate_urls()[1]); | 849 EXPECT_EQ(kAlternateURL1, default_search->alternate_urls()[1]); |
842 | 850 |
| 851 // Query terms replacement requires that the renderer process be a recognized |
| 852 // Instant renderer. Fake it. |
| 853 InstantService* instant_service = |
| 854 InstantServiceFactory::GetForProfile(browser()->profile()); |
| 855 instant_service->AddInstantProcess(browser()->tab_strip_model()-> |
| 856 GetActiveWebContents()->GetRenderProcessHost()->GetID()); |
| 857 |
843 // Verify that searching from the omnibox does search term replacement with | 858 // Verify that searching from the omnibox does search term replacement with |
844 // first URL pattern. | 859 // first URL pattern. |
845 chrome::FocusLocationBar(browser()); | 860 chrome::FocusLocationBar(browser()); |
846 LocationBar* location_bar = browser()->window()->GetLocationBar(); | 861 LocationBar* location_bar = browser()->window()->GetLocationBar(); |
847 ui_test_utils::SendToOmniboxAndSubmit(location_bar, | 862 ui_test_utils::SendToOmniboxAndSubmit(location_bar, |
848 "https://www.google.com/?espv=1#q=foobar"); | 863 "https://www.google.com/?espv=1#q=foobar"); |
849 OmniboxEditModel* model = location_bar->GetLocationEntry()->model(); | 864 OmniboxEditModel* model = location_bar->GetLocationEntry()->model(); |
850 EXPECT_TRUE(model->CurrentMatch().destination_url.is_valid()); | 865 EXPECT_TRUE(model->CurrentMatch().destination_url.is_valid()); |
851 EXPECT_EQ(ASCIIToUTF16("foobar"), model->CurrentMatch().contents); | 866 EXPECT_EQ(ASCIIToUTF16("foobar"), model->CurrentMatch().contents); |
852 | 867 |
(...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1886 this)); | 1901 this)); |
1887 | 1902 |
1888 MessageLoop::current()->Run(); | 1903 MessageLoop::current()->Run(); |
1889 } | 1904 } |
1890 | 1905 |
1891 INSTANTIATE_TEST_CASE_P(MediaStreamDevicesControllerBrowserTestInstance, | 1906 INSTANTIATE_TEST_CASE_P(MediaStreamDevicesControllerBrowserTestInstance, |
1892 MediaStreamDevicesControllerBrowserTest, | 1907 MediaStreamDevicesControllerBrowserTest, |
1893 testing::Bool()); | 1908 testing::Bool()); |
1894 | 1909 |
1895 } // namespace policy | 1910 } // namespace policy |
OLD | NEW |