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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/prefs/pref_service.h" | 6 #include "base/prefs/pref_service.h" |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/test/base/in_process_browser_test.h" | 13 #include "chrome/test/base/in_process_browser_test.h" |
14 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
15 #include "components/google/core/browser/google_switches.h" | 15 #include "components/google/core/browser/google_switches.h" |
16 #include "components/search_engines/search_engines_pref_names.h" | 16 #include "components/search_engines/search_engines_pref_names.h" |
17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
18 #include "content/public/common/url_constants.h" | 18 #include "content/public/common/url_constants.h" |
19 #include "content/public/test/browser_test_utils.h" | 19 #include "content/public/test/browser_test_utils.h" |
20 #include "net/test/spawned_test_server/spawned_test_server.h" | |
21 | 20 |
22 namespace { | 21 namespace { |
23 | 22 |
24 struct IsSearchProviderTestData { | 23 struct IsSearchProviderTestData { |
25 IsSearchProviderTestData() : tab(NULL) {} | 24 IsSearchProviderTestData() : tab(NULL) {} |
26 IsSearchProviderTestData(content::WebContents* t, | 25 IsSearchProviderTestData(content::WebContents* t, |
27 const std::string& h, | 26 const std::string& h, |
28 GURL url) | 27 GURL url) |
29 : tab(t), host(h), test_url(url) {} | 28 : tab(t), host(h), test_url(url) {} |
30 | 29 |
31 content::WebContents* tab; | 30 content::WebContents* tab; |
32 std::string host; | 31 std::string host; |
33 GURL test_url; | 32 GURL test_url; |
34 }; | 33 }; |
35 | 34 |
36 } // namespace | 35 } // namespace |
37 | 36 |
38 class SearchProviderTest : public InProcessBrowserTest { | 37 class SearchProviderTest : public InProcessBrowserTest { |
39 protected: | 38 protected: |
40 SearchProviderTest() {} | 39 SearchProviderTest() {} |
41 | 40 |
42 void SetUpCommandLine(base::CommandLine* command_line) override { | 41 void SetUpCommandLine(base::CommandLine* command_line) override { |
43 ASSERT_TRUE(test_server()->Start()); | 42 ASSERT_TRUE(embedded_test_server()->Start()); |
44 | 43 |
45 // Map all hosts to our local server. | 44 // Map all hosts to our local server. |
46 std::string host_rule( | 45 std::string host_rule("MAP * " + |
47 "MAP * " + test_server()->host_port_pair().ToString()); | 46 embedded_test_server()->host_port_pair().ToString()); |
48 command_line->AppendSwitchASCII(switches::kHostRules, host_rule); | 47 command_line->AppendSwitchASCII(switches::kHostRules, host_rule); |
49 // Use no proxy or otherwise this test will fail on a machine that has a | 48 // Use no proxy or otherwise this test will fail on a machine that has a |
50 // proxy configured. | 49 // proxy configured. |
51 command_line->AppendSwitch(switches::kNoProxyServer); | 50 command_line->AppendSwitch(switches::kNoProxyServer); |
52 | 51 |
53 // Always point google search to a known, non-secure URL. Normally, this | 52 // Always point google search to a known, non-secure URL. Normally, this |
54 // varies based on locale and is a HTTPS host. | 53 // varies based on locale and is a HTTPS host. |
55 command_line->AppendSwitchASCII( | 54 command_line->AppendSwitchASCII( |
56 switches::kGoogleBaseURL, "http://www.google.com"); | 55 switches::kGoogleBaseURL, "http://www.google.com"); |
57 | 56 |
58 // Get the url for the test page. | 57 // Get the url for the test page. |
59 search_provider_test_url_ = | 58 search_provider_test_url_ = |
60 test_server()->GetURL("files/is_search_provider_installed.html"); | 59 embedded_test_server()->GetURL("/is_search_provider_installed.html"); |
61 } | 60 } |
62 | 61 |
63 void SetUpOnMainThread() override { | 62 void SetUpOnMainThread() override { |
64 // Force the country to Canada, which has an installed search provider | 63 // Force the country to Canada, which has an installed search provider |
65 // that's HTTP. | 64 // that's HTTP. |
66 browser()->profile()->GetPrefs()->SetInteger( | 65 browser()->profile()->GetPrefs()->SetInteger( |
67 prefs::kCountryIDAtInstall, ('C' << 8) | 'A'); | 66 prefs::kCountryIDAtInstall, ('C' << 8) | 'A'); |
68 } | 67 } |
69 | 68 |
70 IsSearchProviderTestData StartIsSearchProviderInstalledTest( | 69 IsSearchProviderTestData StartIsSearchProviderInstalledTest( |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 for (size_t i = 0; i < arraysize(test_data); ++i) { | 145 for (size_t i = 0; i < arraysize(test_data); ++i) { |
147 FinishIsSearchProviderInstalledTest(test_data[i]); | 146 FinishIsSearchProviderInstalledTest(test_data[i]); |
148 } | 147 } |
149 #endif | 148 #endif |
150 } | 149 } |
151 | 150 |
152 IN_PROC_BROWSER_TEST_F(SearchProviderTest, | 151 IN_PROC_BROWSER_TEST_F(SearchProviderTest, |
153 TestIsSearchProviderInstalledWithException) { | 152 TestIsSearchProviderInstalledWithException) { |
154 // Change the url for the test page to one that throws an exception when | 153 // Change the url for the test page to one that throws an exception when |
155 // toString is called on the argument given to isSearchProviderInstalled. | 154 // toString is called on the argument given to isSearchProviderInstalled. |
156 search_provider_test_url_ = test_server()->GetURL( | 155 search_provider_test_url_ = embedded_test_server()->GetURL( |
157 "files/is_search_provider_installed_with_exception.html"); | 156 "/is_search_provider_installed_with_exception.html"); |
158 | 157 |
159 FinishIsSearchProviderInstalledTest(StartIsSearchProviderInstalledTest( | 158 FinishIsSearchProviderInstalledTest(StartIsSearchProviderInstalledTest( |
160 browser(), "www.google.com", "")); | 159 browser(), "www.google.com", "")); |
161 } | 160 } |
OLD | NEW |