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

Side by Side Diff: chrome/test/webdriver/webdriver_automation.cc

Issue 7648053: [chromedriver] Add chrome.detach option for configuring Chrome not to quit (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win compile issue Created 9 years, 4 months 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 | Annotate | Revision Log
OLDNEW
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/webdriver/webdriver_automation.h" 5 #include "chrome/test/webdriver/webdriver_automation.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #endif 9 #endif
10 10
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 // browser is installed there. Check the chromium locations lastly. 177 // browser is installed there. Check the chromium locations lastly.
178 return CheckForChromeExe(browser_exes, locations, browser_exe) || 178 return CheckForChromeExe(browser_exes, locations, browser_exe) ||
179 CheckForChromeExe(browser_exes, chromium_locations, browser_exe); 179 CheckForChromeExe(browser_exes, chromium_locations, browser_exe);
180 } 180 }
181 181
182 } // namespace 182 } // namespace
183 183
184 namespace webdriver { 184 namespace webdriver {
185 185
186 Automation::BrowserOptions::BrowserOptions() 186 Automation::BrowserOptions::BrowserOptions()
187 : command(CommandLine::NO_PROGRAM) {} 187 : command(CommandLine::NO_PROGRAM),
188 detach_process(false) {}
188 189
189 Automation::BrowserOptions::~BrowserOptions() {} 190 Automation::BrowserOptions::~BrowserOptions() {}
190 191
191 Automation::Automation() {} 192 Automation::Automation() {}
192 193
193 Automation::~Automation() {} 194 Automation::~Automation() {}
194 195
195 void Automation::Init(const BrowserOptions& options, Error** error) { 196 void Automation::Init(const BrowserOptions& options, Error** error) {
196 // Prepare Chrome's command line. 197 // Prepare Chrome's command line.
197 CommandLine command(CommandLine::NO_PROGRAM); 198 CommandLine command(CommandLine::NO_PROGRAM);
198 command.AppendSwitch(switches::kDisableHangMonitor); 199 command.AppendSwitch(switches::kDisableHangMonitor);
199 command.AppendSwitch(switches::kDisablePromptOnRepost); 200 command.AppendSwitch(switches::kDisablePromptOnRepost);
200 command.AppendSwitch(switches::kDomAutomationController); 201 command.AppendSwitch(switches::kDomAutomationController);
201 command.AppendSwitch(switches::kFullMemoryCrashReport); 202 command.AppendSwitch(switches::kFullMemoryCrashReport);
202 command.AppendSwitch(switches::kNoDefaultBrowserCheck); 203 command.AppendSwitch(switches::kNoDefaultBrowserCheck);
203 command.AppendSwitch(switches::kNoFirstRun); 204 command.AppendSwitch(switches::kNoFirstRun);
205 if (options.detach_process)
206 command.AppendSwitch(switches::kAutomationReinitializeOnChannelError);
204 if (options.user_data_dir.empty()) 207 if (options.user_data_dir.empty())
205 command.AppendSwitchASCII(switches::kHomePage, chrome::kAboutBlankURL); 208 command.AppendSwitchASCII(switches::kHomePage, chrome::kAboutBlankURL);
206 209
207 command.AppendArguments(options.command, true /* include_program */); 210 command.AppendArguments(options.command, true /* include_program */);
208 211
209 // Find the Chrome binary. 212 // Find the Chrome binary.
210 if (command.GetProgram().empty()) { 213 if (command.GetProgram().empty()) {
211 FilePath browser_exe; 214 FilePath browser_exe;
212 if (!GetDefaultChromeExe(&browser_exe)) { 215 if (!GetDefaultChromeExe(&browser_exe)) {
213 *error = new Error(kUnknownError, "Could not find default Chrome binary"); 216 *error = new Error(kUnknownError, "Could not find default Chrome binary");
214 return; 217 return;
215 } 218 }
216 command.SetProgram(browser_exe); 219 command.SetProgram(browser_exe);
217 } 220 }
218 if (!file_util::PathExists(command.GetProgram())) { 221 if (!file_util::PathExists(command.GetProgram())) {
219 std::string message = base::StringPrintf( 222 std::string message = base::StringPrintf(
220 "Could not find Chrome binary at: %" PRFilePath, 223 "Could not find Chrome binary at: %" PRFilePath,
221 command.GetProgram().value().c_str()); 224 command.GetProgram().value().c_str());
222 *error = new Error(kUnknownError, message); 225 *error = new Error(kUnknownError, message);
223 return; 226 return;
224 } 227 }
225 std::string chrome_details = base::StringPrintf( 228 std::string chrome_details = base::StringPrintf(
226 "Using Chrome binary at: %" PRFilePath, 229 "Using Chrome binary at: %" PRFilePath,
227 command.GetProgram().value().c_str()); 230 command.GetProgram().value().c_str());
228 LOG(INFO) << chrome_details; 231 LOG(INFO) << chrome_details;
229 232
230 // Create the ProxyLauncher and launch Chrome. 233 // Create the ProxyLauncher and launch Chrome.
231 if (options.channel_id.empty()) { 234 // In Chrome 13/14, the only way to detach the browser process is to use a
235 // named proxy launcher.
236 // TODO(kkania): Remove this when Chrome 15 is stable.
237 std::string channel_id = options.channel_id;
238 bool launch_browser = false;
239 if (options.detach_process) {
240 launch_browser = true;
241 if (!channel_id.empty()) {
242 *error = new Error(
243 kUnknownError, "Cannot detach an already running browser process");
244 return;
245 }
246 #if defined(OS_WIN)
247 channel_id = "chromedriver" + GenerateRandomID();
248 #elif defined(OS_POSIX)
249 FilePath temp_file;
250 if (!file_util::CreateTemporaryFile(&temp_file) ||
251 !file_util::Delete(temp_file, false /* recursive */)) {
252 *error = new Error(kUnknownError, "Could not create temporary filename");
253 return;
254 }
255 channel_id = temp_file.value();
256 #endif
257 }
258 if (channel_id.empty()) {
232 launcher_.reset(new AnonymousProxyLauncher(false)); 259 launcher_.reset(new AnonymousProxyLauncher(false));
233 } else { 260 } else {
234 launcher_.reset(new NamedProxyLauncher(options.channel_id, false, false)); 261 LOG(INFO) << "Using named testing interface";
262 launcher_.reset(new NamedProxyLauncher(channel_id, launch_browser, false));
235 } 263 }
236 ProxyLauncher::LaunchState launch_props = { 264 ProxyLauncher::LaunchState launch_props = {
237 false, // clear_profile 265 false, // clear_profile
238 options.user_data_dir, // template_user_data 266 options.user_data_dir, // template_user_data
239 base::Closure(), 267 base::Closure(),
240 command, 268 command,
241 true, // include_testing_id 269 true, // include_testing_id
242 true // show_window 270 true // show_window
243 }; 271 };
244 if (!launcher_->InitializeConnection(launch_props, true)) { 272 if (!launcher_->InitializeConnection(launch_props, true)) {
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 768, 0, "Alerts are not supported for this version of Chrome"); 749 768, 0, "Alerts are not supported for this version of Chrome");
722 } 750 }
723 751
724 Error* Automation::CheckAdvancedInteractionsSupported() { 752 Error* Automation::CheckAdvancedInteractionsSupported() {
725 const char* message = 753 const char* message =
726 "Advanced user interactions are not supported for this version of Chrome"; 754 "Advanced user interactions are not supported for this version of Chrome";
727 return CheckVersion(750, 0, message); 755 return CheckVersion(750, 0, message);
728 } 756 }
729 757
730 } // namespace webdriver 758 } // namespace webdriver
OLDNEW
« no previous file with comments | « chrome/test/webdriver/webdriver_automation.h ('k') | chrome/test/webdriver/webdriver_dispatch.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698