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

Side by Side Diff: chrome/browser/external_extension_browsertest.cc

Issue 1409163006: Migrating tests to use EmbeddedTestServer (/chrome/browser misc) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 1 month 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
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 "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" 20 #include "net/test/embedded_test_server/embedded_test_server.h"
21 21
22 namespace { 22 namespace {
23 23
24 struct IsSearchProviderTestData { 24 struct IsSearchProviderTestData {
25 IsSearchProviderTestData() : tab(NULL) {} 25 IsSearchProviderTestData() : tab(NULL) {}
26 IsSearchProviderTestData(content::WebContents* t, 26 IsSearchProviderTestData(content::WebContents* t,
27 const std::string& h, 27 const std::string& h,
28 GURL url) 28 GURL url)
29 : tab(t), host(h), test_url(url) {} 29 : tab(t), host(h), test_url(url) {}
30 30
31 content::WebContents* tab; 31 content::WebContents* tab;
32 std::string host; 32 std::string host;
33 GURL test_url; 33 GURL test_url;
34 }; 34 };
35 35
36 } // namespace 36 } // namespace
37 37
38 class SearchProviderTest : public InProcessBrowserTest { 38 class SearchProviderTest : public InProcessBrowserTest {
39 protected: 39 protected:
40 SearchProviderTest() {} 40 SearchProviderTest() {}
41 41
42 void SetUpCommandLine(base::CommandLine* command_line) override { 42 void SetUpCommandLine(base::CommandLine* command_line) override {
43 ASSERT_TRUE(test_server()->Start()); 43 ASSERT_TRUE(embedded_test_server()->Start());
44 44
45 // Map all hosts to our local server. 45 // Map all hosts to our local server.
46 std::string host_rule( 46 std::string host_rule("MAP * " +
47 "MAP * " + test_server()->host_port_pair().ToString()); 47 embedded_test_server()->host_port_pair().ToString());
48 command_line->AppendSwitchASCII(switches::kHostRules, host_rule); 48 command_line->AppendSwitchASCII(switches::kHostRules, host_rule);
49 // Use no proxy or otherwise this test will fail on a machine that has a 49 // Use no proxy or otherwise this test will fail on a machine that has a
50 // proxy configured. 50 // proxy configured.
51 command_line->AppendSwitch(switches::kNoProxyServer); 51 command_line->AppendSwitch(switches::kNoProxyServer);
52 52
53 // Always point google search to a known, non-secure URL. Normally, this 53 // Always point google search to a known, non-secure URL. Normally, this
54 // varies based on locale and is a HTTPS host. 54 // varies based on locale and is a HTTPS host.
55 command_line->AppendSwitchASCII( 55 command_line->AppendSwitchASCII(
56 switches::kGoogleBaseURL, "http://www.google.com"); 56 switches::kGoogleBaseURL, "http://www.google.com");
57 57
58 // Get the url for the test page. 58 // Get the url for the test page.
59 search_provider_test_url_ = 59 search_provider_test_url_ =
60 test_server()->GetURL("files/is_search_provider_installed.html"); 60 embedded_test_server()->GetURL("/is_search_provider_installed.html");
61 } 61 }
62 62
63 void SetUpOnMainThread() override { 63 void SetUpOnMainThread() override {
64 // Force the country to Canada, which has an installed search provider 64 // Force the country to Canada, which has an installed search provider
65 // that's HTTP. 65 // that's HTTP.
66 browser()->profile()->GetPrefs()->SetInteger( 66 browser()->profile()->GetPrefs()->SetInteger(
67 prefs::kCountryIDAtInstall, ('C' << 8) | 'A'); 67 prefs::kCountryIDAtInstall, ('C' << 8) | 'A');
68 } 68 }
69 69
70 IsSearchProviderTestData StartIsSearchProviderInstalledTest( 70 IsSearchProviderTestData StartIsSearchProviderInstalledTest(
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 for (size_t i = 0; i < arraysize(test_data); ++i) { 146 for (size_t i = 0; i < arraysize(test_data); ++i) {
147 FinishIsSearchProviderInstalledTest(test_data[i]); 147 FinishIsSearchProviderInstalledTest(test_data[i]);
148 } 148 }
149 #endif 149 #endif
150 } 150 }
151 151
152 IN_PROC_BROWSER_TEST_F(SearchProviderTest, 152 IN_PROC_BROWSER_TEST_F(SearchProviderTest,
153 TestIsSearchProviderInstalledWithException) { 153 TestIsSearchProviderInstalledWithException) {
154 // Change the url for the test page to one that throws an exception when 154 // Change the url for the test page to one that throws an exception when
155 // toString is called on the argument given to isSearchProviderInstalled. 155 // toString is called on the argument given to isSearchProviderInstalled.
156 search_provider_test_url_ = test_server()->GetURL( 156 search_provider_test_url_ = embedded_test_server()->GetURL(
157 "files/is_search_provider_installed_with_exception.html"); 157 "/is_search_provider_installed_with_exception.html");
158 158
159 FinishIsSearchProviderInstalledTest(StartIsSearchProviderInstalledTest( 159 FinishIsSearchProviderInstalledTest(StartIsSearchProviderInstalledTest(
160 browser(), "www.google.com", "")); 160 browser(), "www.google.com", ""));
161 } 161 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/window_open_apitest.cc ('k') | chrome/browser/fast_shutdown_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698