Index: chrome/test/automation/automation_json_requests.cc |
diff --git a/chrome/test/automation/automation_json_requests.cc b/chrome/test/automation/automation_json_requests.cc |
index fc5d8f0c2f769b56d30d0472205f7a750f7eeb20..8b63faed91527cbfb0ff05b16b27b8cae8eecfb9 100644 |
--- a/chrome/test/automation/automation_json_requests.cc |
+++ b/chrome/test/automation/automation_json_requests.cc |
@@ -80,6 +80,45 @@ WebKeyEvent::WebKeyEvent(automation::KeyEventTypes type, |
modified_text(modified_text), |
modifiers(modifiers) {} |
+WebViewInfo::WebViewInfo( |
+ AutomationId::Type type, |
+ const WebViewId& view_id, |
+ const std::string& extension_id) |
+ : type(type), |
+ view_id(view_id), |
+ extension_id(extension_id) {} |
+ |
+WebViewInfo::~WebViewInfo() {} |
+ |
+/* |
+WebViewLocator::WebViewLocator() {} |
+ |
+WebViewLocator::~WebViewLocator() {} |
+*/ |
+ |
+void WebViewLocator::UpdateDictionary(DictionaryValue* dict) const { |
+ if (type == kTypeIndexPair) { |
+ dict->SetInteger("windex", locator.index_pair.browser_index); |
+ dict->SetInteger("tab_index", locator.index_pair.tab_index); |
+ } else if (type == kTypeViewId) { |
+ dict->Set("view_id", locator.view_id.ToValue()); |
+ } |
+} |
+ |
+void WebViewId::UpdateDictionary(DictionaryValue* dict) const { |
+ if (type == kTypeTabId) { |
+ dict->SetInteger("id", id.tab_id); |
+ } else if (type == kTypeViewId) { |
+ dict->Set("view_id", id.view_id.ToValue()); |
+ } |
+} |
+ |
+/* |
+WebViewId::WebViewId() {} |
+ |
+WebViewId::~WebViewId() {} |
+*/ |
+ |
bool SendAutomationJSONRequest(AutomationMessageSender* sender, |
const std::string& request, |
int timeout_ms, |
@@ -162,16 +201,14 @@ bool SendNavigateToURLJSONRequest( |
bool SendExecuteJavascriptJSONRequest( |
AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
+ const WebViewLocator& locator, |
const std::string& frame_xpath, |
const std::string& javascript, |
Value** result, |
std::string* error_msg) { |
DictionaryValue dict; |
dict.SetString("command", "ExecuteJavascript"); |
- dict.SetInteger("windex", browser_index); |
- dict.SetInteger("tab_index", tab_index); |
+ locator.UpdateDictionary(&dict); |
dict.SetString("frame_xpath", frame_xpath); |
dict.SetString("javascript", javascript); |
DictionaryValue reply_dict; |
@@ -253,38 +290,6 @@ bool SendCaptureEntirePageJSONRequest( |
return SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg); |
} |
-bool SendGetTabURLJSONRequest( |
- AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
- std::string* url, |
- std::string* error_msg) { |
- DictionaryValue dict; |
- dict.SetString("command", "GetTabURL"); |
- dict.SetInteger("windex", browser_index); |
- dict.SetInteger("tab_index", tab_index); |
- DictionaryValue reply_dict; |
- if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg)) |
- return false; |
- return reply_dict.GetString("url", url); |
-} |
- |
-bool SendGetTabTitleJSONRequest( |
- AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
- std::string* tab_title, |
- std::string* error_msg) { |
- DictionaryValue dict; |
- dict.SetString("command", "GetTabTitle"); |
- dict.SetInteger("windex", browser_index); |
- dict.SetInteger("tab_index", tab_index); |
- DictionaryValue reply_dict; |
- if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg)) |
- return false; |
- return reply_dict.GetString("title", tab_title); |
-} |
- |
bool SendGetCookiesJSONRequest( |
AutomationMessageSender* sender, |
const std::string& url, |
@@ -334,7 +339,7 @@ bool SendSetCookieJSONRequest( |
bool SendGetTabIdsJSONRequest( |
AutomationMessageSender* sender, |
- std::vector<int>* tab_ids, |
+ std::vector<WebViewInfo>* views, |
std::string* error_msg) { |
DictionaryValue dict; |
dict.SetString("command", "GetTabIds"); |
@@ -342,37 +347,84 @@ bool SendGetTabIdsJSONRequest( |
if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg)) |
return false; |
ListValue* id_list; |
- if (!reply_dict.GetList("ids", &id_list)) { |
- LOG(ERROR) << "Returned 'ids' key is missing or invalid"; |
+ if (reply_dict.GetList("ids", &id_list)) { |
+ for (size_t i = 0; i < id_list->GetSize(); ++i) { |
+ int id; |
+ if (!id_list->GetInteger(i, &id)) { |
+ *error_msg = "Returned id in 'tab_ids' is not an integer"; |
+ return false; |
+ } |
+ views->push_back(WebViewInfo( |
+ AutomationId::kTypeTab, WebViewId::ForTab(id), std::string())); |
+ } |
+ } |
+ return true; |
+} |
+ |
+bool SendGetWebViewsJSONRequest( |
+ AutomationMessageSender* sender, |
+ std::vector<WebViewInfo>* views, |
+ std::string* error_msg) { |
+ DictionaryValue dict; |
+ dict.SetString("command", "GetViews"); |
+ DictionaryValue reply_dict; |
+ if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg)) |
+ return false; |
+ ListValue* views_list; |
+ if (!reply_dict.GetList("views", &views_list)) { |
+ *error_msg = "Returned 'views' key is missing or invalid"; |
return false; |
} |
- std::vector<int> temp_ids; |
- for (size_t i = 0; i < id_list->GetSize(); ++i) { |
- int id; |
- if (!id_list->GetInteger(i, &id)) { |
- LOG(ERROR) << "Returned 'ids' key contains non-integer values"; |
+ for (size_t i = 0; i < views_list->GetSize(); ++i) { |
+ DictionaryValue* view_dict; |
+ if (!views_list->GetDictionary(i, &view_dict)) { |
+ *error_msg = "Returned 'views' key contains non-dictionary values"; |
+ return false; |
+ } |
+ Value* view_id_value; |
+ std::string extension_id; |
+ if (!view_dict->Get("view_id", &view_id_value)) { |
+ *error_msg = "Missing 'view_id'"; |
return false; |
} |
- temp_ids.push_back(id); |
+ AutomationId view_id; |
+ if (!AutomationId::FromValue(view_id_value, &view_id, error_msg)) |
+ return false; |
+ view_dict->GetString("extension_id", &extension_id); |
+ views->push_back(WebViewInfo( |
+ static_cast<AutomationId::Type>(0), WebViewId::ForView(view_id), extension_id)); |
} |
- *tab_ids = temp_ids; |
return true; |
} |
bool SendIsTabIdValidJSONRequest( |
AutomationMessageSender* sender, |
- int tab_id, |
+ const WebViewId& view_id, |
bool* is_valid, |
std::string* error_msg) { |
DictionaryValue dict; |
dict.SetString("command", "IsTabIdValid"); |
- dict.SetInteger("id", tab_id); |
+ view_id.UpdateDictionary(&dict); |
DictionaryValue reply_dict; |
if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg)) |
return false; |
return reply_dict.GetBoolean("is_valid", is_valid); |
} |
+bool SendDoesViewExistJSONRequest( |
+ AutomationMessageSender* sender, |
+ const WebViewId& view_id, |
+ bool* does_exist, |
+ std::string* error_msg) { |
+ DictionaryValue dict; |
+ dict.SetString("command", "DoesViewExist"); |
+ view_id.UpdateDictionary(&dict); |
+ DictionaryValue reply_dict; |
+ if (!SendAutomationJSONRequest(sender, dict, &reply_dict, error_msg)) |
+ return false; |
+ return reply_dict.GetBoolean("does_exist", does_exist); |
+} |
+ |
bool SendCloseTabJSONRequest( |
AutomationMessageSender* sender, |
int browser_index, |
@@ -388,15 +440,13 @@ bool SendCloseTabJSONRequest( |
bool SendMouseMoveJSONRequest( |
AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
+ const WebViewLocator& locator, |
int x, |
int y, |
std::string* error_msg) { |
DictionaryValue dict; |
dict.SetString("command", "WebkitMouseMove"); |
- dict.SetInteger("windex", browser_index); |
- dict.SetInteger("tab_index", tab_index); |
+ locator.UpdateDictionary(&dict); |
dict.SetInteger("x", x); |
dict.SetInteger("y", y); |
DictionaryValue reply_dict; |
@@ -405,16 +455,14 @@ bool SendMouseMoveJSONRequest( |
bool SendMouseClickJSONRequest( |
AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
+ const WebViewLocator& locator, |
automation::MouseButton button, |
int x, |
int y, |
std::string* error_msg) { |
DictionaryValue dict; |
dict.SetString("command", "WebkitMouseClick"); |
- dict.SetInteger("windex", browser_index); |
- dict.SetInteger("tab_index", tab_index); |
+ locator.UpdateDictionary(&dict); |
dict.SetInteger("button", button); |
dict.SetInteger("x", x); |
dict.SetInteger("y", y); |
@@ -424,8 +472,7 @@ bool SendMouseClickJSONRequest( |
bool SendMouseDragJSONRequest( |
AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
+ const WebViewLocator& locator, |
int start_x, |
int start_y, |
int end_x, |
@@ -433,8 +480,7 @@ bool SendMouseDragJSONRequest( |
std::string* error_msg) { |
DictionaryValue dict; |
dict.SetString("command", "WebkitMouseDrag"); |
- dict.SetInteger("windex", browser_index); |
- dict.SetInteger("tab_index", tab_index); |
+ locator.UpdateDictionary(&dict); |
dict.SetInteger("start_x", start_x); |
dict.SetInteger("start_y", start_y); |
dict.SetInteger("end_x", end_x); |
@@ -445,15 +491,13 @@ bool SendMouseDragJSONRequest( |
bool SendMouseButtonDownJSONRequest( |
AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
+ const WebViewLocator& locator, |
int x, |
int y, |
std::string* error_msg) { |
DictionaryValue dict; |
dict.SetString("command", "WebkitMouseButtonDown"); |
- dict.SetInteger("windex", browser_index); |
- dict.SetInteger("tab_index", tab_index); |
+ locator.UpdateDictionary(&dict); |
dict.SetInteger("x", x); |
dict.SetInteger("y", y); |
DictionaryValue reply_dict; |
@@ -462,15 +506,13 @@ bool SendMouseButtonDownJSONRequest( |
bool SendMouseButtonUpJSONRequest( |
AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
+ const WebViewLocator& locator, |
int x, |
int y, |
std::string* error_msg) { |
DictionaryValue dict; |
dict.SetString("command", "WebkitMouseButtonUp"); |
- dict.SetInteger("windex", browser_index); |
- dict.SetInteger("tab_index", tab_index); |
+ locator.UpdateDictionary(&dict); |
dict.SetInteger("x", x); |
dict.SetInteger("y", y); |
DictionaryValue reply_dict; |
@@ -479,15 +521,13 @@ bool SendMouseButtonUpJSONRequest( |
bool SendMouseDoubleClickJSONRequest( |
AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
+ const WebViewLocator& locator, |
int x, |
int y, |
std::string* error_msg) { |
DictionaryValue dict; |
dict.SetString("command", "WebkitMouseDoubleClick"); |
- dict.SetInteger("windex", browser_index); |
- dict.SetInteger("tab_index", tab_index); |
+ locator.UpdateDictionary(&dict); |
dict.SetInteger("x", x); |
dict.SetInteger("y", y); |
DictionaryValue reply_dict; |
@@ -496,14 +536,12 @@ bool SendMouseDoubleClickJSONRequest( |
bool SendWebKeyEventJSONRequest( |
AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
+ const WebViewLocator& locator, |
const WebKeyEvent& key_event, |
std::string* error_msg) { |
DictionaryValue dict; |
dict.SetString("command", "SendWebkitKeyEvent"); |
- dict.SetInteger("windex", browser_index); |
- dict.SetInteger("tab_index", tab_index); |
+ locator.UpdateDictionary(&dict); |
dict.SetInteger("type", key_event.type); |
dict.SetInteger("nativeKeyCode", key_event.key_code); |
dict.SetInteger("windowsKeyCode", key_event.key_code); |
@@ -534,16 +572,14 @@ bool SendNativeKeyEventJSONRequest( |
bool SendDragAndDropFilePathsJSONRequest( |
AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
+ const WebViewLocator& locator, |
int x, |
int y, |
const std::vector<FilePath::StringType>& paths, |
std::string* error_msg) { |
DictionaryValue dict; |
dict.SetString("command", "DragAndDropFilePaths"); |
- dict.SetInteger("windex", browser_index); |
- dict.SetInteger("tab_index", tab_index); |
+ locator.UpdateDictionary(&dict); |
dict.SetInteger("x", x); |
dict.SetInteger("y", y); |