| 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 <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 // A collections of functions designed for use with content_browsertests and | 28 // A collections of functions designed for use with content_browsertests and |
| 29 // browser_tests. | 29 // browser_tests. |
| 30 // TO BE CLEAR: any function here must work against both binaries. If it only | 30 // TO BE CLEAR: any function here must work against both binaries. If it only |
| 31 // works with browser_tests, it should be in chrome\test\base\ui_test_utils.h. | 31 // works with browser_tests, it should be in chrome\test\base\ui_test_utils.h. |
| 32 // If it only works with content_browsertests, it should be in | 32 // If it only works with content_browsertests, it should be in |
| 33 // content\test\content_browser_test_utils.h. | 33 // content\test\content_browser_test_utils.h. |
| 34 | 34 |
| 35 namespace content { | 35 namespace content { |
| 36 | 36 |
| 37 class MessageLoopRunner; | 37 class MessageLoopRunner; |
| 38 class RenderViewHost; |
| 38 class WebContents; | 39 class WebContents; |
| 39 | 40 |
| 40 // Simulates clicking at the center of the given tab asynchronously. | 41 // Simulates clicking at the center of the given tab asynchronously. |
| 41 void SimulateMouseClick(WebContents* web_contents); | 42 void SimulateMouseClick(WebContents* web_contents); |
| 42 | 43 |
| 43 // Simulates asynchronously a mouse enter/move/leave event. | 44 // Simulates asynchronously a mouse enter/move/leave event. |
| 44 void SimulateMouseEvent(WebContents* web_contents, | 45 void SimulateMouseEvent(WebContents* web_contents, |
| 45 WebKit::WebInputEvent::Type type, | 46 WebKit::WebInputEvent::Type type, |
| 46 const gfx::Point& point); | 47 const gfx::Point& point); |
| 47 | 48 |
| 48 // Sends a key press asynchronously. | 49 // Sends a key press asynchronously. |
| 49 void SimulateKeyPress(WebContents* web_contents, | 50 void SimulateKeyPress(WebContents* web_contents, |
| 50 ui::KeyboardCode key, | 51 ui::KeyboardCode key, |
| 51 bool control, | 52 bool control, |
| 52 bool shift, | 53 bool shift, |
| 53 bool alt, | 54 bool alt, |
| 54 bool command); | 55 bool command); |
| 55 | 56 |
| 57 // Executes the passed |script| in the frame pointed to by |frame_xpath| (use |
| 58 // empty string for main frame). The |script| should not invoke |
| 59 // domAutomationController.send(); otherwise, your test will hang or be flaky. |
| 60 // If you want to extract a result, use one of the below functions. |
| 61 // Returns true on success. |
| 62 bool ExecuteJavaScript(RenderViewHost* render_view_host, |
| 63 const std::wstring& frame_xpath, |
| 64 const std::wstring& script) WARN_UNUSED_RESULT; |
| 65 |
| 66 // The following methods executes the passed |script| in the frame pointed to by |
| 67 // |frame_xpath| (use empty string for main frame) and sets |result| to the |
| 68 // value returned by the script evaluation. |
| 69 // They return true on success, false if the script evaluation failed or did not |
| 70 // evaluate to the expected type. |
| 71 bool ExecuteJavaScriptAndExtractInt(RenderViewHost* render_view_host, |
| 72 const std::wstring& frame_xpath, |
| 73 const std::wstring& script, |
| 74 int* result) WARN_UNUSED_RESULT; |
| 75 bool ExecuteJavaScriptAndExtractBool(RenderViewHost* render_view_host, |
| 76 const std::wstring& frame_xpath, |
| 77 const std::wstring& script, |
| 78 bool* result) WARN_UNUSED_RESULT; |
| 79 bool ExecuteJavaScriptAndExtractString( |
| 80 RenderViewHost* render_view_host, |
| 81 const std::wstring& frame_xpath, |
| 82 const std::wstring& script, |
| 83 std::string* result) WARN_UNUSED_RESULT; |
| 84 |
| 56 // Watches title changes on a tab, blocking until an expected title is set. | 85 // Watches title changes on a tab, blocking until an expected title is set. |
| 57 class TitleWatcher : public NotificationObserver { | 86 class TitleWatcher : public NotificationObserver { |
| 58 public: | 87 public: |
| 59 // |web_contents| must be non-NULL and needs to stay alive for the | 88 // |web_contents| must be non-NULL and needs to stay alive for the |
| 60 // entire lifetime of |this|. |expected_title| is the title that |this| | 89 // entire lifetime of |this|. |expected_title| is the title that |this| |
| 61 // will wait for. | 90 // will wait for. |
| 62 TitleWatcher(WebContents* web_contents, | 91 TitleWatcher(WebContents* web_contents, |
| 63 const string16& expected_title); | 92 const string16& expected_title); |
| 64 virtual ~TitleWatcher(); | 93 virtual ~TitleWatcher(); |
| 65 | 94 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 87 | 116 |
| 88 bool expected_title_observed_; | 117 bool expected_title_observed_; |
| 89 bool quit_loop_on_observation_; | 118 bool quit_loop_on_observation_; |
| 90 | 119 |
| 91 DISALLOW_COPY_AND_ASSIGN(TitleWatcher); | 120 DISALLOW_COPY_AND_ASSIGN(TitleWatcher); |
| 92 }; | 121 }; |
| 93 | 122 |
| 94 } // namespace content | 123 } // namespace content |
| 95 | 124 |
| 96 #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ | 125 #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ |
| OLD | NEW |