| 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; |
| 35 class Shell; | 34 class Shell; |
| 36 class WebContents; | |
| 37 | 35 |
| 38 // Generate the file path for testing a particular test. | 36 // Generate the file path for testing a particular test. |
| 39 // The file for the tests is all located in | 37 // The file for the tests is all located in |
| 40 // content/test/data/dir/<file> | 38 // content/test/data/dir/<file> |
| 41 // The returned path is FilePath format. | 39 // The returned path is FilePath format. |
| 42 // | 40 // |
| 43 // A null |dir| indicates the root directory - i.e. | 41 // A null |dir| indicates the root directory - i.e. |
| 44 // content/test/data/<file> | 42 // content/test/data/<file> |
| 45 base::FilePath GetTestFilePath(const char* dir, const char* file); | 43 base::FilePath GetTestFilePath(const char* dir, const char* file); |
| 46 | 44 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 103 |
| 106 private: | 104 private: |
| 107 void ShellCreated(Shell* shell); | 105 void ShellCreated(Shell* shell); |
| 108 | 106 |
| 109 Shell* shell_; | 107 Shell* shell_; |
| 110 scoped_refptr<MessageLoopRunner> runner_; | 108 scoped_refptr<MessageLoopRunner> runner_; |
| 111 | 109 |
| 112 DISALLOW_COPY_AND_ASSIGN(ShellAddedObserver); | 110 DISALLOW_COPY_AND_ASSIGN(ShellAddedObserver); |
| 113 }; | 111 }; |
| 114 | 112 |
| 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 | 113 #if defined OS_MACOSX |
| 147 void SetWindowBounds(gfx::NativeWindow window, const gfx::Rect& bounds); | 114 void SetWindowBounds(gfx::NativeWindow window, const gfx::Rect& bounds); |
| 148 | 115 |
| 149 // This method will request the string (word) at |point| inside the |rwh| where | 116 // 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 | 117 // |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 | 118 // 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 | 119 // renderer. The baseline point is the position of the pop-up in AppKit |
| 153 // coordinate system (inverted y-axis). | 120 // coordinate system (inverted y-axis). |
| 154 void GetStringAtPointForRenderWidget( | 121 void GetStringAtPointForRenderWidget( |
| 155 RenderWidgetHost* rwh, | 122 RenderWidgetHost* rwh, |
| 156 const gfx::Point& point, | 123 const gfx::Point& point, |
| 157 base::Callback<void(const std::string&, const gfx::Point&)> | 124 base::Callback<void(const std::string&, const gfx::Point&)> |
| 158 result_callback); | 125 result_callback); |
| 159 | 126 |
| 160 // This method will request the string identified by |range| inside the |rwh|. | 127 // 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 | 128 // When the result comes back, |result_callback| is invoked with the given text |
| 162 // and its position in AppKit coordinates (inverted-y axis). | 129 // and its position in AppKit coordinates (inverted-y axis). |
| 163 void GetStringFromRangeForRenderWidget( | 130 void GetStringFromRangeForRenderWidget( |
| 164 RenderWidgetHost* rwh, | 131 RenderWidgetHost* rwh, |
| 165 const gfx::Range& range, | 132 const gfx::Range& range, |
| 166 base::Callback<void(const std::string&, const gfx::Point&)> | 133 base::Callback<void(const std::string&, const gfx::Point&)> |
| 167 result_callback); | 134 result_callback); |
| 168 | 135 |
| 169 #endif | 136 #endif |
| 170 | 137 |
| 171 } // namespace content | 138 } // namespace content |
| 172 | 139 |
| 173 #endif // CONTENT_PUBLIC_TEST_CONTENT_BROWSER_TEST_UTILS_H_ | 140 #endif // CONTENT_PUBLIC_TEST_CONTENT_BROWSER_TEST_UTILS_H_ |
| OLD | NEW |