| Index: chrome/test/webdriver/automation.cc
|
| ===================================================================
|
| --- chrome/test/webdriver/automation.cc (revision 96579)
|
| +++ chrome/test/webdriver/automation.cc (working copy)
|
| @@ -11,6 +11,7 @@
|
| #include "base/base_paths.h"
|
| #include "base/basictypes.h"
|
| #include "base/callback.h"
|
| +#include "base/command_line.h"
|
| #include "base/environment.h"
|
| #include "base/file_path.h"
|
| #include "base/file_util.h"
|
| @@ -183,63 +184,64 @@
|
|
|
| namespace webdriver {
|
|
|
| -Automation::BrowserOptions::BrowserOptions()
|
| - : cmdline(CommandLine::NO_PROGRAM) {}
|
| -
|
| -Automation::BrowserOptions::~BrowserOptions() {}
|
| -
|
| Automation::Automation() {}
|
|
|
| Automation::~Automation() {}
|
|
|
| -void Automation::Init(const BrowserOptions& 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);
|
| +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;
|
| }
|
| - if (!file_util::PathExists(cmdline.GetProgram())) {
|
| +
|
| + 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)) {
|
| std::string message = base::StringPrintf(
|
| "Could not find Chrome binary at: %" PRFilePath,
|
| - cmdline.GetProgram().value().c_str());
|
| + browser_exe.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;
|
|
|
| - cmdline.AppendSwitch(switches::kDisableHangMonitor);
|
| - cmdline.AppendSwitch(switches::kDisablePromptOnRepost);
|
| - cmdline.AppendSwitch(switches::kDomAutomationController);
|
| - cmdline.AppendSwitch(switches::kFullMemoryCrashReport);
|
| - cmdline.AppendSwitch(switches::kNoDefaultBrowserCheck);
|
| - cmdline.AppendSwitch(switches::kNoFirstRun);
|
| + 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");
|
|
|
| - if (options.user_data_dir.empty())
|
| - cmdline.AppendSwitchASCII(switches::kHomePage, chrome::kAboutBlankURL);
|
| + if (user_data_dir.empty())
|
| + command.AppendSwitchASCII(switches::kHomePage, chrome::kAboutBlankURL);
|
|
|
| - if (options.channel_id.empty()) {
|
| - launcher_.reset(new AnonymousProxyLauncher(false));
|
| - } else {
|
| - launcher_.reset(new NamedProxyLauncher(options.channel_id, false, false));
|
| - }
|
| + command.AppendArguments(options, false);
|
|
|
| + launcher_.reset(new AnonymousProxyLauncher(false));
|
| ProxyLauncher::LaunchState launch_props = {
|
| false, // clear_profile
|
| - options.user_data_dir, // template_user_data
|
| + user_data_dir, // template_user_data
|
| base::Closure(),
|
| - cmdline,
|
| + command,
|
| true, // include_testing_id
|
| true // show_window
|
| };
|
| - if (!launcher_->InitializeConnection(launch_props, true)) {
|
| - LOG(ERROR) << "Failed to initialize connection";
|
| +
|
| + 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)) {
|
| *error = new Error(
|
| kUnknownError,
|
| "Unable to either launch or connect to Chrome. Please check that "
|
| @@ -251,21 +253,28 @@
|
| 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() + ")";
|
| - int version = 0;
|
| - std::string error_msg;
|
| - if (!SendGetChromeDriverAutomationVersion(
|
| - automation(), &version, &error_msg)) {
|
| - *error = new Error(kUnknownError, error_msg + " " + chrome_details);
|
| - return;
|
| + 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;
|
| + }
|
| }
|
| - if (version > automation::kChromeDriverAutomationVersion) {
|
| - *error = new Error(
|
| - kUnknownError,
|
| - "ChromeDriver is not compatible with this version of Chrome. " +
|
| - chrome_details);
|
| - return;
|
| - }
|
| }
|
|
|
| void Automation::Terminate() {
|
|
|