[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_TEST_WEBDRIVER_AUTOMATION_H_ |
| 6 | #define CHROME_TEST_WEBDRIVER_AUTOMATION_H_ |
| 7 | |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 8 | #include <map> |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 9 | #include <string> |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 10 | #include <vector> |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 11 | |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 12 | #include "base/memory/ref_counted.h" |
| 13 | #include "base/memory/scoped_ptr.h" |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 14 | #include "base/task.h" |
[email protected] | 7cc2c91 | 2011-02-13 03:11:21 | [diff] [blame] | 15 | #include "chrome/common/automation_constants.h" |
[email protected] | 7cc2c91 | 2011-02-13 03:11:21 | [diff] [blame] | 16 | #include "ui/base/keycodes/keyboard_codes.h" |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 17 | |
[email protected] | ab6bb8e | 2011-03-03 22:41:16 | [diff] [blame] | 18 | class AutomationProxy; |
[email protected] | f6a9d262 | 2011-05-13 17:33:55 | [diff] [blame] | 19 | class CommandLine; |
[email protected] | 358dc4e | 2011-02-22 22:07:57 | [diff] [blame] | 20 | class DictionaryValue; |
| 21 | class FilePath; |
[email protected] | 6f3b433 | 2011-02-15 23:22:35 | [diff] [blame] | 22 | class GURL; |
[email protected] | e4857a21 | 2011-03-26 17:14:02 | [diff] [blame] | 23 | class ListValue; |
[email protected] | 358dc4e | 2011-02-22 22:07:57 | [diff] [blame] | 24 | class ProxyLauncher; |
[email protected] | 5fb586a | 2011-03-08 00:06:28 | [diff] [blame] | 25 | struct WebKeyEvent; |
[email protected] | 6f3b433 | 2011-02-15 23:22:35 | [diff] [blame] | 26 | |
[email protected] | 81edbaf | 2011-02-22 19:31:48 | [diff] [blame] | 27 | namespace gfx { |
| 28 | class Point; |
| 29 | } |
| 30 | |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 31 | namespace webdriver { |
| 32 | |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame^] | 33 | class Error; |
[email protected] | f5aae77 | 2011-03-11 22:44:08 | [diff] [blame] | 34 | class FramePath; |
| 35 | |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 36 | // Creates and controls the Chrome instance. |
| 37 | // This class should be created and accessed on a single thread. |
[email protected] | 6f3b433 | 2011-02-15 23:22:35 | [diff] [blame] | 38 | // Note: All member functions are void because they are invoked |
| 39 | // by posting a task from NewRunnableMethod. |
[email protected] | 358dc4e | 2011-02-22 22:07:57 | [diff] [blame] | 40 | class Automation { |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 41 | public: |
[email protected] | 808d103 | 2011-02-09 20:16:55 | [diff] [blame] | 42 | Automation(); |
| 43 | virtual ~Automation(); |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 44 | |
[email protected] | c4bdfe65 | 2011-05-17 20:14:20 | [diff] [blame] | 45 | // Creates a browser, using the specified |browser_exe|. |
| 46 | void InitWithBrowserPath(const FilePath& browser_exe, |
| 47 | const CommandLine& options, |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame^] | 48 | Error** error); |
[email protected] | c4bdfe65 | 2011-05-17 20:14:20 | [diff] [blame] | 49 | |
| 50 | // Start the system's default Chrome binary. |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame^] | 51 | void Init(const CommandLine& options, Error** error); |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 52 | |
| 53 | // Terminates this session and disconnects its automation proxy. After |
| 54 | // invoking this method, the Automation can safely be deleted. |
| 55 | void Terminate(); |
| 56 | |
| 57 | // Executes the given |script| in the specified frame of the current |
| 58 | // tab. |result| will be set to the JSON result. Returns true on success. |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 59 | void ExecuteScript(int tab_id, |
[email protected] | f5aae77 | 2011-03-11 22:44:08 | [diff] [blame] | 60 | const FramePath& frame_path, |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 61 | const std::string& script, |
| 62 | std::string* result, |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame^] | 63 | Error** error); |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 64 | |
[email protected] | 47f21f1 | 2011-03-31 15:32:42 | [diff] [blame] | 65 | // Sends a webkit key event to the current browser. Waits until the key has |
[email protected] | 7cc2c91 | 2011-02-13 03:11:21 | [diff] [blame] | 66 | // been processed by the web page. |
[email protected] | 47f21f1 | 2011-03-31 15:32:42 | [diff] [blame] | 67 | void SendWebKeyEvent(int tab_id, |
| 68 | const WebKeyEvent& key_event, |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame^] | 69 | Error** error); |
[email protected] | 47f21f1 | 2011-03-31 15:32:42 | [diff] [blame] | 70 | |
| 71 | // Sends an OS level key event to the current browser. Waits until the key |
| 72 | // has been processed by the browser. |
| 73 | void SendNativeKeyEvent(int tab_id, |
| 74 | ui::KeyboardCode key_code, |
| 75 | int modifiers, |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame^] | 76 | Error** error); |
[email protected] | 7cc2c91 | 2011-02-13 03:11:21 | [diff] [blame] | 77 | |
[email protected] | 98598afb | 2011-03-29 19:29:37 | [diff] [blame] | 78 | // Captures a snapshot of the tab to the specified path. The PNG will |
| 79 | // contain the entire page, including what is not in the current view |
| 80 | // on the screen. |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame^] | 81 | void CaptureEntirePageAsPNG(int tab_id, const FilePath& path, Error** error); |
[email protected] | 98598afb | 2011-03-29 19:29:37 | [diff] [blame] | 82 | |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame^] | 83 | void NavigateToURL(int tab_id, const std::string& url, Error** error); |
| 84 | void GoForward(int tab_id, Error** error); |
| 85 | void GoBack(int tab_id, Error** error); |
| 86 | void Reload(int tab_id, Error** error); |
[email protected] | e4857a21 | 2011-03-26 17:14:02 | [diff] [blame] | 87 | |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame^] | 88 | void GetCookies(const std::string& url, ListValue** cookies, Error** error); |
[email protected] | e4857a21 | 2011-03-26 17:14:02 | [diff] [blame] | 89 | void GetCookiesDeprecated( |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 90 | int tab_id, const GURL& gurl, std::string* cookies, bool* success); |
[email protected] | e4857a21 | 2011-03-26 17:14:02 | [diff] [blame] | 91 | void DeleteCookie(const std::string& url, |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 92 | const std::string& cookie_name, |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame^] | 93 | Error** error); |
[email protected] | e4857a21 | 2011-03-26 17:14:02 | [diff] [blame] | 94 | void DeleteCookieDeprecated(int tab_id, |
| 95 | const GURL& gurl, |
| 96 | const std::string& cookie_name, |
| 97 | bool* success); |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 98 | void SetCookie( |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame^] | 99 | const std::string& url, DictionaryValue* cookie_dict, Error** error); |
[email protected] | e4857a21 | 2011-03-26 17:14:02 | [diff] [blame] | 100 | void SetCookieDeprecated( |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 101 | int tab_id, const GURL& gurl, const std::string& cookie, bool* success); |
[email protected] | e4857a21 | 2011-03-26 17:14:02 | [diff] [blame] | 102 | |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame^] | 103 | void MouseMove(int tab_id, const gfx::Point& p, Error** error); |
[email protected] | 5fb586a | 2011-03-08 00:06:28 | [diff] [blame] | 104 | void MouseClick(int tab_id, |
| 105 | const gfx::Point& p, |
| 106 | automation::MouseButton button, |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame^] | 107 | Error** error); |
[email protected] | 81edbaf | 2011-02-22 19:31:48 | [diff] [blame] | 108 | void MouseDrag(int tab_id, |
| 109 | const gfx::Point& start, |
| 110 | const gfx::Point& end, |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame^] | 111 | Error** error); |
| 112 | void MouseButtonDown(int tab_id, const gfx::Point& p, Error** error); |
| 113 | void MouseButtonUp(int tab_id, const gfx::Point& p, Error** error); |
| 114 | void MouseDoubleClick(int tab_id, const gfx::Point& p, Error** error); |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 115 | |
| 116 | // Get persistent IDs for all the tabs currently open. These IDs can be used |
| 117 | // to identify the tab as long as the tab exists. |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame^] | 118 | void GetTabIds(std::vector<int>* tab_ids, Error** error); |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 119 | |
| 120 | // Check if the given tab exists currently. |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame^] | 121 | void DoesTabExist(int tab_id, bool* does_exist, Error** error); |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 122 | |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame^] | 123 | void CloseTab(int tab_id, Error** error); |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 124 | |
[email protected] | 1662374 | 2011-05-16 20:04:26 | [diff] [blame] | 125 | // Gets the active JavaScript modal dialog's message. |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame^] | 126 | void GetAppModalDialogMessage(std::string* message, Error** error); |
[email protected] | 1662374 | 2011-05-16 20:04:26 | [diff] [blame] | 127 | |
| 128 | // Accepts or dismisses the active JavaScript modal dialog. |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame^] | 129 | void AcceptOrDismissAppModalDialog(bool accept, Error** error); |
[email protected] | 1662374 | 2011-05-16 20:04:26 | [diff] [blame] | 130 | |
| 131 | // Accepts an active prompt JavaScript modal dialog, using the given |
| 132 | // prompt text as the result of the prompt. |
| 133 | void AcceptPromptAppModalDialog(const std::string& prompt_text, |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame^] | 134 | Error** error); |
[email protected] | 1662374 | 2011-05-16 20:04:26 | [diff] [blame] | 135 | |
[email protected] | 02666766 | 2011-02-22 20:48:25 | [diff] [blame] | 136 | // Gets the version of the runing browser. |
[email protected] | e4857a21 | 2011-03-26 17:14:02 | [diff] [blame] | 137 | void GetBrowserVersion(std::string* version); |
[email protected] | 02666766 | 2011-02-22 20:48:25 | [diff] [blame] | 138 | |
[email protected] | 75895ca | 2011-04-07 18:12:57 | [diff] [blame] | 139 | // Gets the ChromeDriver automation version supported by the automation |
| 140 | // server. |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame^] | 141 | void GetChromeDriverAutomationVersion(int* version, Error** error); |
[email protected] | 75895ca | 2011-04-07 18:12:57 | [diff] [blame] | 142 | |
[email protected] | 781dbd7d | 2011-02-25 23:23:27 | [diff] [blame] | 143 | // Waits for all tabs to stop loading. |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame^] | 144 | void WaitForAllTabsToStopLoading(Error** error); |
[email protected] | 781dbd7d | 2011-02-25 23:23:27 | [diff] [blame] | 145 | |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 146 | private: |
[email protected] | ab6bb8e | 2011-03-03 22:41:16 | [diff] [blame] | 147 | AutomationProxy* automation() const; |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame^] | 148 | Error* GetIndicesForTab(int tab_id, int* browser_index, int* tab_index); |
| 149 | Error* CreateChromeError(const std::string& message); |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 150 | |
[email protected] | 358dc4e | 2011-02-22 22:07:57 | [diff] [blame] | 151 | scoped_ptr<ProxyLauncher> launcher_; |
[email protected] | ab6bb8e | 2011-03-03 22:41:16 | [diff] [blame] | 152 | |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 153 | DISALLOW_COPY_AND_ASSIGN(Automation); |
| 154 | }; |
| 155 | |
| 156 | } // namespace webdriver |
| 157 | |
| 158 | DISABLE_RUNNABLE_METHOD_REFCOUNT(webdriver::Automation); |
| 159 | |
| 160 | #endif // CHROME_TEST_WEBDRIVER_AUTOMATION_H_ |