Upstream version 7.36.149.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 <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/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"
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*, 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);
99
100     std::string captureTree(bool debugRenderTree);
101     SkCanvas* capturePixels();
102     void CapturePixelsAsync(base::Callback<void(const SkBitmap&)> callback);
103
104     void setLogConsoleOutput(bool enabled);
105
106     // FIXME: Make this private again.
107     void scheduleComposite();
108
109     void didOpenChooser();
110     void didCloseChooser();
111     bool isChooserShown();
112
113     void displayAsyncThen(base::Closure callback);
114
115     void discardBackingStore();
116
117     blink::WebMIDIClientMock* midiClientMock();
118     MockWebSpeechRecognizer* speechRecognizerMock();
119
120     WebTaskList* taskList() { return &m_taskList; }
121
122     blink::WebView* webView();
123
124     void didForceResize();
125
126     void postSpellCheckEvent(const blink::WebString& eventName);
127
128     // WebCompositeAndReadbackAsyncCallback implementation.
129     virtual void didCompositeAndReadback(const SkBitmap& bitmap);
130
131 protected:
132     WebTestProxyBase();
133     ~WebTestProxyBase();
134
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();
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 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();
187
188 private:
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();
194     SkCanvas* canvas();
195     void invalidateAll();
196     void animateNow();
197     void DrawSelectionRect(SkCanvas* canvas);
198     void DisplayForSoftwareMode(const base::Closure& callback);
199     void DidDisplayAsync(const base::Closure& callback, const SkBitmap& bitmap);
200
201     blink::WebWidget* webWidget();
202
203     TestInterfaces* m_testInterfaces;
204     WebTestDelegate* m_delegate;
205     blink::WebWidget* m_webWidget;
206
207     WebTaskList m_taskList;
208
209     scoped_ptr<SpellCheckClient> m_spellcheck;
210     scoped_ptr<WebUserMediaClientMock> m_userMediaClient;
211
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;
219     std::deque<base::Callback<void(const SkBitmap&)> >
220         m_compositeAndReadbackCallbacks;
221
222     bool m_logConsoleOutput;
223     int m_chooserCount;
224
225     scoped_ptr<blink::WebMIDIClientMock> m_midiClient;
226     scoped_ptr<MockWebSpeechRecognizer> m_speechRecognizer;
227
228 private:
229     DISALLOW_COPY_AND_ASSIGN(WebTestProxyBase);
230 };
231
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)
239     {
240     }
241
242     virtual ~WebTestProxy() { }
243
244     // WebViewClient implementation.
245     virtual void didInvalidateRect(const blink::WebRect& rect)
246     {
247         WebTestProxyBase::didInvalidateRect(rect);
248     }
249     virtual void didScrollRect(int dx, int dy, const blink::WebRect& clipRect)
250     {
251         WebTestProxyBase::didScrollRect(dx, dy, clipRect);
252     }
253     virtual void scheduleComposite()
254     {
255         WebTestProxyBase::scheduleComposite();
256     }
257     virtual void scheduleAnimation()
258     {
259         WebTestProxyBase::scheduleAnimation();
260     }
261     virtual bool isCompositorFramePending() const
262     {
263         return WebTestProxyBase::isCompositorFramePending();
264     }
265     virtual void setWindowRect(const blink::WebRect& rect)
266     {
267         WebTestProxyBase::setWindowRect(rect);
268         Base::setWindowRect(rect);
269     }
270     virtual void show(blink::WebNavigationPolicy policy)
271     {
272         WebTestProxyBase::show(policy);
273         Base::show(policy);
274     }
275     virtual void didAutoResize(const blink::WebSize& newSize)
276     {
277         WebTestProxyBase::didAutoResize(newSize);
278         Base::didAutoResize(newSize);
279     }
280     virtual void postAccessibilityEvent(const blink::WebAXObject& object, blink::WebAXEvent event)
281     {
282         WebTestProxyBase::postAccessibilityEvent(object, event);
283         Base::postAccessibilityEvent(object, event);
284     }
285     virtual void startDragging(blink::WebLocalFrame* frame, const blink::WebDragData& data, blink::WebDragOperationsMask mask, const blink::WebImage& image, const blink::WebPoint& point)
286     {
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.
289     }
290     virtual void didChangeContents()
291     {
292         WebTestProxyBase::didChangeContents();
293         Base::didChangeContents();
294     }
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)
296     {
297         if (!WebTestProxyBase::createView(creator, request, features, frameName, policy, suppressOpener))
298             return 0;
299         return Base::createView(creator, request, features, frameName, policy, suppressOpener);
300     }
301     virtual void setStatusText(const blink::WebString& text)
302     {
303         WebTestProxyBase::setStatusText(text);
304         Base::setStatusText(text);
305     }
306     virtual blink::WebUserMediaClient* userMediaClient()
307     {
308         return WebTestProxyBase::userMediaClient();
309     }
310     virtual void printPage(blink::WebLocalFrame* frame)
311     {
312         WebTestProxyBase::printPage(frame);
313     }
314     virtual blink::WebMIDIClient* webMIDIClient()
315     {
316         return WebTestProxyBase::webMIDIClient();
317     }
318     virtual blink::WebSpeechRecognizer* speechRecognizer()
319     {
320         return WebTestProxyBase::speechRecognizer();
321     }
322     virtual bool requestPointerLock()
323     {
324         return WebTestProxyBase::requestPointerLock();
325     }
326     virtual void requestPointerUnlock()
327     {
328         WebTestProxyBase::requestPointerUnlock();
329     }
330     virtual bool isPointerLocked()
331     {
332         return WebTestProxyBase::isPointerLocked();
333     }
334     virtual void didFocus()
335     {
336         WebTestProxyBase::didFocus();
337         Base::didFocus();
338     }
339     virtual void didBlur()
340     {
341         WebTestProxyBase::didBlur();
342         Base::didBlur();
343     }
344     virtual void setToolTipText(const blink::WebString& text, blink::WebTextDirection hint)
345     {
346         WebTestProxyBase::setToolTipText(text, hint);
347         Base::setToolTipText(text, hint);
348     }
349     virtual void resetInputMethod()
350     {
351         WebTestProxyBase::resetInputMethod();
352     }
353     virtual bool runFileChooser(const blink::WebFileChooserParams& params, blink::WebFileChooserCompletion* completion)
354     {
355         return WebTestProxyBase::runFileChooser(params, completion);
356     }
357     virtual void showValidationMessage(const blink::WebRect& anchorInRootView, const blink::WebString& mainText, const blink::WebString& supplementalText, blink::WebTextDirection hint)
358     {
359         WebTestProxyBase::showValidationMessage(anchorInRootView, mainText, supplementalText, hint);
360     }
361     virtual void hideValidationMessage()
362     {
363         WebTestProxyBase::hideValidationMessage();
364     }
365     virtual void moveValidationMessage(const blink::WebRect& anchorInRootView)
366     {
367         WebTestProxyBase::moveValidationMessage(anchorInRootView);
368     }
369     virtual void postSpellCheckEvent(const blink::WebString& eventName)
370     {
371         WebTestProxyBase::postSpellCheckEvent(eventName);
372     }
373
374 private:
375     DISALLOW_COPY_AND_ASSIGN(WebTestProxy);
376 };
377
378 }  // namespace content
379
380 #endif  // CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBTESTPROXY_H_