| 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 <map> | |
| 9 #include <string> | 8 #include <string> |
| 10 | 9 |
| 11 #include "base/cancelable_callback.h" | 10 #include "base/cancelable_callback.h" |
| 11 #include "base/threading/non_thread_safe.h" |
| 12 #include "content/public/browser/render_view_host_observer.h" | 12 #include "content/public/browser/render_view_host_observer.h" |
| 13 #include "content/public/browser/web_contents_observer.h" |
| 13 | 14 |
| 14 class SkBitmap; | 15 class SkBitmap; |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 | 18 |
| 18 class WebKitTestRunnerHost : public RenderViewHostObserver { | 19 class Shell; |
| 20 |
| 21 class WebKitTestController : public base::NonThreadSafe, |
| 22 public WebContentsObserver { |
| 19 public: | 23 public: |
| 20 static WebKitTestRunnerHost* FromRenderViewHost( | 24 static WebKitTestController* Get(); |
| 21 RenderViewHost* render_view_host); | |
| 22 | 25 |
| 23 // Initialize the WebKitTestRunnerHost for a given test. | 26 WebKitTestController(); |
| 24 static void Init(const std::string& expected_pixel_hash); | 27 virtual ~WebKitTestController(); |
| 25 | 28 |
| 26 explicit WebKitTestRunnerHost(RenderViewHost* render_view_host); | 29 void PrepareForLayoutTest(const GURL& test_url, |
| 27 virtual ~WebKitTestRunnerHost(); | 30 const std::string& expected_pixel_hash); |
| 31 // True if the controller was reset successfully. |
| 32 bool ResetAfterLayoutTest(); |
| 28 | 33 |
| 34 const std::string& expected_pixel_hash() const { |
| 35 return expected_pixel_hash_; |
| 36 } |
| 29 bool should_stay_on_page_after_handling_before_unload() const { | 37 bool should_stay_on_page_after_handling_before_unload() const { |
| 30 return should_stay_on_page_after_handling_before_unload_; | 38 return should_stay_on_page_after_handling_before_unload_; |
| 31 } | 39 } |
| 40 void set_should_stay_on_page_after_handling_before_unload( |
| 41 bool should_stay_on_page_after_handling_before_unload) { |
| 42 should_stay_on_page_after_handling_before_unload_ = |
| 43 should_stay_on_page_after_handling_before_unload; |
| 44 } |
| 45 bool dump_as_text() const { return dump_as_text_; } |
| 46 void set_dump_as_text(bool dump_as_text) { dump_as_text_ = dump_as_text; } |
| 47 bool dump_child_frames() const { return dump_child_frames_; } |
| 48 void set_dump_child_frames(bool dump_child_frames) { |
| 49 dump_child_frames_ = dump_child_frames; |
| 50 } |
| 51 bool is_printing() const { return is_printing_; } |
| 52 void set_is_printing(bool is_printing) { is_printing_ = is_printing; } |
| 53 |
| 54 void LoadFinished(Shell* window); |
| 55 void NotifyDone(); |
| 56 void WaitUntilDone(); |
| 57 void NotImplemented(const std::string& object_name, |
| 58 const std::string& method_name); |
| 59 |
| 60 private: |
| 61 static WebKitTestController* instance_; |
| 62 |
| 63 // WebContentsObserver implementation. |
| 64 virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE; |
| 65 |
| 66 void CaptureDump(); |
| 67 void TimeoutHandler(); |
| 68 |
| 69 Shell* main_window_; |
| 70 |
| 71 std::string expected_pixel_hash_; |
| 72 |
| 73 bool captured_dump_; |
| 74 |
| 75 bool dump_as_text_; |
| 76 bool dump_child_frames_; |
| 77 bool is_printing_; |
| 78 bool should_stay_on_page_after_handling_before_unload_; |
| 79 bool wait_until_done_; |
| 80 |
| 81 base::CancelableClosure watchdog_; |
| 82 |
| 83 DISALLOW_COPY_AND_ASSIGN(WebKitTestController); |
| 84 }; |
| 85 |
| 86 class WebKitTestRunnerHost : public RenderViewHostObserver { |
| 87 public: |
| 88 explicit WebKitTestRunnerHost(RenderViewHost* render_view_host); |
| 89 virtual ~WebKitTestRunnerHost(); |
| 32 | 90 |
| 33 // RenderViewHostObserver implementation. | 91 // RenderViewHostObserver implementation. |
| 34 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 92 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 35 | 93 |
| 36 private: | 94 private: |
| 37 void CaptureDump(); | |
| 38 void TimeoutHandler(); | |
| 39 | |
| 40 // Message handlers. | 95 // Message handlers. |
| 41 void OnDidFinishLoad(); | 96 void OnDidFinishLoad(); |
| 42 void OnTextDump(const std::string& dump); | 97 void OnTextDump(const std::string& dump); |
| 43 void OnImageDump(const std::string& actual_pixel_hash, const SkBitmap& image); | 98 void OnImageDump(const std::string& actual_pixel_hash, const SkBitmap& image); |
| 44 | 99 |
| 45 // testRunner handlers. | 100 // testRunner handlers. |
| 46 void OnNotifyDone(); | 101 void OnNotifyDone(); |
| 47 void OnDumpAsText(); | 102 void OnDumpAsText(); |
| 48 void OnDumpChildFramesAsText(); | 103 void OnDumpChildFramesAsText(); |
| 49 void OnSetPrinting(); | 104 void OnSetPrinting(); |
| 50 void OnSetShouldStayOnPageAfterHandlingBeforeUnload(bool should_stay_on_page); | 105 void OnSetShouldStayOnPageAfterHandlingBeforeUnload(bool should_stay_on_page); |
| 51 void OnWaitUntilDone(); | 106 void OnWaitUntilDone(); |
| 52 | 107 |
| 53 void OnNotImplemented(const std::string& object_name, | 108 void OnNotImplemented(const std::string& object_name, |
| 54 const std::string& method_name); | 109 const std::string& method_name); |
| 55 | 110 |
| 56 static std::map<RenderViewHost*, WebKitTestRunnerHost*> controllers_; | |
| 57 static std::string expected_pixel_hash_; | |
| 58 | |
| 59 bool captured_dump_; | |
| 60 | |
| 61 bool dump_as_text_; | |
| 62 bool dump_child_frames_; | |
| 63 bool is_printing_; | |
| 64 bool should_stay_on_page_after_handling_before_unload_; | |
| 65 bool wait_until_done_; | |
| 66 | |
| 67 base::CancelableClosure watchdog_; | |
| 68 | |
| 69 DISALLOW_COPY_AND_ASSIGN(WebKitTestRunnerHost); | 111 DISALLOW_COPY_AND_ASSIGN(WebKitTestRunnerHost); |
| 70 }; | 112 }; |
| 71 | 113 |
| 72 } // namespace content | 114 } // namespace content |
| 73 | 115 |
| 74 #endif // CONTENT_SHELL_WEBKIT_TEST_RUNNER_HOST_H_ | 116 #endif // CONTENT_SHELL_WEBKIT_TEST_RUNNER_HOST_H_ |
| OLD | NEW |