| 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 30 matching lines...) Expand all Loading... |
| 80 Error* ExecuteScript(const FrameId& frame_id, | 76 Error* ExecuteScript(const FrameId& frame_id, |
| 81 const std::string& script, | 77 const std::string& script, |
| 82 const base::ListValue* const args, | 78 const base::ListValue* const args, |
| 83 base::Value** value); | 79 base::Value** value); |
| 84 | 80 |
| 85 // Same as above, but uses the currently targeted window and frame. | 81 // Same as above, but uses the currently targeted window and frame. |
| 86 Error* ExecuteScript(const std::string& script, | 82 Error* ExecuteScript(const std::string& script, |
| 87 const base::ListValue* const args, | 83 const base::ListValue* const args, |
| 88 base::Value** value); | 84 base::Value** value); |
| 89 | 85 |
| 86 // Executes the given script in the context of the given frame and parses |
| 87 // the value with the given parser. The script should be in the form of an |
| 88 // anonymous function. |script_name| is only used when creating error |
| 89 // messages. This function takes ownership of |args| and |parser|. |
| 90 Error* ExecuteScriptAndParse(const FrameId& frame_id, |
| 91 const std::string& anonymous_func_script, |
| 92 const std::string& script_name, |
| 93 const base::ListValue* args, |
| 94 const ValueParser* parser); |
| 95 |
| 90 // Executes given |script| in the context of the given frame. | 96 // Executes given |script| in the context of the given frame. |
| 91 // The |script| should be in the form of a function body | 97 // The |script| should be in the form of a function body |
| 92 // (e.g. "return arguments[0]"), where |args| is the list of arguments to | 98 // (e.g. "return arguments[0]"), where |args| is the list of arguments to |
| 93 // pass to the function. The caller is responsible for the script result | 99 // pass to the function. The caller is responsible for the script result |
| 94 // |value|, which is set only if there is no error. | 100 // |value|, which is set only if there is no error. |
| 95 Error* ExecuteAsyncScript(const FrameId& frame_id, | 101 Error* ExecuteAsyncScript(const FrameId& frame_id, |
| 96 const std::string& script, | 102 const std::string& script, |
| 97 const base::ListValue* const args, | 103 const base::ListValue* const args, |
| 98 base::Value** value); | 104 base::Value** value); |
| 99 | 105 |
| 100 // Send the given keys to the given element dictionary. This function takes | 106 // Send the given keys to the given element dictionary. This function takes |
| 101 // ownership of |element|. | 107 // ownership of |element|. |
| 102 Error* SendKeys(const WebElementId& element, const string16& keys); | 108 Error* SendKeys(const WebElementId& element, const string16& keys); |
| 103 | 109 |
| 104 // Sets the file paths to the file upload control under the given location. | 110 // Sets the file paths to the file upload control under the given location. |
| 105 Error* DragAndDropFilePaths(const gfx::Point& location, | 111 Error* DragAndDropFilePaths(const Point& location, |
| 106 const std::vector<FilePath::StringType>& paths); | 112 const std::vector<FilePath::StringType>& paths); |
| 107 | 113 |
| 108 // Clicks the mouse at the given location using the given button. | 114 // Clicks the mouse at the given location using the given button. |
| 109 Error* MouseMoveAndClick(const gfx::Point& location, | 115 Error* MouseMoveAndClick(const Point& location, |
| 110 automation::MouseButton button); | 116 automation::MouseButton button); |
| 111 Error* MouseMove(const gfx::Point& location); | 117 Error* MouseMove(const Point& location); |
| 112 Error* MouseDrag(const gfx::Point& start, const gfx::Point& end); | 118 Error* MouseDrag(const Point& start, const Point& end); |
| 113 Error* MouseClick(automation::MouseButton button); | 119 Error* MouseClick(automation::MouseButton button); |
| 114 Error* MouseButtonDown(); | 120 Error* MouseButtonDown(); |
| 115 Error* MouseButtonUp(); | 121 Error* MouseButtonUp(); |
| 116 Error* MouseDoubleClick(); | 122 Error* MouseDoubleClick(); |
| 117 | 123 |
| 118 Error* NavigateToURL(const std::string& url); | 124 Error* NavigateToURL(const std::string& url); |
| 119 Error* GoForward(); | 125 Error* GoForward(); |
| 120 Error* GoBack(); | 126 Error* GoBack(); |
| 121 Error* Reload(); | 127 Error* Reload(); |
| 122 Error* GetURL(std::string* url); | 128 Error* GetURL(std::string* url); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 Error* FindElements(const FrameId& frame_id, | 197 Error* FindElements(const FrameId& frame_id, |
| 192 const WebElementId& root_element, | 198 const WebElementId& root_element, |
| 193 const std::string& locator, | 199 const std::string& locator, |
| 194 const std::string& query, | 200 const std::string& query, |
| 195 std::vector<WebElementId>* elements); | 201 std::vector<WebElementId>* elements); |
| 196 | 202 |
| 197 // Scroll the element into view and get its location relative to | 203 // Scroll the element into view and get its location relative to |
| 198 // the client's viewport. | 204 // the client's viewport. |
| 199 Error* GetElementLocationInView( | 205 Error* GetElementLocationInView( |
| 200 const WebElementId& element, | 206 const WebElementId& element, |
| 201 gfx::Point* location); | 207 Point* location); |
| 202 | 208 |
| 203 // Scroll the element's region into view and get its location relative to | 209 // Scroll the element's region into view and get its location relative to |
| 204 // the client's viewport. If |center| is true, the element will be centered | 210 // the client's viewport. If |center| is true, the element will be centered |
| 205 // if it is too big to fit in view. | 211 // if it is too big to fit in view. |
| 206 Error* GetElementRegionInView( | 212 Error* GetElementRegionInView( |
| 207 const WebElementId& element, | 213 const WebElementId& element, |
| 208 const gfx::Rect& region, | 214 const Rect& region, |
| 209 bool center, | 215 bool center, |
| 210 gfx::Point* location); | 216 Point* location); |
| 211 | 217 |
| 212 // Gets the size of the element from the given window and frame, even if | 218 // Gets the size of the element from the given window and frame, even if |
| 213 // its display is none. | 219 // its display is none. |
| 214 Error* GetElementSize(const FrameId& frame_id, | 220 Error* GetElementSize(const FrameId& frame_id, |
| 215 const WebElementId& element, | 221 const WebElementId& element, |
| 216 gfx::Size* size); | 222 Size* size); |
| 217 | 223 |
| 218 // Gets the size of the element's first client rect. If the element has | 224 // Gets the size of the element's first client rect. If the element has |
| 219 // no client rects, this will return an error. | 225 // no client rects, this will return an error. |
| 220 Error* GetElementFirstClientRect(const FrameId& frame_id, | 226 Error* GetElementFirstClientRect(const FrameId& frame_id, |
| 221 const WebElementId& element, | 227 const WebElementId& element, |
| 222 gfx::Rect* rect); | 228 Rect* rect); |
| 223 | 229 |
| 224 // Gets the element's effective style for the given property. | 230 // Gets the element's effective style for the given property. |
| 225 Error* GetElementEffectiveStyle( | 231 Error* GetElementEffectiveStyle( |
| 226 const FrameId& frame_id, | 232 const FrameId& frame_id, |
| 227 const WebElementId& element, | 233 const WebElementId& element, |
| 228 const std::string& prop, | 234 const std::string& prop, |
| 229 std::string* value); | 235 std::string* value); |
| 230 | 236 |
| 231 // Gets the top and left element border widths for the given frame. | 237 // Gets the top and left element border widths for the given frame. |
| 232 Error* GetElementBorder(const FrameId& frame_id, | 238 Error* GetElementBorder(const FrameId& frame_id, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 251 | 257 |
| 252 // Gets the tag name of the given element. | 258 // Gets the tag name of the given element. |
| 253 Error* GetElementTagName(const FrameId& frame_id, | 259 Error* GetElementTagName(const FrameId& frame_id, |
| 254 const WebElementId& element, | 260 const WebElementId& element, |
| 255 std::string* tag_name); | 261 std::string* tag_name); |
| 256 | 262 |
| 257 // Gets the clickable location of the given element. It will be the center | 263 // Gets the clickable location of the given element. It will be the center |
| 258 // location of the element. If the element is not clickable, or if the | 264 // location of the element. If the element is not clickable, or if the |
| 259 // location cannot be determined, an error will be returned. | 265 // location cannot be determined, an error will be returned. |
| 260 Error* GetClickableLocation(const WebElementId& element, | 266 Error* GetClickableLocation(const WebElementId& element, |
| 261 gfx::Point* location); | 267 Point* location); |
| 262 | 268 |
| 263 // Gets the attribute of the given element. If there are no errors, the | 269 // Gets the attribute of the given element. If there are no errors, the |
| 264 // function sets |value| and the caller takes ownership. | 270 // function sets |value| and the caller takes ownership. |
| 265 Error* GetAttribute(const WebElementId& element, const std::string& key, | 271 Error* GetAttribute(const WebElementId& element, const std::string& key, |
| 266 base::Value** value); | 272 base::Value** value); |
| 267 | 273 |
| 268 // Waits for all tabs to stop loading. Returns true on success. | 274 // Waits for all tabs to stop loading. Returns true on success. |
| 269 Error* WaitForAllTabsToStopLoading(); | 275 Error* WaitForAllTabsToStopLoading(); |
| 270 | 276 |
| 271 const std::string& id() const; | 277 const std::string& id() const; |
| 272 | 278 |
| 273 const FrameId& current_target() const; | 279 const FrameId& current_target() const; |
| 274 | 280 |
| 275 void set_async_script_timeout(int timeout_ms); | 281 void set_async_script_timeout(int timeout_ms); |
| 276 int async_script_timeout() const; | 282 int async_script_timeout() const; |
| 277 | 283 |
| 278 void set_implicit_wait(int timeout_ms); | 284 void set_implicit_wait(int timeout_ms); |
| 279 int implicit_wait() const; | 285 int implicit_wait() const; |
| 280 | 286 |
| 281 void set_screenshot_on_error(bool error); | 287 void set_screenshot_on_error(bool error); |
| 282 bool screenshot_on_error() const; | 288 bool screenshot_on_error() const; |
| 283 | 289 |
| 284 void set_use_native_events(bool use_native_events); | 290 void set_use_native_events(bool use_native_events); |
| 285 bool use_native_events() const; | 291 bool use_native_events() const; |
| 286 | 292 |
| 287 const gfx::Point& get_mouse_position() const; | 293 const Point& get_mouse_position() const; |
| 288 | 294 |
| 289 private: | 295 private: |
| 290 void RunSessionTask(Task* task); | 296 void RunSessionTask(Task* task); |
| 291 void RunSessionTaskOnSessionThread( | 297 void RunSessionTaskOnSessionThread( |
| 292 Task* task, | 298 Task* task, |
| 293 base::WaitableEvent* done_event); | 299 base::WaitableEvent* done_event); |
| 294 void InitOnSessionThread(const FilePath& browser_exe, | 300 void InitOnSessionThread(const FilePath& browser_exe, |
| 295 const FilePath& user_data_dir, | 301 const FilePath& user_data_dir, |
| 296 const CommandLine& options, | 302 const CommandLine& options, |
| 297 Error** error); | 303 Error** error); |
| 298 void TerminateOnSessionThread(); | 304 void TerminateOnSessionThread(); |
| 299 | 305 |
| 300 // Executes the given |script| in the context of the given frame. | 306 // Executes the given |script| in the context of the given frame. |
| 301 // Waits for script to finish and parses the response. | 307 // Waits for script to finish and parses the response. |
| 302 // The caller is responsible for the script result |value|. | 308 // The caller is responsible for the script result |value|. |
| 303 Error* ExecuteScriptAndParseResponse(const FrameId& frame_id, | 309 Error* ExecuteScriptAndParseValue(const FrameId& frame_id, |
| 304 const std::string& script, | 310 const std::string& script, |
| 305 base::Value** value); | 311 base::Value** value); |
| 306 | 312 |
| 307 void SendKeysOnSessionThread(const string16& keys, Error** error); | 313 void SendKeysOnSessionThread(const string16& keys, Error** error); |
| 308 Error* SwitchToFrameWithJavaScriptLocatedFrame( | 314 Error* SwitchToFrameWithJavaScriptLocatedFrame( |
| 309 const std::string& script, | 315 const std::string& script, |
| 310 base::ListValue* args); | 316 base::ListValue* args); |
| 311 Error* FindElementsHelper(const FrameId& frame_id, | 317 Error* FindElementsHelper(const FrameId& frame_id, |
| 312 const WebElementId& root_element, | 318 const WebElementId& root_element, |
| 313 const std::string& locator, | 319 const std::string& locator, |
| 314 const std::string& query, | 320 const std::string& query, |
| 315 bool find_one, | 321 bool find_one, |
| 316 std::vector<WebElementId>* elements); | 322 std::vector<WebElementId>* elements); |
| 317 Error* GetElementRegionInViewHelper( | 323 Error* GetElementRegionInViewHelper( |
| 318 const FrameId& frame_id, | 324 const FrameId& frame_id, |
| 319 const WebElementId& element, | 325 const WebElementId& element, |
| 320 const gfx::Rect& region, | 326 const Rect& region, |
| 321 bool center, | 327 bool center, |
| 322 gfx::Point* location); | 328 Point* location); |
| 323 | 329 |
| 324 const std::string id_; | 330 const std::string id_; |
| 325 FrameId current_target_; | 331 FrameId current_target_; |
| 326 | 332 |
| 327 scoped_ptr<Automation> automation_; | 333 scoped_ptr<Automation> automation_; |
| 328 base::Thread thread_; | 334 base::Thread thread_; |
| 329 | 335 |
| 330 // Timeout (in ms) for asynchronous script execution. | 336 // Timeout (in ms) for asynchronous script execution. |
| 331 int async_script_timeout_; | 337 int async_script_timeout_; |
| 332 | 338 |
| 333 // Time (in ms) of how long to wait while searching for a single element. | 339 // Time (in ms) of how long to wait while searching for a single element. |
| 334 int implicit_wait_; | 340 int implicit_wait_; |
| 335 | 341 |
| 336 // Since screenshots can be very large when in base64 PNG format; the | 342 // Since screenshots can be very large when in base64 PNG format; the |
| 337 // client is allowed to dyamically enable/disable screenshots on error | 343 // client is allowed to dyamically enable/disable screenshots on error |
| 338 // during the lifetime of the session. | 344 // during the lifetime of the session. |
| 339 bool screenshot_on_error_; | 345 bool screenshot_on_error_; |
| 340 | 346 |
| 341 // True if the session should simulate OS-level input. Currently only applies | 347 // True if the session should simulate OS-level input. Currently only applies |
| 342 // to keyboard input. | 348 // to keyboard input. |
| 343 bool use_native_events_; | 349 bool use_native_events_; |
| 344 | 350 |
| 345 // Vector of the |WebElementId|s for each frame of the current target frame | 351 // Vector of the |WebElementId|s for each frame of the current target frame |
| 346 // path. The first refers to the first frame element in the root document. | 352 // path. The first refers to the first frame element in the root document. |
| 347 // If the target frame is window.top, this will be empty. | 353 // If the target frame is window.top, this will be empty. |
| 348 std::vector<WebElementId> frame_elements_; | 354 std::vector<WebElementId> frame_elements_; |
| 349 | 355 |
| 350 // Last mouse position. Advanced APIs need this value. | 356 // Last mouse position. Advanced APIs need this value. |
| 351 gfx::Point mouse_position_; | 357 Point mouse_position_; |
| 352 | 358 |
| 353 // Chrome does not have an individual method for setting the prompt text | 359 // Chrome does not have an individual method for setting the prompt text |
| 354 // of an alert. Instead, when the WebDriver client wants to set the text, | 360 // of an alert. Instead, when the WebDriver client wants to set the text, |
| 355 // we store it here and pass the text when the alert is accepted or | 361 // we store it here and pass the text when the alert is accepted or |
| 356 // dismissed. This text should only be used if |has_alert_prompt_text_| | 362 // dismissed. This text should only be used if |has_alert_prompt_text_| |
| 357 // is true, so that the default prompt text is not overridden. | 363 // is true, so that the default prompt text is not overridden. |
| 358 std::string alert_prompt_text_; | 364 std::string alert_prompt_text_; |
| 359 bool has_alert_prompt_text_; | 365 bool has_alert_prompt_text_; |
| 360 | 366 |
| 361 DISALLOW_COPY_AND_ASSIGN(Session); | 367 DISALLOW_COPY_AND_ASSIGN(Session); |
| 362 }; | 368 }; |
| 363 | 369 |
| 364 } // namespace webdriver | 370 } // namespace webdriver |
| 365 | 371 |
| 366 DISABLE_RUNNABLE_METHOD_REFCOUNT(webdriver::Session); | 372 DISABLE_RUNNABLE_METHOD_REFCOUNT(webdriver::Session); |
| 367 | 373 |
| 368 #endif // CHROME_TEST_WEBDRIVER_SESSION_H_ | 374 #endif // CHROME_TEST_WEBDRIVER_SESSION_H_ |
| OLD | NEW |