[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 | |
[email protected] | 10ba613 | 2011-08-17 15:32:53 | [diff] [blame] | 5 | #ifndef CHROME_TEST_WEBDRIVER_WEBDRIVER_AUTOMATION_H_ |
| 6 | #define CHROME_TEST_WEBDRIVER_WEBDRIVER_AUTOMATION_H_ |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 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] | 16b1429 | 2011-08-15 17:03:45 | [diff] [blame] | 12 | #include "base/command_line.h" |
[email protected] | fcad4945 | 2011-06-28 17:11:57 | [diff] [blame] | 13 | #include "base/file_path.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 14 | #include "base/memory/ref_counted.h" |
| 15 | #include "base/memory/scoped_ptr.h" |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 16 | #include "base/task.h" |
[email protected] | 7cc2c91 | 2011-02-13 03:11:21 | [diff] [blame] | 17 | #include "chrome/common/automation_constants.h" |
[email protected] | 7cc2c91 | 2011-02-13 03:11:21 | [diff] [blame] | 18 | #include "ui/base/keycodes/keyboard_codes.h" |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 19 | |
[email protected] | ab6bb8e | 2011-03-03 22:41:16 | [diff] [blame] | 20 | class AutomationProxy; |
[email protected] | 358dc4e | 2011-02-22 22:07:57 | [diff] [blame] | 21 | class ProxyLauncher; |
[email protected] | 5fb586a | 2011-03-08 00:06:28 | [diff] [blame] | 22 | struct WebKeyEvent; |
[email protected] | 6f3b433 | 2011-02-15 23:22:35 | [diff] [blame] | 23 | |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 24 | namespace base { |
| 25 | class DictionaryValue; |
| 26 | class ListValue; |
| 27 | } |
| 28 | |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 29 | namespace webdriver { |
| 30 | |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame] | 31 | class Error; |
[email protected] | f5aae77 | 2011-03-11 22:44:08 | [diff] [blame] | 32 | class FramePath; |
[email protected] | 3e981b2 | 2011-08-16 15:20:01 | [diff] [blame] | 33 | class Point; |
[email protected] | f5aae77 | 2011-03-11 22:44:08 | [diff] [blame] | 34 | |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 35 | // Creates and controls the Chrome instance. |
| 36 | // This class should be created and accessed on a single thread. |
[email protected] | 6f3b433 | 2011-02-15 23:22:35 | [diff] [blame] | 37 | // Note: All member functions are void because they are invoked |
| 38 | // by posting a task from NewRunnableMethod. |
[email protected] | 358dc4e | 2011-02-22 22:07:57 | [diff] [blame] | 39 | class Automation { |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 40 | public: |
[email protected] | 16b1429 | 2011-08-15 17:03:45 | [diff] [blame] | 41 | struct BrowserOptions { |
| 42 | BrowserOptions(); |
| 43 | ~BrowserOptions(); |
| 44 | |
[email protected] | f0f7cde4 | 2011-08-22 16:29:34 | [diff] [blame] | 45 | // The command line to use for launching the browser. If no program is |
| 46 | // specified, the default browser executable will be used. |
[email protected] | 16b1429 | 2011-08-15 17:03:45 | [diff] [blame] | 47 | CommandLine command; |
[email protected] | f0f7cde4 | 2011-08-22 16:29:34 | [diff] [blame] | 48 | |
| 49 | // The user data directory to be copied and used. If empty, a temporary |
| 50 | // directory will be used. |
[email protected] | 16b1429 | 2011-08-15 17:03:45 | [diff] [blame] | 51 | FilePath user_data_dir; |
[email protected] | f0f7cde4 | 2011-08-22 16:29:34 | [diff] [blame] | 52 | |
| 53 | // The channel ID of an already running browser to connect to. If empty, |
| 54 | // the browser will be launched with an anonymous channel. |
[email protected] | 16b1429 | 2011-08-15 17:03:45 | [diff] [blame] | 55 | std::string channel_id; |
[email protected] | f0f7cde4 | 2011-08-22 16:29:34 | [diff] [blame] | 56 | |
| 57 | // True if the Chrome process should only be terminated if quit is called. |
| 58 | // If false, Chrome will also be terminated if this process is killed or |
| 59 | // shutdown. |
| 60 | bool detach_process; |
[email protected] | 16b1429 | 2011-08-15 17:03:45 | [diff] [blame] | 61 | }; |
| 62 | |
[email protected] | 808d103 | 2011-02-09 20:16:55 | [diff] [blame] | 63 | Automation(); |
| 64 | virtual ~Automation(); |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 65 | |
[email protected] | c4bdfe65 | 2011-05-17 20:14:20 | [diff] [blame] | 66 | // Start the system's default Chrome binary. |
[email protected] | 16b1429 | 2011-08-15 17:03:45 | [diff] [blame] | 67 | void Init(const BrowserOptions& options, Error** error); |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 68 | |
| 69 | // Terminates this session and disconnects its automation proxy. After |
| 70 | // invoking this method, the Automation can safely be deleted. |
| 71 | void Terminate(); |
| 72 | |
| 73 | // Executes the given |script| in the specified frame of the current |
| 74 | // tab. |result| will be set to the JSON result. Returns true on success. |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 75 | void ExecuteScript(int tab_id, |
[email protected] | f5aae77 | 2011-03-11 22:44:08 | [diff] [blame] | 76 | const FramePath& frame_path, |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 77 | const std::string& script, |
| 78 | std::string* result, |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame] | 79 | Error** error); |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 80 | |
[email protected] | 47f21f1 | 2011-03-31 15:32:42 | [diff] [blame] | 81 | // 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] | 82 | // been processed by the web page. |
[email protected] | 47f21f1 | 2011-03-31 15:32:42 | [diff] [blame] | 83 | void SendWebKeyEvent(int tab_id, |
| 84 | const WebKeyEvent& key_event, |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame] | 85 | Error** error); |
[email protected] | 47f21f1 | 2011-03-31 15:32:42 | [diff] [blame] | 86 | |
| 87 | // Sends an OS level key event to the current browser. Waits until the key |
| 88 | // has been processed by the browser. |
| 89 | void SendNativeKeyEvent(int tab_id, |
| 90 | ui::KeyboardCode key_code, |
| 91 | int modifiers, |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame] | 92 | Error** error); |
[email protected] | 7cc2c91 | 2011-02-13 03:11:21 | [diff] [blame] | 93 | |
[email protected] | fcad4945 | 2011-06-28 17:11:57 | [diff] [blame] | 94 | // Drag and drop the file paths to the given location. |
| 95 | void DragAndDropFilePaths(int tab_id, |
[email protected] | 3e981b2 | 2011-08-16 15:20:01 | [diff] [blame] | 96 | const Point& location, |
[email protected] | fcad4945 | 2011-06-28 17:11:57 | [diff] [blame] | 97 | const std::vector<FilePath::StringType>& paths, |
| 98 | Error** error); |
| 99 | |
[email protected] | 98598afb | 2011-03-29 19:29:37 | [diff] [blame] | 100 | // Captures a snapshot of the tab to the specified path. The PNG will |
| 101 | // contain the entire page, including what is not in the current view |
| 102 | // on the screen. |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame] | 103 | void CaptureEntirePageAsPNG(int tab_id, const FilePath& path, Error** error); |
[email protected] | 98598afb | 2011-03-29 19:29:37 | [diff] [blame] | 104 | |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame] | 105 | void NavigateToURL(int tab_id, const std::string& url, Error** error); |
[email protected] | 33ef938 | 2011-08-11 00:04:55 | [diff] [blame] | 106 | void NavigateToURLAsync(int tab_id, const std::string& url, Error** error); |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame] | 107 | void GoForward(int tab_id, Error** error); |
| 108 | void GoBack(int tab_id, Error** error); |
| 109 | void Reload(int tab_id, Error** error); |
[email protected] | e4857a21 | 2011-03-26 17:14:02 | [diff] [blame] | 110 | |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 111 | void GetCookies(const std::string& url, |
| 112 | base::ListValue** cookies, |
| 113 | Error** error); |
[email protected] | e4857a21 | 2011-03-26 17:14:02 | [diff] [blame] | 114 | void DeleteCookie(const std::string& url, |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 115 | const std::string& cookie_name, |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame] | 116 | Error** error); |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 117 | void SetCookie(const std::string& url, |
| 118 | base::DictionaryValue* cookie_dict, |
| 119 | Error** error); |
[email protected] | e4857a21 | 2011-03-26 17:14:02 | [diff] [blame] | 120 | |
[email protected] | 3e981b2 | 2011-08-16 15:20:01 | [diff] [blame] | 121 | void MouseMove(int tab_id, const Point& p, Error** error); |
[email protected] | 5fb586a | 2011-03-08 00:06:28 | [diff] [blame] | 122 | void MouseClick(int tab_id, |
[email protected] | 3e981b2 | 2011-08-16 15:20:01 | [diff] [blame] | 123 | const Point& p, |
[email protected] | 5fb586a | 2011-03-08 00:06:28 | [diff] [blame] | 124 | automation::MouseButton button, |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame] | 125 | Error** error); |
[email protected] | 81edbaf | 2011-02-22 19:31:48 | [diff] [blame] | 126 | void MouseDrag(int tab_id, |
[email protected] | 3e981b2 | 2011-08-16 15:20:01 | [diff] [blame] | 127 | const Point& start, |
| 128 | const Point& end, |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame] | 129 | Error** error); |
[email protected] | 3e981b2 | 2011-08-16 15:20:01 | [diff] [blame] | 130 | void MouseButtonDown(int tab_id, const Point& p, Error** error); |
| 131 | void MouseButtonUp(int tab_id, const Point& p, Error** error); |
| 132 | void MouseDoubleClick(int tab_id, const Point& p, Error** error); |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 133 | |
| 134 | // Get persistent IDs for all the tabs currently open. These IDs can be used |
| 135 | // to identify the tab as long as the tab exists. |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame] | 136 | void GetTabIds(std::vector<int>* tab_ids, Error** error); |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 137 | |
| 138 | // Check if the given tab exists currently. |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame] | 139 | void DoesTabExist(int tab_id, bool* does_exist, Error** error); |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 140 | |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame] | 141 | void CloseTab(int tab_id, Error** error); |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 142 | |
[email protected] | 1662374 | 2011-05-16 20:04:26 | [diff] [blame] | 143 | // Gets the active JavaScript modal dialog's message. |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame] | 144 | void GetAppModalDialogMessage(std::string* message, Error** error); |
[email protected] | 1662374 | 2011-05-16 20:04:26 | [diff] [blame] | 145 | |
| 146 | // Accepts or dismisses the active JavaScript modal dialog. |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame] | 147 | void AcceptOrDismissAppModalDialog(bool accept, Error** error); |
[email protected] | 1662374 | 2011-05-16 20:04:26 | [diff] [blame] | 148 | |
| 149 | // Accepts an active prompt JavaScript modal dialog, using the given |
| 150 | // prompt text as the result of the prompt. |
| 151 | void AcceptPromptAppModalDialog(const std::string& prompt_text, |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame] | 152 | Error** error); |
[email protected] | 1662374 | 2011-05-16 20:04:26 | [diff] [blame] | 153 | |
[email protected] | 02666766 | 2011-02-22 20:48:25 | [diff] [blame] | 154 | // Gets the version of the runing browser. |
[email protected] | e4857a21 | 2011-03-26 17:14:02 | [diff] [blame] | 155 | void GetBrowserVersion(std::string* version); |
[email protected] | 02666766 | 2011-02-22 20:48:25 | [diff] [blame] | 156 | |
[email protected] | 75895ca | 2011-04-07 18:12:57 | [diff] [blame] | 157 | // Gets the ChromeDriver automation version supported by the automation |
| 158 | // server. |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame] | 159 | void GetChromeDriverAutomationVersion(int* version, Error** error); |
[email protected] | 75895ca | 2011-04-07 18:12:57 | [diff] [blame] | 160 | |
[email protected] | 781dbd7d | 2011-02-25 23:23:27 | [diff] [blame] | 161 | // Waits for all tabs to stop loading. |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame] | 162 | void WaitForAllTabsToStopLoading(Error** error); |
[email protected] | 781dbd7d | 2011-02-25 23:23:27 | [diff] [blame] | 163 | |
[email protected] | f5fe361 | 2011-08-01 17:44:23 | [diff] [blame] | 164 | // Install packed extension. |
| 165 | void InstallExtension(const FilePath& path, Error** error); |
| 166 | |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 167 | private: |
[email protected] | ab6bb8e | 2011-03-03 22:41:16 | [diff] [blame] | 168 | AutomationProxy* automation() const; |
[email protected] | 2937a8c | 2011-05-20 15:02:33 | [diff] [blame] | 169 | Error* GetIndicesForTab(int tab_id, int* browser_index, int* tab_index); |
[email protected] | 28c580f | 2011-05-24 03:41:16 | [diff] [blame] | 170 | Error* CompareVersion(int client_build_no, |
| 171 | int client_patch_no, |
| 172 | bool* is_newer_or_equal); |
| 173 | Error* CheckVersion(int client_build_no, |
| 174 | int client_patch_no, |
| 175 | const std::string& error_msg); |
| 176 | Error* CheckAlertsSupported(); |
| 177 | Error* CheckAdvancedInteractionsSupported(); |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 178 | |
[email protected] | 358dc4e | 2011-02-22 22:07:57 | [diff] [blame] | 179 | scoped_ptr<ProxyLauncher> launcher_; |
[email protected] | ab6bb8e | 2011-03-03 22:41:16 | [diff] [blame] | 180 | |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 181 | DISALLOW_COPY_AND_ASSIGN(Automation); |
| 182 | }; |
| 183 | |
| 184 | } // namespace webdriver |
| 185 | |
| 186 | DISABLE_RUNNABLE_METHOD_REFCOUNT(webdriver::Automation); |
| 187 | |
[email protected] | 10ba613 | 2011-08-17 15:32:53 | [diff] [blame] | 188 | #endif // CHROME_TEST_WEBDRIVER_WEBDRIVER_AUTOMATION_H_ |