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