OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBTESTPROXY_H_ | |
6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBTESTPROXY_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/WebTask.h" | |
16 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallbac
k.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" | |
32 | |
33 class SkCanvas; | |
34 | |
35 namespace blink { | |
36 class WebAXObject; | |
37 class WebAudioDevice; | |
38 class WebCachedURLRequest; | |
39 class WebColorChooser; | |
40 class WebColorChooserClient; | |
41 class WebDataSource; | |
42 class WebDragData; | |
43 class WebFileChooserCompletion; | |
44 class WebFrame; | |
45 class WebImage; | |
46 class WebLocalFrame; | |
47 class WebMIDIAccessor; | |
48 class WebMIDIAccessorClient; | |
49 class WebMIDIClient; | |
50 class WebMIDIClientMock; | |
51 class WebNode; | |
52 class WebNotificationPresenter; | |
53 class WebPlugin; | |
54 class WebRange; | |
55 class WebSerializedScriptValue; | |
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; | |
73 } | |
74 | |
75 namespace content { | |
76 | |
77 class MockWebSpeechRecognizer; | |
78 class RenderFrame; | |
79 class SpellCheckClient; | |
80 class TestInterfaces; | |
81 class WebTestDelegate; | |
82 class WebTestInterfaces; | |
83 class WebUserMediaClientMock; | |
84 | |
85 class WebTestProxyBase : public blink::WebCompositeAndReadbackAsyncCallback { | |
86 public: | |
87 void setInterfaces(WebTestInterfaces*); | |
88 void setDelegate(WebTestDelegate*); | |
89 void setWidget(blink::WebWidget*); | |
90 | |
91 void reset(); | |
92 | |
93 blink::WebSpellCheckClient *spellCheckClient() const; | |
94 blink::WebColorChooser* createColorChooser(blink::WebColorChooserClient*, co
nst blink::WebColor&, const blink::WebVector<blink::WebColorSuggestion>& suggest
ions); | |
95 bool runFileChooser(const blink::WebFileChooserParams&, blink::WebFileChoose
rCompletion*); | |
96 void showValidationMessage(const blink::WebRect& anchorInRootView, const bli
nk::WebString& mainText, const blink::WebString& supplementalText, blink::WebTex
tDirection); | |
97 void hideValidationMessage(); | |
98 void moveValidationMessage(const blink::WebRect& anchorInRootView); | |
99 | |
100 std::string captureTree(bool debugRenderTree); | |
101 SkCanvas* capturePixels(); | |
102 void CapturePixelsForPrinting( | |
103 base::Callback<void(const SkBitmap&)> callback); | |
104 void CapturePixelsAsync(base::Callback<void(const SkBitmap&)> callback); | |
105 | |
106 void setLogConsoleOutput(bool enabled); | |
107 | |
108 // FIXME: Make this private again. | |
109 void scheduleComposite(); | |
110 | |
111 void didOpenChooser(); | |
112 void didCloseChooser(); | |
113 bool isChooserShown(); | |
114 | |
115 void displayAsyncThen(base::Closure callback); | |
116 | |
117 void discardBackingStore(); | |
118 | |
119 blink::WebMIDIClientMock* midiClientMock(); | |
120 MockWebSpeechRecognizer* speechRecognizerMock(); | |
121 | |
122 WebTaskList* taskList() { return &m_taskList; } | |
123 | |
124 blink::WebView* webView(); | |
125 | |
126 void didForceResize(); | |
127 | |
128 void postSpellCheckEvent(const blink::WebString& eventName); | |
129 | |
130 // WebCompositeAndReadbackAsyncCallback implementation. | |
131 virtual void didCompositeAndReadback(const SkBitmap& bitmap); | |
132 | |
133 protected: | |
134 WebTestProxyBase(); | |
135 ~WebTestProxyBase(); | |
136 | |
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::WebNa
vigationPolicy, bool suppressOpener); | |
151 blink::WebPlugin* createPlugin(blink::WebLocalFrame*, const blink::WebPlugin
Params&); | |
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::WebSpeechRecognizer* speechRecognizer(); | |
160 bool requestPointerLock(); | |
161 void requestPointerUnlock(); | |
162 bool isPointerLocked(); | |
163 void didFocus(); | |
164 void didBlur(); | |
165 void setToolTipText(const blink::WebString&, blink::WebTextDirection); | |
166 void didAddMessageToConsole(const blink::WebConsoleMessage&, const blink::We
bString& sourceName, unsigned sourceLine); | |
167 void loadURLExternally(blink::WebLocalFrame* frame, const blink::WebURLReque
st& request, blink::WebNavigationPolicy policy, const blink::WebString& suggeste
d_name); | |
168 void didStartProvisionalLoad(blink::WebLocalFrame*); | |
169 void didReceiveServerRedirectForProvisionalLoad(blink::WebLocalFrame*); | |
170 bool didFailProvisionalLoad(blink::WebLocalFrame*, const blink::WebURLError&
); | |
171 void didCommitProvisionalLoad(blink::WebLocalFrame*, const blink::WebHistory
Item&, blink::WebHistoryCommitType); | |
172 void didReceiveTitle(blink::WebLocalFrame*, const blink::WebString& title, b
link::WebTextDirection); | |
173 void didChangeIcon(blink::WebLocalFrame*, blink::WebIconURL::Type); | |
174 void didFinishDocumentLoad(blink::WebLocalFrame*); | |
175 void didHandleOnloadEvents(blink::WebLocalFrame*); | |
176 void didFailLoad(blink::WebLocalFrame*, const blink::WebURLError&); | |
177 void didFinishLoad(blink::WebLocalFrame*); | |
178 void didChangeLocationWithinPage(blink::WebLocalFrame*); | |
179 void didDetectXSS(blink::WebLocalFrame*, const blink::WebURL& insecureURL, b
ool didBlockEntirePage); | |
180 void didDispatchPingLoader(blink::WebLocalFrame*, const blink::WebURL&); | |
181 void willRequestResource(blink::WebLocalFrame*, const blink::WebCachedURLReq
uest&); | |
182 void willSendRequest(blink::WebLocalFrame*, unsigned identifier, blink::WebU
RLRequest&, const blink::WebURLResponse& redirectResponse); | |
183 void didReceiveResponse(blink::WebLocalFrame*, unsigned identifier, const bl
ink::WebURLResponse&); | |
184 void didChangeResourcePriority(blink::WebLocalFrame*, unsigned identifier, c
onst blink::WebURLRequest::Priority&, int intra_priority_value); | |
185 void didFinishResourceLoad(blink::WebLocalFrame*, unsigned identifier); | |
186 blink::WebNavigationPolicy decidePolicyForNavigation(blink::WebLocalFrame*,
blink::WebDataSource::ExtraData*, const blink::WebURLRequest&, blink::WebNavigat
ionType, blink::WebNavigationPolicy defaultPolicy, bool isRedirect); | |
187 bool willCheckAndDispatchMessageEvent(blink::WebLocalFrame* sourceFrame, bli
nk::WebFrame* targetFrame, blink::WebSecurityOrigin target, blink::WebDOMMessage
Event); | |
188 void resetInputMethod(); | |
189 | |
190 private: | |
191 template<class, typename, typename> friend class WebFrameTestProxy; | |
192 void locationChangeDone(blink::WebFrame*); | |
193 void paintRect(const blink::WebRect&); | |
194 void paintInvalidatedRegion(); | |
195 void paintPagesWithBoundaries(); | |
196 SkCanvas* canvas(); | |
197 void invalidateAll(); | |
198 void animateNow(); | |
199 void DrawSelectionRect(SkCanvas* canvas); | |
200 void DisplayForSoftwareMode(const base::Closure& callback); | |
201 void DidDisplayAsync(const base::Closure& callback, const SkBitmap& bitmap); | |
202 | |
203 blink::WebWidget* webWidget(); | |
204 | |
205 TestInterfaces* m_testInterfaces; | |
206 WebTestDelegate* m_delegate; | |
207 blink::WebWidget* m_webWidget; | |
208 | |
209 WebTaskList m_taskList; | |
210 | |
211 scoped_ptr<SpellCheckClient> m_spellcheck; | |
212 scoped_ptr<WebUserMediaClientMock> m_userMediaClient; | |
213 | |
214 // Painting. | |
215 scoped_ptr<SkCanvas> m_canvas; | |
216 blink::WebRect m_paintRect; | |
217 bool m_isPainting; | |
218 bool m_animateScheduled; | |
219 std::map<unsigned, std::string> m_resourceIdentifierMap; | |
220 std::map<unsigned, blink::WebURLRequest> m_requestMap; | |
221 std::deque<base::Callback<void(const SkBitmap&)> > | |
222 m_compositeAndReadbackCallbacks; | |
223 | |
224 bool m_logConsoleOutput; | |
225 int m_chooserCount; | |
226 | |
227 scoped_ptr<blink::WebMIDIClientMock> m_midiClient; | |
228 scoped_ptr<MockWebSpeechRecognizer> m_speechRecognizer; | |
229 | |
230 private: | |
231 DISALLOW_COPY_AND_ASSIGN(WebTestProxyBase); | |
232 }; | |
233 | |
234 // Use this template to inject methods into your WebViewClient/WebFrameClient | |
235 // implementation required for the running layout tests. | |
236 template<class Base, typename T> | |
237 class WebTestProxy : public Base, public WebTestProxyBase { | |
238 public: | |
239 explicit WebTestProxy(T t) | |
240 : Base(t) | |
241 { | |
242 } | |
243 | |
244 virtual ~WebTestProxy() { } | |
245 | |
246 // WebViewClient implementation. | |
247 virtual void didInvalidateRect(const blink::WebRect& rect) | |
248 { | |
249 WebTestProxyBase::didInvalidateRect(rect); | |
250 } | |
251 virtual void didScrollRect(int dx, int dy, const blink::WebRect& clipRect) | |
252 { | |
253 WebTestProxyBase::didScrollRect(dx, dy, clipRect); | |
254 } | |
255 virtual void scheduleComposite() | |
256 { | |
257 WebTestProxyBase::scheduleComposite(); | |
258 } | |
259 virtual void scheduleAnimation() | |
260 { | |
261 WebTestProxyBase::scheduleAnimation(); | |
262 } | |
263 virtual bool isCompositorFramePending() const | |
264 { | |
265 return WebTestProxyBase::isCompositorFramePending(); | |
266 } | |
267 virtual void setWindowRect(const blink::WebRect& rect) | |
268 { | |
269 WebTestProxyBase::setWindowRect(rect); | |
270 Base::setWindowRect(rect); | |
271 } | |
272 virtual void show(blink::WebNavigationPolicy policy) | |
273 { | |
274 WebTestProxyBase::show(policy); | |
275 Base::show(policy); | |
276 } | |
277 virtual void didAutoResize(const blink::WebSize& newSize) | |
278 { | |
279 WebTestProxyBase::didAutoResize(newSize); | |
280 Base::didAutoResize(newSize); | |
281 } | |
282 virtual void postAccessibilityEvent(const blink::WebAXObject& object, blink:
:WebAXEvent event) | |
283 { | |
284 WebTestProxyBase::postAccessibilityEvent(object, event); | |
285 Base::postAccessibilityEvent(object, event); | |
286 } | |
287 virtual void startDragging(blink::WebLocalFrame* frame, const blink::WebDrag
Data& data, blink::WebDragOperationsMask mask, const blink::WebImage& image, con
st blink::WebPoint& point) | |
288 { | |
289 WebTestProxyBase::startDragging(frame, data, mask, image, point); | |
290 // Don't forward this call to Base because we don't want to do a real dr
ag-and-drop. | |
291 } | |
292 virtual void didChangeContents() | |
293 { | |
294 WebTestProxyBase::didChangeContents(); | |
295 Base::didChangeContents(); | |
296 } | |
297 virtual blink::WebView* createView(blink::WebLocalFrame* creator, const blin
k::WebURLRequest& request, const blink::WebWindowFeatures& features, const blink
::WebString& frameName, blink::WebNavigationPolicy policy, bool suppressOpener) | |
298 { | |
299 if (!WebTestProxyBase::createView(creator, request, features, frameName,
policy, suppressOpener)) | |
300 return 0; | |
301 return Base::createView(creator, request, features, frameName, policy, s
uppressOpener); | |
302 } | |
303 virtual void setStatusText(const blink::WebString& text) | |
304 { | |
305 WebTestProxyBase::setStatusText(text); | |
306 Base::setStatusText(text); | |
307 } | |
308 virtual blink::WebUserMediaClient* userMediaClient() | |
309 { | |
310 return WebTestProxyBase::userMediaClient(); | |
311 } | |
312 virtual void printPage(blink::WebLocalFrame* frame) | |
313 { | |
314 WebTestProxyBase::printPage(frame); | |
315 } | |
316 virtual blink::WebMIDIClient* webMIDIClient() | |
317 { | |
318 return WebTestProxyBase::webMIDIClient(); | |
319 } | |
320 virtual blink::WebSpeechRecognizer* speechRecognizer() | |
321 { | |
322 return WebTestProxyBase::speechRecognizer(); | |
323 } | |
324 virtual bool requestPointerLock() | |
325 { | |
326 return WebTestProxyBase::requestPointerLock(); | |
327 } | |
328 virtual void requestPointerUnlock() | |
329 { | |
330 WebTestProxyBase::requestPointerUnlock(); | |
331 } | |
332 virtual bool isPointerLocked() | |
333 { | |
334 return WebTestProxyBase::isPointerLocked(); | |
335 } | |
336 virtual void didFocus() | |
337 { | |
338 WebTestProxyBase::didFocus(); | |
339 Base::didFocus(); | |
340 } | |
341 virtual void didBlur() | |
342 { | |
343 WebTestProxyBase::didBlur(); | |
344 Base::didBlur(); | |
345 } | |
346 virtual void setToolTipText(const blink::WebString& text, blink::WebTextDire
ction hint) | |
347 { | |
348 WebTestProxyBase::setToolTipText(text, hint); | |
349 Base::setToolTipText(text, hint); | |
350 } | |
351 virtual void resetInputMethod() | |
352 { | |
353 WebTestProxyBase::resetInputMethod(); | |
354 } | |
355 virtual bool runFileChooser(const blink::WebFileChooserParams& params, blink
::WebFileChooserCompletion* completion) | |
356 { | |
357 return WebTestProxyBase::runFileChooser(params, completion); | |
358 } | |
359 virtual void showValidationMessage(const blink::WebRect& anchorInRootView, c
onst blink::WebString& mainText, const blink::WebString& supplementalText, blink
::WebTextDirection hint) | |
360 { | |
361 WebTestProxyBase::showValidationMessage(anchorInRootView, mainText, supp
lementalText, hint); | |
362 } | |
363 virtual void hideValidationMessage() | |
364 { | |
365 WebTestProxyBase::hideValidationMessage(); | |
366 } | |
367 virtual void moveValidationMessage(const blink::WebRect& anchorInRootView) | |
368 { | |
369 WebTestProxyBase::moveValidationMessage(anchorInRootView); | |
370 } | |
371 virtual void postSpellCheckEvent(const blink::WebString& eventName) | |
372 { | |
373 WebTestProxyBase::postSpellCheckEvent(eventName); | |
374 } | |
375 | |
376 private: | |
377 DISALLOW_COPY_AND_ASSIGN(WebTestProxy); | |
378 }; | |
379 | |
380 } // namespace content | |
381 | |
382 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBTESTPROXY_H_ | |
OLD | NEW |