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_AUTOMATION_H_ | 5 #ifndef CHROME_TEST_WEBDRIVER_AUTOMATION_H_ |
6 #define CHROME_TEST_WEBDRIVER_AUTOMATION_H_ | 6 #define CHROME_TEST_WEBDRIVER_AUTOMATION_H_ |
7 | 7 |
| 8 #include <map> |
8 #include <string> | 9 #include <string> |
| 10 #include <vector> |
9 | 11 |
10 #include "base/task.h" | 12 #include "base/task.h" |
11 #include "base/ref_counted.h" | 13 #include "base/ref_counted.h" |
12 #include "base/scoped_temp_dir.h" | 14 #include "base/scoped_temp_dir.h" |
13 #include "chrome/common/automation_constants.h" | 15 #include "chrome/common/automation_constants.h" |
14 #include "chrome/test/ui/ui_test.h" | 16 #include "chrome/test/ui/ui_test.h" |
15 #include "ui/base/keycodes/keyboard_codes.h" | 17 #include "ui/base/keycodes/keyboard_codes.h" |
16 | 18 |
17 class GURL; | 19 class GURL; |
| 20 class TabProxy; |
18 | 21 |
19 namespace webdriver { | 22 namespace webdriver { |
20 | 23 |
21 struct WebKeyEvent { | 24 struct WebKeyEvent { |
22 WebKeyEvent(automation::KeyEventTypes type, | 25 WebKeyEvent(automation::KeyEventTypes type, |
23 ui::KeyboardCode key_code, | 26 ui::KeyboardCode key_code, |
24 const std::string& unmodified_text, | 27 const std::string& unmodified_text, |
25 const std::string& modified_text, | 28 const std::string& modified_text, |
26 int modifiers) | 29 int modifiers) |
27 : type(type), | 30 : type(type), |
(...skipping 22 matching lines...) Expand all Loading... |
50 | 53 |
51 // Creates a browser. | 54 // Creates a browser. |
52 void Init(bool* success); | 55 void Init(bool* success); |
53 | 56 |
54 // Terminates this session and disconnects its automation proxy. After | 57 // Terminates this session and disconnects its automation proxy. After |
55 // invoking this method, the Automation can safely be deleted. | 58 // invoking this method, the Automation can safely be deleted. |
56 void Terminate(); | 59 void Terminate(); |
57 | 60 |
58 // Executes the given |script| in the specified frame of the current | 61 // Executes the given |script| in the specified frame of the current |
59 // tab. |result| will be set to the JSON result. Returns true on success. | 62 // tab. |result| will be set to the JSON result. Returns true on success. |
60 void ExecuteScript(const std::string& frame_xpath, | 63 void ExecuteScript(int tab_id, |
| 64 const std::string& frame_xpath, |
61 const std::string& script, | 65 const std::string& script, |
62 std::string* result, | 66 std::string* result, |
63 bool* success); | 67 bool* success); |
64 | 68 |
65 // Sends a key event to the current browser. Waits until the key has | 69 // Sends a key event to the current browser. Waits until the key has |
66 // been processed by the web page. | 70 // been processed by the web page. |
67 void SendWebKeyEvent(const WebKeyEvent& key_event, bool* success); | 71 void SendWebKeyEvent(int tab_id, const WebKeyEvent& key_event, bool* success); |
68 | 72 |
69 void NavigateToURL(const std::string& url, bool* success); | 73 void NavigateToURL(int tab_id, const std::string& url, bool* success); |
70 void GoForward(bool* success); | 74 void GoForward(int tab_id, bool* success); |
71 void GoBack(bool* success); | 75 void GoBack(int tab_id, bool* success); |
72 void Reload(bool* success); | 76 void Reload(int tab_id, bool* success); |
73 void GetURL(std::string* url, bool* success); | 77 void GetURL(int tab_id, std::string* url, bool* success); |
74 void GetGURL(GURL* gurl, bool* success); | 78 void GetGURL(int tab_id, GURL* gurl, bool* success); |
75 void GetTabTitle(std::string* tab_title, bool* success); | 79 void GetTabTitle(int tab_id, std::string* tab_title, bool* success); |
76 void GetCookies(const GURL& gurl, std::string* cookies, bool* success); | 80 void GetCookies( |
77 void GetCookieByName(const GURL& gurl, const std::string& cookie_name, | 81 int tab_id, const GURL& gurl, std::string* cookies, bool* success); |
78 std::string* cookie, bool* success); | 82 void GetCookieByName(int tab_id, |
79 void DeleteCookie(const GURL& gurl, const std::string& cookie_name, | 83 const GURL& gurl, |
| 84 const std::string& cookie_name, |
| 85 std::string* cookie, |
| 86 bool* success); |
| 87 void DeleteCookie(int tab_id, |
| 88 const GURL& gurl, |
| 89 const std::string& cookie_name, |
80 bool* success); | 90 bool* success); |
81 void SetCookie(const GURL& gurl, const std::string& cookie, bool* success); | 91 void SetCookie( |
| 92 int tab_id, const GURL& gurl, const std::string& cookie, bool* success); |
| 93 |
| 94 // Get persistent IDs for all the tabs currently open. These IDs can be used |
| 95 // to identify the tab as long as the tab exists. |
| 96 void GetTabIds(std::vector<int>* tab_ids, bool* success); |
| 97 |
| 98 // Check if the given tab exists currently. |
| 99 void DoesTabExist(int tab_id, bool* does_exist); |
| 100 |
| 101 void CloseTab(int tab_id, bool* success); |
82 | 102 |
83 private: | 103 private: |
84 scoped_refptr<BrowserProxy> browser_; | 104 typedef std::map<int, scoped_refptr<TabProxy> > TabIdMap; |
85 scoped_refptr<TabProxy> tab_; | 105 TabProxy* GetTabById(int tab_id); |
86 | 106 |
| 107 // Map from tab ID to |TabProxy|. The tab ID is simply the |AutomationHandle| |
| 108 // for the proxy. |
| 109 TabIdMap tab_id_map_; |
87 ScopedTempDir profile_dir_; | 110 ScopedTempDir profile_dir_; |
88 | 111 |
89 DISALLOW_COPY_AND_ASSIGN(Automation); | 112 DISALLOW_COPY_AND_ASSIGN(Automation); |
90 }; | 113 }; |
91 | 114 |
92 } // namespace webdriver | 115 } // namespace webdriver |
93 | 116 |
94 DISABLE_RUNNABLE_METHOD_REFCOUNT(webdriver::Automation); | 117 DISABLE_RUNNABLE_METHOD_REFCOUNT(webdriver::Automation); |
95 | 118 |
96 #endif // CHROME_TEST_WEBDRIVER_AUTOMATION_H_ | 119 #endif // CHROME_TEST_WEBDRIVER_AUTOMATION_H_ |
OLD | NEW |