| Index: chrome/test/webdriver/webdriver_session.cc
|
| diff --git a/chrome/test/webdriver/webdriver_session.cc b/chrome/test/webdriver/webdriver_session.cc
|
| index 9ea256dd61bf410ea1e6a82e4ec83698e11fc80c..abb0475a850ee79ecb9c28f71809a209911a6c7d 100644
|
| --- a/chrome/test/webdriver/webdriver_session.cc
|
| +++ b/chrome/test/webdriver/webdriver_session.cc
|
| @@ -56,7 +56,8 @@ FrameId& FrameId::operator=(const FrameId& other) {
|
|
|
| Session::Options::Options()
|
| : use_native_events(false),
|
| - load_async(false) {
|
| + load_async(false),
|
| + no_website_testing_defaults(false) {
|
| }
|
|
|
| Session::Options::~Options() {
|
| @@ -84,11 +85,15 @@ Error* Session::Init(const Automation::BrowserOptions& options) {
|
| }
|
|
|
| Error* error = NULL;
|
| - RunSessionTask(NewRunnableMethod(
|
| - this,
|
| + RunSessionTask(base::Bind(
|
| &Session::InitOnSessionThread,
|
| + base::Unretained(this),
|
| options,
|
| &error));
|
| +
|
| + if (!error)
|
| + error = PostBrowserStartInit();
|
| +
|
| if (error)
|
| Terminate();
|
| return error;
|
| @@ -122,9 +127,9 @@ Error* Session::AfterExecuteCommand() {
|
| }
|
|
|
| void Session::Terminate() {
|
| - RunSessionTask(NewRunnableMethod(
|
| - this,
|
| - &Session::TerminateOnSessionThread));
|
| + RunSessionTask(base::Bind(
|
| + &Session::TerminateOnSessionThread,
|
| + base::Unretained(this)));
|
| delete this;
|
| }
|
|
|
| @@ -262,9 +267,9 @@ Error* Session::SendKeys(const ElementId& element, const string16& keys) {
|
| if (error)
|
| return error;
|
|
|
| - RunSessionTask(NewRunnableMethod(
|
| - this,
|
| + RunSessionTask(base::Bind(
|
| &Session::SendKeysOnSessionThread,
|
| + base::Unretained(this),
|
| keys,
|
| &error));
|
| return error;
|
| @@ -274,9 +279,9 @@ Error* Session::DragAndDropFilePaths(
|
| const Point& location,
|
| const std::vector<FilePath::StringType>& paths) {
|
| Error* error = NULL;
|
| - RunSessionTask(NewRunnableMethod(
|
| - automation_.get(),
|
| + RunSessionTask(base::Bind(
|
| &Automation::DragAndDropFilePaths,
|
| + base::Unretained(automation_.get()),
|
| current_target_.window_id,
|
| location,
|
| paths,
|
| @@ -287,16 +292,16 @@ Error* Session::DragAndDropFilePaths(
|
| Error* Session::NavigateToURL(const std::string& url) {
|
| Error* error = NULL;
|
| if (options_.load_async) {
|
| - RunSessionTask(NewRunnableMethod(
|
| - automation_.get(),
|
| + RunSessionTask(base::Bind(
|
| &Automation::NavigateToURLAsync,
|
| + base::Unretained(automation_.get()),
|
| current_target_.window_id,
|
| url,
|
| &error));
|
| } else {
|
| - RunSessionTask(NewRunnableMethod(
|
| - automation_.get(),
|
| + RunSessionTask(base::Bind(
|
| &Automation::NavigateToURL,
|
| + base::Unretained(automation_.get()),
|
| current_target_.window_id,
|
| url,
|
| &error));
|
| @@ -306,9 +311,9 @@ Error* Session::NavigateToURL(const std::string& url) {
|
|
|
| Error* Session::GoForward() {
|
| Error* error = NULL;
|
| - RunSessionTask(NewRunnableMethod(
|
| - automation_.get(),
|
| + RunSessionTask(base::Bind(
|
| &Automation::GoForward,
|
| + base::Unretained(automation_.get()),
|
| current_target_.window_id,
|
| &error));
|
| return error;
|
| @@ -316,9 +321,9 @@ Error* Session::GoForward() {
|
|
|
| Error* Session::GoBack() {
|
| Error* error = NULL;
|
| - RunSessionTask(NewRunnableMethod(
|
| - automation_.get(),
|
| + RunSessionTask(base::Bind(
|
| &Automation::GoBack,
|
| + base::Unretained(automation_.get()),
|
| current_target_.window_id,
|
| &error));
|
| return error;
|
| @@ -326,9 +331,9 @@ Error* Session::GoBack() {
|
|
|
| Error* Session::Reload() {
|
| Error* error = NULL;
|
| - RunSessionTask(NewRunnableMethod(
|
| - automation_.get(),
|
| + RunSessionTask(base::Bind(
|
| &Automation::Reload,
|
| + base::Unretained(automation_.get()),
|
| current_target_.window_id,
|
| &error));
|
| return error;
|
| @@ -360,9 +365,9 @@ Error* Session::GetTitle(std::string* tab_title) {
|
| Error* Session::MouseMoveAndClick(const Point& location,
|
| automation::MouseButton button) {
|
| Error* error = NULL;
|
| - RunSessionTask(NewRunnableMethod(
|
| - automation_.get(),
|
| + RunSessionTask(base::Bind(
|
| &Automation::MouseClick,
|
| + base::Unretained(automation_.get()),
|
| current_target_.window_id,
|
| location,
|
| button,
|
| @@ -374,9 +379,9 @@ Error* Session::MouseMoveAndClick(const Point& location,
|
|
|
| Error* Session::MouseMove(const Point& location) {
|
| Error* error = NULL;
|
| - RunSessionTask(NewRunnableMethod(
|
| - automation_.get(),
|
| + RunSessionTask(base::Bind(
|
| &Automation::MouseMove,
|
| + base::Unretained(automation_.get()),
|
| current_target_.window_id,
|
| location,
|
| &error));
|
| @@ -388,9 +393,9 @@ Error* Session::MouseMove(const Point& location) {
|
| Error* Session::MouseDrag(const Point& start,
|
| const Point& end) {
|
| Error* error = NULL;
|
| - RunSessionTask(NewRunnableMethod(
|
| - automation_.get(),
|
| + RunSessionTask(base::Bind(
|
| &Automation::MouseDrag,
|
| + base::Unretained(automation_.get()),
|
| current_target_.window_id,
|
| start,
|
| end,
|
| @@ -406,9 +411,9 @@ Error* Session::MouseClick(automation::MouseButton button) {
|
|
|
| Error* Session::MouseButtonDown() {
|
| Error* error = NULL;
|
| - RunSessionTask(NewRunnableMethod(
|
| - automation_.get(),
|
| + RunSessionTask(base::Bind(
|
| &Automation::MouseButtonDown,
|
| + base::Unretained(automation_.get()),
|
| current_target_.window_id,
|
| mouse_position_,
|
| &error));
|
| @@ -417,9 +422,9 @@ Error* Session::MouseButtonDown() {
|
|
|
| Error* Session::MouseButtonUp() {
|
| Error* error = NULL;
|
| - RunSessionTask(NewRunnableMethod(
|
| - automation_.get(),
|
| + RunSessionTask(base::Bind(
|
| &Automation::MouseButtonUp,
|
| + base::Unretained(automation_.get()),
|
| current_target_.window_id,
|
| mouse_position_,
|
| &error));
|
| @@ -428,9 +433,9 @@ Error* Session::MouseButtonUp() {
|
|
|
| Error* Session::MouseDoubleClick() {
|
| Error* error = NULL;
|
| - RunSessionTask(NewRunnableMethod(
|
| - automation_.get(),
|
| + RunSessionTask(base::Bind(
|
| &Automation::MouseDoubleClick,
|
| + base::Unretained(automation_.get()),
|
| current_target_.window_id,
|
| mouse_position_,
|
| &error));
|
| @@ -439,9 +444,9 @@ Error* Session::MouseDoubleClick() {
|
|
|
| Error* Session::GetCookies(const std::string& url, ListValue** cookies) {
|
| Error* error = NULL;
|
| - RunSessionTask(NewRunnableMethod(
|
| - automation_.get(),
|
| + RunSessionTask(base::Bind(
|
| &Automation::GetCookies,
|
| + base::Unretained(automation_.get()),
|
| url,
|
| cookies,
|
| &error));
|
| @@ -451,9 +456,9 @@ Error* Session::GetCookies(const std::string& url, ListValue** cookies) {
|
| Error* Session::DeleteCookie(const std::string& url,
|
| const std::string& cookie_name) {
|
| Error* error = NULL;
|
| - RunSessionTask(NewRunnableMethod(
|
| - automation_.get(),
|
| + RunSessionTask(base::Bind(
|
| &Automation::DeleteCookie,
|
| + base::Unretained(automation_.get()),
|
| url,
|
| cookie_name,
|
| &error));
|
| @@ -463,9 +468,9 @@ Error* Session::DeleteCookie(const std::string& url,
|
| Error* Session::SetCookie(const std::string& url,
|
| DictionaryValue* cookie_dict) {
|
| Error* error = NULL;
|
| - RunSessionTask(NewRunnableMethod(
|
| - automation_.get(),
|
| + RunSessionTask(base::Bind(
|
| &Automation::SetCookie,
|
| + base::Unretained(automation_.get()),
|
| url,
|
| cookie_dict,
|
| &error));
|
| @@ -474,9 +479,9 @@ Error* Session::SetCookie(const std::string& url,
|
|
|
| Error* Session::GetWindowIds(std::vector<int>* window_ids) {
|
| Error* error = NULL;
|
| - RunSessionTask(NewRunnableMethod(
|
| - automation_.get(),
|
| + RunSessionTask(base::Bind(
|
| &Automation::GetTabIds,
|
| + base::Unretained(automation_.get()),
|
| window_ids,
|
| &error));
|
| return error;
|
| @@ -488,9 +493,9 @@ Error* Session::SwitchToWindow(const std::string& name) {
|
| if (base::StringToInt(name, &name_no)) {
|
| Error* error = NULL;
|
| bool does_exist = false;
|
| - RunSessionTask(NewRunnableMethod(
|
| - automation_.get(),
|
| + RunSessionTask(base::Bind(
|
| &Automation::DoesTabExist,
|
| + base::Unretained(automation_.get()),
|
| name_no,
|
| &does_exist,
|
| &error));
|
| @@ -630,9 +635,9 @@ Error* Session::SwitchToTopFrameIfCurrentFrameInvalid() {
|
|
|
| Error* Session::CloseWindow() {
|
| Error* error = NULL;
|
| - RunSessionTask(NewRunnableMethod(
|
| - automation_.get(),
|
| + RunSessionTask(base::Bind(
|
| &Automation::CloseTab,
|
| + base::Unretained(automation_.get()),
|
| current_target_.window_id,
|
| &error));
|
|
|
| @@ -654,9 +659,9 @@ Error* Session::CloseWindow() {
|
|
|
| Error* Session::GetAlertMessage(std::string* text) {
|
| Error* error = NULL;
|
| - RunSessionTask(NewRunnableMethod(
|
| - automation_.get(),
|
| + RunSessionTask(base::Bind(
|
| &Automation::GetAppModalDialogMessage,
|
| + base::Unretained(automation_.get()),
|
| text,
|
| &error));
|
| return error;
|
| @@ -676,15 +681,15 @@ Error* Session::SetAlertPromptText(const std::string& alert_prompt_text) {
|
| Error* Session::AcceptOrDismissAlert(bool accept) {
|
| Error* error = NULL;
|
| if (accept && has_alert_prompt_text_) {
|
| - RunSessionTask(NewRunnableMethod(
|
| - automation_.get(),
|
| + RunSessionTask(base::Bind(
|
| &Automation::AcceptPromptAppModalDialog,
|
| + base::Unretained(automation_.get()),
|
| alert_prompt_text_,
|
| &error));
|
| } else {
|
| - RunSessionTask(NewRunnableMethod(
|
| - automation_.get(),
|
| + RunSessionTask(base::Bind(
|
| &Automation::AcceptOrDismissAppModalDialog,
|
| + base::Unretained(automation_.get()),
|
| accept,
|
| &error));
|
| }
|
| @@ -694,9 +699,9 @@ Error* Session::AcceptOrDismissAlert(bool accept) {
|
|
|
| std::string Session::GetBrowserVersion() {
|
| std::string version;
|
| - RunSessionTask(NewRunnableMethod(
|
| - automation_.get(),
|
| + RunSessionTask(base::Bind(
|
| &Automation::GetBrowserVersion,
|
| + base::Unretained(automation_.get()),
|
| &version));
|
| return version;
|
| }
|
| @@ -992,18 +997,18 @@ Error* Session::WaitForAllTabsToStopLoading() {
|
| if (!automation_.get())
|
| return NULL;
|
| Error* error = NULL;
|
| - RunSessionTask(NewRunnableMethod(
|
| - automation_.get(),
|
| + RunSessionTask(base::Bind(
|
| &Automation::WaitForAllTabsToStopLoading,
|
| + base::Unretained(automation_.get()),
|
| &error));
|
| return error;
|
| }
|
|
|
| Error* Session::InstallExtensionDeprecated(const FilePath& path) {
|
| Error* error = NULL;
|
| - RunSessionTask(NewRunnableMethod(
|
| - automation_.get(),
|
| + RunSessionTask(base::Bind(
|
| &Automation::InstallExtensionDeprecated,
|
| + base::Unretained(automation_.get()),
|
| path,
|
| &error));
|
| return error;
|
| @@ -1032,6 +1037,29 @@ Error* Session::InstallExtension(
|
| return error;
|
| }
|
|
|
| +Error* Session::SetPreference(
|
| + const std::string& pref,
|
| + bool is_user_pref,
|
| + base::Value* value) {
|
| + Error* error = NULL;
|
| + if (is_user_pref) {
|
| + RunSessionTask(base::Bind(
|
| + &Automation::SetPreference,
|
| + base::Unretained(automation_.get()),
|
| + pref,
|
| + value,
|
| + &error));
|
| + } else {
|
| + RunSessionTask(base::Bind(
|
| + &Automation::SetLocalStatePreference,
|
| + base::Unretained(automation_.get()),
|
| + pref,
|
| + value,
|
| + &error));
|
| + }
|
| + return error;
|
| +}
|
| +
|
| const std::string& Session::id() const {
|
| return id_;
|
| }
|
| @@ -1066,9 +1094,9 @@ const Session::Options& Session::options() const {
|
|
|
| void Session::RunSessionTask(Task* task) {
|
| base::WaitableEvent done_event(false, false);
|
| - thread_.message_loop_proxy()->PostTask(FROM_HERE, NewRunnableMethod(
|
| - this,
|
| + thread_.message_loop_proxy()->PostTask(FROM_HERE, base::Bind(
|
| &Session::RunSessionTaskOnSessionThread,
|
| + base::Unretained(this),
|
| task,
|
| &done_event));
|
| done_event.Wait();
|
| @@ -1126,9 +1154,9 @@ Error* Session::ExecuteScriptAndParseValue(const FrameId& frame_id,
|
| Value** script_result) {
|
| std::string response_json;
|
| Error* error = NULL;
|
| - RunSessionTask(NewRunnableMethod(
|
| - automation_.get(),
|
| + RunSessionTask(base::Bind(
|
| &Automation::ExecuteScript,
|
| + base::Unretained(automation_.get()),
|
| frame_id.window_id,
|
| frame_id.frame_path,
|
| script,
|
| @@ -1445,9 +1473,9 @@ Error* Session::GetScreenShot(std::string* png) {
|
| }
|
|
|
| FilePath path = screenshots_dir.path().AppendASCII("screen");
|
| - RunSessionTask(NewRunnableMethod(
|
| - automation_.get(),
|
| + RunSessionTask(base::Bind(
|
| &Automation::CaptureEntirePageAsPNG,
|
| + base::Unretained(automation_.get()),
|
| current_target_.window_id,
|
| path,
|
| &error));
|
| @@ -1476,4 +1504,40 @@ Error* Session::GetAppCacheStatus(int* status) {
|
| CreateDirectValueParser(status));
|
| }
|
|
|
| +Error* Session::PostBrowserStartInit() {
|
| + Error* error = NULL;
|
| + if (!options_.no_website_testing_defaults)
|
| + error = InitForWebsiteTesting();
|
| + if (error)
|
| + return error;
|
| +
|
| + // Install extensions.
|
| + for (size_t i = 0; i < options_.extensions.size(); ++i) {
|
| + error = InstallExtensionDeprecated(options_.extensions[i]);
|
| + if (error)
|
| + return error;
|
| + }
|
| + return NULL;
|
| +}
|
| +
|
| +Error* Session::InitForWebsiteTesting() {
|
| + // Disable checking for SSL certificate revocation.
|
| + Error* error = SetPreference(
|
| + "ssl.rev_checking.enabled",
|
| + false /* is_user_pref */,
|
| + Value::CreateBooleanValue(false));
|
| + if (error)
|
| + return error;
|
| +
|
| + // Allow certain content by default.
|
| + const int kAllowContent = 1;
|
| + DictionaryValue* default_content_settings = new DictionaryValue();
|
| + default_content_settings->SetInteger("geolocation", kAllowContent);
|
| + default_content_settings->SetInteger("notifications", kAllowContent);
|
| + return SetPreference(
|
| + "profile.default_content_settings",
|
| + true /* is_user_pref */,
|
| + default_content_settings);
|
| +}
|
| +
|
| } // namespace webdriver
|
|
|