Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1087)

Side by Side Diff: content/public/test/browser_test_utils.h

Issue 11753009: Simplify ExecuteJavaScript* functions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update prerender_browsertest.cc. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/webrtc_browsertest.cc ('k') | content/public/test/browser_test_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ 5 #ifndef CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_
6 #define CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ 6 #define CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_
7 7
8 #include <queue> 8 #include <queue>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 const gfx::Point& point); 71 const gfx::Point& point);
72 72
73 // Sends a key press asynchronously. 73 // Sends a key press asynchronously.
74 void SimulateKeyPress(WebContents* web_contents, 74 void SimulateKeyPress(WebContents* web_contents,
75 ui::KeyboardCode key, 75 ui::KeyboardCode key,
76 bool control, 76 bool control,
77 bool shift, 77 bool shift,
78 bool alt, 78 bool alt,
79 bool command); 79 bool command);
80 80
81 // Allow ExecuteScript* methods to target either a WebContents or a
82 // RenderViewHost. Targetting a WebContents means executing script in the
83 // RenderViewHost returned by WebContents::GetRenderViewHost(), which is the
84 // "current" RenderViewHost. Pass a specific RenderViewHost to target, for
85 // example, a "swapped-out" RenderViewHost.
86 namespace internal {
87 class ToRenderViewHost {
88 public:
89 ToRenderViewHost(WebContents* web_contents);
90 ToRenderViewHost(RenderViewHost* render_view_host);
91
92 RenderViewHost* render_view_host() const { return render_view_host_; }
93
94 private:
95 RenderViewHost* render_view_host_;
96 };
97 } // namespace internal
98
81 // Executes the passed |script| in the frame pointed to by |frame_xpath| (use 99 // Executes the passed |script| in the frame pointed to by |frame_xpath| (use
82 // empty string for main frame). The |script| should not invoke 100 // empty string for main frame). The |script| should not invoke
83 // domAutomationController.send(); otherwise, your test will hang or be flaky. 101 // domAutomationController.send(); otherwise, your test will hang or be flaky.
84 // If you want to extract a result, use one of the below functions. 102 // If you want to extract a result, use one of the below functions.
85 // Returns true on success. 103 // Returns true on success.
86 bool ExecuteJavaScript(RenderViewHost* render_view_host, 104 bool ExecuteScriptInFrame(const internal::ToRenderViewHost& adapter,
87 const std::string& frame_xpath, 105 const std::string& frame_xpath,
88 const std::string& script) WARN_UNUSED_RESULT; 106 const std::string& script) WARN_UNUSED_RESULT;
89 107
90 // The following methods executes the passed |script| in the frame pointed to by 108 // The following methods executes the passed |script| in the frame pointed to by
91 // |frame_xpath| (use empty string for main frame) and sets |result| to the 109 // |frame_xpath| (use empty string for main frame) and sets |result| to the
92 // value returned by the script evaluation. 110 // value passed to "window.domAutomationController.send" by the executed script.
93 // They return true on success, false if the script evaluation failed or did not 111 // They return true on success, false if the script execution failed or did not
94 // evaluate to the expected type. 112 // evaluate to the expected type.
95 bool ExecuteJavaScriptAndExtractInt(RenderViewHost* render_view_host, 113 bool ExecuteScriptInFrameAndExtractInt(
96 const std::string& frame_xpath, 114 const internal::ToRenderViewHost& adapter,
97 const std::string& script, 115 const std::string& frame_xpath,
98 int* result) WARN_UNUSED_RESULT; 116 const std::string& script,
99 bool ExecuteJavaScriptAndExtractBool(RenderViewHost* render_view_host, 117 int* result) WARN_UNUSED_RESULT;
100 const std::string& frame_xpath, 118 bool ExecuteScriptInFrameAndExtractBool(
101 const std::string& script, 119 const internal::ToRenderViewHost& adapter,
102 bool* result) WARN_UNUSED_RESULT; 120 const std::string& frame_xpath,
103 bool ExecuteJavaScriptAndExtractString( 121 const std::string& script,
104 RenderViewHost* render_view_host, 122 bool* result) WARN_UNUSED_RESULT;
123 bool ExecuteScriptInFrameAndExtractString(
124 const internal::ToRenderViewHost& adapter,
105 const std::string& frame_xpath, 125 const std::string& frame_xpath,
106 const std::string& script, 126 const std::string& script,
107 std::string* result) WARN_UNUSED_RESULT; 127 std::string* result) WARN_UNUSED_RESULT;
108 128
129 // Top-frame script execution helpers (a.k.a., the common case):
130 bool ExecuteScript(const internal::ToRenderViewHost& adapter,
131 const std::string& script) WARN_UNUSED_RESULT;
132 bool ExecuteScriptAndExtractInt(const internal::ToRenderViewHost& adapter,
133 const std::string& script,
134 int* result) WARN_UNUSED_RESULT;
135 bool ExecuteScriptAndExtractBool(const internal::ToRenderViewHost& adapter,
136 const std::string& script,
137 bool* result) WARN_UNUSED_RESULT;
138 bool ExecuteScriptAndExtractString(const internal::ToRenderViewHost& adapter,
139 const std::string& script,
140 std::string* result) WARN_UNUSED_RESULT;
141
109 // Returns the cookies for the given url. 142 // Returns the cookies for the given url.
110 std::string GetCookies(BrowserContext* browser_context, const GURL& url); 143 std::string GetCookies(BrowserContext* browser_context, const GURL& url);
111 144
112 // Sets a cookie for the given url. Returns true on success. 145 // Sets a cookie for the given url. Returns true on success.
113 bool SetCookie(BrowserContext* browser_context, 146 bool SetCookie(BrowserContext* browser_context,
114 const GURL& url, 147 const GURL& url,
115 const std::string& value); 148 const std::string& value);
116 149
117 // Watches title changes on a tab, blocking until an expected title is set. 150 // Watches title changes on a tab, blocking until an expected title is set.
118 class TitleWatcher : public NotificationObserver { 151 class TitleWatcher : public NotificationObserver {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 std::queue<std::string> message_queue_; 212 std::queue<std::string> message_queue_;
180 bool waiting_for_message_; 213 bool waiting_for_message_;
181 scoped_refptr<MessageLoopRunner> message_loop_runner_; 214 scoped_refptr<MessageLoopRunner> message_loop_runner_;
182 215
183 DISALLOW_COPY_AND_ASSIGN(DOMMessageQueue); 216 DISALLOW_COPY_AND_ASSIGN(DOMMessageQueue);
184 }; 217 };
185 218
186 } // namespace content 219 } // namespace content
187 220
188 #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ 221 #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_
OLDNEW
« no previous file with comments | « content/browser/webrtc_browsertest.cc ('k') | content/public/test/browser_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698