summaryrefslogtreecommitdiffstats
path: root/content/shell/webkit_test_controller.h
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-10 14:11:45 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-10 14:11:45 +0000
commit8dafad32e63d4f8657aa88f0b17254d8a91727d6 (patch)
tree507e0efda9a158d7c4cdec63a426dd3329cebe8e /content/shell/webkit_test_controller.h
parent2393323faddbbb25933c7a5942cbde786075e536 (diff)
downloadchromium_src-8dafad32e63d4f8657aa88f0b17254d8a91727d6.zip
chromium_src-8dafad32e63d4f8657aa88f0b17254d8a91727d6.tar.gz
chromium_src-8dafad32e63d4f8657aa88f0b17254d8a91727d6.tar.bz2
[content shell] remove WebKitTestRunnerHost.
Instead of having an observer per WebContents, only observe the main window. In a previous patch, all IPC messages were already routed to this one main window. Also, rename webkit_test_runner_host.* to webkit_test_controller.* BUG=111316 TEST=nothing breaks R=marja@chromium.org Review URL: https://chromiumcodereview.appspot.com/11494004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@172054 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/shell/webkit_test_controller.h')
-rw-r--r--content/shell/webkit_test_controller.h147
1 files changed, 147 insertions, 0 deletions
diff --git a/content/shell/webkit_test_controller.h b/content/shell/webkit_test_controller.h
new file mode 100644
index 0000000..03de47b
--- /dev/null
+++ b/content/shell/webkit_test_controller.h
@@ -0,0 +1,147 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_SHELL_WEBKIT_TEST_CONTROLLER_H_
+#define CONTENT_SHELL_WEBKIT_TEST_CONTROLLER_H_
+
+#include <ostream>
+#include <string>
+
+#include "base/cancelable_callback.h"
+#include "base/file_path.h"
+#include "base/threading/non_thread_safe.h"
+#include "content/public/browser/render_view_host_observer.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "content/shell/shell_webpreferences.h"
+
+class SkBitmap;
+
+namespace content {
+
+class Shell;
+
+class WebKitTestResultPrinter {
+ public:
+ WebKitTestResultPrinter(std::ostream* output, std::ostream* error);
+ ~WebKitTestResultPrinter();
+
+ void reset() {
+ state_ = BEFORE_TEST;
+ }
+ bool in_text_block() const { return state_ == IN_TEXT_BLOCK; }
+ void set_capture_text_only(bool capture_text_only) {
+ capture_text_only_ = capture_text_only;
+ }
+
+ void PrintTextHeader();
+ void PrintTextBlock(const std::string& block);
+ void PrintTextFooter();
+
+ void PrintImageHeader(const std::string& actual_hash,
+ const std::string& expected_hash);
+ void PrintImageBlock(const std::vector<unsigned char>& png_image);
+ void PrintImageFooter();
+
+ void AddMessage(const std::string& message);
+ void AddMessageRaw(const std::string& message);
+ void AddErrorMessage(const std::string& message);
+
+ private:
+ enum State {
+ BEFORE_TEST,
+ IN_TEXT_BLOCK,
+ IN_IMAGE_BLOCK,
+ AFTER_TEST
+ };
+ State state_;
+ bool capture_text_only_;
+
+ std::ostream* output_;
+ std::ostream* error_;
+
+ DISALLOW_COPY_AND_ASSIGN(WebKitTestResultPrinter);
+};
+
+class WebKitTestController : public base::NonThreadSafe,
+ public WebContentsObserver {
+ public:
+ static WebKitTestController* Get();
+
+ WebKitTestController();
+ virtual ~WebKitTestController();
+
+ // True if the controller is ready for testing.
+ bool PrepareForLayoutTest(const GURL& test_url,
+ const FilePath& current_working_directory,
+ bool enable_pixel_dumping,
+ const std::string& expected_pixel_hash);
+ // True if the controller was reset successfully.
+ bool ResetAfterLayoutTest();
+
+ void RendererUnresponsive();
+
+ WebKitTestResultPrinter* printer() { return printer_.get(); }
+ void set_printer(WebKitTestResultPrinter* printer) {
+ printer_.reset(printer);
+ }
+ const ShellWebPreferences& web_preferences() const { return prefs_; }
+ bool should_stay_on_page_after_handling_before_unload() const {
+ return should_stay_on_page_after_handling_before_unload_;
+ }
+
+ // WebContentsObserver implementation.
+ virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
+ virtual void PluginCrashed(const FilePath& plugin_path) OVERRIDE;
+ virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE;
+ virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE;
+ virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE;
+
+ private:
+ static WebKitTestController* instance_;
+
+ void CaptureDump();
+ void TimeoutHandler();
+
+ // Message handlers.
+ void OnDidFinishLoad();
+ void OnImageDump(const std::string& actual_pixel_hash, const SkBitmap& image);
+ void OnTextDump(const std::string& dump);
+ void OnPrintMessage(const std::string& message);
+ void OnOverridePreferences(const ShellWebPreferences& prefs);
+ void OnNotifyDone();
+ void OnDumpAsText();
+ void OnDumpChildFramesAsText();
+ void OnSetPrinting();
+ void OnSetShouldStayOnPageAfterHandlingBeforeUnload(bool should_stay_on_page);
+ void OnWaitUntilDone();
+
+ void OnNotImplemented(const std::string& object_name,
+ const std::string& method_name);
+
+ scoped_ptr<WebKitTestResultPrinter> printer_;
+
+ FilePath current_working_directory_;
+
+ Shell* main_window_;
+
+ bool enable_pixel_dumping_;
+ std::string expected_pixel_hash_;
+
+ bool captured_dump_;
+
+ bool dump_as_text_;
+ bool dump_child_frames_;
+ bool is_printing_;
+ bool should_stay_on_page_after_handling_before_unload_;
+ bool wait_until_done_;
+ ShellWebPreferences prefs_;
+
+ base::CancelableClosure watchdog_;
+
+ DISALLOW_COPY_AND_ASSIGN(WebKitTestController);
+};
+
+} // namespace content
+
+#endif // CONTENT_SHELL_WEBKIT_TEST_CONTROLLER_H_