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 #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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 | 200 |
201 private: | 201 private: |
202 RenderFrameHost* render_frame_host_; | 202 RenderFrameHost* render_frame_host_; |
203 }; | 203 }; |
204 | 204 |
205 RenderFrameHost* ConvertToRenderFrameHost(RenderViewHost* render_view_host); | 205 RenderFrameHost* ConvertToRenderFrameHost(RenderViewHost* render_view_host); |
206 RenderFrameHost* ConvertToRenderFrameHost(RenderFrameHost* render_view_host); | 206 RenderFrameHost* ConvertToRenderFrameHost(RenderFrameHost* render_view_host); |
207 RenderFrameHost* ConvertToRenderFrameHost(WebContents* web_contents); | 207 RenderFrameHost* ConvertToRenderFrameHost(WebContents* web_contents); |
208 | 208 |
209 // Executes the passed |script| in the specified frame with the user gesture. | 209 // Executes the passed |script| in the specified frame with the user gesture. |
210 // The |script| should not invoke domAutomationController.send(); otherwise, | 210 // |
211 // your test will hang or be flaky. If you want to extract a result, use one of | 211 // Appends |domAutomationController.send(...)| to the end of |script| and waits |
212 // the below functions. Returns true on success. | 212 // until the response comes back (pumping the message loop while waiting). The |
| 213 // |script| itself should not invoke domAutomationController.send(); if you want |
| 214 // to call domAutomationController.send(...) yourself and extract the result, |
| 215 // then use one of ExecuteScriptAndExtract... functions). |
| 216 // |
| 217 // Returns true on success (if the renderer responded back with the expected |
| 218 // value). Returns false otherwise (e.g. if the script threw an exception |
| 219 // before calling the appended |domAutomationController.send(...)|, or if the |
| 220 // renderer died or if the renderer called |domAutomationController.send(...)| |
| 221 // with a malformed or unexpected value). |
| 222 // |
| 223 // See also: |
| 224 // - ExecuteScriptAsync |
| 225 // - ExecuteScriptAndExtractBool/Int/String/etc. |
| 226 // - DOMMessageQueue (to manually wait for domAutomationController.send(...)) |
213 bool ExecuteScript(const ToRenderFrameHost& adapter, | 227 bool ExecuteScript(const ToRenderFrameHost& adapter, |
214 const std::string& script) WARN_UNUSED_RESULT; | 228 const std::string& script) WARN_UNUSED_RESULT; |
215 | 229 |
216 // Same as content::ExecuteScript but doesn't send a user gesture to the | 230 // Same as content::ExecuteScript but doesn't send a user gesture to the |
217 // renderer. | 231 // renderer. |
218 bool ExecuteScriptWithoutUserGesture(const ToRenderFrameHost& adapter, | 232 bool ExecuteScriptWithoutUserGesture(const ToRenderFrameHost& adapter, |
219 const std::string& script) | 233 const std::string& script) |
220 WARN_UNUSED_RESULT; | 234 WARN_UNUSED_RESULT; |
221 | 235 |
222 // The following methods execute the passed |script| in the specified frame with | 236 // Similar to ExecuteScript above, but |
223 // the user gesture and set |result| to the value passed to | 237 // - Doesn't modify the |script|. |
224 // "window.domAutomationController.send" by the executed script. They return | 238 // - Kicks off execution of the |script| in the specified frame and returns |
225 // true on success, false if the script execution failed or did not evaluate to | 239 // immediately (without waiting for a response from the renderer and/or |
226 // the expected type. | 240 // without checking that the script succeeded). |
| 241 void ExecuteScriptAsync(const ToRenderFrameHost& adapter, |
| 242 const std::string& script); |
| 243 |
| 244 // The following methods execute the passed |script| in the specified frame and |
| 245 // sets |result| to the value passed to "window.domAutomationController.send" by |
| 246 // the executed script. They return true on success, false if the script |
| 247 // execution failed or did not evaluate to the expected type. |
227 bool ExecuteScriptAndExtractDouble(const ToRenderFrameHost& adapter, | 248 bool ExecuteScriptAndExtractDouble(const ToRenderFrameHost& adapter, |
228 const std::string& script, | 249 const std::string& script, |
229 double* result) WARN_UNUSED_RESULT; | 250 double* result) WARN_UNUSED_RESULT; |
230 bool ExecuteScriptAndExtractInt(const ToRenderFrameHost& adapter, | 251 bool ExecuteScriptAndExtractInt(const ToRenderFrameHost& adapter, |
231 const std::string& script, | 252 const std::string& script, |
232 int* result) WARN_UNUSED_RESULT; | 253 int* result) WARN_UNUSED_RESULT; |
233 bool ExecuteScriptAndExtractBool(const ToRenderFrameHost& adapter, | 254 bool ExecuteScriptAndExtractBool(const ToRenderFrameHost& adapter, |
234 const std::string& script, | 255 const std::string& script, |
235 bool* result) WARN_UNUSED_RESULT; | 256 bool* result) WARN_UNUSED_RESULT; |
236 bool ExecuteScriptAndExtractString(const ToRenderFrameHost& adapter, | 257 bool ExecuteScriptAndExtractString(const ToRenderFrameHost& adapter, |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 const NotificationSource& source, | 535 const NotificationSource& source, |
515 const NotificationDetails& details) override; | 536 const NotificationDetails& details) override; |
516 | 537 |
517 // Overridden WebContentsObserver methods. | 538 // Overridden WebContentsObserver methods. |
518 void RenderProcessGone(base::TerminationStatus status) override; | 539 void RenderProcessGone(base::TerminationStatus status) override; |
519 | 540 |
520 private: | 541 private: |
521 NotificationRegistrar registrar_; | 542 NotificationRegistrar registrar_; |
522 std::queue<std::string> message_queue_; | 543 std::queue<std::string> message_queue_; |
523 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 544 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 545 bool renderer_crashed_ = false; |
524 | 546 |
525 DISALLOW_COPY_AND_ASSIGN(DOMMessageQueue); | 547 DISALLOW_COPY_AND_ASSIGN(DOMMessageQueue); |
526 }; | 548 }; |
527 | 549 |
528 // Used to wait for a new WebContents to be created. Instantiate this object | 550 // Used to wait for a new WebContents to be created. Instantiate this object |
529 // before the operation that will create the window. | 551 // before the operation that will create the window. |
530 class WebContentsAddedObserver { | 552 class WebContentsAddedObserver { |
531 public: | 553 public: |
532 WebContentsAddedObserver(); | 554 WebContentsAddedObserver(); |
533 ~WebContentsAddedObserver(); | 555 ~WebContentsAddedObserver(); |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
864 virtual ~MockOverscrollController() {} | 886 virtual ~MockOverscrollController() {} |
865 | 887 |
866 // Waits until the mock receives a consumed GestureScrollUpdate. | 888 // Waits until the mock receives a consumed GestureScrollUpdate. |
867 virtual void WaitForConsumedScroll() = 0; | 889 virtual void WaitForConsumedScroll() = 0; |
868 }; | 890 }; |
869 #endif // defined(USE_AURA) | 891 #endif // defined(USE_AURA) |
870 | 892 |
871 } // namespace content | 893 } // namespace content |
872 | 894 |
873 #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ | 895 #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ |
OLD | NEW |