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..cd5a11da16be6e8cbd27415d4aa4889fc7cbef2b 100644 |
--- a/chrome/test/webdriver/webdriver_session.cc |
+++ b/chrome/test/webdriver/webdriver_session.cc |
@@ -43,16 +43,20 @@ |
namespace webdriver { |
-FrameId::FrameId(int window_id, const FramePath& frame_path) |
- : window_id(window_id), |
+FrameId::FrameId() {} |
+ |
+FrameId::FrameId(const WebViewId& view_id, const FramePath& frame_path) |
+ : view_id(view_id), |
frame_path(frame_path) { |
} |
+/* |
FrameId& FrameId::operator=(const FrameId& other) { |
- window_id = other.window_id; |
+ view_id = other.view_id; |
frame_path = other.frame_path; |
return *this; |
} |
+*/ |
Session::Options::Options() |
: use_native_events(false), |
@@ -64,7 +68,7 @@ Session::Options::~Options() { |
Session::Session(const Options& options) |
: id_(GenerateRandomID()), |
- current_target_(FrameId(0, FramePath())), |
+ current_target_(FrameId(WebViewId(), FramePath())), |
thread_(id_.c_str()), |
async_script_timeout_(0), |
implicit_wait_(0), |
@@ -277,7 +281,7 @@ Error* Session::DragAndDropFilePaths( |
RunSessionTask(NewRunnableMethod( |
automation_.get(), |
&Automation::DragAndDropFilePaths, |
- current_target_.window_id, |
+ current_target_.view_id.id.tab_id, // FIXME |
location, |
paths, |
&error)); |
@@ -290,14 +294,14 @@ Error* Session::NavigateToURL(const std::string& url) { |
RunSessionTask(NewRunnableMethod( |
automation_.get(), |
&Automation::NavigateToURLAsync, |
- current_target_.window_id, |
+ current_target_.view_id.id.tab_id, // FIXME |
url, |
&error)); |
} else { |
RunSessionTask(NewRunnableMethod( |
automation_.get(), |
&Automation::NavigateToURL, |
- current_target_.window_id, |
+ current_target_.view_id.id.tab_id, // FIXME |
url, |
&error)); |
} |
@@ -309,7 +313,7 @@ Error* Session::GoForward() { |
RunSessionTask(NewRunnableMethod( |
automation_.get(), |
&Automation::GoForward, |
- current_target_.window_id, |
+ current_target_.view_id.id.tab_id, // FIXME |
&error)); |
return error; |
} |
@@ -319,7 +323,7 @@ Error* Session::GoBack() { |
RunSessionTask(NewRunnableMethod( |
automation_.get(), |
&Automation::GoBack, |
- current_target_.window_id, |
+ current_target_.view_id.id.tab_id, // FIXME |
&error)); |
return error; |
} |
@@ -329,7 +333,7 @@ Error* Session::Reload() { |
RunSessionTask(NewRunnableMethod( |
automation_.get(), |
&Automation::Reload, |
- current_target_.window_id, |
+ current_target_.view_id.id.tab_id, // FIXME |
&error)); |
return error; |
} |
@@ -350,7 +354,7 @@ Error* Session::GetTitle(std::string* tab_title) { |
" else" |
" return document.URL;" |
"}"; |
- return ExecuteScriptAndParse(FrameId(current_target_.window_id, FramePath()), |
+ return ExecuteScriptAndParse(FrameId(current_target_.view_id, FramePath()), |
kGetTitleScript, |
"getTitle", |
new ListValue(), |
@@ -363,7 +367,7 @@ Error* Session::MouseMoveAndClick(const Point& location, |
RunSessionTask(NewRunnableMethod( |
automation_.get(), |
&Automation::MouseClick, |
- current_target_.window_id, |
+ current_target_.view_id.id.tab_id, // FIXME |
location, |
button, |
&error)); |
@@ -377,7 +381,7 @@ Error* Session::MouseMove(const Point& location) { |
RunSessionTask(NewRunnableMethod( |
automation_.get(), |
&Automation::MouseMove, |
- current_target_.window_id, |
+ current_target_.view_id.id.tab_id, // FIXME |
location, |
&error)); |
if (!error) |
@@ -391,7 +395,7 @@ Error* Session::MouseDrag(const Point& start, |
RunSessionTask(NewRunnableMethod( |
automation_.get(), |
&Automation::MouseDrag, |
- current_target_.window_id, |
+ current_target_.view_id.id.tab_id, // FIXME |
start, |
end, |
&error)); |
@@ -409,7 +413,7 @@ Error* Session::MouseButtonDown() { |
RunSessionTask(NewRunnableMethod( |
automation_.get(), |
&Automation::MouseButtonDown, |
- current_target_.window_id, |
+ current_target_.view_id.id.tab_id, // FIXME |
mouse_position_, |
&error)); |
return error; |
@@ -420,7 +424,7 @@ Error* Session::MouseButtonUp() { |
RunSessionTask(NewRunnableMethod( |
automation_.get(), |
&Automation::MouseButtonUp, |
- current_target_.window_id, |
+ current_target_.view_id.id.tab_id, // FIXME |
mouse_position_, |
&error)); |
return error; |
@@ -431,7 +435,7 @@ Error* Session::MouseDoubleClick() { |
RunSessionTask(NewRunnableMethod( |
automation_.get(), |
&Automation::MouseDoubleClick, |
- current_target_.window_id, |
+ current_target_.view_id.id.tab_id, // FIXME |
mouse_position_, |
&error)); |
return error; |
@@ -472,61 +476,80 @@ Error* Session::SetCookie(const std::string& url, |
return error; |
} |
-Error* Session::GetWindowIds(std::vector<int>* window_ids) { |
+Error* Session::GetViews(std::vector<WebViewInfo>* views) { |
Error* error = NULL; |
RunSessionTask(NewRunnableMethod( |
automation_.get(), |
- &Automation::GetTabIds, |
- window_ids, |
+ &Automation::GetViews, |
+ views, |
&error)); |
return error; |
} |
-Error* Session::SwitchToWindow(const std::string& name) { |
- int switch_to_id = 0; |
- int name_no = 0; |
- if (base::StringToInt(name, &name_no)) { |
- Error* error = NULL; |
- bool does_exist = false; |
+Error* Session::SwitchToView(const std::string& id_or_name) { |
+ Error* error = NULL; |
+ bool does_exist = false; |
+ |
+ bool new_version = false; |
+ error = CompareBrowserVersion(500, 0, &new_version); |
+ if (error) |
+ return error; |
+ int id_no; |
+ WebViewId new_view; |
+ if (new_version) { |
+ std::vector<std::string> parts; |
+ // Check if valid type. |
+ base::SplitString(id_or_name, '|', &parts); |
+ int type; |
+ if (parts.size() == 2 && base::StringToInt(parts[0], &type)) { |
+ new_view = WebViewId::ForView( |
+ AutomationId(static_cast<AutomationId::Type>(type), |
+ parts[1])); |
+ } |
+ } else if (base::StringToInt(id_or_name, &id_no)) { |
+ new_view = WebViewId::ForTab(id_no); |
+ } |
+ if (new_view.IsValid()) { |
RunSessionTask(NewRunnableMethod( |
automation_.get(), |
- &Automation::DoesTabExist, |
- name_no, |
+ &Automation::DoesViewExist, |
+ new_view, |
&does_exist, |
&error)); |
if (error) |
return error; |
- if (does_exist) |
- switch_to_id = name_no; |
} |
- if (!switch_to_id) { |
- std::vector<int> window_ids; |
- Error* error = GetWindowIds(&window_ids); |
+ if (!does_exist) { |
+ // See if any of the tab window names match |name|. |
+ std::vector<WebViewInfo> views; |
+ Error* error = GetViews(&views); |
if (error) |
return error; |
- // See if any of the window names match |name|. |
- for (size_t i = 0; i < window_ids.size(); ++i) { |
+ for (size_t i = 0; i < views.size(); ++i) { |
+ if (views[i].view_id.type != WebViewId::kTypeTabId) |
+ continue; |
std::string window_name; |
Error* error = ExecuteScriptAndParse( |
- FrameId(window_ids[i], FramePath()), |
+ FrameId(views[i].view_id, FramePath()), |
"function() { return window.name; }", |
"getWindowName", |
new ListValue(), |
CreateDirectValueParser(&window_name)); |
if (error) |
return error; |
- if (name == window_name) { |
- switch_to_id = window_ids[i]; |
+ if (id_or_name == window_name) { |
+ new_view = views[i].view_id; |
+ does_exist = true; |
break; |
} |
} |
} |
- if (!switch_to_id) |
+ if (!does_exist) |
return new Error(kNoSuchWindow); |
frame_elements_.clear(); |
- current_target_ = FrameId(switch_to_id, FramePath()); |
+ current_target_ = FrameId(new_view, FramePath()); |
return NULL; |
} |
@@ -611,7 +634,7 @@ Error* Session::SwitchToTopFrameIfCurrentFrameInvalid() { |
// This code should not execute script in any frame before making sure the |
// frame element is valid, otherwise the automation hangs until a timeout. |
for (size_t i = 0; i < frame_elements_.size(); ++i) { |
- FrameId frame_id(current_target_.window_id, frame_path); |
+ FrameId frame_id(current_target_.view_id, frame_path); |
scoped_ptr<Error> error(ExecuteScriptAndParse( |
frame_id, |
"function(){ }", |
@@ -633,13 +656,13 @@ Error* Session::CloseWindow() { |
RunSessionTask(NewRunnableMethod( |
automation_.get(), |
&Automation::CloseTab, |
- current_target_.window_id, |
+ current_target_.view_id.id.tab_id, // FIXME |
&error)); |
if (!error) { |
- std::vector<int> window_ids; |
- scoped_ptr<Error> error(GetWindowIds(&window_ids)); |
- if (error.get() || window_ids.empty()) { |
+ std::vector<WebViewInfo> views; |
+ scoped_ptr<Error> error(GetViews(&views)); |
+ if (error.get() || views.empty()) { |
// The automation connection will soon be closed, if not already, |
// because we supposedly just closed the last window. Terminate the |
// session. |
@@ -780,7 +803,7 @@ Error* Session::GetElementRegionInView( |
frame_path.IsSubframe(); |
frame_path = frame_path.Parent()) { |
// Find the frame element for the current frame path. |
- FrameId frame_id(current_target_.window_id, frame_path.Parent()); |
+ FrameId frame_id(current_target_.view_id, frame_path.Parent()); |
ElementId frame_element; |
error = FindElement( |
frame_id, ElementId(""), |
@@ -1104,15 +1127,15 @@ void Session::InitOnSessionThread(const Automation::BrowserOptions& options, |
if (*error) |
return; |
- std::vector<int> tab_ids; |
- automation_->GetTabIds(&tab_ids, error); |
+ std::vector<WebViewInfo> views; |
+ automation_->GetViews(&views, error); |
if (*error) |
return; |
- if (tab_ids.empty()) { |
- *error = new Error(kUnknownError, "No tab ids after initialization"); |
+ if (views.empty()) { |
+ *error = new Error(kUnknownError, "No view ids after initialization"); |
return; |
} |
- current_target_ = FrameId(tab_ids[0], FramePath()); |
+ current_target_ = FrameId(views[0].view_id, FramePath()); |
} |
void Session::TerminateOnSessionThread() { |
@@ -1129,7 +1152,7 @@ Error* Session::ExecuteScriptAndParseValue(const FrameId& frame_id, |
RunSessionTask(NewRunnableMethod( |
automation_.get(), |
&Automation::ExecuteScript, |
- frame_id.window_id, |
+ frame_id.view_id, |
frame_id.frame_path, |
script, |
&response_json, |
@@ -1186,13 +1209,14 @@ void Session::SendKeysOnSessionThread(const string16& keys, Error** error) { |
if (key_events[i].type != automation::kRawKeyDownType) |
continue; |
automation_->SendNativeKeyEvent( |
- current_target_.window_id, |
+ current_target_.view_id.id.tab_id, // FIXME |
key_events[i].key_code, |
key_events[i].modifiers, |
error); |
} else { |
automation_->SendWebKeyEvent( |
- current_target_.window_id, key_events[i], error); |
+ current_target_.view_id.id.tab_id, // FIXME |
+ key_events[i], error); |
} |
if (*error) { |
std::string details = base::StringPrintf( |
@@ -1448,7 +1472,7 @@ Error* Session::GetScreenShot(std::string* png) { |
RunSessionTask(NewRunnableMethod( |
automation_.get(), |
&Automation::CaptureEntirePageAsPNG, |
- current_target_.window_id, |
+ current_target_.view_id.id.tab_id, // FIXME |
path, |
&error)); |
if (error) |