OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_BROWSER_WEBKIT_TEST_CONTROLLER_H_ | 5 #ifndef CONTENT_SHELL_BROWSER_BLINK_TEST_CONTROLLER_H_ |
6 #define CONTENT_SHELL_BROWSER_WEBKIT_TEST_CONTROLLER_H_ | 6 #define CONTENT_SHELL_BROWSER_BLINK_TEST_CONTROLLER_H_ |
7 | 7 |
8 #include <ostream> | 8 #include <ostream> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/cancelable_callback.h" | 11 #include "base/cancelable_callback.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
14 #include "base/threading/non_thread_safe.h" | 14 #include "base/threading/non_thread_safe.h" |
15 #include "content/public/browser/gpu_data_manager_observer.h" | 15 #include "content/public/browser/gpu_data_manager_observer.h" |
16 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
(...skipping 18 matching lines...) Expand all Loading... |
35 // Android uses a nested message loop for running layout tests because the | 35 // Android uses a nested message loop for running layout tests because the |
36 // default message loop, provided by the system, does not offer a blocking | 36 // default message loop, provided by the system, does not offer a blocking |
37 // Run() method. The loop itself, implemented as NestedMessagePumpAndroid, | 37 // Run() method. The loop itself, implemented as NestedMessagePumpAndroid, |
38 // uses a base::WaitableEvent allowing it to sleep until more events arrive. | 38 // uses a base::WaitableEvent allowing it to sleep until more events arrive. |
39 class ScopedAllowWaitForAndroidLayoutTests { | 39 class ScopedAllowWaitForAndroidLayoutTests { |
40 private: | 40 private: |
41 base::ThreadRestrictions::ScopedAllowWait wait; | 41 base::ThreadRestrictions::ScopedAllowWait wait; |
42 }; | 42 }; |
43 #endif | 43 #endif |
44 | 44 |
45 class WebKitTestResultPrinter { | 45 class BlinkTestResultPrinter { |
46 public: | 46 public: |
47 WebKitTestResultPrinter(std::ostream* output, std::ostream* error); | 47 BlinkTestResultPrinter(std::ostream* output, std::ostream* error); |
48 ~WebKitTestResultPrinter(); | 48 ~BlinkTestResultPrinter(); |
49 | 49 |
50 void reset() { | 50 void reset() { |
51 state_ = DURING_TEST; | 51 state_ = DURING_TEST; |
52 } | 52 } |
53 bool output_finished() const { return state_ == AFTER_TEST; } | 53 bool output_finished() const { return state_ == AFTER_TEST; } |
54 void set_capture_text_only(bool capture_text_only) { | 54 void set_capture_text_only(bool capture_text_only) { |
55 capture_text_only_ = capture_text_only; | 55 capture_text_only_ = capture_text_only; |
56 } | 56 } |
57 | 57 |
58 void set_encode_binary_data(bool encode_binary_data) { | 58 void set_encode_binary_data(bool encode_binary_data) { |
(...skipping 30 matching lines...) Expand all Loading... |
89 AFTER_TEST | 89 AFTER_TEST |
90 }; | 90 }; |
91 State state_; | 91 State state_; |
92 | 92 |
93 bool capture_text_only_; | 93 bool capture_text_only_; |
94 bool encode_binary_data_; | 94 bool encode_binary_data_; |
95 | 95 |
96 std::ostream* output_; | 96 std::ostream* output_; |
97 std::ostream* error_; | 97 std::ostream* error_; |
98 | 98 |
99 DISALLOW_COPY_AND_ASSIGN(WebKitTestResultPrinter); | 99 DISALLOW_COPY_AND_ASSIGN(BlinkTestResultPrinter); |
100 }; | 100 }; |
101 | 101 |
102 class WebKitTestController : public base::NonThreadSafe, | 102 class BlinkTestController : public base::NonThreadSafe, |
103 public WebContentsObserver, | 103 public WebContentsObserver, |
104 public NotificationObserver, | 104 public NotificationObserver, |
105 public GpuDataManagerObserver { | 105 public GpuDataManagerObserver { |
106 public: | 106 public: |
107 static WebKitTestController* Get(); | 107 static BlinkTestController* Get(); |
108 | 108 |
109 WebKitTestController(); | 109 BlinkTestController(); |
110 ~WebKitTestController() override; | 110 ~BlinkTestController() override; |
111 | 111 |
112 // True if the controller is ready for testing. | 112 // True if the controller is ready for testing. |
113 bool PrepareForLayoutTest(const GURL& test_url, | 113 bool PrepareForLayoutTest(const GURL& test_url, |
114 const base::FilePath& current_working_directory, | 114 const base::FilePath& current_working_directory, |
115 bool enable_pixel_dumping, | 115 bool enable_pixel_dumping, |
116 const std::string& expected_pixel_hash); | 116 const std::string& expected_pixel_hash); |
117 // True if the controller was reset successfully. | 117 // True if the controller was reset successfully. |
118 bool ResetAfterLayoutTest(); | 118 bool ResetAfterLayoutTest(); |
119 | 119 |
120 void SetTempPath(const base::FilePath& temp_path); | 120 void SetTempPath(const base::FilePath& temp_path); |
121 void RendererUnresponsive(); | 121 void RendererUnresponsive(); |
122 void WorkerCrashed(); | 122 void WorkerCrashed(); |
123 void OverrideWebkitPrefs(WebPreferences* prefs); | 123 void OverrideWebkitPrefs(WebPreferences* prefs); |
124 void OpenURL(const GURL& url); | 124 void OpenURL(const GURL& url); |
125 void TestFinishedInSecondaryWindow(); | 125 void TestFinishedInSecondaryWindow(); |
126 bool IsMainWindow(WebContents* web_contents) const; | 126 bool IsMainWindow(WebContents* web_contents) const; |
127 | 127 |
128 WebKitTestResultPrinter* printer() { return printer_.get(); } | 128 BlinkTestResultPrinter* printer() { return printer_.get(); } |
129 void set_printer(WebKitTestResultPrinter* printer) { | 129 void set_printer(BlinkTestResultPrinter* printer) { printer_.reset(printer); } |
130 printer_.reset(printer); | |
131 } | |
132 | 130 |
133 void DevToolsProcessCrashed(); | 131 void DevToolsProcessCrashed(); |
134 | 132 |
135 // WebContentsObserver implementation. | 133 // WebContentsObserver implementation. |
136 bool OnMessageReceived(const IPC::Message& message) override; | 134 bool OnMessageReceived(const IPC::Message& message) override; |
137 void PluginCrashed(const base::FilePath& plugin_path, | 135 void PluginCrashed(const base::FilePath& plugin_path, |
138 base::ProcessId plugin_pid) override; | 136 base::ProcessId plugin_pid) override; |
139 void RenderViewCreated(RenderViewHost* render_view_host) override; | 137 void RenderViewCreated(RenderViewHost* render_view_host) override; |
140 void RenderProcessGone(base::TerminationStatus status) override; | 138 void RenderProcessGone(base::TerminationStatus status) override; |
141 void WebContentsDestroyed() override; | 139 void WebContentsDestroyed() override; |
142 | 140 |
143 // NotificationObserver implementation. | 141 // NotificationObserver implementation. |
144 void Observe(int type, | 142 void Observe(int type, |
145 const NotificationSource& source, | 143 const NotificationSource& source, |
146 const NotificationDetails& details) override; | 144 const NotificationDetails& details) override; |
147 | 145 |
148 // GpuDataManagerObserver implementation. | 146 // GpuDataManagerObserver implementation. |
149 void OnGpuProcessCrashed(base::TerminationStatus exit_code) override; | 147 void OnGpuProcessCrashed(base::TerminationStatus exit_code) override; |
150 | 148 |
151 private: | 149 private: |
152 enum TestPhase { | 150 enum TestPhase { |
153 BETWEEN_TESTS, | 151 BETWEEN_TESTS, |
154 DURING_TEST, | 152 DURING_TEST, |
155 CLEAN_UP | 153 CLEAN_UP |
156 }; | 154 }; |
157 | 155 |
158 static WebKitTestController* instance_; | 156 static BlinkTestController* instance_; |
159 | 157 |
160 void DiscardMainWindow(); | 158 void DiscardMainWindow(); |
161 void SendTestConfiguration(); | 159 void SendTestConfiguration(); |
162 | 160 |
163 // Message handlers. | 161 // Message handlers. |
164 void OnAudioDump(const std::vector<unsigned char>& audio_dump); | 162 void OnAudioDump(const std::vector<unsigned char>& audio_dump); |
165 void OnImageDump(const std::string& actual_pixel_hash, const SkBitmap& image); | 163 void OnImageDump(const std::string& actual_pixel_hash, const SkBitmap& image); |
166 void OnTextDump(const std::string& dump); | 164 void OnTextDump(const std::string& dump); |
167 void OnPrintMessage(const std::string& message); | 165 void OnPrintMessage(const std::string& message); |
168 void OnOverridePreferences(const WebPreferences& prefs); | 166 void OnOverridePreferences(const WebPreferences& prefs); |
169 void OnTestFinished(); | 167 void OnTestFinished(); |
170 void OnClearDevToolsLocalStorage(); | 168 void OnClearDevToolsLocalStorage(); |
171 void OnShowDevTools(const std::string& settings, | 169 void OnShowDevTools(const std::string& settings, |
172 const std::string& frontend_url); | 170 const std::string& frontend_url); |
173 void OnCloseDevTools(); | 171 void OnCloseDevTools(); |
174 void OnGoToOffset(int offset); | 172 void OnGoToOffset(int offset); |
175 void OnReload(); | 173 void OnReload(); |
176 void OnLoadURLForFrame(const GURL& url, const std::string& frame_name); | 174 void OnLoadURLForFrame(const GURL& url, const std::string& frame_name); |
177 void OnCaptureSessionHistory(); | 175 void OnCaptureSessionHistory(); |
178 void OnCloseRemainingWindows(); | 176 void OnCloseRemainingWindows(); |
179 void OnResetDone(); | 177 void OnResetDone(); |
180 void OnLeakDetectionDone(const content::LeakDetectionResult& result); | 178 void OnLeakDetectionDone(const content::LeakDetectionResult& result); |
181 | 179 |
182 scoped_ptr<WebKitTestResultPrinter> printer_; | 180 scoped_ptr<BlinkTestResultPrinter> printer_; |
183 | 181 |
184 base::FilePath current_working_directory_; | 182 base::FilePath current_working_directory_; |
185 base::FilePath temp_path_; | 183 base::FilePath temp_path_; |
186 | 184 |
187 Shell* main_window_; | 185 Shell* main_window_; |
188 | 186 |
189 // The PID of the render process of the render view host of main_window_. | 187 // The PID of the render process of the render view host of main_window_. |
190 int current_pid_; | 188 int current_pid_; |
191 | 189 |
192 // True if we should set the test configuration to the next RenderViewHost | 190 // True if we should set the test configuration to the next RenderViewHost |
(...skipping 23 matching lines...) Expand all Loading... |
216 bool crash_when_leak_found_; | 214 bool crash_when_leak_found_; |
217 | 215 |
218 LayoutTestDevToolsFrontend* devtools_frontend_; | 216 LayoutTestDevToolsFrontend* devtools_frontend_; |
219 | 217 |
220 #if defined(OS_ANDROID) | 218 #if defined(OS_ANDROID) |
221 // Because of the nested message pump implementation, Android needs to allow | 219 // Because of the nested message pump implementation, Android needs to allow |
222 // waiting on the UI thread while layout tests are being ran. | 220 // waiting on the UI thread while layout tests are being ran. |
223 ScopedAllowWaitForAndroidLayoutTests reduced_restrictions_; | 221 ScopedAllowWaitForAndroidLayoutTests reduced_restrictions_; |
224 #endif | 222 #endif |
225 | 223 |
226 DISALLOW_COPY_AND_ASSIGN(WebKitTestController); | 224 DISALLOW_COPY_AND_ASSIGN(BlinkTestController); |
227 }; | 225 }; |
228 | 226 |
229 } // namespace content | 227 } // namespace content |
230 | 228 |
231 #endif // CONTENT_SHELL_BROWSER_WEBKIT_TEST_CONTROLLER_H_ | 229 #endif // CONTENT_SHELL_BROWSER_BLINK_TEST_CONTROLLER_H_ |
OLD | NEW |