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" |
11 #include "content/public/common/page_type.h" | 12 #include "content/public/common/page_type.h" |
12 #include "ui/gfx/native_widget_types.h" | 13 #include "ui/gfx/native_widget_types.h" |
13 #include "url/gurl.h" | 14 #include "url/gurl.h" |
14 | 15 |
15 namespace base { | 16 namespace base { |
16 class FilePath; | 17 class FilePath; |
17 } | 18 } |
18 | 19 |
19 namespace gfx { | 20 namespace gfx { |
20 class Rect; | 21 class Rect; |
21 } | 22 } |
22 | 23 |
23 // A collections of functions designed for use with content_shell based browser | 24 // A collections of functions designed for use with content_shell based browser |
24 // tests. | 25 // tests. |
25 // Note: if a function here also works with browser_tests, it should be in | 26 // Note: if a function here also works with browser_tests, it should be in |
26 // content\public\test\browser_test_utils.h | 27 // content\public\test\browser_test_utils.h |
27 | 28 |
28 namespace content { | 29 namespace content { |
29 | 30 |
30 class MessageLoopRunner; | 31 class MessageLoopRunner; |
31 class Shell; | 32 class Shell; |
| 33 class WebContents; |
32 | 34 |
33 // Generate the file path for testing a particular test. | 35 // Generate the file path for testing a particular test. |
34 // The file for the tests is all located in | 36 // The file for the tests is all located in |
35 // content/test/data/dir/<file> | 37 // content/test/data/dir/<file> |
36 // The returned path is FilePath format. | 38 // The returned path is FilePath format. |
37 base::FilePath GetTestFilePath(const char* dir, const char* file); | 39 base::FilePath GetTestFilePath(const char* dir, const char* file); |
38 | 40 |
39 // Generate the URL for testing a particular test. | 41 // Generate the URL for testing a particular test. |
40 // HTML for the tests is all located in | 42 // HTML for the tests is all located in |
41 // test_root_directory/dir/<file> | 43 // test_root_directory/dir/<file> |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 93 |
92 private: | 94 private: |
93 void ShellCreated(Shell* shell); | 95 void ShellCreated(Shell* shell); |
94 | 96 |
95 Shell* shell_; | 97 Shell* shell_; |
96 scoped_refptr<MessageLoopRunner> runner_; | 98 scoped_refptr<MessageLoopRunner> runner_; |
97 | 99 |
98 DISALLOW_COPY_AND_ASSIGN(ShellAddedObserver); | 100 DISALLOW_COPY_AND_ASSIGN(ShellAddedObserver); |
99 }; | 101 }; |
100 | 102 |
| 103 // A WebContentsDelegate that catches messages sent to the console. |
| 104 class ConsoleObserverDelegate : public WebContentsDelegate { |
| 105 public: |
| 106 ConsoleObserverDelegate(WebContents* web_contents, const std::string& filter); |
| 107 ~ConsoleObserverDelegate() override; |
| 108 |
| 109 // WebContentsDelegate method: |
| 110 bool AddMessageToConsole(WebContents* source, |
| 111 int32_t level, |
| 112 const base::string16& message, |
| 113 int32_t line_no, |
| 114 const base::string16& source_id) override; |
| 115 |
| 116 // Returns the most recent message sent to the console. |
| 117 std::string message() { return message_; } |
| 118 |
| 119 // Waits for the next message captured by the filter to be sent to the |
| 120 // console. |
| 121 void Wait(); |
| 122 |
| 123 private: |
| 124 WebContents* web_contents_; |
| 125 std::string filter_; |
| 126 std::string message_; |
| 127 |
| 128 // The MessageLoopRunner used to spin the message loop. |
| 129 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 130 |
| 131 DISALLOW_COPY_AND_ASSIGN(ConsoleObserverDelegate); |
| 132 }; |
| 133 |
101 #if defined OS_MACOSX | 134 #if defined OS_MACOSX |
102 void SetWindowBounds(gfx::NativeWindow window, const gfx::Rect& bounds); | 135 void SetWindowBounds(gfx::NativeWindow window, const gfx::Rect& bounds); |
103 #endif | 136 #endif |
104 | 137 |
105 } // namespace content | 138 } // namespace content |
106 | 139 |
107 #endif // CONTENT_PUBLIC_TEST_CONTENT_BROWSER_TEST_UTILS_H_ | 140 #endif // CONTENT_PUBLIC_TEST_CONTENT_BROWSER_TEST_UTILS_H_ |
OLD | NEW |