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 |
| 19 class TabProxy; |
| 20 |
17 namespace webdriver { | 21 namespace webdriver { |
18 | 22 |
19 struct WebKeyEvent { | 23 struct WebKeyEvent { |
20 WebKeyEvent(automation::KeyEventTypes type, | 24 WebKeyEvent(automation::KeyEventTypes type, |
21 ui::KeyboardCode key_code, | 25 ui::KeyboardCode key_code, |
22 const std::string& unmodified_text, | 26 const std::string& unmodified_text, |
23 const std::string& modified_text, | 27 const std::string& modified_text, |
24 int modifiers) | 28 int modifiers) |
25 : type(type), | 29 : type(type), |
26 key_code(key_code), | 30 key_code(key_code), |
(...skipping 19 matching lines...) Expand all Loading... |
46 | 50 |
47 // Creates a browser. | 51 // Creates a browser. |
48 void Init(bool* success); | 52 void Init(bool* success); |
49 | 53 |
50 // Terminates this session and disconnects its automation proxy. After | 54 // Terminates this session and disconnects its automation proxy. After |
51 // invoking this method, the Automation can safely be deleted. | 55 // invoking this method, the Automation can safely be deleted. |
52 void Terminate(); | 56 void Terminate(); |
53 | 57 |
54 // Executes the given |script| in the specified frame of the current | 58 // Executes the given |script| in the specified frame of the current |
55 // tab. |result| will be set to the JSON result. Returns true on success. | 59 // tab. |result| will be set to the JSON result. Returns true on success. |
56 void ExecuteScript(const std::string& frame_xpath, | 60 void ExecuteScript(int tab_id, |
| 61 const std::string& frame_xpath, |
57 const std::string& script, | 62 const std::string& script, |
58 std::string* result, | 63 std::string* result, |
59 bool* success); | 64 bool* success); |
60 | 65 |
61 // Sends a key event to the current browser. Waits until the key has | 66 // Sends a key event to the current browser. Waits until the key has |
62 // been processed by the web page. | 67 // been processed by the web page. |
63 void SendWebKeyEvent(const WebKeyEvent& key_event, bool* success); | 68 void SendWebKeyEvent(int tab_id, const WebKeyEvent& key_event, bool* success); |
64 | 69 |
65 void NavigateToURL(const std::string& url, bool* success); | 70 void NavigateToURL(int tab_id, const std::string& url, bool* success); |
66 void GoForward(bool* success); | 71 void GoForward(int tab_id, bool* success); |
67 void GoBack(bool* success); | 72 void GoBack(int tab_id, bool* success); |
68 void Reload(bool* success); | 73 void Reload(int tab_id, bool* success); |
69 void GetURL(std::string* url, bool* success); | 74 void GetURL(int tab_id, std::string* url, bool* success); |
70 void GetTabTitle(std::string* tab_title, bool* success); | 75 void GetTabTitle(int tab_id, std::string* tab_title, bool* success); |
| 76 |
| 77 // Get persistent IDs for all the tabs currently open. These IDs can be used |
| 78 // to identify the tab as long as the tab exists. |
| 79 void GetTabIds(std::vector<int>* tab_ids, bool* success); |
| 80 |
| 81 // Check if the given tab exists currently. |
| 82 void DoesTabExist(int tab_id, bool* does_exist); |
| 83 |
| 84 void CloseTab(int tab_id, bool* success); |
71 | 85 |
72 private: | 86 private: |
73 scoped_refptr<BrowserProxy> browser_; | 87 typedef std::map<int, scoped_refptr<TabProxy> > TabIdMap; |
74 scoped_refptr<TabProxy> tab_; | 88 TabProxy* GetTabById(int tab_id); |
75 | 89 |
| 90 // Map from tab ID to |TabProxy|. The tab ID is simply the |AutomationHandle| |
| 91 // for the proxy. |
| 92 TabIdMap tab_id_map_; |
76 ScopedTempDir profile_dir_; | 93 ScopedTempDir profile_dir_; |
77 | 94 |
78 DISALLOW_COPY_AND_ASSIGN(Automation); | 95 DISALLOW_COPY_AND_ASSIGN(Automation); |
79 }; | 96 }; |
80 | 97 |
81 } // namespace webdriver | 98 } // namespace webdriver |
82 | 99 |
83 DISABLE_RUNNABLE_METHOD_REFCOUNT(webdriver::Automation); | 100 DISABLE_RUNNABLE_METHOD_REFCOUNT(webdriver::Automation); |
84 | 101 |
85 #endif // CHROME_TEST_WEBDRIVER_AUTOMATION_H_ | 102 #endif // CHROME_TEST_WEBDRIVER_AUTOMATION_H_ |
OLD | NEW |