[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] | 75895ca | 2011-04-07 18:12:57 | [diff] [blame^] | 16 | #include "chrome/test/webdriver/error_codes.h" |
[email protected] | 7cc2c91 | 2011-02-13 03:11:21 | [diff] [blame] | 17 | #include "ui/base/keycodes/keyboard_codes.h" |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 18 | |
[email protected] | ab6bb8e | 2011-03-03 22:41:16 | [diff] [blame] | 19 | class AutomationProxy; |
[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] | f5aae77 | 2011-03-11 22:44:08 | [diff] [blame] | 33 | class FramePath; |
| 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] | 808d103 | 2011-02-09 20:16:55 | [diff] [blame] | 41 | Automation(); |
| 42 | virtual ~Automation(); |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 43 | |
[email protected] | 358dc4e | 2011-02-22 22:07:57 | [diff] [blame] | 44 | // Creates a browser, using the exe found in |browser_dir|. If |browser_dir| |
| 45 | // is empty, it will search in all the default locations. |
[email protected] | 75895ca | 2011-04-07 18:12:57 | [diff] [blame^] | 46 | void Init(const FilePath& browser_dir, ErrorCode* code); |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 47 | |
| 48 | // Terminates this session and disconnects its automation proxy. After |
| 49 | // invoking this method, the Automation can safely be deleted. |
| 50 | void Terminate(); |
| 51 | |
| 52 | // Executes the given |script| in the specified frame of the current |
| 53 | // tab. |result| will be set to the JSON result. Returns true on success. |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 54 | void ExecuteScript(int tab_id, |
[email protected] | f5aae77 | 2011-03-11 22:44:08 | [diff] [blame] | 55 | const FramePath& frame_path, |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 56 | const std::string& script, |
| 57 | std::string* result, |
| 58 | bool* success); |
| 59 | |
[email protected] | 47f21f1 | 2011-03-31 15:32:42 | [diff] [blame] | 60 | // 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] | 61 | // been processed by the web page. |
[email protected] | 47f21f1 | 2011-03-31 15:32:42 | [diff] [blame] | 62 | void SendWebKeyEvent(int tab_id, |
| 63 | const WebKeyEvent& key_event, |
| 64 | bool* success); |
| 65 | |
| 66 | // Sends an OS level key event to the current browser. Waits until the key |
| 67 | // has been processed by the browser. |
| 68 | void SendNativeKeyEvent(int tab_id, |
| 69 | ui::KeyboardCode key_code, |
| 70 | int modifiers, |
| 71 | bool* success); |
[email protected] | 7cc2c91 | 2011-02-13 03:11:21 | [diff] [blame] | 72 | |
[email protected] | 98598afb | 2011-03-29 19:29:37 | [diff] [blame] | 73 | // Captures a snapshot of the tab to the specified path. The PNG will |
| 74 | // contain the entire page, including what is not in the current view |
| 75 | // on the screen. |
| 76 | void CaptureEntirePageAsPNG(int tab_id, const FilePath& path, bool* success); |
| 77 | |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 78 | void NavigateToURL(int tab_id, const std::string& url, bool* success); |
| 79 | void GoForward(int tab_id, bool* success); |
| 80 | void GoBack(int tab_id, bool* success); |
| 81 | void Reload(int tab_id, bool* success); |
[email protected] | e4857a21 | 2011-03-26 17:14:02 | [diff] [blame] | 82 | |
| 83 | void GetCookies(const std::string& url, ListValue** cookies, bool* success); |
| 84 | void GetCookiesDeprecated( |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 85 | int tab_id, const GURL& gurl, std::string* cookies, bool* success); |
[email protected] | e4857a21 | 2011-03-26 17:14:02 | [diff] [blame] | 86 | void DeleteCookie(const std::string& url, |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 87 | const std::string& cookie_name, |
[email protected] | 6f3b433 | 2011-02-15 23:22:35 | [diff] [blame] | 88 | bool* success); |
[email protected] | e4857a21 | 2011-03-26 17:14:02 | [diff] [blame] | 89 | void DeleteCookieDeprecated(int tab_id, |
| 90 | const GURL& gurl, |
| 91 | const std::string& cookie_name, |
| 92 | bool* success); |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 93 | void SetCookie( |
[email protected] | e4857a21 | 2011-03-26 17:14:02 | [diff] [blame] | 94 | const std::string& url, DictionaryValue* cookie_dict, bool* success); |
| 95 | void SetCookieDeprecated( |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 96 | int tab_id, const GURL& gurl, const std::string& cookie, bool* success); |
[email protected] | e4857a21 | 2011-03-26 17:14:02 | [diff] [blame] | 97 | |
[email protected] | 81edbaf | 2011-02-22 19:31:48 | [diff] [blame] | 98 | void MouseMove(int tab_id, const gfx::Point& p, bool* success); |
[email protected] | 5fb586a | 2011-03-08 00:06:28 | [diff] [blame] | 99 | void MouseClick(int tab_id, |
| 100 | const gfx::Point& p, |
| 101 | automation::MouseButton button, |
| 102 | bool* success); |
[email protected] | 81edbaf | 2011-02-22 19:31:48 | [diff] [blame] | 103 | void MouseDrag(int tab_id, |
| 104 | const gfx::Point& start, |
| 105 | const gfx::Point& end, |
| 106 | bool* success); |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 107 | |
| 108 | // Get persistent IDs for all the tabs currently open. These IDs can be used |
| 109 | // to identify the tab as long as the tab exists. |
| 110 | void GetTabIds(std::vector<int>* tab_ids, bool* success); |
| 111 | |
| 112 | // Check if the given tab exists currently. |
[email protected] | 5fb586a | 2011-03-08 00:06:28 | [diff] [blame] | 113 | void DoesTabExist(int tab_id, bool* does_exist, bool* success); |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 114 | |
| 115 | void CloseTab(int tab_id, bool* success); |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 116 | |
[email protected] | 02666766 | 2011-02-22 20:48:25 | [diff] [blame] | 117 | // Gets the version of the runing browser. |
[email protected] | e4857a21 | 2011-03-26 17:14:02 | [diff] [blame] | 118 | void GetBrowserVersion(std::string* version); |
[email protected] | 02666766 | 2011-02-22 20:48:25 | [diff] [blame] | 119 | |
[email protected] | 75895ca | 2011-04-07 18:12:57 | [diff] [blame^] | 120 | // Gets the ChromeDriver automation version supported by the automation |
| 121 | // server. |
| 122 | void GetChromeDriverAutomationVersion(int* version, bool* success); |
| 123 | |
[email protected] | 781dbd7d | 2011-02-25 23:23:27 | [diff] [blame] | 124 | // Waits for all tabs to stop loading. |
| 125 | void WaitForAllTabsToStopLoading(bool* success); |
| 126 | |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 127 | private: |
[email protected] | ab6bb8e | 2011-03-03 22:41:16 | [diff] [blame] | 128 | AutomationProxy* automation() const; |
[email protected] | 5fb586a | 2011-03-08 00:06:28 | [diff] [blame] | 129 | bool GetIndicesForTab(int tab_id, int* browser_index, int* tab_index); |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 130 | |
[email protected] | 358dc4e | 2011-02-22 22:07:57 | [diff] [blame] | 131 | scoped_ptr<ProxyLauncher> launcher_; |
[email protected] | ab6bb8e | 2011-03-03 22:41:16 | [diff] [blame] | 132 | |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 133 | DISALLOW_COPY_AND_ASSIGN(Automation); |
| 134 | }; |
| 135 | |
| 136 | } // namespace webdriver |
| 137 | |
| 138 | DISABLE_RUNNABLE_METHOD_REFCOUNT(webdriver::Automation); |
| 139 | |
| 140 | #endif // CHROME_TEST_WEBDRIVER_AUTOMATION_H_ |