summaryrefslogtreecommitdiffstats
path: root/chrome/test/webdriver
diff options
context:
space:
mode:
authorhnguyen@chromium.org <hnguyen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-17 20:14:20 +0000
committerhnguyen@chromium.org <hnguyen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-17 20:14:20 +0000
commitc4bdfe6586f6dd43c69102e4306872da504a1942 (patch)
tree0dd0299c8870fd65c5b185b8fde5e6156b2edaa2 /chrome/test/webdriver
parent16f91e72d16cdb3bf529e025ba12ccb7fb6830b0 (diff)
downloadchromium_src-c4bdfe6586f6dd43c69102e4306872da504a1942.zip
chromium_src-c4bdfe6586f6dd43c69102e4306872da504a1942.tar.gz
chromium_src-c4bdfe6586f6dd43c69102e4306872da504a1942.tar.bz2
In ChromeDriver, allow user to specify location of Chrome executable.
BUG=NONE TEST=NONE Review URL: http://codereview.chromium.org/6982016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85665 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/webdriver')
-rw-r--r--chrome/test/webdriver/automation.cc62
-rw-r--r--chrome/test/webdriver/automation.h11
-rw-r--r--chrome/test/webdriver/commands/create_session.cc9
-rw-r--r--chrome/test/webdriver/session.cc11
-rw-r--r--chrome/test/webdriver/session.h8
5 files changed, 61 insertions, 40 deletions
diff --git a/chrome/test/webdriver/automation.cc b/chrome/test/webdriver/automation.cc
index ddfa662..8e53342 100644
--- a/chrome/test/webdriver/automation.cc
+++ b/chrome/test/webdriver/automation.cc
@@ -36,9 +36,8 @@
namespace {
-// Gets the path to the default Chrome executable directory. Returns true on
-// success.
-bool GetDefaultChromeExeDir(FilePath* browser_directory) {
+// Gets the path to the default Chrome executable. Returns true on success.
+bool GetDefaultChromeExe(FilePath* browser_exe) {
std::vector<FilePath> locations;
// Add the directory which this module resides in.
FilePath module_dir;
@@ -102,9 +101,9 @@ bool GetDefaultChromeExeDir(FilePath* browser_directory) {
// Determine the default directory.
for (size_t i = 0; i < locations.size(); ++i) {
- if (file_util::PathExists(
- locations[i].Append(chrome::kBrowserProcessExecutablePath))) {
- *browser_directory = locations[i];
+ FilePath path = locations[i].Append(chrome::kBrowserProcessExecutablePath);
+ if (file_util::PathExists(path)) {
+ *browser_exe = path;
return true;
}
}
@@ -119,41 +118,52 @@ Automation::Automation() {}
Automation::~Automation() {}
-void Automation::Init(const FilePath& browser_exe,
- const CommandLine& options, ErrorCode* code) {
- FilePath browser = browser_exe;
- if (browser.empty() && !GetDefaultChromeExeDir(&browser)) {
+void Automation::Init(const CommandLine& options,
+ ErrorCode* code) {
+ FilePath browser_exe;
+ if (!GetDefaultChromeExe(&browser_exe)) {
*code = kBrowserCouldNotBeFound;
return;
}
- CommandLine args(CommandLine::NO_PROGRAM);
- args.AppendSwitch(switches::kDisableHangMonitor);
- args.AppendSwitch(switches::kDisablePromptOnRepost);
- args.AppendSwitch(switches::kDomAutomationController);
- args.AppendSwitch(switches::kFullMemoryCrashReport);
- args.AppendSwitchASCII(switches::kHomePage, chrome::kAboutBlankURL);
- args.AppendSwitch(switches::kNoDefaultBrowserCheck);
- args.AppendSwitch(switches::kNoFirstRun);
- args.AppendSwitchASCII(switches::kTestType, "webdriver");
+ InitWithBrowserPath(browser_exe, options, code);
+}
+
+void Automation::InitWithBrowserPath(const FilePath& browser_exe,
+ const CommandLine& options,
+ ErrorCode* code) {
+ if (!file_util::PathExists(browser_exe)) {
+ *code = kBrowserCouldNotBeFound;
+ return;
+ }
- args.AppendArguments(options, false);
+ CommandLine command(browser_exe);
+ command.AppendSwitch(switches::kDisableHangMonitor);
+ command.AppendSwitch(switches::kDisablePromptOnRepost);
+ command.AppendSwitch(switches::kDomAutomationController);
+ command.AppendSwitch(switches::kFullMemoryCrashReport);
+ command.AppendSwitchASCII(switches::kHomePage, chrome::kAboutBlankURL);
+ command.AppendSwitch(switches::kNoDefaultBrowserCheck);
+ command.AppendSwitch(switches::kNoFirstRun);
+ command.AppendSwitchASCII(switches::kTestType, "webdriver");
+
+ command.AppendArguments(options, false);
launcher_.reset(new AnonymousProxyLauncher(false));
ProxyLauncher::LaunchState launch_props = {
false, // clear_profile
FilePath(), // template_user_data
ProxyLauncher::DEFAULT_THEME,
- browser,
- args,
+ command,
true, // include_testing_id
true // show_window
};
- launcher_->LaunchBrowserAndServer(launch_props, true);
- if (!launcher_->IsBrowserRunning()) {
+
+ if (!launcher_->LaunchBrowserAndServer(launch_props, true)) {
*code = kBrowserFailedToStart;
return;
}
+
int version = 0;
if (!SendGetChromeDriverAutomationVersion(automation(), &version) ||
version > automation::kChromeDriverAutomationVersion) {
@@ -164,7 +174,9 @@ void Automation::Init(const FilePath& browser_exe,
}
void Automation::Terminate() {
- launcher_->QuitBrowser();
+ if (launcher_.get() && launcher_->process() != base::kNullProcessHandle) {
+ launcher_->QuitBrowser();
+ }
}
void Automation::ExecuteScript(int tab_id,
diff --git a/chrome/test/webdriver/automation.h b/chrome/test/webdriver/automation.h
index 4d0582d..6b70f63 100644
--- a/chrome/test/webdriver/automation.h
+++ b/chrome/test/webdriver/automation.h
@@ -42,10 +42,13 @@ class Automation {
Automation();
virtual ~Automation();
- // Creates a browser, using the exe found in |browser_exe|. If |browser_exe|
- // is empty, it will search in all the default locations. |options| contains
- // extra parameters to be used on the command line when lauching the browser.
- void Init(const FilePath& browser_exe, const CommandLine& options,
+ // Creates a browser, using the specified |browser_exe|.
+ void InitWithBrowserPath(const FilePath& browser_exe,
+ const CommandLine& options,
+ ErrorCode* code);
+
+ // Start the system's default Chrome binary.
+ void Init(const CommandLine& options,
ErrorCode* code);
// Terminates this session and disconnects its automation proxy. After
diff --git a/chrome/test/webdriver/commands/create_session.cc b/chrome/test/webdriver/commands/create_session.cc
index 4c9d51b..c2f37e2 100644
--- a/chrome/test/webdriver/commands/create_session.cc
+++ b/chrome/test/webdriver/commands/create_session.cc
@@ -31,9 +31,9 @@ CreateSession::~CreateSession() {}
bool CreateSession::DoesPost() { return true; }
void CreateSession::ExecutePost(Response* const response) {
- SessionManager* session_manager = SessionManager::GetInstance();
DictionaryValue *added_options = NULL, *desiredCapabilities = NULL;
CommandLine options(CommandLine::NO_PROGRAM);
+ FilePath user_browser_exe;
if (!GetDictionaryParameter("desiredCapabilities", &desiredCapabilities)) {
desiredCapabilities = NULL;
@@ -59,12 +59,14 @@ void CreateSession::ExecutePost(Response* const response) {
}
++i;
}
+ FilePath::StringType path;
+ desiredCapabilities->GetString("chrome.binary", &path);
+ user_browser_exe = FilePath(path);
}
// Session manages its own liftime, so do not call delete.
Session* session = new Session();
- ErrorCode code = session->Init(session_manager->chrome_dir(),
- options);
+ ErrorCode code = session->Init(user_browser_exe, options);
if (code == kBrowserCouldNotBeFound) {
SET_WEBDRIVER_ERROR(response,
@@ -110,6 +112,7 @@ void CreateSession::ExecutePost(Response* const response) {
VLOG(1) << "Created session " << session->id();
std::ostringstream stream;
+ SessionManager* session_manager = SessionManager::GetInstance();
stream << "http://" << session_manager->GetAddress() << "/session/"
<< session->id();
response->SetStatus(kSeeOther);
diff --git a/chrome/test/webdriver/session.cc b/chrome/test/webdriver/session.cc
index 1f60ff7..85e673b 100644
--- a/chrome/test/webdriver/session.cc
+++ b/chrome/test/webdriver/session.cc
@@ -70,7 +70,7 @@ Session::~Session() {
SessionManager::GetInstance()->Remove(id_);
}
-ErrorCode Session::Init(const FilePath& browser_dir,
+ErrorCode Session::Init(const FilePath& browser_exe,
const CommandLine& options) {
if (!thread_.Start()) {
LOG(ERROR) << "Cannot start session thread";
@@ -82,7 +82,7 @@ ErrorCode Session::Init(const FilePath& browser_dir,
RunSessionTask(NewRunnableMethod(
this,
&Session::InitOnSessionThread,
- browser_dir,
+ browser_exe,
options,
&code));
if (code != kSuccess)
@@ -976,11 +976,14 @@ void Session::RunSessionTaskOnSessionThread(Task* task,
done_event->Signal();
}
-void Session::InitOnSessionThread(const FilePath& browser_dir,
+void Session::InitOnSessionThread(const FilePath& browser_exe,
const CommandLine& options,
ErrorCode* code) {
automation_.reset(new Automation());
- automation_->Init(browser_dir, options, code);
+ if (browser_exe.empty())
+ automation_->Init(options, code);
+ else
+ automation_->InitWithBrowserPath(browser_exe, options, code);
if (*code != kSuccess)
return;
diff --git a/chrome/test/webdriver/session.h b/chrome/test/webdriver/session.h
index b515881..9090691 100644
--- a/chrome/test/webdriver/session.h
+++ b/chrome/test/webdriver/session.h
@@ -60,11 +60,11 @@ class Session {
// Removes this |Session| from the |SessionManager|.
~Session();
- // Starts the session thread and a new browser, using the exe found in
- // |browser_dir|. If |browser_dir| is empty, it will search in all the default
+ // Starts the session thread and a new browser, using the exe found at
+ // |browser_exe|. If |browser_exe| is empty, it will search in all the default
// locations. Returns true on success. On failure, the session will delete
// itself and return an error code.
- ErrorCode Init(const FilePath& browser_dir,
+ ErrorCode Init(const FilePath& browser_exe,
const CommandLine& options);
// Terminates this session and deletes itself.
@@ -259,7 +259,7 @@ class Session {
void RunSessionTaskOnSessionThread(
Task* task,
base::WaitableEvent* done_event);
- void InitOnSessionThread(const FilePath& browser_dir,
+ void InitOnSessionThread(const FilePath& browser_exe,
const CommandLine& options,
ErrorCode* code);
void TerminateOnSessionThread();