OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_WEB_TEST_PROXY_H_ | |
6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_WEB_TEST_PROXY_H_ | |
7 | |
8 #include <deque> | |
9 #include <map> | |
10 #include <string> | |
11 | |
12 #include "base/basictypes.h" | |
13 #include "base/callback.h" | |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "content/shell/renderer/test_runner/web_task.h" | |
16 #include "third_party/WebKit/public/platform/WebImage.h" | |
17 #include "third_party/WebKit/public/platform/WebRect.h" | |
18 #include "third_party/WebKit/public/platform/WebScreenInfo.h" | |
19 #include "third_party/WebKit/public/platform/WebURLError.h" | |
20 #include "third_party/WebKit/public/platform/WebURLRequest.h" | |
21 #include "third_party/WebKit/public/web/WebAXEnums.h" | |
22 #include "third_party/WebKit/public/web/WebDOMMessageEvent.h" | |
23 #include "third_party/WebKit/public/web/WebDataSource.h" | |
24 #include "third_party/WebKit/public/web/WebDragOperation.h" | |
25 #include "third_party/WebKit/public/web/WebFrame.h" | |
26 #include "third_party/WebKit/public/web/WebFrameClient.h" | |
27 #include "third_party/WebKit/public/web/WebHistoryCommitType.h" | |
28 #include "third_party/WebKit/public/web/WebIconURL.h" | |
29 #include "third_party/WebKit/public/web/WebNavigationPolicy.h" | |
30 #include "third_party/WebKit/public/web/WebNavigationType.h" | |
31 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | |
32 #include "third_party/WebKit/public/web/WebTextAffinity.h" | |
33 #include "third_party/WebKit/public/web/WebTextDirection.h" | |
34 | |
35 class SkBitmap; | |
36 class SkCanvas; | |
37 | |
38 namespace blink { | |
39 class WebAXObject; | |
40 class WebAudioDevice; | |
41 class WebCachedURLRequest; | |
42 class WebColorChooser; | |
43 class WebColorChooserClient; | |
44 class WebDataSource; | |
45 class WebDragData; | |
46 class WebFileChooserCompletion; | |
47 class WebFrame; | |
48 class WebLocalFrame; | |
49 class WebMIDIAccessor; | |
50 class WebMIDIAccessorClient; | |
51 class WebNode; | |
52 class WebPlugin; | |
53 class WebRange; | |
54 class WebSerializedScriptValue; | |
55 class WebSpeechRecognizer; | |
56 class WebSpellCheckClient; | |
57 class WebString; | |
58 class WebURL; | |
59 class WebURLResponse; | |
60 class WebUserMediaClient; | |
61 class WebView; | |
62 class WebWidget; | |
63 struct WebColorSuggestion; | |
64 struct WebConsoleMessage; | |
65 struct WebContextMenuData; | |
66 struct WebFileChooserParams; | |
67 struct WebPluginParams; | |
68 struct WebPoint; | |
69 struct WebSize; | |
70 struct WebWindowFeatures; | |
71 typedef unsigned WebColor; | |
72 } | |
73 | |
74 namespace content { | |
75 | |
76 class MockCredentialManagerClient; | |
77 class MockScreenOrientationClient; | |
78 class MockWebSpeechRecognizer; | |
79 class MockWebUserMediaClient; | |
80 class RenderFrame; | |
81 class SpellCheckClient; | |
82 class TestInterfaces; | |
83 class WebTestDelegate; | |
84 class WebTestInterfaces; | |
85 | |
86 // WebTestProxyBase is the "brain" of WebTestProxy in the sense that | |
87 // WebTestProxy does the bridge between RenderViewImpl and WebTestProxyBase and | |
88 // when it requires a behavior to be different from the usual, it will call | |
89 // WebTestProxyBase that implements the expected behavior. | |
90 // See WebTestProxy class comments for more information. | |
91 class WebTestProxyBase { | |
92 public: | |
93 void SetInterfaces(WebTestInterfaces* interfaces); | |
94 void SetDelegate(WebTestDelegate* delegate); | |
95 void set_widget(blink::WebWidget* widget) { web_widget_ = widget; } | |
96 | |
97 void Reset(); | |
98 | |
99 blink::WebSpellCheckClient* GetSpellCheckClient() const; | |
100 blink::WebColorChooser* CreateColorChooser( | |
101 blink::WebColorChooserClient* client, | |
102 const blink::WebColor& color, | |
103 const blink::WebVector<blink::WebColorSuggestion>& suggestions); | |
104 bool RunFileChooser(const blink::WebFileChooserParams& params, | |
105 blink::WebFileChooserCompletion* completion); | |
106 void ShowValidationMessage(const base::string16& message, | |
107 const base::string16& sub_message); | |
108 void HideValidationMessage(); | |
109 void MoveValidationMessage(const blink::WebRect& anchor_in_root_view); | |
110 | |
111 std::string CaptureTree(bool debug_render_tree); | |
112 void CapturePixelsForPrinting( | |
113 const base::Callback<void(const SkBitmap&)>& callback); | |
114 void CopyImageAtAndCapturePixels( | |
115 int x, int y, const base::Callback<void(const SkBitmap&)>& callback); | |
116 void CapturePixelsAsync( | |
117 const base::Callback<void(const SkBitmap&)>& callback); | |
118 | |
119 void SetLogConsoleOutput(bool enabled); | |
120 | |
121 void DidOpenChooser(); | |
122 void DidCloseChooser(); | |
123 bool IsChooserShown(); | |
124 | |
125 void LayoutAndPaintAsyncThen(const base::Closure& callback); | |
126 | |
127 void GetScreenOrientationForTesting(blink::WebScreenInfo&); | |
128 MockScreenOrientationClient* GetScreenOrientationClientMock(); | |
129 MockWebSpeechRecognizer* GetSpeechRecognizerMock(); | |
130 MockCredentialManagerClient* GetCredentialManagerClientMock(); | |
131 | |
132 WebTaskList* mutable_task_list() { return &task_list_; } | |
133 | |
134 blink::WebView* GetWebView() const; | |
135 | |
136 void PostSpellCheckEvent(const blink::WebString& event_name); | |
137 | |
138 void SetAcceptLanguages(const std::string& accept_languages); | |
139 | |
140 protected: | |
141 WebTestProxyBase(); | |
142 ~WebTestProxyBase(); | |
143 | |
144 void ScheduleAnimation(); | |
145 void PostAccessibilityEvent(const blink::WebAXObject&, blink::WebAXEvent); | |
146 void StartDragging(blink::WebLocalFrame* frame, | |
147 const blink::WebDragData& data, | |
148 blink::WebDragOperationsMask mask, | |
149 const blink::WebImage& image, | |
150 const blink::WebPoint& point); | |
151 void DidChangeSelection(bool isEmptySelection); | |
152 void DidChangeContents(); | |
153 void DidEndEditing(); | |
154 bool CreateView(blink::WebLocalFrame* creator, | |
155 const blink::WebURLRequest& request, | |
156 const blink::WebWindowFeatures& features, | |
157 const blink::WebString& frame_name, | |
158 blink::WebNavigationPolicy policy, | |
159 bool suppress_opener); | |
160 blink::WebPlugin* CreatePlugin(blink::WebLocalFrame* frame, | |
161 const blink::WebPluginParams& params); | |
162 void SetStatusText(const blink::WebString& text); | |
163 void DidStopLoading(); | |
164 void ShowContextMenu(blink::WebLocalFrame* frame, | |
165 const blink::WebContextMenuData& data); | |
166 blink::WebUserMediaClient* GetUserMediaClient(); | |
167 void PrintPage(blink::WebLocalFrame* frame); | |
168 blink::WebSpeechRecognizer* GetSpeechRecognizer(); | |
169 bool RequestPointerLock(); | |
170 void RequestPointerUnlock(); | |
171 bool IsPointerLocked(); | |
172 void DidFocus(); | |
173 void DidBlur(); | |
174 void SetToolTipText(const blink::WebString& text, | |
175 blink::WebTextDirection direction); | |
176 void DidAddMessageToConsole(const blink::WebConsoleMessage& text, | |
177 const blink::WebString& source_name, | |
178 unsigned source_line); | |
179 void LoadURLExternally(blink::WebLocalFrame* frame, | |
180 const blink::WebURLRequest& request, | |
181 blink::WebNavigationPolicy policy, | |
182 const blink::WebString& suggested_name); | |
183 void DidStartProvisionalLoad(blink::WebLocalFrame*); | |
184 void DidReceiveServerRedirectForProvisionalLoad(blink::WebLocalFrame* frame); | |
185 bool DidFailProvisionalLoad(blink::WebLocalFrame* frame, | |
186 const blink::WebURLError& error, | |
187 blink::WebHistoryCommitType commit_type); | |
188 void DidCommitProvisionalLoad(blink::WebLocalFrame* frame, | |
189 const blink::WebHistoryItem& history_item, | |
190 blink::WebHistoryCommitType history_type); | |
191 void DidReceiveTitle(blink::WebLocalFrame* frame, | |
192 const blink::WebString& title, | |
193 blink::WebTextDirection text_direction); | |
194 void DidChangeIcon(blink::WebLocalFrame* frame, | |
195 blink::WebIconURL::Type icon_type); | |
196 void DidFinishDocumentLoad(blink::WebLocalFrame* frame); | |
197 void DidHandleOnloadEvents(blink::WebLocalFrame* frame); | |
198 void DidFailLoad(blink::WebLocalFrame* frame, | |
199 const blink::WebURLError& error, | |
200 blink::WebHistoryCommitType commit_type); | |
201 void DidFinishLoad(blink::WebLocalFrame* frame); | |
202 void DidChangeLocationWithinPage(blink::WebLocalFrame* frame); | |
203 void DidDetectXSS(blink::WebLocalFrame* frame, | |
204 const blink::WebURL& insecure_url, | |
205 bool did_block_entire_page); | |
206 void DidDispatchPingLoader(blink::WebLocalFrame* frame, | |
207 const blink::WebURL& url); | |
208 void WillRequestResource(blink::WebLocalFrame* frame, | |
209 const blink::WebCachedURLRequest& url_request); | |
210 void WillSendRequest(blink::WebLocalFrame* frame, | |
211 unsigned identifier, | |
212 blink::WebURLRequest& request, | |
213 const blink::WebURLResponse& redirect_response); | |
214 void DidReceiveResponse(blink::WebLocalFrame* frame, | |
215 unsigned identifier, | |
216 const blink::WebURLResponse& response); | |
217 void DidChangeResourcePriority(blink::WebLocalFrame* frame, | |
218 unsigned identifier, | |
219 const blink::WebURLRequest::Priority& priority, | |
220 int intra_priority_value); | |
221 void DidFinishResourceLoad(blink::WebLocalFrame* frame, unsigned identifier); | |
222 blink::WebNavigationPolicy DecidePolicyForNavigation( | |
223 const blink::WebFrameClient::NavigationPolicyInfo& info); | |
224 bool WillCheckAndDispatchMessageEvent(blink::WebLocalFrame* source_frame, | |
225 blink::WebFrame* target_frame, | |
226 blink::WebSecurityOrigin target, | |
227 blink::WebDOMMessageEvent event); | |
228 void ResetInputMethod(); | |
229 | |
230 blink::WebString acceptLanguages(); | |
231 | |
232 private: | |
233 template <class, typename, typename> | |
234 friend class WebFrameTestProxy; | |
235 | |
236 enum CheckDoneReason { | |
237 LoadFinished, | |
238 MainResourceLoadFailed, | |
239 ResourceLoadCompleted | |
240 }; | |
241 void CheckDone(blink::WebLocalFrame* frame, CheckDoneReason reason); | |
242 void AnimateNow(); | |
243 void DrawSelectionRect(SkCanvas* canvas); | |
244 void DidCapturePixelsAsync( | |
245 const base::Callback<void(const SkBitmap&)>& callback, | |
246 const SkBitmap& bitmap); | |
247 | |
248 blink::WebWidget* web_widget() const { return web_widget_; } | |
249 | |
250 TestInterfaces* test_interfaces_; | |
251 WebTestDelegate* delegate_; | |
252 blink::WebWidget* web_widget_; | |
253 | |
254 WebTaskList task_list_; | |
255 | |
256 blink::WebImage drag_image_; | |
257 | |
258 scoped_ptr<SpellCheckClient> spellcheck_; | |
259 scoped_ptr<MockWebUserMediaClient> user_media_client_; | |
260 | |
261 bool animate_scheduled_; | |
262 std::map<unsigned, std::string> resource_identifier_map_; | |
263 | |
264 bool log_console_output_; | |
265 int chooser_count_; | |
266 | |
267 scoped_ptr<MockCredentialManagerClient> credential_manager_client_; | |
268 scoped_ptr<MockWebSpeechRecognizer> speech_recognizer_; | |
269 scoped_ptr<MockScreenOrientationClient> screen_orientation_client_; | |
270 | |
271 std::string accept_languages_; | |
272 | |
273 private: | |
274 DISALLOW_COPY_AND_ASSIGN(WebTestProxyBase); | |
275 }; | |
276 | |
277 // WebTestProxy is used during LayoutTests and always instantiated, at time of | |
278 // writing with Base=RenderViewImpl. It does not directly inherit from it for | |
279 // layering purposes. | |
280 // The intent of that class is to wrap RenderViewImpl for tests purposes in | |
281 // order to reduce the amount of test specific code in the production code. | |
282 // WebTestProxy is only doing the glue between RenderViewImpl and | |
283 // WebTestProxyBase, that means that there is no logic living in this class | |
284 // except deciding which base class should be called (could be both). | |
285 // | |
286 // Examples of usage: | |
287 // * when a fooClient has a mock implementation, WebTestProxy can override the | |
288 // fooClient() call and have WebTestProxyBase return the mock implementation. | |
289 // * when a value needs to be overridden by LayoutTests, WebTestProxy can | |
290 // override RenderViewImpl's getter and call a getter from WebTestProxyBase | |
291 // instead. In addition, WebTestProxyBase will have a public setter that | |
292 // could be called from the TestRunner. | |
293 template <class Base, typename T> | |
294 class WebTestProxy : public Base, public WebTestProxyBase { | |
295 public: | |
296 explicit WebTestProxy(T t) : Base(t) {} | |
297 | |
298 // WebWidgetClient implementation. | |
299 virtual blink::WebScreenInfo screenInfo() { | |
300 blink::WebScreenInfo info = Base::screenInfo(); | |
301 WebTestProxyBase::GetScreenOrientationForTesting(info); | |
302 return info; | |
303 } | |
304 | |
305 // WebViewClient implementation. | |
306 virtual void scheduleAnimation() { WebTestProxyBase::ScheduleAnimation(); } | |
307 virtual void postAccessibilityEvent(const blink::WebAXObject& object, | |
308 blink::WebAXEvent event) { | |
309 WebTestProxyBase::PostAccessibilityEvent(object, event); | |
310 Base::postAccessibilityEvent(object, event); | |
311 } | |
312 virtual void startDragging(blink::WebLocalFrame* frame, | |
313 const blink::WebDragData& data, | |
314 blink::WebDragOperationsMask mask, | |
315 const blink::WebImage& image, | |
316 const blink::WebPoint& point) { | |
317 WebTestProxyBase::StartDragging(frame, data, mask, image, point); | |
318 // Don't forward this call to Base because we don't want to do a real | |
319 // drag-and-drop. | |
320 } | |
321 virtual void didChangeContents() { | |
322 WebTestProxyBase::DidChangeContents(); | |
323 Base::didChangeContents(); | |
324 } | |
325 virtual blink::WebView* createView(blink::WebLocalFrame* creator, | |
326 const blink::WebURLRequest& request, | |
327 const blink::WebWindowFeatures& features, | |
328 const blink::WebString& frame_name, | |
329 blink::WebNavigationPolicy policy, | |
330 bool suppress_opener) { | |
331 if (!WebTestProxyBase::CreateView( | |
332 creator, request, features, frame_name, policy, suppress_opener)) | |
333 return 0; | |
334 return Base::createView( | |
335 creator, request, features, frame_name, policy, suppress_opener); | |
336 } | |
337 virtual void setStatusText(const blink::WebString& text) { | |
338 WebTestProxyBase::SetStatusText(text); | |
339 Base::setStatusText(text); | |
340 } | |
341 virtual void printPage(blink::WebLocalFrame* frame) { | |
342 WebTestProxyBase::PrintPage(frame); | |
343 } | |
344 virtual blink::WebSpeechRecognizer* speechRecognizer() { | |
345 return WebTestProxyBase::GetSpeechRecognizer(); | |
346 } | |
347 virtual bool requestPointerLock() { | |
348 return WebTestProxyBase::RequestPointerLock(); | |
349 } | |
350 virtual void requestPointerUnlock() { | |
351 WebTestProxyBase::RequestPointerUnlock(); | |
352 } | |
353 virtual bool isPointerLocked() { return WebTestProxyBase::IsPointerLocked(); } | |
354 virtual void didFocus() { | |
355 WebTestProxyBase::DidFocus(); | |
356 Base::didFocus(); | |
357 } | |
358 virtual void didBlur() { | |
359 WebTestProxyBase::DidBlur(); | |
360 Base::didBlur(); | |
361 } | |
362 virtual void setToolTipText(const blink::WebString& text, | |
363 blink::WebTextDirection hint) { | |
364 WebTestProxyBase::SetToolTipText(text, hint); | |
365 Base::setToolTipText(text, hint); | |
366 } | |
367 virtual void resetInputMethod() { WebTestProxyBase::ResetInputMethod(); } | |
368 virtual bool runFileChooser(const blink::WebFileChooserParams& params, | |
369 blink::WebFileChooserCompletion* completion) { | |
370 return WebTestProxyBase::RunFileChooser(params, completion); | |
371 } | |
372 virtual void showValidationMessage(const blink::WebRect& anchor_in_root_view, | |
373 const blink::WebString& main_message, | |
374 blink::WebTextDirection main_message_hint, | |
375 const blink::WebString& sub_message, | |
376 blink::WebTextDirection sub_message_hint) { | |
377 base::string16 wrapped_main_text = main_message; | |
378 base::string16 wrapped_sub_text = sub_message; | |
379 | |
380 Base::SetValidationMessageDirection( | |
381 &wrapped_main_text, main_message_hint, &wrapped_sub_text, sub_message_hi
nt); | |
382 | |
383 WebTestProxyBase::ShowValidationMessage( | |
384 wrapped_main_text, wrapped_sub_text); | |
385 } | |
386 virtual void postSpellCheckEvent(const blink::WebString& event_name) { | |
387 WebTestProxyBase::PostSpellCheckEvent(event_name); | |
388 } | |
389 virtual blink::WebString acceptLanguages() { | |
390 return WebTestProxyBase::acceptLanguages(); | |
391 } | |
392 | |
393 private: | |
394 virtual ~WebTestProxy() {} | |
395 | |
396 DISALLOW_COPY_AND_ASSIGN(WebTestProxy); | |
397 }; | |
398 | |
399 } // namespace content | |
400 | |
401 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_WEB_TEST_PROXY_H_ | |
OLD | NEW |