[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 | |
| 12 | #include "base/task.h" |
| 13 | #include "base/ref_counted.h" |
[email protected] | 358dc4e | 2011-02-22 22:07:57 | [diff] [blame] | 14 | #include "base/scoped_ptr.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] | 358dc4e | 2011-02-22 22:07:57 | [diff] [blame] | 19 | class DictionaryValue; |
| 20 | class FilePath; |
[email protected] | 6f3b433 | 2011-02-15 23:22:35 | [diff] [blame] | 21 | class GURL; |
[email protected] | 358dc4e | 2011-02-22 22:07:57 | [diff] [blame] | 22 | class ProxyLauncher; |
[email protected] | 5fb586a | 2011-03-08 00:06:28 | [diff] [blame^] | 23 | struct WebKeyEvent; |
[email protected] | 6f3b433 | 2011-02-15 23:22:35 | [diff] [blame] | 24 | |
[email protected] | 81edbaf | 2011-02-22 19:31:48 | [diff] [blame] | 25 | namespace gfx { |
| 26 | class Point; |
| 27 | } |
| 28 | |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 29 | namespace webdriver { |
| 30 | |
| 31 | // Creates and controls the Chrome instance. |
| 32 | // This class should be created and accessed on a single thread. |
[email protected] | 6f3b433 | 2011-02-15 23:22:35 | [diff] [blame] | 33 | // Note: All member functions are void because they are invoked |
| 34 | // by posting a task from NewRunnableMethod. |
[email protected] | 358dc4e | 2011-02-22 22:07:57 | [diff] [blame] | 35 | class Automation { |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 36 | public: |
[email protected] | 808d103 | 2011-02-09 20:16:55 | [diff] [blame] | 37 | Automation(); |
| 38 | virtual ~Automation(); |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 39 | |
[email protected] | 358dc4e | 2011-02-22 22:07:57 | [diff] [blame] | 40 | // Creates a browser, using the exe found in |browser_dir|. If |browser_dir| |
| 41 | // is empty, it will search in all the default locations. |
| 42 | void Init(const FilePath& browser_dir, bool* success); |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 43 | |
| 44 | // Terminates this session and disconnects its automation proxy. After |
| 45 | // invoking this method, the Automation can safely be deleted. |
| 46 | void Terminate(); |
| 47 | |
| 48 | // Executes the given |script| in the specified frame of the current |
| 49 | // tab. |result| will be set to the JSON result. Returns true on success. |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 50 | void ExecuteScript(int tab_id, |
| 51 | const std::string& frame_xpath, |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 52 | const std::string& script, |
| 53 | std::string* result, |
| 54 | bool* success); |
| 55 | |
[email protected] | 7cc2c91 | 2011-02-13 03:11:21 | [diff] [blame] | 56 | // Sends a key event to the current browser. Waits until the key has |
| 57 | // been processed by the web page. |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 58 | void SendWebKeyEvent(int tab_id, const WebKeyEvent& key_event, bool* success); |
[email protected] | 7cc2c91 | 2011-02-13 03:11:21 | [diff] [blame] | 59 | |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 60 | void NavigateToURL(int tab_id, const std::string& url, bool* success); |
| 61 | void GoForward(int tab_id, bool* success); |
| 62 | void GoBack(int tab_id, bool* success); |
| 63 | void Reload(int tab_id, bool* success); |
| 64 | void GetURL(int tab_id, std::string* url, bool* success); |
| 65 | void GetGURL(int tab_id, GURL* gurl, bool* success); |
| 66 | void GetTabTitle(int tab_id, std::string* tab_title, bool* success); |
| 67 | void GetCookies( |
| 68 | int tab_id, const GURL& gurl, std::string* cookies, bool* success); |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 69 | void DeleteCookie(int tab_id, |
| 70 | const GURL& gurl, |
| 71 | const std::string& cookie_name, |
[email protected] | 6f3b433 | 2011-02-15 23:22:35 | [diff] [blame] | 72 | bool* success); |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 73 | void SetCookie( |
| 74 | int tab_id, const GURL& gurl, const std::string& cookie, bool* success); |
[email protected] | 81edbaf | 2011-02-22 19:31:48 | [diff] [blame] | 75 | void MouseMove(int tab_id, const gfx::Point& p, bool* success); |
[email protected] | 5fb586a | 2011-03-08 00:06:28 | [diff] [blame^] | 76 | void MouseClick(int tab_id, |
| 77 | const gfx::Point& p, |
| 78 | automation::MouseButton button, |
| 79 | bool* success); |
[email protected] | 81edbaf | 2011-02-22 19:31:48 | [diff] [blame] | 80 | void MouseDrag(int tab_id, |
| 81 | const gfx::Point& start, |
| 82 | const gfx::Point& end, |
| 83 | bool* success); |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 84 | |
| 85 | // Get persistent IDs for all the tabs currently open. These IDs can be used |
| 86 | // to identify the tab as long as the tab exists. |
| 87 | void GetTabIds(std::vector<int>* tab_ids, bool* success); |
| 88 | |
| 89 | // Check if the given tab exists currently. |
[email protected] | 5fb586a | 2011-03-08 00:06:28 | [diff] [blame^] | 90 | void DoesTabExist(int tab_id, bool* does_exist, bool* success); |
[email protected] | 496e579 | 2011-02-17 17:02:53 | [diff] [blame] | 91 | |
| 92 | void CloseTab(int tab_id, bool* success); |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 93 | |
[email protected] | 02666766 | 2011-02-22 20:48:25 | [diff] [blame] | 94 | // Gets the version of the runing browser. |
| 95 | void GetVersion(std::string* version); |
| 96 | |
[email protected] | 781dbd7d | 2011-02-25 23:23:27 | [diff] [blame] | 97 | // Waits for all tabs to stop loading. |
| 98 | void WaitForAllTabsToStopLoading(bool* success); |
| 99 | |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 100 | private: |
[email protected] | ab6bb8e | 2011-03-03 22:41:16 | [diff] [blame] | 101 | AutomationProxy* automation() const; |
[email protected] | 5fb586a | 2011-03-08 00:06:28 | [diff] [blame^] | 102 | bool GetIndicesForTab(int tab_id, int* browser_index, int* tab_index); |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 103 | |
[email protected] | 358dc4e | 2011-02-22 22:07:57 | [diff] [blame] | 104 | scoped_ptr<ProxyLauncher> launcher_; |
[email protected] | ab6bb8e | 2011-03-03 22:41:16 | [diff] [blame] | 105 | |
[email protected] | 2a28e0b2 | 2011-02-03 21:49:03 | [diff] [blame] | 106 | DISALLOW_COPY_AND_ASSIGN(Automation); |
| 107 | }; |
| 108 | |
| 109 | } // namespace webdriver |
| 110 | |
| 111 | DISABLE_RUNNABLE_METHOD_REFCOUNT(webdriver::Automation); |
| 112 | |
| 113 | #endif // CHROME_TEST_WEBDRIVER_AUTOMATION_H_ |