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
3 // found in the LICENSE file.
5 #ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBTESTPROXY_H_
6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBTESTPROXY_H_
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "content/shell/renderer/test_runner/WebTask.h"
14 #include "third_party/WebKit/public/platform/WebRect.h"
15 #include "third_party/WebKit/public/platform/WebURLError.h"
16 #include "third_party/WebKit/public/platform/WebURLRequest.h"
17 #include "third_party/WebKit/public/web/WebAXEnums.h"
18 #include "third_party/WebKit/public/web/WebDOMMessageEvent.h"
19 #include "third_party/WebKit/public/web/WebDataSource.h"
20 #include "third_party/WebKit/public/web/WebDragOperation.h"
21 #include "third_party/WebKit/public/web/WebIconURL.h"
22 #include "third_party/WebKit/public/web/WebNavigationPolicy.h"
23 #include "third_party/WebKit/public/web/WebNavigationType.h"
24 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
25 #include "third_party/WebKit/public/web/WebTextAffinity.h"
26 #include "third_party/WebKit/public/web/WebTextDirection.h"
31 class WebCachedURLRequest;
32 class WebColorChooser;
33 class WebColorChooserClient;
36 class WebFileChooserCompletion;
39 class WebMIDIAccessor;
40 class WebMIDIAccessorClient;
42 class WebMIDIClientMock;
44 class WebNotificationPresenter;
47 class WebSerializedScriptValue;
48 class WebSpeechInputController;
49 class WebSpeechInputListener;
50 class WebSpeechRecognizer;
51 class WebSpellCheckClient;
55 class WebUserMediaClient;
58 struct WebColorSuggestion;
59 struct WebConsoleMessage;
60 struct WebContextMenuData;
61 struct WebFileChooserParams;
62 struct WebPluginParams;
65 struct WebWindowFeatures;
66 typedef unsigned WebColor;
75 namespace WebTestRunner {
77 class MockWebSpeechInputController;
78 class MockWebSpeechRecognizer;
79 class SpellCheckClient;
81 class WebTestDelegate;
82 class WebTestInterfaces;
84 class WebUserMediaClientMock;
86 class WebTestProxyBase {
88 void setInterfaces(WebTestInterfaces*);
89 void setDelegate(WebTestDelegate*);
90 void setWidget(blink::WebWidget*);
94 blink::WebSpellCheckClient *spellCheckClient() const;
95 blink::WebColorChooser* createColorChooser(blink::WebColorChooserClient*, const blink::WebColor&);
96 blink::WebColorChooser* createColorChooser(blink::WebColorChooserClient*, const blink::WebColor&, const blink::WebVector<blink::WebColorSuggestion>& suggestions);
97 bool runFileChooser(const blink::WebFileChooserParams&, blink::WebFileChooserCompletion*);
98 void showValidationMessage(const blink::WebRect& anchorInRootView, const blink::WebString& mainText, const blink::WebString& supplementalText, blink::WebTextDirection);
99 void hideValidationMessage();
100 void moveValidationMessage(const blink::WebRect& anchorInRootView);
102 std::string captureTree(bool debugRenderTree);
103 SkCanvas* capturePixels();
105 void setLogConsoleOutput(bool enabled);
107 // FIXME: Make this private again.
108 void scheduleComposite();
110 void didOpenChooser();
111 void didCloseChooser();
112 bool isChooserShown();
115 void displayInvalidatedRegion();
116 void discardBackingStore();
118 blink::WebMIDIClientMock* midiClientMock();
119 MockWebSpeechInputController* speechInputControllerMock();
120 MockWebSpeechRecognizer* speechRecognizerMock();
122 WebTaskList* taskList() { return &m_taskList; }
124 blink::WebView* webView();
126 void didForceResize();
128 void postSpellCheckEvent(const blink::WebString& eventName);
134 void didInvalidateRect(const blink::WebRect&);
135 void didScrollRect(int, int, const blink::WebRect&);
136 void scheduleAnimation();
137 bool isCompositorFramePending() const;
138 // FIXME: Remove once we switch to use didForceResize.
139 void setWindowRect(const blink::WebRect&);
140 void show(blink::WebNavigationPolicy);
141 void didAutoResize(const blink::WebSize&);
142 void postAccessibilityEvent(const blink::WebAXObject&, blink::WebAXEvent);
143 void startDragging(blink::WebFrame*, const blink::WebDragData&, blink::WebDragOperationsMask, const blink::WebImage&, const blink::WebPoint&);
144 void didChangeSelection(bool isEmptySelection);
145 void didChangeContents();
146 void didEndEditing();
147 bool createView(blink::WebFrame* creator, const blink::WebURLRequest&, const blink::WebWindowFeatures&, const blink::WebString& frameName, blink::WebNavigationPolicy, bool suppressOpener);
148 blink::WebPlugin* createPlugin(blink::WebFrame*, const blink::WebPluginParams&);
149 void setStatusText(const blink::WebString&);
150 void didStopLoading();
151 void showContextMenu(blink::WebFrame*, const blink::WebContextMenuData&);
152 blink::WebUserMediaClient* userMediaClient();
153 void printPage(blink::WebFrame*);
154 blink::WebNotificationPresenter* notificationPresenter();
155 blink::WebMIDIClient* webMIDIClient();
156 blink::WebSpeechInputController* speechInputController(blink::WebSpeechInputListener*);
157 blink::WebSpeechRecognizer* speechRecognizer();
158 bool requestPointerLock();
159 void requestPointerUnlock();
160 bool isPointerLocked();
163 void setToolTipText(const blink::WebString&, blink::WebTextDirection);
164 void didAddMessageToConsole(const blink::WebConsoleMessage&, const blink::WebString& sourceName, unsigned sourceLine);
165 void runModalAlertDialog(blink::WebFrame*, const blink::WebString&);
166 bool runModalConfirmDialog(blink::WebFrame*, const blink::WebString&);
167 bool runModalPromptDialog(blink::WebFrame*, const blink::WebString& message, const blink::WebString& defaultValue, blink::WebString* actualValue);
168 bool runModalBeforeUnloadDialog(blink::WebFrame*, const blink::WebString&);
170 void didStartProvisionalLoad(blink::WebFrame*);
171 void didReceiveServerRedirectForProvisionalLoad(blink::WebFrame*);
172 bool didFailProvisionalLoad(blink::WebFrame*, const blink::WebURLError&);
173 void didCommitProvisionalLoad(blink::WebFrame*, bool isNewNavigation);
174 void didReceiveTitle(blink::WebFrame*, const blink::WebString& title, blink::WebTextDirection);
175 void didChangeIcon(blink::WebFrame*, blink::WebIconURL::Type);
176 void didFinishDocumentLoad(blink::WebFrame*);
177 void didHandleOnloadEvents(blink::WebFrame*);
178 void didFailLoad(blink::WebFrame*, const blink::WebURLError&);
179 void didFinishLoad(blink::WebFrame*);
180 void didChangeLocationWithinPage(blink::WebFrame*);
181 void didDetectXSS(blink::WebFrame*, const blink::WebURL& insecureURL, bool didBlockEntirePage);
182 void didDispatchPingLoader(blink::WebFrame*, const blink::WebURL&);
183 void willRequestResource(blink::WebFrame*, const blink::WebCachedURLRequest&);
184 void willSendRequest(blink::WebFrame*, unsigned identifier, blink::WebURLRequest&, const blink::WebURLResponse& redirectResponse);
185 void didReceiveResponse(blink::WebFrame*, unsigned identifier, const blink::WebURLResponse&);
186 void didChangeResourcePriority(blink::WebFrame*, unsigned identifier, const blink::WebURLRequest::Priority&);
187 void didFinishResourceLoad(blink::WebFrame*, unsigned identifier);
188 blink::WebNavigationPolicy decidePolicyForNavigation(blink::WebFrame*, blink::WebDataSource::ExtraData*, const blink::WebURLRequest&, blink::WebNavigationType, blink::WebNavigationPolicy defaultPolicy, bool isRedirect);
189 bool willCheckAndDispatchMessageEvent(blink::WebFrame* sourceFrame, blink::WebFrame* targetFrame, blink::WebSecurityOrigin target, blink::WebDOMMessageEvent);
190 void resetInputMethod();
193 template<class, typename, typename> friend class WebFrameTestProxy;
194 void locationChangeDone(blink::WebFrame*);
195 void paintRect(const blink::WebRect&);
196 void paintInvalidatedRegion();
197 void paintPagesWithBoundaries();
199 void displayRepaintMask();
200 void invalidateAll();
203 blink::WebWidget* webWidget();
205 TestInterfaces* m_testInterfaces;
206 WebTestDelegate* m_delegate;
207 blink::WebWidget* m_webWidget;
209 WebTaskList m_taskList;
211 scoped_ptr<SpellCheckClient> m_spellcheck;
212 scoped_ptr<WebUserMediaClientMock> m_userMediaClient;
215 scoped_ptr<SkCanvas> m_canvas;
216 blink::WebRect m_paintRect;
218 bool m_animateScheduled;
219 std::map<unsigned, std::string> m_resourceIdentifierMap;
220 std::map<unsigned, blink::WebURLRequest> m_requestMap;
222 bool m_logConsoleOutput;
225 scoped_ptr<blink::WebMIDIClientMock> m_midiClient;
226 scoped_ptr<MockWebSpeechRecognizer> m_speechRecognizer;
227 scoped_ptr<MockWebSpeechInputController> m_speechInputController;
230 DISALLOW_COPY_AND_ASSIGN(WebTestProxyBase);
233 // Use this template to inject methods into your WebViewClient/WebFrameClient
234 // implementation required for the running layout tests.
235 template<class Base, typename T>
236 class WebTestProxy : public Base, public WebTestProxyBase {
238 explicit WebTestProxy(T t)
243 virtual ~WebTestProxy() { }
245 // WebViewClient implementation.
246 virtual void didInvalidateRect(const blink::WebRect& rect)
248 WebTestProxyBase::didInvalidateRect(rect);
250 virtual void didScrollRect(int dx, int dy, const blink::WebRect& clipRect)
252 WebTestProxyBase::didScrollRect(dx, dy, clipRect);
254 virtual void scheduleComposite()
256 WebTestProxyBase::scheduleComposite();
258 virtual void scheduleAnimation()
260 WebTestProxyBase::scheduleAnimation();
262 virtual bool isCompositorFramePending() const
264 return WebTestProxyBase::isCompositorFramePending();
266 virtual void setWindowRect(const blink::WebRect& rect)
268 WebTestProxyBase::setWindowRect(rect);
269 Base::setWindowRect(rect);
271 virtual void show(blink::WebNavigationPolicy policy)
273 WebTestProxyBase::show(policy);
276 virtual void didAutoResize(const blink::WebSize& newSize)
278 WebTestProxyBase::didAutoResize(newSize);
279 Base::didAutoResize(newSize);
281 virtual void postAccessibilityEvent(const blink::WebAXObject& object, blink::WebAXEvent event)
283 WebTestProxyBase::postAccessibilityEvent(object, event);
284 Base::postAccessibilityEvent(object, event);
286 virtual void startDragging(blink::WebFrame* frame, const blink::WebDragData& data, blink::WebDragOperationsMask mask, const blink::WebImage& image, const blink::WebPoint& point)
288 WebTestProxyBase::startDragging(frame, data, mask, image, point);
289 // Don't forward this call to Base because we don't want to do a real drag-and-drop.
291 virtual void didChangeSelection(bool isEmptySelection)
293 WebTestProxyBase::didChangeSelection(isEmptySelection);
294 Base::didChangeSelection(isEmptySelection);
296 virtual void didChangeContents()
298 WebTestProxyBase::didChangeContents();
299 Base::didChangeContents();
301 virtual blink::WebView* createView(blink::WebFrame* creator, const blink::WebURLRequest& request, const blink::WebWindowFeatures& features, const blink::WebString& frameName, blink::WebNavigationPolicy policy, bool suppressOpener)
303 if (!WebTestProxyBase::createView(creator, request, features, frameName, policy, suppressOpener))
305 return Base::createView(creator, request, features, frameName, policy, suppressOpener);
307 virtual void setStatusText(const blink::WebString& text)
309 WebTestProxyBase::setStatusText(text);
310 Base::setStatusText(text);
312 virtual void didStopLoading()
314 WebTestProxyBase::didStopLoading();
315 Base::didStopLoading();
317 virtual void showContextMenu(blink::WebFrame* frame, const blink::WebContextMenuData& contextMenuData)
319 WebTestProxyBase::showContextMenu(frame, contextMenuData);
320 Base::showContextMenu(frame, contextMenuData);
322 virtual blink::WebUserMediaClient* userMediaClient()
324 return WebTestProxyBase::userMediaClient();
326 virtual void printPage(blink::WebFrame* frame)
328 WebTestProxyBase::printPage(frame);
330 virtual blink::WebNotificationPresenter* notificationPresenter()
332 return WebTestProxyBase::notificationPresenter();
334 virtual blink::WebMIDIClient* webMIDIClient()
336 return WebTestProxyBase::webMIDIClient();
338 virtual blink::WebSpeechInputController* speechInputController(blink::WebSpeechInputListener* listener)
340 return WebTestProxyBase::speechInputController(listener);
342 virtual blink::WebSpeechRecognizer* speechRecognizer()
344 return WebTestProxyBase::speechRecognizer();
346 virtual bool requestPointerLock()
348 return WebTestProxyBase::requestPointerLock();
350 virtual void requestPointerUnlock()
352 WebTestProxyBase::requestPointerUnlock();
354 virtual bool isPointerLocked()
356 return WebTestProxyBase::isPointerLocked();
358 virtual void didFocus()
360 WebTestProxyBase::didFocus();
363 virtual void didBlur()
365 WebTestProxyBase::didBlur();
368 virtual void setToolTipText(const blink::WebString& text, blink::WebTextDirection hint)
370 WebTestProxyBase::setToolTipText(text, hint);
371 Base::setToolTipText(text, hint);
373 virtual void resetInputMethod()
375 WebTestProxyBase::resetInputMethod();
378 virtual void didStartProvisionalLoad(blink::WebFrame* frame)
380 WebTestProxyBase::didStartProvisionalLoad(frame);
381 Base::didStartProvisionalLoad(frame);
383 virtual void didReceiveServerRedirectForProvisionalLoad(blink::WebFrame* frame)
385 WebTestProxyBase::didReceiveServerRedirectForProvisionalLoad(frame);
386 Base::didReceiveServerRedirectForProvisionalLoad(frame);
388 virtual void didFailProvisionalLoad(blink::WebFrame* frame, const blink::WebURLError& error)
390 // If the test finished, don't notify the embedder of the failed load,
391 // as we already destroyed the document loader.
392 if (WebTestProxyBase::didFailProvisionalLoad(frame, error))
394 Base::didFailProvisionalLoad(frame, error);
396 virtual void didCommitProvisionalLoad(blink::WebFrame* frame, bool isNewNavigation)
398 WebTestProxyBase::didCommitProvisionalLoad(frame, isNewNavigation);
399 Base::didCommitProvisionalLoad(frame, isNewNavigation);
401 virtual void didReceiveTitle(blink::WebFrame* frame, const blink::WebString& title, blink::WebTextDirection direction)
403 WebTestProxyBase::didReceiveTitle(frame, title, direction);
404 Base::didReceiveTitle(frame, title, direction);
406 virtual void didChangeIcon(blink::WebFrame* frame, blink::WebIconURL::Type iconType)
408 WebTestProxyBase::didChangeIcon(frame, iconType);
409 Base::didChangeIcon(frame, iconType);
411 virtual void didFinishDocumentLoad(blink::WebFrame* frame)
413 WebTestProxyBase::didFinishDocumentLoad(frame);
414 Base::didFinishDocumentLoad(frame);
416 virtual void didHandleOnloadEvents(blink::WebFrame* frame)
418 WebTestProxyBase::didHandleOnloadEvents(frame);
419 Base::didHandleOnloadEvents(frame);
421 virtual void didFailLoad(blink::WebFrame* frame, const blink::WebURLError& error)
423 WebTestProxyBase::didFailLoad(frame, error);
424 Base::didFailLoad(frame, error);
426 virtual void didFinishLoad(blink::WebFrame* frame)
428 WebTestProxyBase::didFinishLoad(frame);
429 Base::didFinishLoad(frame);
431 virtual void didDetectXSS(blink::WebFrame* frame, const blink::WebURL& insecureURL, bool didBlockEntirePage)
433 WebTestProxyBase::didDetectXSS(frame, insecureURL, didBlockEntirePage);
434 Base::didDetectXSS(frame, insecureURL, didBlockEntirePage);
436 virtual void willRequestResource(blink::WebFrame* frame, const blink::WebCachedURLRequest& request)
438 WebTestProxyBase::willRequestResource(frame, request);
439 Base::willRequestResource(frame, request);
441 virtual void willSendRequest(blink::WebFrame* frame, unsigned identifier, blink::WebURLRequest& request, const blink::WebURLResponse& redirectResponse)
443 WebTestProxyBase::willSendRequest(frame, identifier, request, redirectResponse);
444 Base::willSendRequest(frame, identifier, request, redirectResponse);
446 virtual void didReceiveResponse(blink::WebFrame* frame, unsigned identifier, const blink::WebURLResponse& response)
448 WebTestProxyBase::didReceiveResponse(frame, identifier, response);
449 Base::didReceiveResponse(frame, identifier, response);
451 virtual void didChangeResourcePriority(blink::WebFrame* frame, unsigned identifier, const blink::WebURLRequest::Priority& priority)
453 WebTestProxyBase::didChangeResourcePriority(frame, identifier, priority);
454 Base::didChangeResourcePriority(frame, identifier, priority);
456 virtual void didFinishResourceLoad(blink::WebFrame* frame, unsigned identifier)
458 WebTestProxyBase::didFinishResourceLoad(frame, identifier);
459 Base::didFinishResourceLoad(frame, identifier);
461 virtual void didAddMessageToConsole(const blink::WebConsoleMessage& message, const blink::WebString& sourceName, unsigned sourceLine, const blink::WebString& stackTrace)
463 WebTestProxyBase::didAddMessageToConsole(message, sourceName, sourceLine);
464 Base::didAddMessageToConsole(message, sourceName, sourceLine, stackTrace);
466 virtual void runModalAlertDialog(blink::WebFrame* frame, const blink::WebString& message)
468 WebTestProxyBase::runModalAlertDialog(frame, message);
469 Base::runModalAlertDialog(frame, message);
471 virtual bool runModalConfirmDialog(blink::WebFrame* frame, const blink::WebString& message)
473 WebTestProxyBase::runModalConfirmDialog(frame, message);
474 return Base::runModalConfirmDialog(frame, message);
476 virtual bool runModalPromptDialog(blink::WebFrame* frame, const blink::WebString& message, const blink::WebString& defaultValue, blink::WebString* actualValue)
478 WebTestProxyBase::runModalPromptDialog(frame, message, defaultValue, actualValue);
479 return Base::runModalPromptDialog(frame, message, defaultValue, actualValue);
481 virtual bool runModalBeforeUnloadDialog(blink::WebFrame* frame, const blink::WebString& message)
483 return WebTestProxyBase::runModalBeforeUnloadDialog(frame, message);
485 virtual blink::WebNavigationPolicy DecidePolicyForNavigation(content::RenderFrame* render_frame, blink::WebFrame* frame, blink::WebDataSource::ExtraData* extraData, const blink::WebURLRequest& request, blink::WebNavigationType type, blink::WebNavigationPolicy defaultPolicy, bool isRedirect)
487 blink::WebNavigationPolicy policy = WebTestProxyBase::decidePolicyForNavigation(frame, extraData, request, type, defaultPolicy, isRedirect);
488 if (policy == blink::WebNavigationPolicyIgnore)
490 return Base::DecidePolicyForNavigation(render_frame, frame, extraData, request, type, defaultPolicy, isRedirect);
492 virtual bool willCheckAndDispatchMessageEvent(blink::WebFrame* sourceFrame, blink::WebFrame* targetFrame, blink::WebSecurityOrigin target, blink::WebDOMMessageEvent event)
494 if (WebTestProxyBase::willCheckAndDispatchMessageEvent(sourceFrame, targetFrame, target, event))
496 return Base::willCheckAndDispatchMessageEvent(sourceFrame, targetFrame, target, event);
498 virtual blink::WebColorChooser* createColorChooser(blink::WebColorChooserClient* client, const blink::WebColor& color)
500 return WebTestProxyBase::createColorChooser(client, color);
502 virtual blink::WebColorChooser* createColorChooser(blink::WebColorChooserClient* client, const blink::WebColor& color, const blink::WebVector<blink::WebColorSuggestion>& suggestions)
504 return WebTestProxyBase::createColorChooser(client, color, suggestions);
506 virtual bool runFileChooser(const blink::WebFileChooserParams& params, blink::WebFileChooserCompletion* completion)
508 return WebTestProxyBase::runFileChooser(params, completion);
510 virtual void showValidationMessage(const blink::WebRect& anchorInRootView, const blink::WebString& mainText, const blink::WebString& supplementalText, blink::WebTextDirection hint)
512 WebTestProxyBase::showValidationMessage(anchorInRootView, mainText, supplementalText, hint);
514 virtual void hideValidationMessage()
516 WebTestProxyBase::hideValidationMessage();
518 virtual void moveValidationMessage(const blink::WebRect& anchorInRootView)
520 WebTestProxyBase::moveValidationMessage(anchorInRootView);
522 virtual void postSpellCheckEvent(const blink::WebString& eventName)
524 WebTestProxyBase::postSpellCheckEvent(eventName);
528 DISALLOW_COPY_AND_ASSIGN(WebTestProxy);
533 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBTESTPROXY_H_