Index: content/public/test/browser_test_utils.h |
diff --git a/content/public/test/browser_test_utils.h b/content/public/test/browser_test_utils.h |
index 4d02c44c9e6dae39b4f98780befcbc0443ea7688..89b0210f8e0581ff485bcc71504f4f810ea3ee7e 100644 |
--- a/content/public/test/browser_test_utils.h |
+++ b/content/public/test/browser_test_utils.h |
@@ -22,6 +22,7 @@ |
#include "content/public/browser/notification_observer.h" |
#include "content/public/browser/notification_registrar.h" |
#include "content/public/browser/render_process_host_observer.h" |
+#include "content/public/browser/web_contents_delegate.h" |
#include "content/public/browser/web_contents_observer.h" |
#include "content/public/common/page_type.h" |
#include "ipc/message_filter.h" |
@@ -657,6 +658,37 @@ class TestNavigationManager : public WebContentsObserver { |
DISALLOW_COPY_AND_ASSIGN(TestNavigationManager); |
}; |
+// A WebContentsDelegate that catches messages sent to the console. |
+class ConsoleObserverDelegate : public WebContentsDelegate { |
+ public: |
+ ConsoleObserverDelegate(WebContents* web_contents, const std::string& filter); |
+ ~ConsoleObserverDelegate() override; |
+ |
+ // WebContentsDelegate method: |
+ bool AddMessageToConsole(WebContents* source, |
+ int32_t level, |
+ const base::string16& message, |
+ int32_t line_no, |
+ const base::string16& source_id) override; |
+ |
+ // Returns the most recent message sent to the console. |
+ std::string message() { return message_; } |
+ |
+ // Waits for the next message captured by the filter to be sent to the |
+ // console. |
+ void Wait(); |
+ |
+ private: |
+ WebContents* web_contents_; |
+ std::string filter_; |
+ std::string message_; |
+ |
+ // The MessageLoopRunner used to spin the message loop. |
+ scoped_refptr<MessageLoopRunner> message_loop_runner_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ConsoleObserverDelegate); |
+}; |
+ |
} // namespace content |
#endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ |