[safe-browsing] Database full hash matches like prefix match.
[chromium-blink-merge.git] / content / shell / renderer / test_runner / WebTestProxy.h
blobd87518e5a101ee49ea590e8b70b260d1176bf546
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_
8 #include <map>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "content/shell/renderer/test_runner/WebTask.h"
15 #include "third_party/WebKit/public/platform/WebRect.h"
16 #include "third_party/WebKit/public/platform/WebURLError.h"
17 #include "third_party/WebKit/public/platform/WebURLRequest.h"
18 #include "third_party/WebKit/public/web/WebAXEnums.h"
19 #include "third_party/WebKit/public/web/WebDOMMessageEvent.h"
20 #include "third_party/WebKit/public/web/WebDataSource.h"
21 #include "third_party/WebKit/public/web/WebDragOperation.h"
22 #include "third_party/WebKit/public/web/WebFrame.h"
23 #include "third_party/WebKit/public/web/WebHistoryCommitType.h"
24 #include "third_party/WebKit/public/web/WebIconURL.h"
25 #include "third_party/WebKit/public/web/WebNavigationPolicy.h"
26 #include "third_party/WebKit/public/web/WebNavigationType.h"
27 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
28 #include "third_party/WebKit/public/web/WebTextAffinity.h"
29 #include "third_party/WebKit/public/web/WebTextDirection.h"
31 class SkCanvas;
33 namespace blink {
34 class WebAXObject;
35 class WebAudioDevice;
36 class WebCachedURLRequest;
37 class WebColorChooser;
38 class WebColorChooserClient;
39 class WebDataSource;
40 class WebDragData;
41 class WebFileChooserCompletion;
42 class WebFrame;
43 class WebImage;
44 class WebLocalFrame;
45 class WebMIDIAccessor;
46 class WebMIDIAccessorClient;
47 class WebMIDIClient;
48 class WebMIDIClientMock;
49 class WebNode;
50 class WebNotificationPresenter;
51 class WebPlugin;
52 class WebRange;
53 class WebSerializedScriptValue;
54 class WebSpeechInputController;
55 class WebSpeechInputListener;
56 class WebSpeechRecognizer;
57 class WebSpellCheckClient;
58 class WebString;
59 class WebURL;
60 class WebURLResponse;
61 class WebUserMediaClient;
62 class WebView;
63 class WebWidget;
64 struct WebColorSuggestion;
65 struct WebConsoleMessage;
66 struct WebContextMenuData;
67 struct WebFileChooserParams;
68 struct WebPluginParams;
69 struct WebPoint;
70 struct WebSize;
71 struct WebWindowFeatures;
72 typedef unsigned WebColor;
75 namespace WebTestRunner {
76 class MockWebSpeechInputController;
77 class MockWebSpeechRecognizer;
78 class SpellCheckClient;
79 class TestInterfaces;
80 class WebTestDelegate;
81 class WebTestInterfaces;
82 class WebUserMediaClientMock;
85 namespace content {
87 class RenderFrame;
89 class WebTestProxyBase {
90 public:
91 void setInterfaces(WebTestRunner::WebTestInterfaces*);
92 void setDelegate(WebTestRunner::WebTestDelegate*);
93 void setWidget(blink::WebWidget*);
95 void reset();
97 blink::WebSpellCheckClient *spellCheckClient() const;
98 blink::WebColorChooser* createColorChooser(blink::WebColorChooserClient*, const blink::WebColor&, const blink::WebVector<blink::WebColorSuggestion>& suggestions);
99 bool runFileChooser(const blink::WebFileChooserParams&, blink::WebFileChooserCompletion*);
100 void showValidationMessage(const blink::WebRect& anchorInRootView, const blink::WebString& mainText, const blink::WebString& supplementalText, blink::WebTextDirection);
101 void hideValidationMessage();
102 void moveValidationMessage(const blink::WebRect& anchorInRootView);
104 std::string captureTree(bool debugRenderTree);
105 SkCanvas* capturePixels();
107 void setLogConsoleOutput(bool enabled);
109 // FIXME: Make this private again.
110 void scheduleComposite();
112 void didOpenChooser();
113 void didCloseChooser();
114 bool isChooserShown();
116 void display(base::Closure callback);
117 void displayAsyncThen(base::Closure callback);
119 void discardBackingStore();
121 blink::WebMIDIClientMock* midiClientMock();
122 WebTestRunner::MockWebSpeechInputController* speechInputControllerMock();
123 WebTestRunner::MockWebSpeechRecognizer* speechRecognizerMock();
125 WebTestRunner::WebTaskList* taskList() { return &m_taskList; }
127 blink::WebView* webView();
129 void didForceResize();
131 void postSpellCheckEvent(const blink::WebString& eventName);
133 protected:
134 WebTestProxyBase();
135 ~WebTestProxyBase();
137 void didInvalidateRect(const blink::WebRect&);
138 void didScrollRect(int, int, const blink::WebRect&);
139 void scheduleAnimation();
140 bool isCompositorFramePending() const;
141 // FIXME: Remove once we switch to use didForceResize.
142 void setWindowRect(const blink::WebRect&);
143 void show(blink::WebNavigationPolicy);
144 void didAutoResize(const blink::WebSize&);
145 void postAccessibilityEvent(const blink::WebAXObject&, blink::WebAXEvent);
146 void startDragging(blink::WebLocalFrame*, const blink::WebDragData&, blink::WebDragOperationsMask, const blink::WebImage&, const blink::WebPoint&);
147 void didChangeSelection(bool isEmptySelection);
148 void didChangeContents();
149 void didEndEditing();
150 bool createView(blink::WebLocalFrame* creator, const blink::WebURLRequest&, const blink::WebWindowFeatures&, const blink::WebString& frameName, blink::WebNavigationPolicy, bool suppressOpener);
151 blink::WebPlugin* createPlugin(blink::WebLocalFrame*, const blink::WebPluginParams&);
152 void setStatusText(const blink::WebString&);
153 void didStopLoading();
154 void showContextMenu(blink::WebLocalFrame*, const blink::WebContextMenuData&);
155 blink::WebUserMediaClient* userMediaClient();
156 void printPage(blink::WebLocalFrame*);
157 blink::WebNotificationPresenter* notificationPresenter();
158 blink::WebMIDIClient* webMIDIClient();
159 blink::WebSpeechInputController* speechInputController(blink::WebSpeechInputListener*);
160 blink::WebSpeechRecognizer* speechRecognizer();
161 bool requestPointerLock();
162 void requestPointerUnlock();
163 bool isPointerLocked();
164 void didFocus();
165 void didBlur();
166 void setToolTipText(const blink::WebString&, blink::WebTextDirection);
167 void didAddMessageToConsole(const blink::WebConsoleMessage&, const blink::WebString& sourceName, unsigned sourceLine);
168 void loadURLExternally(blink::WebLocalFrame* frame, const blink::WebURLRequest& request, blink::WebNavigationPolicy policy, const blink::WebString& suggested_name);
169 void didStartProvisionalLoad(blink::WebLocalFrame*);
170 void didReceiveServerRedirectForProvisionalLoad(blink::WebLocalFrame*);
171 bool didFailProvisionalLoad(blink::WebLocalFrame*, const blink::WebURLError&);
172 void didCommitProvisionalLoad(blink::WebLocalFrame*, const blink::WebHistoryItem&, blink::WebHistoryCommitType);
173 void didReceiveTitle(blink::WebLocalFrame*, const blink::WebString& title, blink::WebTextDirection);
174 void didChangeIcon(blink::WebLocalFrame*, blink::WebIconURL::Type);
175 void didFinishDocumentLoad(blink::WebLocalFrame*);
176 void didHandleOnloadEvents(blink::WebLocalFrame*);
177 void didFailLoad(blink::WebLocalFrame*, const blink::WebURLError&);
178 void didFinishLoad(blink::WebLocalFrame*);
179 void didChangeLocationWithinPage(blink::WebLocalFrame*);
180 void didDetectXSS(blink::WebLocalFrame*, const blink::WebURL& insecureURL, bool didBlockEntirePage);
181 void didDispatchPingLoader(blink::WebLocalFrame*, const blink::WebURL&);
182 void willRequestResource(blink::WebLocalFrame*, const blink::WebCachedURLRequest&);
183 void willSendRequest(blink::WebLocalFrame*, unsigned identifier, blink::WebURLRequest&, const blink::WebURLResponse& redirectResponse);
184 void didReceiveResponse(blink::WebLocalFrame*, unsigned identifier, const blink::WebURLResponse&);
185 void didChangeResourcePriority(blink::WebLocalFrame*, unsigned identifier, const blink::WebURLRequest::Priority&, int intra_priority_value);
186 void didFinishResourceLoad(blink::WebLocalFrame*, unsigned identifier);
187 blink::WebNavigationPolicy decidePolicyForNavigation(blink::WebLocalFrame*, blink::WebDataSource::ExtraData*, const blink::WebURLRequest&, blink::WebNavigationType, blink::WebNavigationPolicy defaultPolicy, bool isRedirect);
188 bool willCheckAndDispatchMessageEvent(blink::WebLocalFrame* sourceFrame, blink::WebFrame* targetFrame, blink::WebSecurityOrigin target, blink::WebDOMMessageEvent);
189 void resetInputMethod();
191 private:
192 template<class, typename, typename> friend class WebFrameTestProxy;
193 void locationChangeDone(blink::WebFrame*);
194 void paintRect(const blink::WebRect&);
195 void paintInvalidatedRegion();
196 void paintPagesWithBoundaries();
197 SkCanvas* canvas();
198 void invalidateAll();
199 void animateNow();
201 blink::WebWidget* webWidget();
203 WebTestRunner::TestInterfaces* m_testInterfaces;
204 ::WebTestRunner::WebTestDelegate* m_delegate;
205 blink::WebWidget* m_webWidget;
207 WebTestRunner::WebTaskList m_taskList;
209 scoped_ptr<WebTestRunner::SpellCheckClient> m_spellcheck;
210 scoped_ptr<WebTestRunner::WebUserMediaClientMock> m_userMediaClient;
212 // Painting.
213 scoped_ptr<SkCanvas> m_canvas;
214 blink::WebRect m_paintRect;
215 bool m_isPainting;
216 bool m_animateScheduled;
217 std::map<unsigned, std::string> m_resourceIdentifierMap;
218 std::map<unsigned, blink::WebURLRequest> m_requestMap;
220 bool m_logConsoleOutput;
221 int m_chooserCount;
223 scoped_ptr<blink::WebMIDIClientMock> m_midiClient;
224 scoped_ptr<WebTestRunner::MockWebSpeechRecognizer> m_speechRecognizer;
225 scoped_ptr<WebTestRunner::MockWebSpeechInputController>
226 m_speechInputController;
228 private:
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 {
236 public:
237 explicit WebTestProxy(T t)
238 : Base(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);
273 Base::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))
298 return 0;
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::WebSpeechInputController* speechInputController(blink::WebSpeechInputListener* listener)
320 return WebTestProxyBase::speechInputController(listener);
322 virtual blink::WebSpeechRecognizer* speechRecognizer()
324 return WebTestProxyBase::speechRecognizer();
326 virtual bool requestPointerLock()
328 return WebTestProxyBase::requestPointerLock();
330 virtual void requestPointerUnlock()
332 WebTestProxyBase::requestPointerUnlock();
334 virtual bool isPointerLocked()
336 return WebTestProxyBase::isPointerLocked();
338 virtual void didFocus()
340 WebTestProxyBase::didFocus();
341 Base::didFocus();
343 virtual void didBlur()
345 WebTestProxyBase::didBlur();
346 Base::didBlur();
348 virtual void setToolTipText(const blink::WebString& text, blink::WebTextDirection hint)
350 WebTestProxyBase::setToolTipText(text, hint);
351 Base::setToolTipText(text, hint);
353 virtual void resetInputMethod()
355 WebTestProxyBase::resetInputMethod();
357 virtual bool runFileChooser(const blink::WebFileChooserParams& params, blink::WebFileChooserCompletion* completion)
359 return WebTestProxyBase::runFileChooser(params, completion);
361 virtual void showValidationMessage(const blink::WebRect& anchorInRootView, const blink::WebString& mainText, const blink::WebString& supplementalText, blink::WebTextDirection hint)
363 WebTestProxyBase::showValidationMessage(anchorInRootView, mainText, supplementalText, hint);
365 virtual void hideValidationMessage()
367 WebTestProxyBase::hideValidationMessage();
369 virtual void moveValidationMessage(const blink::WebRect& anchorInRootView)
371 WebTestProxyBase::moveValidationMessage(anchorInRootView);
373 virtual void postSpellCheckEvent(const blink::WebString& eventName)
375 WebTestProxyBase::postSpellCheckEvent(eventName);
378 private:
379 DISALLOW_COPY_AND_ASSIGN(WebTestProxy);
382 } // namespace content
384 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBTESTPROXY_H_