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_CONTENT_BROWSER_TEST_UTILS_H_ | 5 #ifndef CONTENT_PUBLIC_TEST_CONTENT_BROWSER_TEST_UTILS_H_ |
6 #define CONTENT_PUBLIC_TEST_CONTENT_BROWSER_TEST_UTILS_H_ | 6 #define CONTENT_PUBLIC_TEST_CONTENT_BROWSER_TEST_UTILS_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "content/public/browser/web_contents_delegate.h" | |
12 #include "content/public/common/page_type.h" | 11 #include "content/public/common/page_type.h" |
13 #include "ui/gfx/native_widget_types.h" | 12 #include "ui/gfx/native_widget_types.h" |
14 #include "url/gurl.h" | 13 #include "url/gurl.h" |
15 | 14 |
16 namespace base { | 15 namespace base { |
17 class FilePath; | 16 class FilePath; |
18 } | 17 } |
19 | 18 |
20 namespace gfx { | 19 namespace gfx { |
21 class Point; | 20 class Point; |
22 class Range; | 21 class Range; |
23 class Rect; | 22 class Rect; |
24 } | 23 } |
25 | 24 |
26 // A collections of functions designed for use with content_shell based browser | 25 // A collections of functions designed for use with content_shell based browser |
27 // tests. | 26 // tests. |
28 // Note: if a function here also works with browser_tests, it should be in | 27 // Note: if a function here also works with browser_tests, it should be in |
29 // content\public\test\browser_test_utils.h | 28 // content\public\test\browser_test_utils.h |
30 | 29 |
31 namespace content { | 30 namespace content { |
32 | 31 |
33 class MessageLoopRunner; | 32 class MessageLoopRunner; |
34 class RenderFrameHost; | 33 class RenderFrameHost; |
| 34 class RenderWidgetHost; |
35 class Shell; | 35 class Shell; |
36 class WebContents; | |
37 | 36 |
38 // Generate the file path for testing a particular test. | 37 // Generate the file path for testing a particular test. |
39 // The file for the tests is all located in | 38 // The file for the tests is all located in |
40 // content/test/data/dir/<file> | 39 // content/test/data/dir/<file> |
41 // The returned path is FilePath format. | 40 // The returned path is FilePath format. |
42 // | 41 // |
43 // A null |dir| indicates the root directory - i.e. | 42 // A null |dir| indicates the root directory - i.e. |
44 // content/test/data/<file> | 43 // content/test/data/<file> |
45 base::FilePath GetTestFilePath(const char* dir, const char* file); | 44 base::FilePath GetTestFilePath(const char* dir, const char* file); |
46 | 45 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 104 |
106 private: | 105 private: |
107 void ShellCreated(Shell* shell); | 106 void ShellCreated(Shell* shell); |
108 | 107 |
109 Shell* shell_; | 108 Shell* shell_; |
110 scoped_refptr<MessageLoopRunner> runner_; | 109 scoped_refptr<MessageLoopRunner> runner_; |
111 | 110 |
112 DISALLOW_COPY_AND_ASSIGN(ShellAddedObserver); | 111 DISALLOW_COPY_AND_ASSIGN(ShellAddedObserver); |
113 }; | 112 }; |
114 | 113 |
115 // A WebContentsDelegate that catches messages sent to the console. | |
116 class ConsoleObserverDelegate : public WebContentsDelegate { | |
117 public: | |
118 ConsoleObserverDelegate(WebContents* web_contents, const std::string& filter); | |
119 ~ConsoleObserverDelegate() override; | |
120 | |
121 // WebContentsDelegate method: | |
122 bool AddMessageToConsole(WebContents* source, | |
123 int32_t level, | |
124 const base::string16& message, | |
125 int32_t line_no, | |
126 const base::string16& source_id) override; | |
127 | |
128 // Returns the most recent message sent to the console. | |
129 std::string message() { return message_; } | |
130 | |
131 // Waits for the next message captured by the filter to be sent to the | |
132 // console. | |
133 void Wait(); | |
134 | |
135 private: | |
136 WebContents* web_contents_; | |
137 std::string filter_; | |
138 std::string message_; | |
139 | |
140 // The MessageLoopRunner used to spin the message loop. | |
141 scoped_refptr<MessageLoopRunner> message_loop_runner_; | |
142 | |
143 DISALLOW_COPY_AND_ASSIGN(ConsoleObserverDelegate); | |
144 }; | |
145 | |
146 #if defined OS_MACOSX | 114 #if defined OS_MACOSX |
147 void SetWindowBounds(gfx::NativeWindow window, const gfx::Rect& bounds); | 115 void SetWindowBounds(gfx::NativeWindow window, const gfx::Rect& bounds); |
148 | 116 |
149 // This method will request the string (word) at |point| inside the |rwh| where | 117 // This method will request the string (word) at |point| inside the |rwh| where |
150 // |point| is with respect to the |rwh| coordinates. |result_callback| is called | 118 // |point| is with respect to the |rwh| coordinates. |result_callback| is called |
151 // with the word as well as |baselinePoint| when the result comes back from the | 119 // with the word as well as |baselinePoint| when the result comes back from the |
152 // renderer. The baseline point is the position of the pop-up in AppKit | 120 // renderer. The baseline point is the position of the pop-up in AppKit |
153 // coordinate system (inverted y-axis). | 121 // coordinate system (inverted y-axis). |
154 void GetStringAtPointForRenderWidget( | 122 void GetStringAtPointForRenderWidget( |
155 RenderWidgetHost* rwh, | 123 RenderWidgetHost* rwh, |
156 const gfx::Point& point, | 124 const gfx::Point& point, |
157 base::Callback<void(const std::string&, const gfx::Point&)> | 125 base::Callback<void(const std::string&, const gfx::Point&)> |
158 result_callback); | 126 result_callback); |
159 | 127 |
160 // This method will request the string identified by |range| inside the |rwh|. | 128 // This method will request the string identified by |range| inside the |rwh|. |
161 // When the result comes back, |result_callback| is invoked with the given text | 129 // When the result comes back, |result_callback| is invoked with the given text |
162 // and its position in AppKit coordinates (inverted-y axis). | 130 // and its position in AppKit coordinates (inverted-y axis). |
163 void GetStringFromRangeForRenderWidget( | 131 void GetStringFromRangeForRenderWidget( |
164 RenderWidgetHost* rwh, | 132 RenderWidgetHost* rwh, |
165 const gfx::Range& range, | 133 const gfx::Range& range, |
166 base::Callback<void(const std::string&, const gfx::Point&)> | 134 base::Callback<void(const std::string&, const gfx::Point&)> |
167 result_callback); | 135 result_callback); |
168 | 136 |
169 #endif | 137 #endif |
170 | 138 |
171 } // namespace content | 139 } // namespace content |
172 | 140 |
173 #endif // CONTENT_PUBLIC_TEST_CONTENT_BROWSER_TEST_UTILS_H_ | 141 #endif // CONTENT_PUBLIC_TEST_CONTENT_BROWSER_TEST_UTILS_H_ |
OLD | NEW |