Suppression for crbug/241044.
[chromium-blink-merge.git] / chrome / test / automation / tab_proxy.h
blob5e660469fa08f04fd2635a7301e3d49e00b29647
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.
5 #ifndef CHROME_TEST_AUTOMATION_TAB_PROXY_H_
6 #define CHROME_TEST_AUTOMATION_TAB_PROXY_H_
8 #include "build/build_config.h" // NOLINT
10 #if defined(OS_WIN)
11 #include <wtypes.h> // NOLINT
12 #endif
14 #include <string>
15 #include <vector>
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/keycodes/keyboard_codes.h"
27 #include "ui/base/window_open_disposition.h"
29 class BrowserProxy;
30 class GURL;
32 namespace IPC {
33 class Message;
36 namespace base {
37 class FilePath;
38 class Value;
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;
48 virtual void OnChannelError(TabProxy* tab) {}
50 protected:
51 virtual ~TabProxyDelegate() {}
54 TabProxy(AutomationMessageSender* sender,
55 AutomationHandleTracker* tracker,
56 int handle);
58 // Gets the current url of the tab.
59 bool GetCurrentURL(GURL* url) const WARN_UNUSED_RESULT;
61 // Gets the title of the tab.
62 bool GetTabTitle(std::wstring* title) const WARN_UNUSED_RESULT;
64 // Gets the tabstrip index of the tab.
65 bool GetTabIndex(int* index) const WARN_UNUSED_RESULT;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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.
134 // Note that this proxy is invalid after this call.
135 bool Close() WARN_UNUSED_RESULT;
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).
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;
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);
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;
164 #if defined(OS_WIN)
165 // The functions in this block are for external tabs, hence Windows only.
167 // The container of an externally hosted tab calls this to reflect any
168 // accelerator keys that it did not process. This gives the tab a chance
169 // to handle the keys
170 bool ProcessUnhandledAccelerator(const MSG& msg) WARN_UNUSED_RESULT;
172 // Ask the tab to set focus to either the first or last element on the page.
173 // When the restore_focus_to_view parameter is true, the render view
174 // associated with the current tab is informed that it is receiving focus.
175 // For external tabs only.
176 bool SetInitialFocus(bool reverse, bool restore_focus_to_view)
177 WARN_UNUSED_RESULT;
179 // Navigates to a url in an externally hosted tab.
180 // This method accepts the same kinds of URL input that
181 // can be passed to Chrome on the command line. This is a synchronous call and
182 // hence blocks until the navigation completes.
183 AutomationMsg_NavigationResponseValues NavigateInExternalTab(
184 const GURL& url, const GURL& referrer) WARN_UNUSED_RESULT;
186 AutomationMsg_NavigationResponseValues NavigateExternalTabAtIndex(
187 int index) WARN_UNUSED_RESULT;
189 // Posts a message to the external tab.
190 void HandleMessageFromExternalHost(const std::string& message,
191 const std::string& origin,
192 const std::string& target);
193 #endif // defined(OS_WIN)
195 // Sends off an asynchronous request for printing.
196 bool PrintAsync() WARN_UNUSED_RESULT;
198 // Waits until the infobar count is |count|.
199 // Returns true on success.
200 bool WaitForInfoBarCount(size_t count) WARN_UNUSED_RESULT;
202 // Uses the specified encoding to override encoding of the page in the tab.
203 bool OverrideEncoding(const std::string& encoding) WARN_UNUSED_RESULT;
205 // Captures the entire page and saves as a PNG at the given path. Returns
206 // true on success.
207 bool CaptureEntirePageAsPNG(const base::FilePath& path) WARN_UNUSED_RESULT;
209 #if defined(OS_WIN)
210 // Resizes the tab window.
211 // The parent_window parameter allows a parent to be specified for the window
212 // passed in.
213 void Reposition(HWND window, HWND window_insert_after, int left, int top,
214 int width, int height, int flags, HWND parent_window);
216 // Sends the selected context menu command to the chrome instance
217 void SendContextMenuCommand(int selected_command);
219 // To be called when the window hosting the tab has moved.
220 void OnHostMoved();
221 #endif // defined(OS_WIN)
223 // Selects all contents on the page.
224 void SelectAll();
226 // Edit operations on the page.
227 void Cut();
228 void Copy();
229 void Paste();
231 // Simulates a key press. |key| is the virtual key code of the key pressed.
232 void SimulateKeyPress(ui::KeyboardCode key);
234 // These handlers issue asynchronous Reload, Stop and SaveAs notifications to
235 // the chrome instance.
236 void ReloadAsync();
237 void StopAsync();
238 void SaveAsAsync();
240 // Notify the JavaScript engine in the render to change its parameters
241 // while performing stress testing. See
242 // |ViewHostMsg_JavaScriptStressTestControl_Commands| in render_messages.h
243 // for information on the arguments.
244 void JavaScriptStressTestControl(int cmd, int param);
246 // Calls delegates
247 void AddObserver(TabProxyDelegate* observer);
248 void RemoveObserver(TabProxyDelegate* observer);
249 bool OnMessageReceived(const IPC::Message& message);
250 void OnChannelError();
251 protected:
252 virtual ~TabProxy();
254 // Called when tracking the first object. Used for reference counting
255 // purposes.
256 void FirstObjectAdded();
258 // Called when no longer tracking any objects. Used for reference counting
259 // purposes.
260 void LastObjectRemoved();
262 // Caller takes ownership over returned value. Returns NULL on failure.
263 base::Value* ExecuteAndExtractValue(
264 const std::wstring& frame_xpath,
265 const std::wstring& jscript) WARN_UNUSED_RESULT;
267 private:
268 base::Lock list_lock_; // Protects the observers_list_.
269 ObserverList<TabProxyDelegate> observers_list_;
270 DISALLOW_COPY_AND_ASSIGN(TabProxy);
273 #endif // CHROME_TEST_AUTOMATION_TAB_PROXY_H_