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

Unified Diff: chrome/test/webdriver/automation.cc

Issue 7523060: Let pyauto create an attached webdriver instance to manipulate web pages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: move bools into struct Created 9 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/webdriver/automation.cc
diff --git a/chrome/test/webdriver/automation.cc b/chrome/test/webdriver/automation.cc
index 3d7c311d62eb6704a7d1f89df6e5048ad430542a..a63d2c35665d9fff82b53e1ac86038768d11845a 100644
--- a/chrome/test/webdriver/automation.cc
+++ b/chrome/test/webdriver/automation.cc
@@ -10,7 +10,6 @@
#include "base/base_paths.h"
#include "base/callback.h"
-#include "base/command_line.h"
#include "base/environment.h"
#include "base/file_path.h"
#include "base/file_util.h"
@@ -119,64 +118,68 @@ bool GetDefaultChromeExe(FilePath* browser_exe) {
namespace webdriver {
+Automation::InitOptions::InitOptions() : cmdline(CommandLine::NO_PROGRAM) {
+}
+
+Automation::InitOptions::~InitOptions() {
+}
+
Automation::Automation() {}
Automation::~Automation() {}
-void Automation::Init(const CommandLine& options,
- const FilePath& user_data_dir,
- Error** error) {
- FilePath browser_exe;
- if (!GetDefaultChromeExe(&browser_exe)) {
- *error = new Error(kUnknownError, "Could not find default Chrome binary");
- return;
+void Automation::Init(const InitOptions& options, Error** error) {
+ CommandLine cmdline = options.cmdline;
+ if (cmdline.GetProgram().empty()) {
+ FilePath browser_exe;
+ if (!GetDefaultChromeExe(&browser_exe)) {
+ *error = new Error(kUnknownError, "Could not find default Chrome binary");
+ return;
+ }
+ cmdline.SetProgram(browser_exe);
}
-
- InitWithBrowserPath(browser_exe, user_data_dir, options, error);
-}
-
-void Automation::InitWithBrowserPath(const FilePath& browser_exe,
- const FilePath& user_data_dir,
- const CommandLine& options,
- Error** error) {
- if (!file_util::PathExists(browser_exe)) {
+ if (!file_util::PathExists(cmdline.GetProgram())) {
std::string message = base::StringPrintf(
"Could not find Chrome binary at: %" PRFilePath,
- browser_exe.value().c_str());
+ cmdline.GetProgram().value().c_str());
*error = new Error(kUnknownError, message);
return;
}
+ std::string chrome_details = base::StringPrintf(
+ "Using Chrome binary at: %" PRFilePath,
+ cmdline.GetProgram().value().c_str());
+ LOG(INFO) << chrome_details;
- CommandLine command(browser_exe);
- command.AppendSwitch(switches::kDisableHangMonitor);
- command.AppendSwitch(switches::kDisablePromptOnRepost);
- command.AppendSwitch(switches::kDomAutomationController);
- command.AppendSwitch(switches::kFullMemoryCrashReport);
- command.AppendSwitch(switches::kNoDefaultBrowserCheck);
- command.AppendSwitch(switches::kNoFirstRun);
- command.AppendSwitchASCII(switches::kTestType, "webdriver");
+ cmdline.AppendSwitch(switches::kDisableHangMonitor);
+ cmdline.AppendSwitch(switches::kDisablePromptOnRepost);
+ cmdline.AppendSwitch(switches::kDomAutomationController);
+ cmdline.AppendSwitch(switches::kFullMemoryCrashReport);
+ cmdline.AppendSwitch(switches::kNoDefaultBrowserCheck);
+ cmdline.AppendSwitch(switches::kNoFirstRun);
- if (user_data_dir.empty())
- command.AppendSwitchASCII(switches::kHomePage, chrome::kAboutBlankURL);
+ if (options.user_data_dir.empty())
+ cmdline.AppendSwitchASCII(switches::kHomePage, chrome::kAboutBlankURL);
- command.AppendArguments(options, false);
+ if (options.channel_id.empty()) {
+ launcher_.reset(new AnonymousProxyLauncher(false));
+ } else {
+ NamedProxyLauncher::InitParams params;
+ params.launch_browser = false;
+ params.disconnect_on_failure = false;
+ params.wait_for_server_channel = false;
+ launcher_.reset(new NamedProxyLauncher(options.channel_id, params));
+ }
- launcher_.reset(new AnonymousProxyLauncher(false));
ProxyLauncher::LaunchState launch_props = {
false, // clear_profile
- user_data_dir, // template_user_data
+ options.user_data_dir, // template_user_data
base::Closure(),
- command,
+ cmdline,
true, // include_testing_id
true // show_window
};
-
- std::string chrome_details = base::StringPrintf(
- "Using Chrome binary at: %" PRFilePath,
- browser_exe.value().c_str());
- LOG(INFO) << chrome_details;
-
- if (!launcher_->LaunchBrowserAndServer(launch_props, true)) {
+ if (!launcher_->InitializeConnection(launch_props, true)) {
+ LOG(ERROR) << "Failed to initialize connection";
*error = new Error(
kUnknownError,
"Unable to either launch or connect to Chrome. Please check that "
@@ -188,27 +191,20 @@ void Automation::InitWithBrowserPath(const FilePath& browser_exe,
LOG(INFO) << "Chrome launched successfully. Version: "
<< automation()->server_version();
- bool has_automation_version = false;
- *error = CompareVersion(730, 0, &has_automation_version);
- if (*error)
- return;
-
chrome_details += ", version (" + automation()->server_version() + ")";
- if (has_automation_version) {
- int version = 0;
- std::string error_msg;
- if (!SendGetChromeDriverAutomationVersion(
- automation(), &version, &error_msg)) {
- *error = new Error(kUnknownError, error_msg + " " + chrome_details);
- return;
- }
- if (version > automation::kChromeDriverAutomationVersion) {
- *error = new Error(
- kUnknownError,
- "ChromeDriver is not compatible with this version of Chrome. " +
- chrome_details);
- return;
- }
+ int version = 0;
+ std::string error_msg;
+ if (!SendGetChromeDriverAutomationVersion(
+ automation(), &version, &error_msg)) {
+ *error = new Error(kUnknownError, error_msg + " " + chrome_details);
+ return;
+ }
+ if (version > automation::kChromeDriverAutomationVersion) {
+ *error = new Error(
+ kUnknownError,
+ "ChromeDriver is not compatible with this version of Chrome. " +
+ chrome_details);
+ return;
}
}

Powered by Google App Engine
This is Rietveld 408576698