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_WEBDRIVER_SESSION_H_ | 5 #ifndef CHROME_TEST_WEBDRIVER_SESSION_H_ |
6 #define CHROME_TEST_WEBDRIVER_SESSION_H_ | 6 #define CHROME_TEST_WEBDRIVER_SESSION_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/string16.h" | 14 #include "base/string16.h" |
15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
16 #include "chrome/common/automation_constants.h" | 16 #include "chrome/common/automation_constants.h" |
17 #include "chrome/test/webdriver/automation.h" | 17 #include "chrome/test/webdriver/automation.h" |
18 #include "chrome/test/webdriver/frame_path.h" | 18 #include "chrome/test/webdriver/frame_path.h" |
19 #include "chrome/test/webdriver/web_element_id.h" | 19 #include "chrome/test/webdriver/web_element_id.h" |
20 #include "ui/gfx/point.h" | 20 #include "chrome/test/webdriver/webdriver_basic_types.h" |
21 | 21 |
22 class CommandLine; | 22 class CommandLine; |
23 class FilePath; | 23 class FilePath; |
24 | 24 |
25 namespace base { | 25 namespace base { |
26 class DictionaryValue; | 26 class DictionaryValue; |
27 class ListValue; | 27 class ListValue; |
28 class Value; | 28 class Value; |
29 class WaitableEvent; | 29 class WaitableEvent; |
30 } | 30 } |
31 | 31 |
32 namespace gfx { | |
33 class Rect; | |
34 class Size; | |
35 } | |
36 | |
37 namespace webdriver { | 32 namespace webdriver { |
38 | 33 |
39 class Error; | 34 class Error; |
| 35 class ValueParser; |
40 | 36 |
41 // A window ID and frame path combination that uniquely identifies a specific | 37 // A window ID and frame path combination that uniquely identifies a specific |
42 // frame within a session. | 38 // frame within a session. |
43 struct FrameId { | 39 struct FrameId { |
44 FrameId(int window_id, const FramePath& frame_path); | 40 FrameId(int window_id, const FramePath& frame_path); |
45 FrameId& operator=(const FrameId& other); | 41 FrameId& operator=(const FrameId& other); |
46 int window_id; | 42 int window_id; |
47 FramePath frame_path; | 43 FramePath frame_path; |
48 }; | 44 }; |
49 | 45 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 Error* ExecuteScript(const FrameId& frame_id, | 92 Error* ExecuteScript(const FrameId& frame_id, |
97 const std::string& script, | 93 const std::string& script, |
98 const base::ListValue* const args, | 94 const base::ListValue* const args, |
99 base::Value** value); | 95 base::Value** value); |
100 | 96 |
101 // Same as above, but uses the currently targeted window and frame. | 97 // Same as above, but uses the currently targeted window and frame. |
102 Error* ExecuteScript(const std::string& script, | 98 Error* ExecuteScript(const std::string& script, |
103 const base::ListValue* const args, | 99 const base::ListValue* const args, |
104 base::Value** value); | 100 base::Value** value); |
105 | 101 |
| 102 // Executes the given script in the context of the given frame and parses |
| 103 // the value with the given parser. The script should be in the form of an |
| 104 // anonymous function. |script_name| is only used when creating error |
| 105 // messages. This function takes ownership of |args| and |parser|. |
| 106 Error* ExecuteScriptAndParse(const FrameId& frame_id, |
| 107 const std::string& anonymous_func_script, |
| 108 const std::string& script_name, |
| 109 const base::ListValue* args, |
| 110 const ValueParser* parser); |
| 111 |
106 // Executes given |script| in the context of the given frame. | 112 // Executes given |script| in the context of the given frame. |
107 // The |script| should be in the form of a function body | 113 // The |script| should be in the form of a function body |
108 // (e.g. "return arguments[0]"), where |args| is the list of arguments to | 114 // (e.g. "return arguments[0]"), where |args| is the list of arguments to |
109 // pass to the function. The caller is responsible for the script result | 115 // pass to the function. The caller is responsible for the script result |
110 // |value|, which is set only if there is no error. | 116 // |value|, which is set only if there is no error. |
111 Error* ExecuteAsyncScript(const FrameId& frame_id, | 117 Error* ExecuteAsyncScript(const FrameId& frame_id, |
112 const std::string& script, | 118 const std::string& script, |
113 const base::ListValue* const args, | 119 const base::ListValue* const args, |
114 base::Value** value); | 120 base::Value** value); |
115 | 121 |
116 // Send the given keys to the given element dictionary. This function takes | 122 // Send the given keys to the given element dictionary. This function takes |
117 // ownership of |element|. | 123 // ownership of |element|. |
118 Error* SendKeys(const WebElementId& element, const string16& keys); | 124 Error* SendKeys(const WebElementId& element, const string16& keys); |
119 | 125 |
120 // Sets the file paths to the file upload control under the given location. | 126 // Sets the file paths to the file upload control under the given location. |
121 Error* DragAndDropFilePaths(const gfx::Point& location, | 127 Error* DragAndDropFilePaths(const Point& location, |
122 const std::vector<FilePath::StringType>& paths); | 128 const std::vector<FilePath::StringType>& paths); |
123 | 129 |
124 // Clicks the mouse at the given location using the given button. | 130 // Clicks the mouse at the given location using the given button. |
125 Error* MouseMoveAndClick(const gfx::Point& location, | 131 Error* MouseMoveAndClick(const Point& location, |
126 automation::MouseButton button); | 132 automation::MouseButton button); |
127 Error* MouseMove(const gfx::Point& location); | 133 Error* MouseMove(const Point& location); |
128 Error* MouseDrag(const gfx::Point& start, const gfx::Point& end); | 134 Error* MouseDrag(const Point& start, const Point& end); |
129 Error* MouseClick(automation::MouseButton button); | 135 Error* MouseClick(automation::MouseButton button); |
130 Error* MouseButtonDown(); | 136 Error* MouseButtonDown(); |
131 Error* MouseButtonUp(); | 137 Error* MouseButtonUp(); |
132 Error* MouseDoubleClick(); | 138 Error* MouseDoubleClick(); |
133 | 139 |
134 Error* NavigateToURL(const std::string& url); | 140 Error* NavigateToURL(const std::string& url); |
135 Error* GoForward(); | 141 Error* GoForward(); |
136 Error* GoBack(); | 142 Error* GoBack(); |
137 Error* Reload(); | 143 Error* Reload(); |
138 Error* GetURL(std::string* url); | 144 Error* GetURL(std::string* url); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 Error* FindElements(const FrameId& frame_id, | 213 Error* FindElements(const FrameId& frame_id, |
208 const WebElementId& root_element, | 214 const WebElementId& root_element, |
209 const std::string& locator, | 215 const std::string& locator, |
210 const std::string& query, | 216 const std::string& query, |
211 std::vector<WebElementId>* elements); | 217 std::vector<WebElementId>* elements); |
212 | 218 |
213 // Scroll the element into view and get its location relative to | 219 // Scroll the element into view and get its location relative to |
214 // the client's viewport. | 220 // the client's viewport. |
215 Error* GetElementLocationInView( | 221 Error* GetElementLocationInView( |
216 const WebElementId& element, | 222 const WebElementId& element, |
217 gfx::Point* location); | 223 Point* location); |
218 | 224 |
219 // Scroll the element's region into view and get its location relative to | 225 // Scroll the element's region into view and get its location relative to |
220 // the client's viewport. If |center| is true, the element will be centered | 226 // the client's viewport. If |center| is true, the element will be centered |
221 // if it is too big to fit in view. If |verify_clickable_at_middle| is true, | 227 // if it is too big to fit in view. If |verify_clickable_at_middle| is true, |
222 // an error will be returned if the element is not clickable in the middle | 228 // an error will be returned if the element is not clickable in the middle |
223 // of the given region. | 229 // of the given region. |
224 Error* GetElementRegionInView( | 230 Error* GetElementRegionInView( |
225 const WebElementId& element, | 231 const WebElementId& element, |
226 const gfx::Rect& region, | 232 const Rect& region, |
227 bool center, | 233 bool center, |
228 bool verify_clickable_at_middle, | 234 bool verify_clickable_at_middle, |
229 gfx::Point* location); | 235 Point* location); |
230 | 236 |
231 // Gets the size of the element from the given window and frame, even if | 237 // Gets the size of the element from the given window and frame, even if |
232 // its display is none. | 238 // its display is none. |
233 Error* GetElementSize(const FrameId& frame_id, | 239 Error* GetElementSize(const FrameId& frame_id, |
234 const WebElementId& element, | 240 const WebElementId& element, |
235 gfx::Size* size); | 241 Size* size); |
236 | 242 |
237 // Gets the size of the element's first client rect. If the element has | 243 // Gets the size of the element's first client rect. If the element has |
238 // no client rects, this will return an error. | 244 // no client rects, this will return an error. |
239 Error* GetElementFirstClientRect(const FrameId& frame_id, | 245 Error* GetElementFirstClientRect(const FrameId& frame_id, |
240 const WebElementId& element, | 246 const WebElementId& element, |
241 gfx::Rect* rect); | 247 Rect* rect); |
242 | 248 |
243 // Gets the element's effective style for the given property. | 249 // Gets the element's effective style for the given property. |
244 Error* GetElementEffectiveStyle( | 250 Error* GetElementEffectiveStyle( |
245 const FrameId& frame_id, | 251 const FrameId& frame_id, |
246 const WebElementId& element, | 252 const WebElementId& element, |
247 const std::string& prop, | 253 const std::string& prop, |
248 std::string* value); | 254 std::string* value); |
249 | 255 |
250 // Gets the top and left element border widths for the given frame. | 256 // Gets the top and left element border widths for the given frame. |
251 Error* GetElementBorder(const FrameId& frame_id, | 257 Error* GetElementBorder(const FrameId& frame_id, |
(...skipping 30 matching lines...) Expand all Loading... |
282 | 288 |
283 // Gets the tag name of the given element. | 289 // Gets the tag name of the given element. |
284 Error* GetElementTagName(const FrameId& frame_id, | 290 Error* GetElementTagName(const FrameId& frame_id, |
285 const WebElementId& element, | 291 const WebElementId& element, |
286 std::string* tag_name); | 292 std::string* tag_name); |
287 | 293 |
288 // Gets the clickable location of the given element. It will be the center | 294 // Gets the clickable location of the given element. It will be the center |
289 // location of the element. If the element is not clickable, or if the | 295 // location of the element. If the element is not clickable, or if the |
290 // location cannot be determined, an error will be returned. | 296 // location cannot be determined, an error will be returned. |
291 Error* GetClickableLocation(const WebElementId& element, | 297 Error* GetClickableLocation(const WebElementId& element, |
292 gfx::Point* location); | 298 Point* location); |
293 | 299 |
294 // Gets the attribute of the given element. If there are no errors, the | 300 // Gets the attribute of the given element. If there are no errors, the |
295 // function sets |value| and the caller takes ownership. | 301 // function sets |value| and the caller takes ownership. |
296 Error* GetAttribute(const WebElementId& element, const std::string& key, | 302 Error* GetAttribute(const WebElementId& element, const std::string& key, |
297 base::Value** value); | 303 base::Value** value); |
298 | 304 |
299 // Waits for all tabs to stop loading. Returns true on success. | 305 // Waits for all tabs to stop loading. Returns true on success. |
300 Error* WaitForAllTabsToStopLoading(); | 306 Error* WaitForAllTabsToStopLoading(); |
301 | 307 |
302 // Install packed extension at |path|. | 308 // Install packed extension at |path|. |
303 Error* InstallExtension(const FilePath& path); | 309 Error* InstallExtension(const FilePath& path); |
304 | 310 |
305 const std::string& id() const; | 311 const std::string& id() const; |
306 | 312 |
307 const FrameId& current_target() const; | 313 const FrameId& current_target() const; |
308 | 314 |
309 void set_async_script_timeout(int timeout_ms); | 315 void set_async_script_timeout(int timeout_ms); |
310 int async_script_timeout() const; | 316 int async_script_timeout() const; |
311 | 317 |
312 void set_implicit_wait(int timeout_ms); | 318 void set_implicit_wait(int timeout_ms); |
313 int implicit_wait() const; | 319 int implicit_wait() const; |
314 | 320 |
315 const gfx::Point& get_mouse_position() const; | 321 const Point& get_mouse_position() const; |
316 | 322 |
317 const Options& options() const; | 323 const Options& options() const; |
318 | 324 |
319 // Gets the browser connection state. | 325 // Gets the browser connection state. |
320 Error* GetBrowserConnectionState(bool* online); | 326 Error* GetBrowserConnectionState(bool* online); |
321 | 327 |
322 // Gets the status of the application cache. | 328 // Gets the status of the application cache. |
323 Error* GetAppCacheStatus(int* status); | 329 Error* GetAppCacheStatus(int* status); |
324 | 330 |
325 private: | 331 private: |
326 void RunSessionTask(Task* task); | 332 void RunSessionTask(Task* task); |
327 void RunSessionTaskOnSessionThread( | 333 void RunSessionTaskOnSessionThread( |
328 Task* task, | 334 Task* task, |
329 base::WaitableEvent* done_event); | 335 base::WaitableEvent* done_event); |
330 void InitOnSessionThread(const Automation::BrowserOptions& options, | 336 void InitOnSessionThread(const Automation::BrowserOptions& options, |
331 Error** error); | 337 Error** error); |
332 void TerminateOnSessionThread(); | 338 void TerminateOnSessionThread(); |
333 | 339 |
334 // Executes the given |script| in the context of the given frame. | 340 // Executes the given |script| in the context of the given frame. |
335 // Waits for script to finish and parses the response. | 341 // Waits for script to finish and parses the response. |
336 // The caller is responsible for the script result |value|. | 342 // The caller is responsible for the script result |value|. |
337 Error* ExecuteScriptAndParseResponse(const FrameId& frame_id, | 343 Error* ExecuteScriptAndParseValue(const FrameId& frame_id, |
338 const std::string& script, | 344 const std::string& script, |
339 base::Value** value); | 345 base::Value** value); |
340 | 346 |
341 void SendKeysOnSessionThread(const string16& keys, Error** error); | 347 void SendKeysOnSessionThread(const string16& keys, Error** error); |
342 Error* SwitchToFrameWithJavaScriptLocatedFrame( | 348 Error* SwitchToFrameWithJavaScriptLocatedFrame( |
343 const std::string& script, | 349 const std::string& script, |
344 base::ListValue* args); | 350 base::ListValue* args); |
345 Error* FindElementsHelper(const FrameId& frame_id, | 351 Error* FindElementsHelper(const FrameId& frame_id, |
346 const WebElementId& root_element, | 352 const WebElementId& root_element, |
347 const std::string& locator, | 353 const std::string& locator, |
348 const std::string& query, | 354 const std::string& query, |
349 bool find_one, | 355 bool find_one, |
350 std::vector<WebElementId>* elements); | 356 std::vector<WebElementId>* elements); |
| 357 Error* ExecuteFindElementScriptAndParse(const FrameId& frame_id, |
| 358 const WebElementId& root_element, |
| 359 const std::string& locator, |
| 360 const std::string& query, |
| 361 bool find_one, |
| 362 std::vector<WebElementId>* elements); |
351 // Returns an error if the element is not clickable. | 363 // Returns an error if the element is not clickable. |
352 Error* VerifyElementIsClickable( | 364 Error* VerifyElementIsClickable( |
353 const FrameId& frame_id, | 365 const FrameId& frame_id, |
354 const WebElementId& element, | 366 const WebElementId& element, |
355 const gfx::Point& location); | 367 const Point& location); |
356 Error* GetElementRegionInViewHelper( | 368 Error* GetElementRegionInViewHelper( |
357 const FrameId& frame_id, | 369 const FrameId& frame_id, |
358 const WebElementId& element, | 370 const WebElementId& element, |
359 const gfx::Rect& region, | 371 const Rect& region, |
360 bool center, | 372 bool center, |
361 bool verify_clickable_at_middle, | 373 bool verify_clickable_at_middle, |
362 gfx::Point* location); | 374 Point* location); |
363 | 375 |
364 const std::string id_; | 376 const std::string id_; |
365 FrameId current_target_; | 377 FrameId current_target_; |
366 | 378 |
367 scoped_ptr<Automation> automation_; | 379 scoped_ptr<Automation> automation_; |
368 base::Thread thread_; | 380 base::Thread thread_; |
369 | 381 |
370 // Timeout (in ms) for asynchronous script execution. | 382 // Timeout (in ms) for asynchronous script execution. |
371 int async_script_timeout_; | 383 int async_script_timeout_; |
372 | 384 |
373 // Time (in ms) of how long to wait while searching for a single element. | 385 // Time (in ms) of how long to wait while searching for a single element. |
374 int implicit_wait_; | 386 int implicit_wait_; |
375 | 387 |
376 // Vector of the |WebElementId|s for each frame of the current target frame | 388 // Vector of the |WebElementId|s for each frame of the current target frame |
377 // path. The first refers to the first frame element in the root document. | 389 // path. The first refers to the first frame element in the root document. |
378 // If the target frame is window.top, this will be empty. | 390 // If the target frame is window.top, this will be empty. |
379 std::vector<WebElementId> frame_elements_; | 391 std::vector<WebElementId> frame_elements_; |
380 | 392 |
381 // Last mouse position. Advanced APIs need this value. | 393 // Last mouse position. Advanced APIs need this value. |
382 gfx::Point mouse_position_; | 394 Point mouse_position_; |
383 | 395 |
384 // Chrome does not have an individual method for setting the prompt text | 396 // Chrome does not have an individual method for setting the prompt text |
385 // of an alert. Instead, when the WebDriver client wants to set the text, | 397 // of an alert. Instead, when the WebDriver client wants to set the text, |
386 // we store it here and pass the text when the alert is accepted or | 398 // we store it here and pass the text when the alert is accepted or |
387 // dismissed. This text should only be used if |has_alert_prompt_text_| | 399 // dismissed. This text should only be used if |has_alert_prompt_text_| |
388 // is true, so that the default prompt text is not overridden. | 400 // is true, so that the default prompt text is not overridden. |
389 std::string alert_prompt_text_; | 401 std::string alert_prompt_text_; |
390 bool has_alert_prompt_text_; | 402 bool has_alert_prompt_text_; |
391 | 403 |
392 Options options_; | 404 Options options_; |
393 | 405 |
394 DISALLOW_COPY_AND_ASSIGN(Session); | 406 DISALLOW_COPY_AND_ASSIGN(Session); |
395 }; | 407 }; |
396 | 408 |
397 } // namespace webdriver | 409 } // namespace webdriver |
398 | 410 |
399 DISABLE_RUNNABLE_METHOD_REFCOUNT(webdriver::Session); | 411 DISABLE_RUNNABLE_METHOD_REFCOUNT(webdriver::Session); |
400 | 412 |
401 #endif // CHROME_TEST_WEBDRIVER_SESSION_H_ | 413 #endif // CHROME_TEST_WEBDRIVER_SESSION_H_ |
OLD | NEW |