Implement nacl_irt_memory for non-sfi mode.
[chromium-blink-merge.git] / chrome / test / automation / tab_proxy.h
blobf79f60ebd1be2a145cbd602e6d81a5dcd91c3da5
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/window_open_disposition.h"
27 #include "ui/events/keycodes/keyboard_codes.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;
163 // Waits until the infobar count is |count|.
164 // Returns true on success.
165 bool WaitForInfoBarCount(size_t count) WARN_UNUSED_RESULT;
167 // Uses the specified encoding to override encoding of the page in the tab.
168 bool OverrideEncoding(const std::string& encoding) WARN_UNUSED_RESULT;
170 // Selects all contents on the page.
171 void SelectAll();
173 // Edit operations on the page.
174 void Cut();
175 void Copy();
176 void Paste();
178 // These handlers issue asynchronous Reload, Stop and SaveAs notifications to
179 // the chrome instance.
180 void ReloadAsync();
181 void StopAsync();
183 // Notify the JavaScript engine in the render to change its parameters
184 // while performing stress testing. See
185 // |ViewHostMsg_JavaScriptStressTestControl_Commands| in render_messages.h
186 // for information on the arguments.
187 void JavaScriptStressTestControl(int cmd, int param);
189 // Calls delegates
190 void AddObserver(TabProxyDelegate* observer);
191 void RemoveObserver(TabProxyDelegate* observer);
192 bool OnMessageReceived(const IPC::Message& message);
193 void OnChannelError();
194 protected:
195 virtual ~TabProxy();
197 // Called when tracking the first object. Used for reference counting
198 // purposes.
199 void FirstObjectAdded();
201 // Called when no longer tracking any objects. Used for reference counting
202 // purposes.
203 void LastObjectRemoved();
205 // Caller takes ownership over returned value. Returns NULL on failure.
206 base::Value* ExecuteAndExtractValue(
207 const std::wstring& frame_xpath,
208 const std::wstring& jscript) WARN_UNUSED_RESULT;
210 private:
211 base::Lock list_lock_; // Protects the observers_list_.
212 ObserverList<TabProxyDelegate> observers_list_;
213 DISALLOW_COPY_AND_ASSIGN(TabProxy);
216 #endif // CHROME_TEST_AUTOMATION_TAB_PROXY_H_