OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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_AUTOMATION_TAB_PROXY_H_ | |
6 #define CHROME_TEST_AUTOMATION_TAB_PROXY_H_ | |
7 | |
8 #include "build/build_config.h" // NOLINT | |
9 | |
10 #if defined(OS_WIN) | |
11 #include <wtypes.h> // NOLINT | |
12 #endif | |
13 | |
14 #include <string> | |
15 #include <vector> | |
16 | |
17 #include "base/compiler_specific.h" | |
18 #include "base/memory/ref_counted.h" | |
19 #include "base/observer_list.h" | |
20 #include "chrome/common/automation_constants.h" | |
21 #include "chrome/test/automation/automation_handle_tracker.h" | |
22 #include "content/public/browser/save_page_type.h" | |
23 #include "content/public/common/page_type.h" | |
24 #include "content/public/common/security_style.h" | |
25 #include "net/cert/cert_status_flags.h" | |
26 #include "ui/base/window_open_disposition.h" | |
27 #include "ui/events/keycodes/keyboard_codes.h" | |
28 | |
29 class BrowserProxy; | |
30 class GURL; | |
31 | |
32 namespace IPC { | |
33 class Message; | |
34 } | |
35 | |
36 namespace base { | |
37 class FilePath; | |
38 class Value; | |
39 } | |
40 | |
41 class TabProxy : public AutomationResourceProxy { | |
42 public: | |
43 class TabProxyDelegate { | |
44 public: | |
45 virtual bool OnMessageReceived(TabProxy* tab, const IPC::Message& msg) { | |
46 return false; | |
47 } | |
48 virtual void OnChannelError(TabProxy* tab) {} | |
49 | |
50 protected: | |
51 virtual ~TabProxyDelegate() {} | |
52 }; | |
53 | |
54 TabProxy(AutomationMessageSender* sender, | |
55 AutomationHandleTracker* tracker, | |
56 int handle); | |
57 | |
58 // Gets the current url of the tab. | |
59 bool GetCurrentURL(GURL* url) const WARN_UNUSED_RESULT; | |
60 | |
61 // Gets the title of the tab. | |
62 bool GetTabTitle(std::wstring* title) const WARN_UNUSED_RESULT; | |
63 | |
64 // Gets the tabstrip index of the tab. | |
65 bool GetTabIndex(int* index) const WARN_UNUSED_RESULT; | |
66 | |
67 // Executes a javascript in a frame's context whose xpath is provided as the | |
68 // first parameter and extract the values from the resulting json string. | |
69 // Examples: | |
70 // jscript = "window.domAutomationController.send('string');" | |
71 // will result in value = "string" | |
72 // jscript = "window.domAutomationController.send(24);" | |
73 // will result in value = 24 | |
74 // NOTE: If this is called from a ui test, |dom_automation_enabled_| must be | |
75 // set to true for these functions to work. | |
76 bool ExecuteAndExtractString(const std::wstring& frame_xpath, | |
77 const std::wstring& jscript, | |
78 std::wstring* value) WARN_UNUSED_RESULT; | |
79 bool ExecuteAndExtractBool(const std::wstring& frame_xpath, | |
80 const std::wstring& jscript, | |
81 bool* value) WARN_UNUSED_RESULT; | |
82 bool ExecuteAndExtractInt(const std::wstring& frame_xpath, | |
83 const std::wstring& jscript, | |
84 int* value) WARN_UNUSED_RESULT; | |
85 | |
86 // Navigates to a url. This method accepts the same kinds of URL input that | |
87 // can be passed to Chrome on the command line. This is a synchronous call and | |
88 // hence blocks until the navigation completes. | |
89 AutomationMsg_NavigationResponseValues NavigateToURL( | |
90 const GURL& url) WARN_UNUSED_RESULT; | |
91 | |
92 // Navigates to a url. This method accepts the same kinds of URL input that | |
93 // can be passed to Chrome on the command line. This is a synchronous call and | |
94 // hence blocks until the |number_of_navigations| navigations complete. | |
95 AutomationMsg_NavigationResponseValues | |
96 NavigateToURLBlockUntilNavigationsComplete( | |
97 const GURL& url, int number_of_navigations) WARN_UNUSED_RESULT; | |
98 | |
99 | |
100 // Navigates to a url. This is an asynchronous version of NavigateToURL. | |
101 // The function returns immediately after sending the LoadURL notification | |
102 // to the browser. | |
103 // TODO(vibhor): Add a callback if needed in future. | |
104 // TODO(mpcomplete): If the navigation results in an auth challenge, the | |
105 // TabProxy we attach won't know about it. See bug 666730. | |
106 bool NavigateToURLAsync(const GURL& url) WARN_UNUSED_RESULT; | |
107 | |
108 // Equivalent to hitting the Back button. This is a synchronous call and | |
109 // hence blocks until the navigation completes. | |
110 AutomationMsg_NavigationResponseValues GoBack() WARN_UNUSED_RESULT; | |
111 | |
112 // Equivalent to hitting the Back button. This is a synchronous call and | |
113 // hence blocks until the |number_of_navigations| navigations complete. | |
114 AutomationMsg_NavigationResponseValues GoBackBlockUntilNavigationsComplete( | |
115 int number_of_navigations) WARN_UNUSED_RESULT; | |
116 | |
117 // Equivalent to hitting the Forward button. This is a synchronous call and | |
118 // hence blocks until the navigation completes. | |
119 AutomationMsg_NavigationResponseValues GoForward() WARN_UNUSED_RESULT; | |
120 | |
121 // Equivalent to hitting the Forward button. This is a synchronous call and | |
122 // hence blocks until the |number_of_navigations| navigations complete. | |
123 AutomationMsg_NavigationResponseValues GoForwardBlockUntilNavigationsComplete( | |
124 int number_of_navigations) WARN_UNUSED_RESULT; | |
125 | |
126 // Equivalent to hitting the Reload button. This is a synchronous call and | |
127 // hence blocks until the navigation completes. | |
128 AutomationMsg_NavigationResponseValues Reload() WARN_UNUSED_RESULT; | |
129 | |
130 // Closes the tab. This is synchronous, but does NOT block until the tab has | |
131 // closed, rather it blocks until the browser has initiated the close. Use | |
132 // Close(true) if you need to block until tab completely closes. | |
133 // | |
134 // Note that this proxy is invalid after this call. | |
135 bool Close() WARN_UNUSED_RESULT; | |
136 | |
137 // Variant of close that allows you to specify whether you want to block | |
138 // until the tab has completely closed (wait_until_closed == true) or block | |
139 // until the browser has initiated the close (wait_until_closed = false). | |
140 // | |
141 // When a tab is closed the browser does additional work via invoke later | |
142 // and may wait for messages from the renderer. Supplying a value of true to | |
143 // this method waits until all processing is done. Be careful with this, | |
144 // when closing the last tab it is possible for the browser to shutdown BEFORE | |
145 // the tab has completely closed. In other words, this may NOT be sent for | |
146 // the last tab. | |
147 bool Close(bool wait_until_closed) WARN_UNUSED_RESULT; | |
148 | |
149 // Starts a search within the current tab. The parameter |search_string| | |
150 // specifies what string to search for, |forward| specifies whether to search | |
151 // in forward direction, and |match_case| specifies case sensitivity | |
152 // (true=case sensitive). |find_next| specifies whether this is a new search | |
153 // or a continuation of the old one. |ordinal| is an optional parameter that | |
154 // returns the ordinal of the active match (also known as "the 7" part of | |
155 // "7 of 9"). A return value of -1 indicates failure. | |
156 int FindInPage(const std::wstring& search_string, FindInPageDirection forward, | |
157 FindInPageCase match_case, bool find_next, int* ordinal); | |
158 | |
159 bool GetCookies(const GURL& url, std::string* cookies) WARN_UNUSED_RESULT; | |
160 bool GetCookieByName(const GURL& url, | |
161 const std::string& name, | |
162 std::string* cookies) WARN_UNUSED_RESULT; | |
163 // Waits until the infobar count is |count|. | |
164 // Returns true on success. | |
165 bool WaitForInfoBarCount(size_t count) WARN_UNUSED_RESULT; | |
166 | |
167 // Uses the specified encoding to override encoding of the page in the tab. | |
168 bool OverrideEncoding(const std::string& encoding) WARN_UNUSED_RESULT; | |
169 | |
170 // These handlers issue asynchronous Reload, Stop and SaveAs notifications to | |
171 // the chrome instance. | |
172 void ReloadAsync(); | |
173 void StopAsync(); | |
174 | |
175 // Notify the JavaScript engine in the render to change its parameters | |
176 // while performing stress testing. See | |
177 // |ViewHostMsg_JavaScriptStressTestControl_Commands| in render_messages.h | |
178 // for information on the arguments. | |
179 void JavaScriptStressTestControl(int cmd, int param); | |
180 | |
181 // Calls delegates | |
182 void AddObserver(TabProxyDelegate* observer); | |
183 void RemoveObserver(TabProxyDelegate* observer); | |
184 bool OnMessageReceived(const IPC::Message& message); | |
185 void OnChannelError(); | |
186 protected: | |
187 virtual ~TabProxy(); | |
188 | |
189 // Called when tracking the first object. Used for reference counting | |
190 // purposes. | |
191 void FirstObjectAdded(); | |
192 | |
193 // Called when no longer tracking any objects. Used for reference counting | |
194 // purposes. | |
195 void LastObjectRemoved(); | |
196 | |
197 // Caller takes ownership over returned value. Returns NULL on failure. | |
198 base::Value* ExecuteAndExtractValue( | |
199 const std::wstring& frame_xpath, | |
200 const std::wstring& jscript) WARN_UNUSED_RESULT; | |
201 | |
202 private: | |
203 base::Lock list_lock_; // Protects the observers_list_. | |
204 ObserverList<TabProxyDelegate> observers_list_; | |
205 DISALLOW_COPY_AND_ASSIGN(TabProxy); | |
206 }; | |
207 | |
208 #endif // CHROME_TEST_AUTOMATION_TAB_PROXY_H_ | |
OLD | NEW |