OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_TEST_AUTOMATION_AUTOMATION_JSON_REQUESTS_H_ | 5 #ifndef CHROME_TEST_AUTOMATION_AUTOMATION_JSON_REQUESTS_H_ |
6 #define CHROME_TEST_AUTOMATION_AUTOMATION_JSON_REQUESTS_H_ | 6 #define CHROME_TEST_AUTOMATION_AUTOMATION_JSON_REQUESTS_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 14 #include "chrome/browser/automation/automation_provider_json.h" |
14 #include "chrome/common/automation_constants.h" | 15 #include "chrome/common/automation_constants.h" |
15 #include "ui/base/keycodes/keyboard_codes.h" | 16 #include "ui/base/keycodes/keyboard_codes.h" |
16 | 17 |
17 class AutomationMessageSender; | 18 class AutomationMessageSender; |
18 class FilePath; | 19 class FilePath; |
19 | 20 |
20 namespace base { | 21 namespace base { |
21 class DictionaryValue; | 22 class DictionaryValue; |
22 class ListValue; | 23 class ListValue; |
23 class Value; | 24 class Value; |
24 } | 25 } |
25 | 26 |
26 struct WebKeyEvent { | 27 struct WebKeyEvent { |
27 WebKeyEvent(automation::KeyEventTypes type, | 28 WebKeyEvent(automation::KeyEventTypes type, |
28 ui::KeyboardCode key_code, | 29 ui::KeyboardCode key_code, |
29 const std::string& unmodified_text, | 30 const std::string& unmodified_text, |
30 const std::string& modified_text, | 31 const std::string& modified_text, |
31 int modifiers); | 32 int modifiers); |
32 | 33 |
33 automation::KeyEventTypes type; | 34 automation::KeyEventTypes type; |
34 ui::KeyboardCode key_code; | 35 ui::KeyboardCode key_code; |
35 std::string unmodified_text; | 36 std::string unmodified_text; |
36 std::string modified_text; | 37 std::string modified_text; |
37 int modifiers; | 38 int modifiers; |
38 }; | 39 }; |
39 | 40 |
| 41 struct WebViewLocator { |
| 42 enum Type { |
| 43 kTypeIndexPair = 0, |
| 44 kTypeViewId, |
| 45 }; |
| 46 struct IndexPair { |
| 47 int browser_index; |
| 48 int tab_index; |
| 49 }; |
| 50 struct Locator { |
| 51 Locator() { } |
| 52 ~Locator() { } |
| 53 |
| 54 IndexPair index_pair; |
| 55 AutomationId view_id; |
| 56 }; |
| 57 |
| 58 WebViewLocator(){} |
| 59 ~WebViewLocator(){} |
| 60 void UpdateDictionary(base::DictionaryValue* dict) const; |
| 61 |
| 62 Type type; |
| 63 Locator locator; |
| 64 }; |
| 65 |
| 66 struct WebViewId { |
| 67 enum Type { |
| 68 kTypeTabId = 0, |
| 69 kTypeViewId, |
| 70 kMaxTypes |
| 71 }; |
| 72 struct Id { |
| 73 Id() { } |
| 74 ~Id() { } |
| 75 |
| 76 int tab_id; |
| 77 AutomationId view_id; |
| 78 }; |
| 79 |
| 80 static WebViewId ForTab(int tab_id) { |
| 81 WebViewId id; |
| 82 id.type = kTypeTabId; |
| 83 id.id.tab_id = tab_id; |
| 84 return id; |
| 85 } |
| 86 |
| 87 static WebViewId ForView(const AutomationId& view_id) { |
| 88 WebViewId id; |
| 89 id.type = kTypeViewId; |
| 90 id.id.view_id = view_id; |
| 91 return id; |
| 92 } |
| 93 |
| 94 WebViewId() { } |
| 95 ~WebViewId() {} |
| 96 bool IsValid() const { |
| 97 if (type == kTypeTabId) { |
| 98 return id.tab_id != 0; |
| 99 } |
| 100 if (type == kTypeViewId) { |
| 101 return id.view_id.is_valid(); |
| 102 } |
| 103 return false; |
| 104 } |
| 105 void UpdateDictionary(base::DictionaryValue* dictionary) const; |
| 106 |
| 107 Type type; |
| 108 Id id; |
| 109 }; |
| 110 |
| 111 struct WebViewInfo { |
| 112 WebViewInfo(AutomationId::Type type, |
| 113 const WebViewId& view_id, |
| 114 const std::string& extension_id); |
| 115 ~WebViewInfo(); |
| 116 |
| 117 AutomationId::Type type; |
| 118 WebViewId view_id; |
| 119 std::string extension_id; |
| 120 }; |
| 121 |
40 // Sends a JSON request to the chrome automation provider. Returns true | 122 // Sends a JSON request to the chrome automation provider. Returns true |
41 // if the JSON request was successfully sent and the reply was received. | 123 // if the JSON request was successfully sent and the reply was received. |
42 // If true, |success| will be set to whether the JSON request was | 124 // If true, |success| will be set to whether the JSON request was |
43 // completed successfully by the automation provider. | 125 // completed successfully by the automation provider. |
44 bool SendAutomationJSONRequest(AutomationMessageSender* sender, | 126 bool SendAutomationJSONRequest(AutomationMessageSender* sender, |
45 const std::string& request, | 127 const std::string& request, |
46 int timeout_ms, | 128 int timeout_ms, |
47 std::string* reply, | 129 std::string* reply, |
48 bool* success) WARN_UNUSED_RESULT; | 130 bool* success) WARN_UNUSED_RESULT; |
49 | 131 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 const std::string& url, | 164 const std::string& url, |
83 int navigation_count, | 165 int navigation_count, |
84 AutomationMsg_NavigationResponseValues* nav_response, | 166 AutomationMsg_NavigationResponseValues* nav_response, |
85 std::string* error_msg) WARN_UNUSED_RESULT; | 167 std::string* error_msg) WARN_UNUSED_RESULT; |
86 | 168 |
87 // Requests the given javascript to be executed in the frame specified by the | 169 // Requests the given javascript to be executed in the frame specified by the |
88 // given xpath. Returns true on success. If true, |result| will be set to the | 170 // given xpath. Returns true on success. If true, |result| will be set to the |
89 // result of the execution and ownership will be given to the caller. | 171 // result of the execution and ownership will be given to the caller. |
90 bool SendExecuteJavascriptJSONRequest( | 172 bool SendExecuteJavascriptJSONRequest( |
91 AutomationMessageSender* sender, | 173 AutomationMessageSender* sender, |
92 int browser_index, | 174 const WebViewLocator& locator, |
93 int tab_index, | |
94 const std::string& frame_xpath, | 175 const std::string& frame_xpath, |
95 const std::string& javascript, | 176 const std::string& javascript, |
96 base::Value** result, | 177 base::Value** result, |
97 std::string* error_msg) WARN_UNUSED_RESULT; | 178 std::string* error_msg) WARN_UNUSED_RESULT; |
98 | 179 |
99 // Requests the specified tab to go forward. Waits for the load to complete. | 180 // Requests the specified tab to go forward. Waits for the load to complete. |
100 // Returns true on success. | 181 // Returns true on success. |
101 bool SendGoForwardJSONRequest( | 182 bool SendGoForwardJSONRequest( |
102 AutomationMessageSender* sender, | 183 AutomationMessageSender* sender, |
103 int browser_index, | 184 int browser_index, |
(...skipping 19 matching lines...) Expand all Loading... |
123 // Requests a snapshot of the entire page to be saved to the given path | 204 // Requests a snapshot of the entire page to be saved to the given path |
124 // in PNG format. | 205 // in PNG format. |
125 // Returns true on success. | 206 // Returns true on success. |
126 bool SendCaptureEntirePageJSONRequest( | 207 bool SendCaptureEntirePageJSONRequest( |
127 AutomationMessageSender* sender, | 208 AutomationMessageSender* sender, |
128 int browser_index, | 209 int browser_index, |
129 int tab_index, | 210 int tab_index, |
130 const FilePath& path, | 211 const FilePath& path, |
131 std::string* error_msg) WARN_UNUSED_RESULT; | 212 std::string* error_msg) WARN_UNUSED_RESULT; |
132 | 213 |
133 // Requests the url of the specified tab. Returns true on success. | |
134 bool SendGetTabURLJSONRequest( | |
135 AutomationMessageSender* sender, | |
136 int browser_index, | |
137 int tab_index, | |
138 std::string* url, | |
139 std::string* error_msg) WARN_UNUSED_RESULT; | |
140 | |
141 // Requests the title of the specified tab. Returns true on success. | |
142 bool SendGetTabTitleJSONRequest( | |
143 AutomationMessageSender* sender, | |
144 int browser_index, | |
145 int tab_index, | |
146 std::string* tab_title, | |
147 std::string* error_msg) WARN_UNUSED_RESULT; | |
148 | |
149 // Requests all the cookies for the given URL. On success returns true and | 214 // Requests all the cookies for the given URL. On success returns true and |
150 // caller takes ownership of |cookies|, which is a list of all the cookies in | 215 // caller takes ownership of |cookies|, which is a list of all the cookies in |
151 // dictionary format. | 216 // dictionary format. |
152 bool SendGetCookiesJSONRequest( | 217 bool SendGetCookiesJSONRequest( |
153 AutomationMessageSender* sender, | 218 AutomationMessageSender* sender, |
154 const std::string& url, | 219 const std::string& url, |
155 base::ListValue** cookies, | 220 base::ListValue** cookies, |
156 std::string* error_msg) WARN_UNUSED_RESULT; | 221 std::string* error_msg) WARN_UNUSED_RESULT; |
157 | 222 |
158 // Requests deletion of the cookie with the given name and URL. Returns true | 223 // Requests deletion of the cookie with the given name and URL. Returns true |
159 // on success. | 224 // on success. |
160 bool SendDeleteCookieJSONRequest( | 225 bool SendDeleteCookieJSONRequest( |
161 AutomationMessageSender* sender, | 226 AutomationMessageSender* sender, |
162 const std::string& url, | 227 const std::string& url, |
163 const std::string& cookie_name, | 228 const std::string& cookie_name, |
164 std::string* error_msg) WARN_UNUSED_RESULT; | 229 std::string* error_msg) WARN_UNUSED_RESULT; |
165 | 230 |
166 // Requests setting the given cookie for the given URL. Returns true on | 231 // Requests setting the given cookie for the given URL. Returns true on |
167 // success. The caller retains ownership of |cookie_dict|. | 232 // success. The caller retains ownership of |cookie_dict|. |
168 bool SendSetCookieJSONRequest( | 233 bool SendSetCookieJSONRequest( |
169 AutomationMessageSender* sender, | 234 AutomationMessageSender* sender, |
170 const std::string& url, | 235 const std::string& url, |
171 base::DictionaryValue* cookie_dict, | 236 base::DictionaryValue* cookie_dict, |
172 std::string* error_msg) WARN_UNUSED_RESULT; | 237 std::string* error_msg) WARN_UNUSED_RESULT; |
173 | 238 |
174 // Requests the IDs for all open tabs. Returns true on success. | 239 // Requests the IDs for all open tabs. Returns true on success. |
175 bool SendGetTabIdsJSONRequest( | 240 bool SendGetTabIdsJSONRequest( |
176 AutomationMessageSender* sender, | 241 AutomationMessageSender* sender, |
177 std::vector<int>* tab_ids, | 242 std::vector<WebViewInfo>* views, |
| 243 std::string* error_msg) WARN_UNUSED_RESULT; |
| 244 |
| 245 // Requests info for all open views. Returns true on success. |
| 246 bool SendGetWebViewsJSONRequest( |
| 247 AutomationMessageSender* sender, |
| 248 std::vector<WebViewInfo>* views, |
178 std::string* error_msg) WARN_UNUSED_RESULT; | 249 std::string* error_msg) WARN_UNUSED_RESULT; |
179 | 250 |
180 // Requests whether the given tab ID is valid. Returns true on success. | 251 // Requests whether the given tab ID is valid. Returns true on success. |
181 bool SendIsTabIdValidJSONRequest( | 252 bool SendIsTabIdValidJSONRequest( |
182 AutomationMessageSender* sender, | 253 AutomationMessageSender* sender, |
183 int tab_id, | 254 const WebViewId& view_id, |
184 bool* is_valid, | 255 bool* is_valid, |
185 std::string* error_msg) WARN_UNUSED_RESULT; | 256 std::string* error_msg) WARN_UNUSED_RESULT; |
186 | 257 |
| 258 // Requests whether the given view ID is valid. Returns true on success. |
| 259 bool SendDoesViewExistJSONRequest( |
| 260 AutomationMessageSender* sender, |
| 261 const WebViewId& view_id, |
| 262 bool* does_exist, |
| 263 std::string* error_msg) WARN_UNUSED_RESULT; |
| 264 |
187 // Requests to close the given tab. Returns true on success. | 265 // Requests to close the given tab. Returns true on success. |
188 bool SendCloseTabJSONRequest( | 266 bool SendCloseTabJSONRequest( |
189 AutomationMessageSender* sender, | 267 AutomationMessageSender* sender, |
190 int browser_index, | 268 int browser_index, |
191 int tab_index, | 269 int tab_index, |
192 std::string* error_msg) WARN_UNUSED_RESULT; | 270 std::string* error_msg) WARN_UNUSED_RESULT; |
193 | 271 |
194 // Requests to send the WebKit event for a mouse move to the given | 272 // Requests to send the WebKit event for a mouse move to the given |
195 // coordinate in the specified tab. Returns true on success. | 273 // coordinate in the specified tab. Returns true on success. |
196 bool SendMouseMoveJSONRequest( | 274 bool SendMouseMoveJSONRequest( |
197 AutomationMessageSender* sender, | 275 AutomationMessageSender* sender, |
198 int browser_index, | 276 const WebViewLocator& locator, |
199 int tab_index, | |
200 int x, | 277 int x, |
201 int y, | 278 int y, |
202 std::string* error_msg) WARN_UNUSED_RESULT; | 279 std::string* error_msg) WARN_UNUSED_RESULT; |
203 | 280 |
204 // Requests to send the WebKit events for a mouse click at the given | 281 // Requests to send the WebKit events for a mouse click at the given |
205 // coordinate in the specified tab. Returns true on success. | 282 // coordinate in the specified tab. Returns true on success. |
206 bool SendMouseClickJSONRequest( | 283 bool SendMouseClickJSONRequest( |
207 AutomationMessageSender* sender, | 284 AutomationMessageSender* sender, |
208 int browser_index, | 285 const WebViewLocator& locator, |
209 int tab_index, | |
210 automation::MouseButton button, | 286 automation::MouseButton button, |
211 int x, | 287 int x, |
212 int y, | 288 int y, |
213 std::string* error_msg) WARN_UNUSED_RESULT; | 289 std::string* error_msg) WARN_UNUSED_RESULT; |
214 | 290 |
215 // Requests to send the WebKit events for a mouse drag from the start to end | 291 // Requests to send the WebKit events for a mouse drag from the start to end |
216 // coordinates given in the specified tab. Returns true on success. | 292 // coordinates given in the specified tab. Returns true on success. |
217 bool SendMouseDragJSONRequest( | 293 bool SendMouseDragJSONRequest( |
218 AutomationMessageSender* sender, | 294 AutomationMessageSender* sender, |
219 int browser_index, | 295 const WebViewLocator& locator, |
220 int tab_index, | |
221 int start_x, | 296 int start_x, |
222 int start_y, | 297 int start_y, |
223 int end_x, | 298 int end_x, |
224 int end_y, | 299 int end_y, |
225 std::string* error_msg) WARN_UNUSED_RESULT; | 300 std::string* error_msg) WARN_UNUSED_RESULT; |
226 | 301 |
227 // Requests to send the WebKit event for a mouse button down at the given | 302 // Requests to send the WebKit event for a mouse button down at the given |
228 // coordinate in the specified tab. Returns true on success. | 303 // coordinate in the specified tab. Returns true on success. |
229 bool SendMouseButtonDownJSONRequest( | 304 bool SendMouseButtonDownJSONRequest( |
230 AutomationMessageSender* sender, | 305 AutomationMessageSender* sender, |
231 int browser_index, | 306 const WebViewLocator& locator, |
232 int tab_index, | |
233 int x, | 307 int x, |
234 int y, | 308 int y, |
235 std::string* error_msg) WARN_UNUSED_RESULT; | 309 std::string* error_msg) WARN_UNUSED_RESULT; |
236 | 310 |
237 // Requests to send the WebKit event for a mouse button up at the given | 311 // Requests to send the WebKit event for a mouse button up at the given |
238 // coordinate in the specified tab. Returns true on success. | 312 // coordinate in the specified tab. Returns true on success. |
239 bool SendMouseButtonUpJSONRequest( | 313 bool SendMouseButtonUpJSONRequest( |
240 AutomationMessageSender* sender, | 314 AutomationMessageSender* sender, |
241 int browser_index, | 315 const WebViewLocator& locator, |
242 int tab_index, | |
243 int x, | 316 int x, |
244 int y, | 317 int y, |
245 std::string* error_msg) WARN_UNUSED_RESULT; | 318 std::string* error_msg) WARN_UNUSED_RESULT; |
246 | 319 |
247 // Requests to send the WebKit event for a mouse double click at the given | 320 // Requests to send the WebKit event for a mouse double click at the given |
248 // coordinate in the specified tab. Returns true on success. | 321 // coordinate in the specified tab. Returns true on success. |
249 bool SendMouseDoubleClickJSONRequest( | 322 bool SendMouseDoubleClickJSONRequest( |
250 AutomationMessageSender* sender, | 323 AutomationMessageSender* sender, |
251 int browser_index, | 324 const WebViewLocator& locator, |
252 int tab_index, | |
253 int x, | 325 int x, |
254 int y, | 326 int y, |
255 std::string* error_msg) WARN_UNUSED_RESULT; | 327 std::string* error_msg) WARN_UNUSED_RESULT; |
256 | 328 |
257 // Requests to send the WebKit event for the given |WebKeyEvent| in a | 329 // Requests to send the WebKit event for the given |WebKeyEvent| in a |
258 // specified tab. Returns true on success. | 330 // specified tab. Returns true on success. |
259 bool SendWebKeyEventJSONRequest( | 331 bool SendWebKeyEventJSONRequest( |
260 AutomationMessageSender* sender, | 332 AutomationMessageSender* sender, |
261 int browser_index, | 333 const WebViewLocator& locator, |
262 int tab_index, | |
263 const WebKeyEvent& key_event, | 334 const WebKeyEvent& key_event, |
264 std::string* error_msg) WARN_UNUSED_RESULT; | 335 std::string* error_msg) WARN_UNUSED_RESULT; |
265 | 336 |
266 // Requests to send the key event for the given keycode+modifiers to a | 337 // Requests to send the key event for the given keycode+modifiers to a |
267 // browser window containing the specified tab. Returns true on success. | 338 // browser window containing the specified tab. Returns true on success. |
268 bool SendNativeKeyEventJSONRequest( | 339 bool SendNativeKeyEventJSONRequest( |
269 AutomationMessageSender* sender, | 340 AutomationMessageSender* sender, |
270 int browser_index, | 341 int browser_index, |
271 int tab_index, | 342 int tab_index, |
272 ui::KeyboardCode key_code, | 343 ui::KeyboardCode key_code, |
273 int modifiers, | 344 int modifiers, |
274 std::string* error_msg) WARN_UNUSED_RESULT; | 345 std::string* error_msg) WARN_UNUSED_RESULT; |
275 | 346 |
276 // Requests to drag and drop the file paths at the given coordinate in the | 347 // Requests to drag and drop the file paths at the given coordinate in the |
277 // specified tab. Returns true on success. | 348 // specified tab. Returns true on success. |
278 bool SendDragAndDropFilePathsJSONRequest( | 349 bool SendDragAndDropFilePathsJSONRequest( |
279 AutomationMessageSender* sender, | 350 AutomationMessageSender* sender, |
280 int browser_index, | 351 const WebViewLocator& locator, |
281 int tab_index, | |
282 int x, | 352 int x, |
283 int y, | 353 int y, |
284 const std::vector<FilePath::StringType>& paths, | 354 const std::vector<FilePath::StringType>& paths, |
285 std::string* error_msg) WARN_UNUSED_RESULT; | 355 std::string* error_msg) WARN_UNUSED_RESULT; |
286 | 356 |
287 // Requests to get the active JavaScript modal dialog's message. Returns true | 357 // Requests to get the active JavaScript modal dialog's message. Returns true |
288 // on success. | 358 // on success. |
289 bool SendGetAppModalDialogMessageJSONRequest( | 359 bool SendGetAppModalDialogMessageJSONRequest( |
290 AutomationMessageSender* sender, | 360 AutomationMessageSender* sender, |
291 std::string* message, | 361 std::string* message, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 // Requests that the given extension be installed. If |with_ui| is false, | 396 // Requests that the given extension be installed. If |with_ui| is false, |
327 // the extension will be installed silently. Returns true on success. | 397 // the extension will be installed silently. Returns true on success. |
328 bool SendInstallExtensionJSONRequest( | 398 bool SendInstallExtensionJSONRequest( |
329 AutomationMessageSender* sender, | 399 AutomationMessageSender* sender, |
330 const FilePath& path, | 400 const FilePath& path, |
331 bool with_ui, | 401 bool with_ui, |
332 std::string* extension_id, | 402 std::string* extension_id, |
333 std::string* error_msg) WARN_UNUSED_RESULT; | 403 std::string* error_msg) WARN_UNUSED_RESULT; |
334 | 404 |
335 #endif // CHROME_TEST_AUTOMATION_AUTOMATION_JSON_REQUESTS_H_ | 405 #endif // CHROME_TEST_AUTOMATION_AUTOMATION_JSON_REQUESTS_H_ |
OLD | NEW |