Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / content / shell / renderer / test_runner / WebTestProxy.h
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 <map>
9 #include <string>
10
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"
27
28 namespace blink {
29 class WebAXObject;
30 class WebAudioDevice;
31 class WebCachedURLRequest;
32 class WebColorChooser;
33 class WebColorChooserClient;
34 class WebDataSource;
35 class WebDragData;
36 class WebFileChooserCompletion;
37 class WebFrame;
38 class WebImage;
39 class WebMIDIAccessor;
40 class WebMIDIAccessorClient;
41 class WebMIDIClient;
42 class WebMIDIClientMock;
43 class WebNode;
44 class WebNotificationPresenter;
45 class WebPlugin;
46 class WebRange;
47 class WebSerializedScriptValue;
48 class WebSpeechInputController;
49 class WebSpeechInputListener;
50 class WebSpeechRecognizer;
51 class WebSpellCheckClient;
52 class WebString;
53 class WebURL;
54 class WebURLResponse;
55 class WebUserMediaClient;
56 class WebView;
57 class WebWidget;
58 struct WebColorSuggestion;
59 struct WebConsoleMessage;
60 struct WebContextMenuData;
61 struct WebFileChooserParams;
62 struct WebPluginParams;
63 struct WebPoint;
64 struct WebSize;
65 struct WebWindowFeatures;
66 typedef unsigned WebColor;
67 }
68
69 namespace content {
70 class RenderFrame;
71 }
72
73 class SkCanvas;
74
75 namespace WebTestRunner {
76
77 class MockWebSpeechInputController;
78 class MockWebSpeechRecognizer;
79 class SpellCheckClient;
80 class TestInterfaces;
81 class WebTestDelegate;
82 class WebTestInterfaces;
83 class WebTestRunner;
84 class WebUserMediaClientMock;
85
86 class WebTestProxyBase {
87 public:
88     void setInterfaces(WebTestInterfaces*);
89     void setDelegate(WebTestDelegate*);
90     void setWidget(blink::WebWidget*);
91
92     void reset();
93
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);
101
102     std::string captureTree(bool debugRenderTree);
103     SkCanvas* capturePixels();
104
105     void setLogConsoleOutput(bool enabled);
106
107     // FIXME: Make this private again.
108     void scheduleComposite();
109
110     void didOpenChooser();
111     void didCloseChooser();
112     bool isChooserShown();
113
114     void display();
115     void displayInvalidatedRegion();
116     void discardBackingStore();
117
118     blink::WebMIDIClientMock* midiClientMock();
119     MockWebSpeechInputController* speechInputControllerMock();
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 protected:
131     WebTestProxyBase();
132     ~WebTestProxyBase();
133
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();
161     void didFocus();
162     void didBlur();
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&);
169
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();
191
192 private:
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();
198     SkCanvas* canvas();
199     void displayRepaintMask();
200     void invalidateAll();
201     void animateNow();
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
222     bool m_logConsoleOutput;
223     int m_chooserCount;
224
225     scoped_ptr<blink::WebMIDIClientMock> m_midiClient;
226     scoped_ptr<MockWebSpeechRecognizer> m_speechRecognizer;
227     scoped_ptr<MockWebSpeechInputController> m_speechInputController;
228
229 private:
230     DISALLOW_COPY_AND_ASSIGN(WebTestProxyBase);
231 };
232
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 {
237 public:
238     explicit WebTestProxy(T t)
239         : Base(t)
240     {
241     }
242
243     virtual ~WebTestProxy() { }
244
245     // WebViewClient implementation.
246     virtual void didInvalidateRect(const blink::WebRect& rect)
247     {
248         WebTestProxyBase::didInvalidateRect(rect);
249     }
250     virtual void didScrollRect(int dx, int dy, const blink::WebRect& clipRect)
251     {
252         WebTestProxyBase::didScrollRect(dx, dy, clipRect);
253     }
254     virtual void scheduleComposite()
255     {
256         WebTestProxyBase::scheduleComposite();
257     }
258     virtual void scheduleAnimation()
259     {
260         WebTestProxyBase::scheduleAnimation();
261     }
262     virtual bool isCompositorFramePending() const
263     {
264         return WebTestProxyBase::isCompositorFramePending();
265     }
266     virtual void setWindowRect(const blink::WebRect& rect)
267     {
268         WebTestProxyBase::setWindowRect(rect);
269         Base::setWindowRect(rect);
270     }
271     virtual void show(blink::WebNavigationPolicy policy)
272     {
273         WebTestProxyBase::show(policy);
274         Base::show(policy);
275     }
276     virtual void didAutoResize(const blink::WebSize& newSize)
277     {
278         WebTestProxyBase::didAutoResize(newSize);
279         Base::didAutoResize(newSize);
280     }
281     virtual void postAccessibilityEvent(const blink::WebAXObject& object, blink::WebAXEvent event)
282     {
283         WebTestProxyBase::postAccessibilityEvent(object, event);
284         Base::postAccessibilityEvent(object, event);
285     }
286     virtual void startDragging(blink::WebFrame* frame, const blink::WebDragData& data, blink::WebDragOperationsMask mask, const blink::WebImage& image, const blink::WebPoint& point)
287     {
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.
290     }
291     virtual void didChangeSelection(bool isEmptySelection)
292     {
293         WebTestProxyBase::didChangeSelection(isEmptySelection);
294         Base::didChangeSelection(isEmptySelection);
295     }
296     virtual void didChangeContents()
297     {
298         WebTestProxyBase::didChangeContents();
299         Base::didChangeContents();
300     }
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)
302     {
303         if (!WebTestProxyBase::createView(creator, request, features, frameName, policy, suppressOpener))
304             return 0;
305         return Base::createView(creator, request, features, frameName, policy, suppressOpener);
306     }
307     virtual void setStatusText(const blink::WebString& text)
308     {
309         WebTestProxyBase::setStatusText(text);
310         Base::setStatusText(text);
311     }
312     virtual void didStopLoading()
313     {
314         WebTestProxyBase::didStopLoading();
315         Base::didStopLoading();
316     }
317     virtual void showContextMenu(blink::WebFrame* frame, const blink::WebContextMenuData& contextMenuData)
318     {
319         WebTestProxyBase::showContextMenu(frame, contextMenuData);
320         Base::showContextMenu(frame, contextMenuData);
321     }
322     virtual blink::WebUserMediaClient* userMediaClient()
323     {
324         return WebTestProxyBase::userMediaClient();
325     }
326     virtual void printPage(blink::WebFrame* frame)
327     {
328         WebTestProxyBase::printPage(frame);
329     }
330     virtual blink::WebNotificationPresenter* notificationPresenter()
331     {
332         return WebTestProxyBase::notificationPresenter();
333     }
334     virtual blink::WebMIDIClient* webMIDIClient()
335     {
336         return WebTestProxyBase::webMIDIClient();
337     }
338     virtual blink::WebSpeechInputController* speechInputController(blink::WebSpeechInputListener* listener)
339     {
340         return WebTestProxyBase::speechInputController(listener);
341     }
342     virtual blink::WebSpeechRecognizer* speechRecognizer()
343     {
344         return WebTestProxyBase::speechRecognizer();
345     }
346     virtual bool requestPointerLock()
347     {
348         return WebTestProxyBase::requestPointerLock();
349     }
350     virtual void requestPointerUnlock()
351     {
352         WebTestProxyBase::requestPointerUnlock();
353     }
354     virtual bool isPointerLocked()
355     {
356         return WebTestProxyBase::isPointerLocked();
357     }
358     virtual void didFocus()
359     {
360         WebTestProxyBase::didFocus();
361         Base::didFocus();
362     }
363     virtual void didBlur()
364     {
365         WebTestProxyBase::didBlur();
366         Base::didBlur();
367     }
368     virtual void setToolTipText(const blink::WebString& text, blink::WebTextDirection hint)
369     {
370         WebTestProxyBase::setToolTipText(text, hint);
371         Base::setToolTipText(text, hint);
372     }
373     virtual void resetInputMethod()
374     {
375         WebTestProxyBase::resetInputMethod();
376     }
377
378     virtual void didStartProvisionalLoad(blink::WebFrame* frame)
379     {
380         WebTestProxyBase::didStartProvisionalLoad(frame);
381         Base::didStartProvisionalLoad(frame);
382     }
383     virtual void didReceiveServerRedirectForProvisionalLoad(blink::WebFrame* frame)
384     {
385         WebTestProxyBase::didReceiveServerRedirectForProvisionalLoad(frame);
386         Base::didReceiveServerRedirectForProvisionalLoad(frame);
387     }
388     virtual void didFailProvisionalLoad(blink::WebFrame* frame, const blink::WebURLError& error)
389     {
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))
393             return;
394         Base::didFailProvisionalLoad(frame, error);
395     }
396     virtual void didCommitProvisionalLoad(blink::WebFrame* frame, bool isNewNavigation)
397     {
398         WebTestProxyBase::didCommitProvisionalLoad(frame, isNewNavigation);
399         Base::didCommitProvisionalLoad(frame, isNewNavigation);
400     }
401     virtual void didReceiveTitle(blink::WebFrame* frame, const blink::WebString& title, blink::WebTextDirection direction)
402     {
403         WebTestProxyBase::didReceiveTitle(frame, title, direction);
404         Base::didReceiveTitle(frame, title, direction);
405     }
406     virtual void didChangeIcon(blink::WebFrame* frame, blink::WebIconURL::Type iconType)
407     {
408         WebTestProxyBase::didChangeIcon(frame, iconType);
409         Base::didChangeIcon(frame, iconType);
410     }
411     virtual void didFinishDocumentLoad(blink::WebFrame* frame)
412     {
413         WebTestProxyBase::didFinishDocumentLoad(frame);
414         Base::didFinishDocumentLoad(frame);
415     }
416     virtual void didHandleOnloadEvents(blink::WebFrame* frame)
417     {
418         WebTestProxyBase::didHandleOnloadEvents(frame);
419         Base::didHandleOnloadEvents(frame);
420     }
421     virtual void didFailLoad(blink::WebFrame* frame, const blink::WebURLError& error)
422     {
423         WebTestProxyBase::didFailLoad(frame, error);
424         Base::didFailLoad(frame, error);
425     }
426     virtual void didFinishLoad(blink::WebFrame* frame)
427     {
428         WebTestProxyBase::didFinishLoad(frame);
429         Base::didFinishLoad(frame);
430     }
431     virtual void didDetectXSS(blink::WebFrame* frame, const blink::WebURL& insecureURL, bool didBlockEntirePage)
432     {
433         WebTestProxyBase::didDetectXSS(frame, insecureURL, didBlockEntirePage);
434         Base::didDetectXSS(frame, insecureURL, didBlockEntirePage);
435     }
436     virtual void willRequestResource(blink::WebFrame* frame, const blink::WebCachedURLRequest& request)
437     {
438         WebTestProxyBase::willRequestResource(frame, request);
439         Base::willRequestResource(frame, request);
440     }
441     virtual void willSendRequest(blink::WebFrame* frame, unsigned identifier, blink::WebURLRequest& request, const blink::WebURLResponse& redirectResponse)
442     {
443         WebTestProxyBase::willSendRequest(frame, identifier, request, redirectResponse);
444         Base::willSendRequest(frame, identifier, request, redirectResponse);
445     }
446     virtual void didReceiveResponse(blink::WebFrame* frame, unsigned identifier, const blink::WebURLResponse& response)
447     {
448         WebTestProxyBase::didReceiveResponse(frame, identifier, response);
449         Base::didReceiveResponse(frame, identifier, response);
450     }
451     virtual void didChangeResourcePriority(blink::WebFrame* frame, unsigned identifier, const blink::WebURLRequest::Priority& priority)
452     {
453         WebTestProxyBase::didChangeResourcePriority(frame, identifier, priority);
454         Base::didChangeResourcePriority(frame, identifier, priority);
455     }
456     virtual void didFinishResourceLoad(blink::WebFrame* frame, unsigned identifier)
457     {
458         WebTestProxyBase::didFinishResourceLoad(frame, identifier);
459         Base::didFinishResourceLoad(frame, identifier);
460     }
461     virtual void didAddMessageToConsole(const blink::WebConsoleMessage& message, const blink::WebString& sourceName, unsigned sourceLine, const blink::WebString& stackTrace)
462     {
463         WebTestProxyBase::didAddMessageToConsole(message, sourceName, sourceLine);
464         Base::didAddMessageToConsole(message, sourceName, sourceLine, stackTrace);
465     }
466     virtual void runModalAlertDialog(blink::WebFrame* frame, const blink::WebString& message)
467     {
468         WebTestProxyBase::runModalAlertDialog(frame, message);
469         Base::runModalAlertDialog(frame, message);
470     }
471     virtual bool runModalConfirmDialog(blink::WebFrame* frame, const blink::WebString& message)
472     {
473         WebTestProxyBase::runModalConfirmDialog(frame, message);
474         return Base::runModalConfirmDialog(frame, message);
475     }
476     virtual bool runModalPromptDialog(blink::WebFrame* frame, const blink::WebString& message, const blink::WebString& defaultValue, blink::WebString* actualValue)
477     {
478         WebTestProxyBase::runModalPromptDialog(frame, message, defaultValue, actualValue);
479         return Base::runModalPromptDialog(frame, message, defaultValue, actualValue);
480     }
481     virtual bool runModalBeforeUnloadDialog(blink::WebFrame* frame, const blink::WebString& message)
482     {
483         return WebTestProxyBase::runModalBeforeUnloadDialog(frame, message);
484     }
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)
486     {
487         blink::WebNavigationPolicy policy = WebTestProxyBase::decidePolicyForNavigation(frame, extraData, request, type, defaultPolicy, isRedirect);
488         if (policy == blink::WebNavigationPolicyIgnore)
489             return policy;
490         return Base::DecidePolicyForNavigation(render_frame, frame, extraData, request, type, defaultPolicy, isRedirect);
491     }
492     virtual bool willCheckAndDispatchMessageEvent(blink::WebFrame* sourceFrame, blink::WebFrame* targetFrame, blink::WebSecurityOrigin target, blink::WebDOMMessageEvent event)
493     {
494         if (WebTestProxyBase::willCheckAndDispatchMessageEvent(sourceFrame, targetFrame, target, event))
495             return true;
496         return Base::willCheckAndDispatchMessageEvent(sourceFrame, targetFrame, target, event);
497     }
498     virtual blink::WebColorChooser* createColorChooser(blink::WebColorChooserClient* client, const blink::WebColor& color)
499     {
500         return WebTestProxyBase::createColorChooser(client, color);
501     }
502     virtual blink::WebColorChooser* createColorChooser(blink::WebColorChooserClient* client, const blink::WebColor& color, const blink::WebVector<blink::WebColorSuggestion>& suggestions)
503     {
504         return WebTestProxyBase::createColorChooser(client, color, suggestions);
505     }
506     virtual bool runFileChooser(const blink::WebFileChooserParams& params, blink::WebFileChooserCompletion* completion)
507     {
508         return WebTestProxyBase::runFileChooser(params, completion);
509     }
510     virtual void showValidationMessage(const blink::WebRect& anchorInRootView, const blink::WebString& mainText, const blink::WebString& supplementalText, blink::WebTextDirection hint)
511     {
512         WebTestProxyBase::showValidationMessage(anchorInRootView, mainText, supplementalText, hint);
513     }
514     virtual void hideValidationMessage()
515     {
516         WebTestProxyBase::hideValidationMessage();
517     }
518     virtual void moveValidationMessage(const blink::WebRect& anchorInRootView)
519     {
520         WebTestProxyBase::moveValidationMessage(anchorInRootView);
521     }
522     virtual void postSpellCheckEvent(const blink::WebString& eventName)
523     {
524         WebTestProxyBase::postSpellCheckEvent(eventName);
525     }
526
527 private:
528     DISALLOW_COPY_AND_ASSIGN(WebTestProxy);
529 };
530
531 }
532
533 #endif  // CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBTESTPROXY_H_