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_
12 #include "base/basictypes.h"
13 #include "base/callback.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "content/shell/renderer/test_runner/WebTask.h"
16 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallback.h"
17 #include "third_party/WebKit/public/platform/WebRect.h"
18 #include "third_party/WebKit/public/platform/WebURLError.h"
19 #include "third_party/WebKit/public/platform/WebURLRequest.h"
20 #include "third_party/WebKit/public/web/WebAXEnums.h"
21 #include "third_party/WebKit/public/web/WebDOMMessageEvent.h"
22 #include "third_party/WebKit/public/web/WebDataSource.h"
23 #include "third_party/WebKit/public/web/WebDragOperation.h"
24 #include "third_party/WebKit/public/web/WebFrame.h"
25 #include "third_party/WebKit/public/web/WebHistoryCommitType.h"
26 #include "third_party/WebKit/public/web/WebIconURL.h"
27 #include "third_party/WebKit/public/web/WebNavigationPolicy.h"
28 #include "third_party/WebKit/public/web/WebNavigationType.h"
29 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
30 #include "third_party/WebKit/public/web/WebTextAffinity.h"
31 #include "third_party/WebKit/public/web/WebTextDirection.h"
38 class WebCachedURLRequest;
39 class WebColorChooser;
40 class WebColorChooserClient;
43 class WebFileChooserCompletion;
47 class WebMIDIAccessor;
48 class WebMIDIAccessorClient;
50 class WebMIDIClientMock;
52 class WebNotificationPresenter;
55 class WebSerializedScriptValue;
56 class WebSpeechRecognizer;
57 class WebSpellCheckClient;
61 class WebUserMediaClient;
64 struct WebColorSuggestion;
65 struct WebConsoleMessage;
66 struct WebContextMenuData;
67 struct WebFileChooserParams;
68 struct WebPluginParams;
71 struct WebWindowFeatures;
72 typedef unsigned WebColor;
77 class MockWebSpeechRecognizer;
79 class SpellCheckClient;
81 class WebTestDelegate;
82 class WebTestInterfaces;
83 class WebUserMediaClientMock;
85 class WebTestProxyBase : public blink::WebCompositeAndReadbackAsyncCallback {
87 void setInterfaces(WebTestInterfaces*);
88 void setDelegate(WebTestDelegate*);
89 void setWidget(blink::WebWidget*);
93 blink::WebSpellCheckClient *spellCheckClient() const;
94 blink::WebColorChooser* createColorChooser(blink::WebColorChooserClient*, const blink::WebColor&, const blink::WebVector<blink::WebColorSuggestion>& suggestions);
95 bool runFileChooser(const blink::WebFileChooserParams&, blink::WebFileChooserCompletion*);
96 void showValidationMessage(const blink::WebRect& anchorInRootView, const blink::WebString& mainText, const blink::WebString& supplementalText, blink::WebTextDirection);
97 void hideValidationMessage();
98 void moveValidationMessage(const blink::WebRect& anchorInRootView);
100 std::string captureTree(bool debugRenderTree);
101 SkCanvas* capturePixels();
102 void CapturePixelsAsync(base::Callback<void(const SkBitmap&)> callback);
104 void setLogConsoleOutput(bool enabled);
106 // FIXME: Make this private again.
107 void scheduleComposite();
109 void didOpenChooser();
110 void didCloseChooser();
111 bool isChooserShown();
113 void displayAsyncThen(base::Closure callback);
115 void discardBackingStore();
117 blink::WebMIDIClientMock* midiClientMock();
118 MockWebSpeechRecognizer* speechRecognizerMock();
120 WebTaskList* taskList() { return &m_taskList; }
122 blink::WebView* webView();
124 void didForceResize();
126 void postSpellCheckEvent(const blink::WebString& eventName);
128 // WebCompositeAndReadbackAsyncCallback implementation.
129 virtual void didCompositeAndReadback(const SkBitmap& bitmap);
135 void didInvalidateRect(const blink::WebRect&);
136 void didScrollRect(int, int, const blink::WebRect&);
137 void scheduleAnimation();
138 bool isCompositorFramePending() const;
139 // FIXME: Remove once we switch to use didForceResize.
140 void setWindowRect(const blink::WebRect&);
141 void show(blink::WebNavigationPolicy);
142 void didAutoResize(const blink::WebSize&);
143 void postAccessibilityEvent(const blink::WebAXObject&, blink::WebAXEvent);
144 void startDragging(blink::WebLocalFrame*, const blink::WebDragData&, blink::WebDragOperationsMask, const blink::WebImage&, const blink::WebPoint&);
145 void didChangeSelection(bool isEmptySelection);
146 void didChangeContents();
147 void didEndEditing();
148 bool createView(blink::WebLocalFrame* creator, const blink::WebURLRequest&, const blink::WebWindowFeatures&, const blink::WebString& frameName, blink::WebNavigationPolicy, bool suppressOpener);
149 blink::WebPlugin* createPlugin(blink::WebLocalFrame*, const blink::WebPluginParams&);
150 void setStatusText(const blink::WebString&);
151 void didStopLoading();
152 void showContextMenu(blink::WebLocalFrame*, const blink::WebContextMenuData&);
153 blink::WebUserMediaClient* userMediaClient();
154 void printPage(blink::WebLocalFrame*);
155 blink::WebNotificationPresenter* notificationPresenter();
156 blink::WebMIDIClient* webMIDIClient();
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 loadURLExternally(blink::WebLocalFrame* frame, const blink::WebURLRequest& request, blink::WebNavigationPolicy policy, const blink::WebString& suggested_name);
166 void didStartProvisionalLoad(blink::WebLocalFrame*);
167 void didReceiveServerRedirectForProvisionalLoad(blink::WebLocalFrame*);
168 bool didFailProvisionalLoad(blink::WebLocalFrame*, const blink::WebURLError&);
169 void didCommitProvisionalLoad(blink::WebLocalFrame*, const blink::WebHistoryItem&, blink::WebHistoryCommitType);
170 void didReceiveTitle(blink::WebLocalFrame*, const blink::WebString& title, blink::WebTextDirection);
171 void didChangeIcon(blink::WebLocalFrame*, blink::WebIconURL::Type);
172 void didFinishDocumentLoad(blink::WebLocalFrame*);
173 void didHandleOnloadEvents(blink::WebLocalFrame*);
174 void didFailLoad(blink::WebLocalFrame*, const blink::WebURLError&);
175 void didFinishLoad(blink::WebLocalFrame*);
176 void didChangeLocationWithinPage(blink::WebLocalFrame*);
177 void didDetectXSS(blink::WebLocalFrame*, const blink::WebURL& insecureURL, bool didBlockEntirePage);
178 void didDispatchPingLoader(blink::WebLocalFrame*, const blink::WebURL&);
179 void willRequestResource(blink::WebLocalFrame*, const blink::WebCachedURLRequest&);
180 void willSendRequest(blink::WebLocalFrame*, unsigned identifier, blink::WebURLRequest&, const blink::WebURLResponse& redirectResponse);
181 void didReceiveResponse(blink::WebLocalFrame*, unsigned identifier, const blink::WebURLResponse&);
182 void didChangeResourcePriority(blink::WebLocalFrame*, unsigned identifier, const blink::WebURLRequest::Priority&, int intra_priority_value);
183 void didFinishResourceLoad(blink::WebLocalFrame*, unsigned identifier);
184 blink::WebNavigationPolicy decidePolicyForNavigation(blink::WebLocalFrame*, blink::WebDataSource::ExtraData*, const blink::WebURLRequest&, blink::WebNavigationType, blink::WebNavigationPolicy defaultPolicy, bool isRedirect);
185 bool willCheckAndDispatchMessageEvent(blink::WebLocalFrame* sourceFrame, blink::WebFrame* targetFrame, blink::WebSecurityOrigin target, blink::WebDOMMessageEvent);
186 void resetInputMethod();
189 template<class, typename, typename> friend class WebFrameTestProxy;
190 void locationChangeDone(blink::WebFrame*);
191 void paintRect(const blink::WebRect&);
192 void paintInvalidatedRegion();
193 void paintPagesWithBoundaries();
195 void invalidateAll();
197 void DrawSelectionRect(SkCanvas* canvas);
198 void DisplayForSoftwareMode(const base::Closure& callback);
199 void DidDisplayAsync(const base::Closure& callback, const SkBitmap& bitmap);
201 blink::WebWidget* webWidget();
203 TestInterfaces* m_testInterfaces;
204 WebTestDelegate* m_delegate;
205 blink::WebWidget* m_webWidget;
207 WebTaskList m_taskList;
209 scoped_ptr<SpellCheckClient> m_spellcheck;
210 scoped_ptr<WebUserMediaClientMock> m_userMediaClient;
213 scoped_ptr<SkCanvas> m_canvas;
214 blink::WebRect m_paintRect;
216 bool m_animateScheduled;
217 std::map<unsigned, std::string> m_resourceIdentifierMap;
218 std::map<unsigned, blink::WebURLRequest> m_requestMap;
219 std::deque<base::Callback<void(const SkBitmap&)> >
220 m_compositeAndReadbackCallbacks;
222 bool m_logConsoleOutput;
225 scoped_ptr<blink::WebMIDIClientMock> m_midiClient;
226 scoped_ptr<MockWebSpeechRecognizer> m_speechRecognizer;
229 DISALLOW_COPY_AND_ASSIGN(WebTestProxyBase);
232 // Use this template to inject methods into your WebViewClient/WebFrameClient
233 // implementation required for the running layout tests.
234 template<class Base, typename T>
235 class WebTestProxy : public Base, public WebTestProxyBase {
237 explicit WebTestProxy(T t)
242 virtual ~WebTestProxy() { }
244 // WebViewClient implementation.
245 virtual void didInvalidateRect(const blink::WebRect& rect)
247 WebTestProxyBase::didInvalidateRect(rect);
249 virtual void didScrollRect(int dx, int dy, const blink::WebRect& clipRect)
251 WebTestProxyBase::didScrollRect(dx, dy, clipRect);
253 virtual void scheduleComposite()
255 WebTestProxyBase::scheduleComposite();
257 virtual void scheduleAnimation()
259 WebTestProxyBase::scheduleAnimation();
261 virtual bool isCompositorFramePending() const
263 return WebTestProxyBase::isCompositorFramePending();
265 virtual void setWindowRect(const blink::WebRect& rect)
267 WebTestProxyBase::setWindowRect(rect);
268 Base::setWindowRect(rect);
270 virtual void show(blink::WebNavigationPolicy policy)
272 WebTestProxyBase::show(policy);
275 virtual void didAutoResize(const blink::WebSize& newSize)
277 WebTestProxyBase::didAutoResize(newSize);
278 Base::didAutoResize(newSize);
280 virtual void postAccessibilityEvent(const blink::WebAXObject& object, blink::WebAXEvent event)
282 WebTestProxyBase::postAccessibilityEvent(object, event);
283 Base::postAccessibilityEvent(object, event);
285 virtual void startDragging(blink::WebLocalFrame* frame, const blink::WebDragData& data, blink::WebDragOperationsMask mask, const blink::WebImage& image, const blink::WebPoint& point)
287 WebTestProxyBase::startDragging(frame, data, mask, image, point);
288 // Don't forward this call to Base because we don't want to do a real drag-and-drop.
290 virtual void didChangeContents()
292 WebTestProxyBase::didChangeContents();
293 Base::didChangeContents();
295 virtual blink::WebView* createView(blink::WebLocalFrame* creator, const blink::WebURLRequest& request, const blink::WebWindowFeatures& features, const blink::WebString& frameName, blink::WebNavigationPolicy policy, bool suppressOpener)
297 if (!WebTestProxyBase::createView(creator, request, features, frameName, policy, suppressOpener))
299 return Base::createView(creator, request, features, frameName, policy, suppressOpener);
301 virtual void setStatusText(const blink::WebString& text)
303 WebTestProxyBase::setStatusText(text);
304 Base::setStatusText(text);
306 virtual blink::WebUserMediaClient* userMediaClient()
308 return WebTestProxyBase::userMediaClient();
310 virtual void printPage(blink::WebLocalFrame* frame)
312 WebTestProxyBase::printPage(frame);
314 virtual blink::WebMIDIClient* webMIDIClient()
316 return WebTestProxyBase::webMIDIClient();
318 virtual blink::WebSpeechRecognizer* speechRecognizer()
320 return WebTestProxyBase::speechRecognizer();
322 virtual bool requestPointerLock()
324 return WebTestProxyBase::requestPointerLock();
326 virtual void requestPointerUnlock()
328 WebTestProxyBase::requestPointerUnlock();
330 virtual bool isPointerLocked()
332 return WebTestProxyBase::isPointerLocked();
334 virtual void didFocus()
336 WebTestProxyBase::didFocus();
339 virtual void didBlur()
341 WebTestProxyBase::didBlur();
344 virtual void setToolTipText(const blink::WebString& text, blink::WebTextDirection hint)
346 WebTestProxyBase::setToolTipText(text, hint);
347 Base::setToolTipText(text, hint);
349 virtual void resetInputMethod()
351 WebTestProxyBase::resetInputMethod();
353 virtual bool runFileChooser(const blink::WebFileChooserParams& params, blink::WebFileChooserCompletion* completion)
355 return WebTestProxyBase::runFileChooser(params, completion);
357 virtual void showValidationMessage(const blink::WebRect& anchorInRootView, const blink::WebString& mainText, const blink::WebString& supplementalText, blink::WebTextDirection hint)
359 WebTestProxyBase::showValidationMessage(anchorInRootView, mainText, supplementalText, hint);
361 virtual void hideValidationMessage()
363 WebTestProxyBase::hideValidationMessage();
365 virtual void moveValidationMessage(const blink::WebRect& anchorInRootView)
367 WebTestProxyBase::moveValidationMessage(anchorInRootView);
369 virtual void postSpellCheckEvent(const blink::WebString& eventName)
371 WebTestProxyBase::postSpellCheckEvent(eventName);
375 DISALLOW_COPY_AND_ASSIGN(WebTestProxy);
378 } // namespace content
380 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBTESTPROXY_H_