OLD | NEW |
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 #include "content/public/test/browser_test_utils.h" | 5 #include "content/public/test/browser_test_utils.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <tuple> | 8 #include <tuple> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver); | 130 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver); |
131 }; | 131 }; |
132 | 132 |
133 // Specifying a prototype so that we can add the WARN_UNUSED_RESULT attribute. | 133 // Specifying a prototype so that we can add the WARN_UNUSED_RESULT attribute. |
134 bool ExecuteScriptHelper(RenderFrameHost* render_frame_host, | 134 bool ExecuteScriptHelper(RenderFrameHost* render_frame_host, |
135 const std::string& original_script, | 135 const std::string& original_script, |
136 bool user_gesture, | 136 bool user_gesture, |
137 std::unique_ptr<base::Value>* result) | 137 std::unique_ptr<base::Value>* result) |
138 WARN_UNUSED_RESULT; | 138 WARN_UNUSED_RESULT; |
139 | 139 |
140 // Executes the passed |original_script| in the frame specified by | 140 // Executes the passed |script| in the frame specified by |render_frame_host|. |
141 // |render_frame_host|. If |result| is not NULL, stores the value that the | 141 // If |result| is not NULL, stores the value that the evaluation of the script |
142 // evaluation of the script in |result|. Returns true on success. | 142 // in |result|. Returns true on success. |
143 bool ExecuteScriptHelper(RenderFrameHost* render_frame_host, | 143 bool ExecuteScriptHelper(RenderFrameHost* render_frame_host, |
144 const std::string& original_script, | 144 const std::string& script, |
145 bool user_gesture, | 145 bool user_gesture, |
146 std::unique_ptr<base::Value>* result) { | 146 std::unique_ptr<base::Value>* result) { |
147 // TODO(jcampan): we should make the domAutomationController not require an | |
148 // automation id. | |
149 std::string script = | |
150 "window.domAutomationController.setAutomationId(0);" + original_script; | |
151 // TODO(lukasza): Only get messages from the specific |render_frame_host|. | 147 // TODO(lukasza): Only get messages from the specific |render_frame_host|. |
152 DOMMessageQueue dom_message_queue( | 148 DOMMessageQueue dom_message_queue( |
153 WebContents::FromRenderFrameHost(render_frame_host)); | 149 WebContents::FromRenderFrameHost(render_frame_host)); |
154 if (user_gesture) { | 150 if (user_gesture) { |
155 render_frame_host->ExecuteJavaScriptWithUserGestureForTests( | 151 render_frame_host->ExecuteJavaScriptWithUserGestureForTests( |
156 base::UTF8ToUTF16(script)); | 152 base::UTF8ToUTF16(script)); |
157 } else { | 153 } else { |
158 render_frame_host->ExecuteJavaScriptForTests(base::UTF8ToUTF16(script)); | 154 render_frame_host->ExecuteJavaScriptForTests(base::UTF8ToUTF16(script)); |
159 } | 155 } |
160 std::string json; | 156 std::string json; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 | 205 |
210 // Specifying a prototype so that we can add the WARN_UNUSED_RESULT attribute. | 206 // Specifying a prototype so that we can add the WARN_UNUSED_RESULT attribute. |
211 bool ExecuteScriptInIsolatedWorldHelper(RenderFrameHost* render_frame_host, | 207 bool ExecuteScriptInIsolatedWorldHelper(RenderFrameHost* render_frame_host, |
212 const int world_id, | 208 const int world_id, |
213 const std::string& original_script, | 209 const std::string& original_script, |
214 std::unique_ptr<base::Value>* result) | 210 std::unique_ptr<base::Value>* result) |
215 WARN_UNUSED_RESULT; | 211 WARN_UNUSED_RESULT; |
216 | 212 |
217 bool ExecuteScriptInIsolatedWorldHelper(RenderFrameHost* render_frame_host, | 213 bool ExecuteScriptInIsolatedWorldHelper(RenderFrameHost* render_frame_host, |
218 const int world_id, | 214 const int world_id, |
219 const std::string& original_script, | 215 const std::string& script, |
220 std::unique_ptr<base::Value>* result) { | 216 std::unique_ptr<base::Value>* result) { |
221 // TODO(jcampan): we should make the domAutomationController not require an | |
222 // automation id. | |
223 std::string script = | |
224 "window.domAutomationController.setAutomationId(0);" + original_script; | |
225 // TODO(lukasza): Only get messages from the specific |render_frame_host|. | 217 // TODO(lukasza): Only get messages from the specific |render_frame_host|. |
226 DOMMessageQueue dom_message_queue( | 218 DOMMessageQueue dom_message_queue( |
227 WebContents::FromRenderFrameHost(render_frame_host)); | 219 WebContents::FromRenderFrameHost(render_frame_host)); |
228 render_frame_host->ExecuteJavaScriptInIsolatedWorld( | 220 render_frame_host->ExecuteJavaScriptInIsolatedWorld( |
229 base::UTF8ToUTF16(script), | 221 base::UTF8ToUTF16(script), |
230 content::RenderFrameHost::JavaScriptResultCallback(), world_id); | 222 content::RenderFrameHost::JavaScriptResultCallback(), world_id); |
231 std::string json; | 223 std::string json; |
232 if (!dom_message_queue.WaitForMessage(&json)) { | 224 if (!dom_message_queue.WaitForMessage(&json)) { |
233 DLOG(ERROR) << "Cannot communicate with DOMMessageQueue."; | 225 DLOG(ERROR) << "Cannot communicate with DOMMessageQueue."; |
234 return false; | 226 return false; |
(...skipping 1903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2138 RenderWidgetHostViewAura* rwhva = | 2130 RenderWidgetHostViewAura* rwhva = |
2139 static_cast<RenderWidgetHostViewAura*>(rwhv); | 2131 static_cast<RenderWidgetHostViewAura*>(rwhv); |
2140 rwhva->SetOverscrollControllerForTesting(std::move(mock)); | 2132 rwhva->SetOverscrollControllerForTesting(std::move(mock)); |
2141 | 2133 |
2142 return raw_mock; | 2134 return raw_mock; |
2143 } | 2135 } |
2144 | 2136 |
2145 #endif // defined(USE_AURA) | 2137 #endif // defined(USE_AURA) |
2146 | 2138 |
2147 } // namespace content | 2139 } // namespace content |
OLD | NEW |