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

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

Issue 7629019: Revert 96556 - Let pyauto create an attached webdriver instance to manipulate web pages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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
« no previous file with comments | « chrome/test/webdriver/automation.h ('k') | chrome/test/webdriver/commands/create_session.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/automation.h" 5 #include "chrome/test/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
11 #include "base/base_paths.h" 11 #include "base/base_paths.h"
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/command_line.h"
14 #include "base/environment.h" 15 #include "base/environment.h"
15 #include "base/file_path.h" 16 #include "base/file_path.h"
16 #include "base/file_util.h" 17 #include "base/file_util.h"
17 #include "base/json/json_writer.h" 18 #include "base/json/json_writer.h"
18 #include "base/logging.h" 19 #include "base/logging.h"
19 #include "base/memory/ref_counted.h" 20 #include "base/memory/ref_counted.h"
20 #include "base/path_service.h" 21 #include "base/path_service.h"
21 #include "base/string_number_conversions.h" 22 #include "base/string_number_conversions.h"
22 #include "base/string_split.h" 23 #include "base/string_split.h"
23 #include "base/stringprintf.h" 24 #include "base/stringprintf.h"
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 // Step 3: For each browser exe path, check each location to see if the 177 // Step 3: For each browser exe path, check each location to see if the
177 // browser is installed there. Check the chromium locations lastly. 178 // browser is installed there. Check the chromium locations lastly.
178 return CheckForChromeExe(browser_exes, locations, browser_exe) || 179 return CheckForChromeExe(browser_exes, locations, browser_exe) ||
179 CheckForChromeExe(browser_exes, chromium_locations, browser_exe); 180 CheckForChromeExe(browser_exes, chromium_locations, browser_exe);
180 } 181 }
181 182
182 } // namespace 183 } // namespace
183 184
184 namespace webdriver { 185 namespace webdriver {
185 186
186 Automation::BrowserOptions::BrowserOptions()
187 : cmdline(CommandLine::NO_PROGRAM) {}
188
189 Automation::BrowserOptions::~BrowserOptions() {}
190
191 Automation::Automation() {} 187 Automation::Automation() {}
192 188
193 Automation::~Automation() {} 189 Automation::~Automation() {}
194 190
195 void Automation::Init(const BrowserOptions& options, Error** error) { 191 void Automation::Init(const CommandLine& options,
196 CommandLine cmdline = options.cmdline; 192 const FilePath& user_data_dir,
197 if (cmdline.GetProgram().empty()) { 193 Error** error) {
198 FilePath browser_exe; 194 FilePath browser_exe;
199 if (!GetDefaultChromeExe(&browser_exe)) { 195 if (!GetDefaultChromeExe(&browser_exe)) {
200 *error = new Error(kUnknownError, "Could not find default Chrome binary"); 196 *error = new Error(kUnknownError, "Could not find default Chrome binary");
201 return; 197 return;
202 }
203 cmdline.SetProgram(browser_exe);
204 } 198 }
205 if (!file_util::PathExists(cmdline.GetProgram())) { 199
200 InitWithBrowserPath(browser_exe, user_data_dir, options, error);
201 }
202
203 void Automation::InitWithBrowserPath(const FilePath& browser_exe,
204 const FilePath& user_data_dir,
205 const CommandLine& options,
206 Error** error) {
207 if (!file_util::PathExists(browser_exe)) {
206 std::string message = base::StringPrintf( 208 std::string message = base::StringPrintf(
207 "Could not find Chrome binary at: %" PRFilePath, 209 "Could not find Chrome binary at: %" PRFilePath,
208 cmdline.GetProgram().value().c_str()); 210 browser_exe.value().c_str());
209 *error = new Error(kUnknownError, message); 211 *error = new Error(kUnknownError, message);
210 return; 212 return;
211 } 213 }
212 std::string chrome_details = base::StringPrintf(
213 "Using Chrome binary at: %" PRFilePath,
214 cmdline.GetProgram().value().c_str());
215 LOG(INFO) << chrome_details;
216 214
217 cmdline.AppendSwitch(switches::kDisableHangMonitor); 215 CommandLine command(browser_exe);
218 cmdline.AppendSwitch(switches::kDisablePromptOnRepost); 216 command.AppendSwitch(switches::kDisableHangMonitor);
219 cmdline.AppendSwitch(switches::kDomAutomationController); 217 command.AppendSwitch(switches::kDisablePromptOnRepost);
220 cmdline.AppendSwitch(switches::kFullMemoryCrashReport); 218 command.AppendSwitch(switches::kDomAutomationController);
221 cmdline.AppendSwitch(switches::kNoDefaultBrowserCheck); 219 command.AppendSwitch(switches::kFullMemoryCrashReport);
222 cmdline.AppendSwitch(switches::kNoFirstRun); 220 command.AppendSwitch(switches::kNoDefaultBrowserCheck);
221 command.AppendSwitch(switches::kNoFirstRun);
222 command.AppendSwitchASCII(switches::kTestType, "webdriver");
223 223
224 if (options.user_data_dir.empty()) 224 if (user_data_dir.empty())
225 cmdline.AppendSwitchASCII(switches::kHomePage, chrome::kAboutBlankURL); 225 command.AppendSwitchASCII(switches::kHomePage, chrome::kAboutBlankURL);
226 226
227 if (options.channel_id.empty()) { 227 command.AppendArguments(options, false);
228 launcher_.reset(new AnonymousProxyLauncher(false));
229 } else {
230 launcher_.reset(new NamedProxyLauncher(options.channel_id, false, false));
231 }
232 228
229 launcher_.reset(new AnonymousProxyLauncher(false));
233 ProxyLauncher::LaunchState launch_props = { 230 ProxyLauncher::LaunchState launch_props = {
234 false, // clear_profile 231 false, // clear_profile
235 options.user_data_dir, // template_user_data 232 user_data_dir, // template_user_data
236 base::Closure(), 233 base::Closure(),
237 cmdline, 234 command,
238 true, // include_testing_id 235 true, // include_testing_id
239 true // show_window 236 true // show_window
240 }; 237 };
241 if (!launcher_->InitializeConnection(launch_props, true)) { 238
242 LOG(ERROR) << "Failed to initialize connection"; 239 std::string chrome_details = base::StringPrintf(
240 "Using Chrome binary at: %" PRFilePath,
241 browser_exe.value().c_str());
242 LOG(INFO) << chrome_details;
243
244 if (!launcher_->LaunchBrowserAndServer(launch_props, true)) {
243 *error = new Error( 245 *error = new Error(
244 kUnknownError, 246 kUnknownError,
245 "Unable to either launch or connect to Chrome. Please check that " 247 "Unable to either launch or connect to Chrome. Please check that "
246 "ChromeDriver is up-to-date. " + chrome_details); 248 "ChromeDriver is up-to-date. " + chrome_details);
247 return; 249 return;
248 } 250 }
249 251
250 launcher_->automation()->set_action_timeout_ms(base::kNoTimeout); 252 launcher_->automation()->set_action_timeout_ms(base::kNoTimeout);
251 LOG(INFO) << "Chrome launched successfully. Version: " 253 LOG(INFO) << "Chrome launched successfully. Version: "
252 << automation()->server_version(); 254 << automation()->server_version();
253 255
256 bool has_automation_version = false;
257 *error = CompareVersion(730, 0, &has_automation_version);
258 if (*error)
259 return;
260
254 chrome_details += ", version (" + automation()->server_version() + ")"; 261 chrome_details += ", version (" + automation()->server_version() + ")";
255 int version = 0; 262 if (has_automation_version) {
256 std::string error_msg; 263 int version = 0;
257 if (!SendGetChromeDriverAutomationVersion( 264 std::string error_msg;
258 automation(), &version, &error_msg)) { 265 if (!SendGetChromeDriverAutomationVersion(
259 *error = new Error(kUnknownError, error_msg + " " + chrome_details); 266 automation(), &version, &error_msg)) {
260 return; 267 *error = new Error(kUnknownError, error_msg + " " + chrome_details);
261 } 268 return;
262 if (version > automation::kChromeDriverAutomationVersion) { 269 }
263 *error = new Error( 270 if (version > automation::kChromeDriverAutomationVersion) {
264 kUnknownError, 271 *error = new Error(
265 "ChromeDriver is not compatible with this version of Chrome. " + 272 kUnknownError,
266 chrome_details); 273 "ChromeDriver is not compatible with this version of Chrome. " +
267 return; 274 chrome_details);
275 return;
276 }
268 } 277 }
269 } 278 }
270 279
271 void Automation::Terminate() { 280 void Automation::Terminate() {
272 if (launcher_.get() && launcher_->process() != base::kNullProcessHandle) { 281 if (launcher_.get() && launcher_->process() != base::kNullProcessHandle) {
273 launcher_->QuitBrowser(); 282 launcher_->QuitBrowser();
274 } 283 }
275 } 284 }
276 285
277 void Automation::ExecuteScript(int tab_id, 286 void Automation::ExecuteScript(int tab_id,
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 768, 0, "Alerts are not supported for this version of Chrome"); 720 768, 0, "Alerts are not supported for this version of Chrome");
712 } 721 }
713 722
714 Error* Automation::CheckAdvancedInteractionsSupported() { 723 Error* Automation::CheckAdvancedInteractionsSupported() {
715 const char* message = 724 const char* message =
716 "Advanced user interactions are not supported for this version of Chrome"; 725 "Advanced user interactions are not supported for this version of Chrome";
717 return CheckVersion(750, 0, message); 726 return CheckVersion(750, 0, message);
718 } 727 }
719 728
720 } // namespace webdriver 729 } // namespace webdriver
OLDNEW
« no previous file with comments | « chrome/test/webdriver/automation.h ('k') | chrome/test/webdriver/commands/create_session.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698