| 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" | 37 #include "net/base/mock_host_resolver.h" |
| 39 #include "net/test/test_server.h" | 38 #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 | 39 |
| 47 #if defined(OS_CHROMEOS) | 40 #if defined(OS_CHROMEOS) |
| 48 #include "chrome/browser/chromeos/audio_handler.h" | 41 #include "chrome/browser/chromeos/audio_handler.h" |
| 49 #endif | 42 #endif |
| 50 | 43 |
| 51 extern int BrowserMain(const MainFunctionParams&); | |
| 52 | |
| 53 // Passed as value of kTestType. | 44 // Passed as value of kTestType. |
| 54 static const char kBrowserTestType[] = "browser"; | 45 static const char kBrowserTestType[] = "browser"; |
| 55 | 46 |
| 56 InProcessBrowserTest::InProcessBrowserTest() | 47 InProcessBrowserTest::InProcessBrowserTest() |
| 57 : browser_(NULL), | 48 : browser_(NULL), |
| 58 show_window_(false), | 49 show_window_(false), |
| 59 dom_automation_enabled_(false), | 50 dom_automation_enabled_(false), |
| 60 tab_closeable_state_watcher_enabled_(false) { | 51 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 | 52 // 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 | 53 // 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 | 54 // processes, on Linux at least (failure to do so will cause a browser_test to |
| 69 // be run instead of a renderer). | 55 // be run instead of a renderer). |
| 70 FilePath chrome_path; | 56 FilePath chrome_path; |
| 71 CHECK(PathService::Get(base::FILE_EXE, &chrome_path)); | 57 CHECK(PathService::Get(base::FILE_EXE, &chrome_path)); |
| 72 chrome_path = chrome_path.DirName(); | 58 chrome_path = chrome_path.DirName(); |
| 73 chrome_path = chrome_path.Append(chrome::kBrowserProcessExecutablePath); | 59 chrome_path = chrome_path.Append(chrome::kBrowserProcessExecutablePath); |
| 74 CHECK(PathService::Override(base::FILE_EXE, chrome_path)); | 60 CHECK(PathService::Override(base::FILE_EXE, chrome_path)); |
| 75 | 61 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 // to avoid external dependency. It won't break the tests. | 111 // to avoid external dependency. It won't break the tests. |
| 126 host_resolver_->AddSimulatedFailure("*.google.com"); | 112 host_resolver_->AddSimulatedFailure("*.google.com"); |
| 127 | 113 |
| 128 // See http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol | 114 // See http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol |
| 129 // We don't want the test code to use it. | 115 // We don't want the test code to use it. |
| 130 host_resolver_->AddSimulatedFailure("wpad"); | 116 host_resolver_->AddSimulatedFailure("wpad"); |
| 131 | 117 |
| 132 net::ScopedDefaultHostResolverProc scoped_host_resolver_proc( | 118 net::ScopedDefaultHostResolverProc scoped_host_resolver_proc( |
| 133 host_resolver_.get()); | 119 host_resolver_.get()); |
| 134 | 120 |
| 135 SandboxInitWrapper sandbox_wrapper; | 121 BrowserTestBase::SetUp(); |
| 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 } | 122 } |
| 144 | 123 |
| 145 void InProcessBrowserTest::PrepareTestCommandLine(CommandLine* command_line) { | 124 void InProcessBrowserTest::PrepareTestCommandLine(CommandLine* command_line) { |
| 146 // Propagate commandline settings from test_launcher_utils. | 125 // Propagate commandline settings from test_launcher_utils. |
| 147 test_launcher_utils::PrepareBrowserCommandLineForTests(command_line); | 126 test_launcher_utils::PrepareBrowserCommandLineForTests(command_line); |
| 148 | 127 |
| 149 if (dom_automation_enabled_) | 128 if (dom_automation_enabled_) |
| 150 command_line->AppendSwitch(switches::kDomAutomationController); | 129 command_line->AppendSwitch(switches::kDomAutomationController); |
| 151 | 130 |
| 152 // This is a Browser test. | 131 // 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 \"" | 171 LOG(ERROR) << "Could not create temporary user data directory \"" |
| 193 << temp_user_data_dir_.path().value() << "\"."; | 172 << temp_user_data_dir_.path().value() << "\"."; |
| 194 return false; | 173 return false; |
| 195 } | 174 } |
| 196 } | 175 } |
| 197 return test_launcher_utils::OverrideUserDataDir(user_data_dir); | 176 return test_launcher_utils::OverrideUserDataDir(user_data_dir); |
| 198 } | 177 } |
| 199 | 178 |
| 200 void InProcessBrowserTest::TearDown() { | 179 void InProcessBrowserTest::TearDown() { |
| 201 DCHECK(!g_browser_process); | 180 DCHECK(!g_browser_process); |
| 181 BrowserTestBase::TearDown(); |
| 202 } | 182 } |
| 203 | 183 |
| 204 void InProcessBrowserTest::AddTabAtIndexToBrowser( | 184 void InProcessBrowserTest::AddTabAtIndexToBrowser( |
| 205 Browser* browser, | 185 Browser* browser, |
| 206 int index, | 186 int index, |
| 207 const GURL& url, | 187 const GURL& url, |
| 208 PageTransition::Type transition) { | 188 PageTransition::Type transition) { |
| 209 browser::NavigateParams params(browser, url, transition); | 189 browser::NavigateParams params(browser, url, transition); |
| 210 params.tabstrip_index = index; | 190 params.tabstrip_index = index; |
| 211 params.disposition = NEW_FOREGROUND_TAB; | 191 params.disposition = NEW_FOREGROUND_TAB; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 return; | 289 return; |
| 310 | 290 |
| 311 // Invoke CloseAllBrowsersAndMayExit on a running message loop. | 291 // Invoke CloseAllBrowsersAndMayExit on a running message loop. |
| 312 // CloseAllBrowsersAndMayExit exits the message loop after everything has been | 292 // CloseAllBrowsersAndMayExit exits the message loop after everything has been |
| 313 // shut down properly. | 293 // shut down properly. |
| 314 MessageLoopForUI::current()->PostTask( | 294 MessageLoopForUI::current()->PostTask( |
| 315 FROM_HERE, | 295 FROM_HERE, |
| 316 NewRunnableFunction(&BrowserList::AttemptExit)); | 296 NewRunnableFunction(&BrowserList::AttemptExit)); |
| 317 ui_test_utils::RunMessageLoop(); | 297 ui_test_utils::RunMessageLoop(); |
| 318 } | 298 } |
| OLD | NEW |