Index: chrome/test/automation/automation_json_requests.h |
diff --git a/chrome/test/automation/automation_json_requests.h b/chrome/test/automation/automation_json_requests.h |
index 28d607d334d6a466747a8cb020b6b1f32b4359e9..be3187994178929daf7fd28a4e1b9dadeeed5996 100644 |
--- a/chrome/test/automation/automation_json_requests.h |
+++ b/chrome/test/automation/automation_json_requests.h |
@@ -11,7 +11,9 @@ |
#include "base/compiler_specific.h" |
#include "base/file_path.h" |
+#include "base/string_number_conversions.h" |
#include "chrome/common/automation_constants.h" |
+#include "chrome/common/automation_id.h" |
#include "ui/base/keycodes/keyboard_codes.h" |
class AutomationMessageSender; |
@@ -37,6 +39,112 @@ struct WebKeyEvent { |
int modifiers; |
}; |
+// Uniquely identifies a particular WebView. |
+// This is needed because Chrome used to accept just tab IDs, while |
+// now it accepts IDs for other types of WebViews. |
+// TOOD(kkania): Remove this abstraction once Chrome 16 is unsupported. |
+class WebViewId { |
+ public: |
+ // Creates an ID for the given view ID. |
+ static WebViewId ForView(const AutomationId& view_id); |
+ |
+ // Creates an ID for the given tab ID. |
+ static WebViewId ForOldStyleTab(int tab_id); |
+ |
+ // Creates an invalid ID. |
+ WebViewId(); |
+ |
+ // Updates the given dictionary to include this ID. If the ID refers to a |
+ // view ID, |view_id_key| will be the key modified in the dictionary. |
+ void UpdateDictionary(base::DictionaryValue* dictionary, |
+ const std::string& view_id_key) const; |
+ |
+ // Returns whether this ID is valid. Even if it is valid, the object it |
+ // refers to may not exist. |
+ bool IsValid() const; |
+ |
+ // Returns an |AutomationId| made from this ID. |
+ AutomationId GetId() const; |
+ |
+ // Returns whether this ID refers to a tab. |
+ bool IsTab() const; |
+ |
+ int tab_id() const; |
+ |
+ // The old style is to use a single integer ID for a tab. The new style is |
+ // to use an automation ID which may refer to a number of different object |
+ // types. |
+ bool old_style() const; |
+ |
+ private: |
+ // Whether this ID is an old-style integer tab ID. |
+ bool old_style_; |
+ |
+ AutomationId id_; |
+ int tab_id_; |
+}; |
+ |
+// Used to locate a WebView. The same locator may locate different WebViews |
+// at different times. This is needed because Chrome used to only accept |
+// browser/tab indices, while the new Chrome accepts a unique ID. |
+// TOOD(kkania): Simplify this once Chrome 16 is unsupported. |
+class WebViewLocator { |
+ public: |
+ // Creates a locator for locating the given tab. |
+ static WebViewLocator ForIndexPair(int browser_index, int tab_index); |
+ |
+ // Creates a locator for locating the given view. |
+ static WebViewLocator ForViewId(const AutomationId& view_id); |
+ |
+ // Creates an invalid locator. |
+ WebViewLocator(); |
+ ~WebViewLocator(); |
+ |
+ // Updates the given dictionary to include the given locator information. |
+ // If this locator is a view ID, |view_id_key| will be the name of the key |
+ // to update. |
+ void UpdateDictionary(base::DictionaryValue* dict, |
+ const std::string& view_id_key) const; |
+ |
+ int browser_index() const; |
+ int tab_index() const; |
+ |
+ private: |
+ enum Type { |
+ kTypeIndexPair, |
+ kTypeViewId, |
+ }; |
+ |
+ struct IndexPair { |
+ int browser_index; |
+ int tab_index; |
+ }; |
+ |
+ struct Locator { |
+ Locator(); |
+ ~Locator(); |
+ |
+ IndexPair index_pair; |
+ AutomationId view_id; |
+ }; |
+ |
+ Type type_; |
+ Locator locator_; |
+}; |
+ |
+// Collection of info about a given WebView. |
+struct WebViewInfo { |
+ WebViewInfo(const WebViewId& view_id, |
+ const std::string& extension_id); |
+ ~WebViewInfo(); |
+ |
+ // The view's unique ID. |
+ WebViewId view_id; |
+ |
+ // If this view belongs to an extension, this ID will be set to it. |
+ std::string extension_id; |
+}; |
+ |
// Sends a JSON request to the chrome automation provider. Returns true |
// if the JSON request was successfully sent and the reply was received. |
// If true, |success| will be set to whether the JSON request was |
@@ -77,8 +185,7 @@ bool SendGetIndicesFromTabHandleJSONRequest( |
// navigations to complete. Returns true on success. |
bool SendNavigateToURLJSONRequest( |
AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
+ const WebViewLocator& locator, |
const std::string& url, |
int navigation_count, |
AutomationMsg_NavigationResponseValues* nav_response, |
@@ -89,35 +196,31 @@ bool SendNavigateToURLJSONRequest( |
// result of the execution and ownership will be given to the caller. |
bool SendExecuteJavascriptJSONRequest( |
AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
+ const WebViewLocator& locator, |
const std::string& frame_xpath, |
const std::string& javascript, |
base::Value** result, |
std::string* error_msg) WARN_UNUSED_RESULT; |
-// Requests the specified tab to go forward. Waits for the load to complete. |
+// Requests the specified view to go forward. Waits for the load to complete. |
// Returns true on success. |
bool SendGoForwardJSONRequest( |
AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
+ const WebViewLocator& locator, |
std::string* error_msg) WARN_UNUSED_RESULT; |
-// Requests the specified tab to go back. Waits for the load to complete. |
+// Requests the specified view to go back. Waits for the load to complete. |
// Returns true on success. |
bool SendGoBackJSONRequest( |
AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
+ const WebViewLocator& locator, |
std::string* error_msg) WARN_UNUSED_RESULT; |
-// Requests the specified tab to reload. Waits for the load to complete. |
+// Requests the specified view to reload. Waits for the load to complete. |
// Returns true on success. |
bool SendReloadJSONRequest( |
AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
+ const WebViewLocator& locator, |
std::string* error_msg) WARN_UNUSED_RESULT; |
// Requests a snapshot of the entire page to be saved to the given path |
@@ -125,27 +228,10 @@ bool SendReloadJSONRequest( |
// Returns true on success. |
bool SendCaptureEntirePageJSONRequest( |
AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
+ const WebViewLocator& locator, |
const FilePath& path, |
std::string* error_msg) WARN_UNUSED_RESULT; |
-// Requests the url of the specified tab. Returns true on success. |
-bool SendGetTabURLJSONRequest( |
- AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
- std::string* url, |
- std::string* error_msg) WARN_UNUSED_RESULT; |
- |
-// Requests the title of the specified tab. Returns true on success. |
-bool SendGetTabTitleJSONRequest( |
- AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
- std::string* tab_title, |
- std::string* error_msg) WARN_UNUSED_RESULT; |
- |
// Requests all the cookies for the given URL. On success returns true and |
// caller takes ownership of |cookies|, which is a list of all the cookies in |
// dictionary format. |
@@ -174,50 +260,60 @@ bool SendSetCookieJSONRequest( |
// Requests the IDs for all open tabs. Returns true on success. |
bool SendGetTabIdsJSONRequest( |
AutomationMessageSender* sender, |
- std::vector<int>* tab_ids, |
+ std::vector<WebViewInfo>* views, |
+ std::string* error_msg) WARN_UNUSED_RESULT; |
+ |
+// Requests info for all open views. Returns true on success. |
+bool SendGetWebViewsJSONRequest( |
+ AutomationMessageSender* sender, |
+ std::vector<WebViewInfo>* views, |
std::string* error_msg) WARN_UNUSED_RESULT; |
// Requests whether the given tab ID is valid. Returns true on success. |
bool SendIsTabIdValidJSONRequest( |
AutomationMessageSender* sender, |
- int tab_id, |
+ const WebViewId& view_id, |
bool* is_valid, |
std::string* error_msg) WARN_UNUSED_RESULT; |
-// Requests to close the given tab. Returns true on success. |
-bool SendCloseTabJSONRequest( |
+// Requests whether the given automation ID refers to an actual automation |
+// object. Returns true on success. |
+bool SendDoesAutomationObjectExistJSONRequest( |
AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
+ const WebViewId& view_id, |
+ bool* does_exist, |
+ std::string* error_msg) WARN_UNUSED_RESULT; |
+ |
+// Requests to close the given view. Returns true on success. |
+bool SendCloseViewJSONRequest( |
+ AutomationMessageSender* sender, |
+ const WebViewLocator& locator, |
std::string* error_msg) WARN_UNUSED_RESULT; |
// Requests to send the WebKit event for a mouse move to the given |
-// coordinate in the specified tab. Returns true on success. |
+// coordinate in the specified view. Returns true on success. |
bool SendMouseMoveJSONRequest( |
AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
+ const WebViewLocator& locator, |
int x, |
int y, |
std::string* error_msg) WARN_UNUSED_RESULT; |
// Requests to send the WebKit events for a mouse click at the given |
-// coordinate in the specified tab. Returns true on success. |
+// coordinate in the specified view. Returns true on success. |
bool SendMouseClickJSONRequest( |
AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
+ const WebViewLocator& locator, |
automation::MouseButton button, |
int x, |
int y, |
std::string* error_msg) WARN_UNUSED_RESULT; |
// Requests to send the WebKit events for a mouse drag from the start to end |
-// coordinates given in the specified tab. Returns true on success. |
+// coordinates given in the specified view. Returns true on success. |
bool SendMouseDragJSONRequest( |
AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
+ const WebViewLocator& locator, |
int start_x, |
int start_y, |
int end_x, |
@@ -225,60 +321,54 @@ bool SendMouseDragJSONRequest( |
std::string* error_msg) WARN_UNUSED_RESULT; |
// Requests to send the WebKit event for a mouse button down at the given |
-// coordinate in the specified tab. Returns true on success. |
+// coordinate in the specified view. Returns true on success. |
bool SendMouseButtonDownJSONRequest( |
AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
+ const WebViewLocator& locator, |
int x, |
int y, |
std::string* error_msg) WARN_UNUSED_RESULT; |
// Requests to send the WebKit event for a mouse button up at the given |
-// coordinate in the specified tab. Returns true on success. |
+// coordinate in the specified view. Returns true on success. |
bool SendMouseButtonUpJSONRequest( |
AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
+ const WebViewLocator& locator, |
int x, |
int y, |
std::string* error_msg) WARN_UNUSED_RESULT; |
// Requests to send the WebKit event for a mouse double click at the given |
-// coordinate in the specified tab. Returns true on success. |
+// coordinate in the specified view. Returns true on success. |
bool SendMouseDoubleClickJSONRequest( |
AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
+ const WebViewLocator& locator, |
int x, |
int y, |
std::string* error_msg) WARN_UNUSED_RESULT; |
// Requests to send the WebKit event for the given |WebKeyEvent| in a |
-// specified tab. Returns true on success. |
+// specified view. Returns true on success. |
bool SendWebKeyEventJSONRequest( |
AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
+ const WebViewLocator& locator, |
const WebKeyEvent& key_event, |
std::string* error_msg) WARN_UNUSED_RESULT; |
// Requests to send the key event for the given keycode+modifiers to a |
-// browser window containing the specified tab. Returns true on success. |
+// browser window containing the specified view. Returns true on success. |
bool SendNativeKeyEventJSONRequest( |
AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
+ const WebViewLocator& locator, |
ui::KeyboardCode key_code, |
int modifiers, |
std::string* error_msg) WARN_UNUSED_RESULT; |
// Requests to drag and drop the file paths at the given coordinate in the |
-// specified tab. Returns true on success. |
+// specified view. Returns true on success. |
bool SendDragAndDropFilePathsJSONRequest( |
AutomationMessageSender* sender, |
- int browser_index, |
- int tab_index, |
+ const WebViewLocator& locator, |
int x, |
int y, |
const std::vector<FilePath::StringType>& paths, |
@@ -305,8 +395,8 @@ bool SendAcceptPromptAppModalDialogJSONRequest( |
const std::string& prompt_text, |
std::string* error_msg) WARN_UNUSED_RESULT; |
-// Requests to wait for all tabs to stop loading. Returns true on success. |
-bool SendWaitForAllTabsToStopLoadingJSONRequest( |
+// Requests to wait for all views to stop loading. Returns true on success. |
+bool SendWaitForAllViewsToStopLoadingJSONRequest( |
AutomationMessageSender* sender, |
std::string* error_msg) WARN_UNUSED_RESULT; |
@@ -317,12 +407,6 @@ bool SendGetChromeDriverAutomationVersion( |
int* version, |
std::string* error_msg) WARN_UNUSED_RESULT; |
-// Requests info about all installed extensions. Returns true on success. |
-bool SendGetExtensionsInfoJSONRequest( |
- AutomationMessageSender* sender, |
- base::ListValue* extensions_list, |
- std::string* error_msg) WARN_UNUSED_RESULT; |
- |
// Requests that the given extension be installed. If |with_ui| is false, |
// the extension will be installed silently. Returns true on success. |
bool SendInstallExtensionJSONRequest( |
@@ -332,4 +416,42 @@ bool SendInstallExtensionJSONRequest( |
std::string* extension_id, |
std::string* error_msg) WARN_UNUSED_RESULT; |
+// Requests info about all installed extensions. Returns true on success. |
+bool SendGetExtensionsInfoJSONRequest( |
+ AutomationMessageSender* sender, |
+ base::ListValue* extensions_list, |
+ std::string* error_msg) WARN_UNUSED_RESULT; |
+ |
+// Requests whether the given extension's page action is visible in the |
+// given tab. |
+bool SendIsPageActionVisibleJSONRequest( |
+ AutomationMessageSender* sender, |
+ const WebViewId& tab_id, |
+ const std::string& extension_id, |
+ bool* is_visible, |
+ std::string* error_msg) WARN_UNUSED_RESULT; |
+ |
+// Requests a modification of the given extension state. Returns true on |
+// success. |
+bool SendSetExtensionStateJSONRequest( |
+ AutomationMessageSender* sender, |
+ const std::string& extension_id, |
+ bool enable, |
+ bool allow_in_incognito, |
+ std::string* error_msg) WARN_UNUSED_RESULT; |
+ |
+// Requests the given extension's action button be pressed. Returns true on |
+// success. |
+bool SendClickExtensionButtonJSONRequest( |
+ AutomationMessageSender* sender, |
+ const std::string& extension_id, |
+ bool browser_action, |
+ std::string* error_msg) WARN_UNUSED_RESULT; |
+ |
+// Requests the given extension be uninstalled. Returns true on success. |
+bool SendUninstallExtensionJSONRequest( |
+ AutomationMessageSender* sender, |
+ const std::string& extension_id, |
+ std::string* error_msg) WARN_UNUSED_RESULT; |
+ |
#endif // CHROME_TEST_AUTOMATION_AUTOMATION_JSON_REQUESTS_H_ |