OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/test/base/in_process_browser_test.h" | 5 #include "chrome/test/base/in_process_browser_test.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/debug/stack_trace.h" | 8 #include "base/debug/stack_trace.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
27 #include "chrome/common/logging_chrome.h" | 27 #include "chrome/common/logging_chrome.h" |
28 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
29 #include "chrome/test/base/test_launcher_utils.h" | 29 #include "chrome/test/base/test_launcher_utils.h" |
30 #include "chrome/test/base/testing_browser_process.h" | 30 #include "chrome/test/base/testing_browser_process.h" |
31 #include "chrome/test/base/ui_test_utils.h" | 31 #include "chrome/test/base/ui_test_utils.h" |
32 #include "content/browser/browser_thread.h" | 32 #include "content/browser/browser_thread.h" |
33 #include "content/browser/renderer_host/render_process_host.h" | 33 #include "content/browser/renderer_host/render_process_host.h" |
34 #include "content/browser/tab_contents/tab_contents.h" | 34 #include "content/browser/tab_contents/tab_contents.h" |
35 #include "content/common/content_notification_types.h" | 35 #include "content/common/content_notification_types.h" |
36 #include "content/common/main_function_params.h" | |
37 #include "content/renderer/mock_content_renderer_client.h" | 36 #include "content/renderer/mock_content_renderer_client.h" |
38 #include "net/base/mock_host_resolver.h" | |
39 #include "net/test/test_server.h" | 37 #include "net/test/test_server.h" |
40 #include "sandbox/src/dep.h" | |
41 | |
42 #if defined(OS_MACOSX) | |
43 #include "base/mac/mac_util.h" | |
44 #include "base/system_monitor/system_monitor.h" | |
45 #endif | |
46 | 38 |
47 #if defined(OS_CHROMEOS) | 39 #if defined(OS_CHROMEOS) |
48 #include "chrome/browser/chromeos/audio_handler.h" | 40 #include "chrome/browser/chromeos/audio_handler.h" |
49 #endif | 41 #endif |
50 | 42 |
51 extern int BrowserMain(const MainFunctionParams&); | |
52 | |
53 // Passed as value of kTestType. | 43 // Passed as value of kTestType. |
54 static const char kBrowserTestType[] = "browser"; | 44 static const char kBrowserTestType[] = "browser"; |
55 | 45 |
56 InProcessBrowserTest::InProcessBrowserTest() | 46 InProcessBrowserTest::InProcessBrowserTest() |
57 : browser_(NULL), | 47 : browser_(NULL), |
58 show_window_(false), | 48 show_window_(false), |
59 dom_automation_enabled_(false), | 49 dom_automation_enabled_(false), |
60 tab_closeable_state_watcher_enabled_(false) { | 50 tab_closeable_state_watcher_enabled_(false) { |
61 #if defined(OS_MACOSX) | |
62 base::mac::SetOverrideAmIBundled(true); | |
63 base::SystemMonitor::AllocateSystemIOPorts(); | |
64 #endif | |
65 | |
66 // Before we run the browser, we have to hack the path to the exe to match | 51 // Before we run the browser, we have to hack the path to the exe to match |
67 // what it would be if Chrome was running, because it is used to fork renderer | 52 // what it would be if Chrome was running, because it is used to fork renderer |
68 // processes, on Linux at least (failure to do so will cause a browser_test to | 53 // processes, on Linux at least (failure to do so will cause a browser_test to |
69 // be run instead of a renderer). | 54 // be run instead of a renderer). |
70 FilePath chrome_path; | 55 FilePath chrome_path; |
71 CHECK(PathService::Get(base::FILE_EXE, &chrome_path)); | 56 CHECK(PathService::Get(base::FILE_EXE, &chrome_path)); |
72 chrome_path = chrome_path.DirName(); | 57 chrome_path = chrome_path.DirName(); |
73 chrome_path = chrome_path.Append(chrome::kBrowserProcessExecutablePath); | 58 chrome_path = chrome_path.Append(chrome::kBrowserProcessExecutablePath); |
74 CHECK(PathService::Override(base::FILE_EXE, chrome_path)); | 59 CHECK(PathService::Override(base::FILE_EXE, chrome_path)); |
75 | 60 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 content::GetContentClient()->set_renderer( | 97 content::GetContentClient()->set_renderer( |
113 single_process_renderer_client_.get()); | 98 single_process_renderer_client_.get()); |
114 } | 99 } |
115 | 100 |
116 #if defined(OS_CHROMEOS) | 101 #if defined(OS_CHROMEOS) |
117 // Make sure that the log directory exists. | 102 // Make sure that the log directory exists. |
118 FilePath log_dir = logging::GetSessionLogFile(*command_line).DirName(); | 103 FilePath log_dir = logging::GetSessionLogFile(*command_line).DirName(); |
119 file_util::CreateDirectory(log_dir); | 104 file_util::CreateDirectory(log_dir); |
120 #endif // defined(OS_CHROMEOS) | 105 #endif // defined(OS_CHROMEOS) |
121 | 106 |
122 host_resolver_ = new net::RuleBasedHostResolverProc(NULL); | 107 BrowserTestBase::SetUp(); |
123 | |
124 // Something inside the browser does this lookup implicitly. Make it fail | |
125 // to avoid external dependency. It won't break the tests. | |
126 host_resolver_->AddSimulatedFailure("*.google.com"); | |
127 | |
128 // See http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol | |
129 // We don't want the test code to use it. | |
130 host_resolver_->AddSimulatedFailure("wpad"); | |
131 | |
132 net::ScopedDefaultHostResolverProc scoped_host_resolver_proc( | |
133 host_resolver_.get()); | |
134 | |
135 SandboxInitWrapper sandbox_wrapper; | |
136 MainFunctionParams params(*command_line, sandbox_wrapper, NULL); | |
137 params.ui_task = | |
138 NewRunnableMethod(this, &InProcessBrowserTest::RunTestOnMainThreadLoop); | |
139 | |
140 SetUpInProcessBrowserTestFixture(); | |
141 BrowserMain(params); | |
142 TearDownInProcessBrowserTestFixture(); | |
143 } | 108 } |
144 | 109 |
145 void InProcessBrowserTest::PrepareTestCommandLine(CommandLine* command_line) { | 110 void InProcessBrowserTest::PrepareTestCommandLine(CommandLine* command_line) { |
146 // Propagate commandline settings from test_launcher_utils. | 111 // Propagate commandline settings from test_launcher_utils. |
147 test_launcher_utils::PrepareBrowserCommandLineForTests(command_line); | 112 test_launcher_utils::PrepareBrowserCommandLineForTests(command_line); |
148 | 113 |
149 if (dom_automation_enabled_) | 114 if (dom_automation_enabled_) |
150 command_line->AppendSwitch(switches::kDomAutomationController); | 115 command_line->AppendSwitch(switches::kDomAutomationController); |
151 | 116 |
152 // This is a Browser test. | 117 // This is a Browser test. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 LOG(ERROR) << "Could not create temporary user data directory \"" | 157 LOG(ERROR) << "Could not create temporary user data directory \"" |
193 << temp_user_data_dir_.path().value() << "\"."; | 158 << temp_user_data_dir_.path().value() << "\"."; |
194 return false; | 159 return false; |
195 } | 160 } |
196 } | 161 } |
197 return test_launcher_utils::OverrideUserDataDir(user_data_dir); | 162 return test_launcher_utils::OverrideUserDataDir(user_data_dir); |
198 } | 163 } |
199 | 164 |
200 void InProcessBrowserTest::TearDown() { | 165 void InProcessBrowserTest::TearDown() { |
201 DCHECK(!g_browser_process); | 166 DCHECK(!g_browser_process); |
| 167 BrowserTestBase::TearDown(); |
202 } | 168 } |
203 | 169 |
204 void InProcessBrowserTest::AddTabAtIndexToBrowser( | 170 void InProcessBrowserTest::AddTabAtIndexToBrowser( |
205 Browser* browser, | 171 Browser* browser, |
206 int index, | 172 int index, |
207 const GURL& url, | 173 const GURL& url, |
208 PageTransition::Type transition) { | 174 PageTransition::Type transition) { |
209 browser::NavigateParams params(browser, url, transition); | 175 browser::NavigateParams params(browser, url, transition); |
210 params.tabstrip_index = index; | 176 params.tabstrip_index = index; |
211 params.disposition = NEW_FOREGROUND_TAB; | 177 params.disposition = NEW_FOREGROUND_TAB; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 return; | 275 return; |
310 | 276 |
311 // Invoke CloseAllBrowsersAndMayExit on a running message loop. | 277 // Invoke CloseAllBrowsersAndMayExit on a running message loop. |
312 // CloseAllBrowsersAndMayExit exits the message loop after everything has been | 278 // CloseAllBrowsersAndMayExit exits the message loop after everything has been |
313 // shut down properly. | 279 // shut down properly. |
314 MessageLoopForUI::current()->PostTask( | 280 MessageLoopForUI::current()->PostTask( |
315 FROM_HERE, | 281 FROM_HERE, |
316 NewRunnableFunction(&BrowserList::AttemptExit)); | 282 NewRunnableFunction(&BrowserList::AttemptExit)); |
317 ui_test_utils::RunMessageLoop(); | 283 ui_test_utils::RunMessageLoop(); |
318 } | 284 } |
OLD | NEW |