| 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_SHELL_WEBKIT_TEST_RUNNER_HOST_H_ | 5 #ifndef CONTENT_SHELL_WEBKIT_TEST_RUNNER_HOST_H_ |
| 6 #define CONTENT_SHELL_WEBKIT_TEST_RUNNER_HOST_H_ | 6 #define CONTENT_SHELL_WEBKIT_TEST_RUNNER_HOST_H_ |
| 7 | 7 |
| 8 #include <ostream> |
| 8 #include <string> | 9 #include <string> |
| 9 | 10 |
| 10 #include "base/cancelable_callback.h" | 11 #include "base/cancelable_callback.h" |
| 11 #include "base/threading/non_thread_safe.h" | 12 #include "base/threading/non_thread_safe.h" |
| 12 #include "content/public/browser/render_view_host_observer.h" | 13 #include "content/public/browser/render_view_host_observer.h" |
| 13 #include "content/public/browser/web_contents_observer.h" | 14 #include "content/public/browser/web_contents_observer.h" |
| 14 | 15 |
| 15 class SkBitmap; | 16 class SkBitmap; |
| 16 | 17 |
| 17 namespace content { | 18 namespace content { |
| 18 | 19 |
| 19 class Shell; | 20 class Shell; |
| 20 | 21 |
| 21 class WebKitTestResultPrinter { | 22 class WebKitTestResultPrinter { |
| 22 public: | 23 public: |
| 23 WebKitTestResultPrinter(); | 24 WebKitTestResultPrinter(std::ostream* output, std::ostream* error); |
| 24 ~WebKitTestResultPrinter(); | 25 ~WebKitTestResultPrinter(); |
| 25 | 26 |
| 26 void reset() { | 27 void reset() { |
| 27 state_ = BEFORE_TEST; | 28 state_ = BEFORE_TEST; |
| 28 } | 29 } |
| 29 bool in_text_block() const { return state_ == IN_TEXT_BLOCK; } | 30 bool in_text_block() const { return state_ == IN_TEXT_BLOCK; } |
| 31 void set_capture_text_only(bool capture_text_only) { |
| 32 capture_text_only_ = capture_text_only; |
| 33 } |
| 30 | 34 |
| 31 void PrintTextHeader(); | 35 void PrintTextHeader(); |
| 32 void PrintTextBlock(const std::string& block); | 36 void PrintTextBlock(const std::string& block); |
| 33 void PrintTextFooter(); | 37 void PrintTextFooter(); |
| 34 | 38 |
| 35 void PrintImageHeader(const std::string& actual_hash, | 39 void PrintImageHeader(const std::string& actual_hash, |
| 36 const std::string& expected_hash); | 40 const std::string& expected_hash); |
| 37 void PrintImageBlock(const std::vector<unsigned char>& png_image); | 41 void PrintImageBlock(const std::vector<unsigned char>& png_image); |
| 38 void PrintImageFooter(); | 42 void PrintImageFooter(); |
| 39 | 43 |
| 40 void AddMessage(const std::string& message); | 44 void AddMessage(const std::string& message); |
| 41 void AddErrorMessage(const std::string& message); | 45 void AddErrorMessage(const std::string& message); |
| 42 | 46 |
| 43 private: | 47 private: |
| 44 enum State { | 48 enum State { |
| 45 BEFORE_TEST, | 49 BEFORE_TEST, |
| 46 IN_TEXT_BLOCK, | 50 IN_TEXT_BLOCK, |
| 47 IN_IMAGE_BLOCK, | 51 IN_IMAGE_BLOCK, |
| 48 AFTER_TEST | 52 AFTER_TEST |
| 49 }; | 53 }; |
| 50 State state_; | 54 State state_; |
| 55 bool capture_text_only_; |
| 56 |
| 57 std::ostream* output_; |
| 58 std::ostream* error_; |
| 51 | 59 |
| 52 DISALLOW_COPY_AND_ASSIGN(WebKitTestResultPrinter); | 60 DISALLOW_COPY_AND_ASSIGN(WebKitTestResultPrinter); |
| 53 }; | 61 }; |
| 54 | 62 |
| 55 class WebKitTestController : public base::NonThreadSafe, | 63 class WebKitTestController : public base::NonThreadSafe, |
| 56 public WebContentsObserver { | 64 public WebContentsObserver { |
| 57 public: | 65 public: |
| 58 static WebKitTestController* Get(); | 66 static WebKitTestController* Get(); |
| 59 | 67 |
| 60 WebKitTestController(); | 68 WebKitTestController(); |
| 61 virtual ~WebKitTestController(); | 69 virtual ~WebKitTestController(); |
| 62 | 70 |
| 63 // True if the controller is ready for testing. | 71 // True if the controller is ready for testing. |
| 64 bool PrepareForLayoutTest(const GURL& test_url, | 72 bool PrepareForLayoutTest(const GURL& test_url, |
| 65 bool enable_pixel_dumping, | 73 bool enable_pixel_dumping, |
| 66 const std::string& expected_pixel_hash); | 74 const std::string& expected_pixel_hash); |
| 67 // True if the controller was reset successfully. | 75 // True if the controller was reset successfully. |
| 68 bool ResetAfterLayoutTest(); | 76 bool ResetAfterLayoutTest(); |
| 69 | 77 |
| 70 void RendererUnresponsive(); | 78 void RendererUnresponsive(); |
| 71 | 79 |
| 72 WebKitTestResultPrinter& printer() { return printer_; } | 80 WebKitTestResultPrinter* printer() { return printer_.get(); } |
| 81 void set_printer(WebKitTestResultPrinter* printer) { |
| 82 printer_.reset(printer); |
| 83 } |
| 73 | 84 |
| 74 // Interface for WebKitTestRunnerHost. | 85 // Interface for WebKitTestRunnerHost. |
| 75 void NotifyDone(); | 86 void NotifyDone(); |
| 76 void WaitUntilDone(); | 87 void WaitUntilDone(); |
| 77 void NotImplemented(const std::string& object_name, | 88 void NotImplemented(const std::string& object_name, |
| 78 const std::string& method_name); | 89 const std::string& method_name); |
| 79 | 90 |
| 80 bool should_stay_on_page_after_handling_before_unload() const { | 91 bool should_stay_on_page_after_handling_before_unload() const { |
| 81 return should_stay_on_page_after_handling_before_unload_; | 92 return should_stay_on_page_after_handling_before_unload_; |
| 82 } | 93 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 104 static WebKitTestController* instance_; | 115 static WebKitTestController* instance_; |
| 105 | 116 |
| 106 void CaptureDump(); | 117 void CaptureDump(); |
| 107 void TimeoutHandler(); | 118 void TimeoutHandler(); |
| 108 | 119 |
| 109 // Message handlers. | 120 // Message handlers. |
| 110 void OnDidFinishLoad(); | 121 void OnDidFinishLoad(); |
| 111 void OnImageDump(const std::string& actual_pixel_hash, const SkBitmap& image); | 122 void OnImageDump(const std::string& actual_pixel_hash, const SkBitmap& image); |
| 112 void OnTextDump(const std::string& dump); | 123 void OnTextDump(const std::string& dump); |
| 113 | 124 |
| 114 WebKitTestResultPrinter printer_; | 125 scoped_ptr<WebKitTestResultPrinter> printer_; |
| 115 | 126 |
| 116 Shell* main_window_; | 127 Shell* main_window_; |
| 117 | 128 |
| 118 bool pumping_messages_; | 129 bool pumping_messages_; |
| 119 bool renderer_crashed_; | 130 bool renderer_crashed_; |
| 120 bool enable_pixel_dumping_; | 131 bool enable_pixel_dumping_; |
| 121 std::string expected_pixel_hash_; | 132 std::string expected_pixel_hash_; |
| 122 | 133 |
| 123 bool captured_dump_; | 134 bool captured_dump_; |
| 124 | 135 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 152 | 163 |
| 153 void OnNotImplemented(const std::string& object_name, | 164 void OnNotImplemented(const std::string& object_name, |
| 154 const std::string& method_name); | 165 const std::string& method_name); |
| 155 | 166 |
| 156 DISALLOW_COPY_AND_ASSIGN(WebKitTestRunnerHost); | 167 DISALLOW_COPY_AND_ASSIGN(WebKitTestRunnerHost); |
| 157 }; | 168 }; |
| 158 | 169 |
| 159 } // namespace content | 170 } // namespace content |
| 160 | 171 |
| 161 #endif // CONTENT_SHELL_WEBKIT_TEST_RUNNER_HOST_H_ | 172 #endif // CONTENT_SHELL_WEBKIT_TEST_RUNNER_HOST_H_ |
| OLD | NEW |