Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / shell / renderer / test_runner / WebFrameTestProxy.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_WEBFRAMETESTPROXY_H_
6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBFRAMETESTPROXY_H_
7
8 #include "base/basictypes.h"
9 #include "content/shell/renderer/test_runner/test_runner.h"
10 #include "content/shell/renderer/test_runner/TestInterfaces.h"
11 #include "content/shell/renderer/test_runner/WebTestDelegate.h"
12 #include "content/shell/renderer/test_runner/WebTestProxy.h"
13 #include "third_party/WebKit/public/platform/WebString.h"
14
15 namespace content {
16
17 // Templetized wrapper around RenderFrameImpl objects, which implement
18 // the WebFrameClient interface.
19 template<class Base, typename P, typename R>
20 class WebFrameTestProxy : public Base {
21 public:
22     WebFrameTestProxy(P p, R r)
23         : Base(p, r)
24         , m_baseProxy(0) { }
25
26     virtual ~WebFrameTestProxy() { }
27
28     void setBaseProxy(WebTestProxyBase* proxy)
29     {
30         m_baseProxy = proxy;
31     }
32
33     blink::WebPlugin* createPlugin(blink::WebLocalFrame* frame, const blink::WebPluginParams& params)
34     {
35         blink::WebPlugin* plugin = m_baseProxy->createPlugin(frame, params);
36         if (plugin)
37             return plugin;
38         return Base::createPlugin(frame, params);
39     }
40
41     // WebFrameClient implementation.
42     virtual void didAddMessageToConsole(const blink::WebConsoleMessage& message, const blink::WebString& sourceName, unsigned sourceLine, const blink::WebString& stackTrace)
43     {
44         m_baseProxy->didAddMessageToConsole(message, sourceName, sourceLine);
45         Base::didAddMessageToConsole(message, sourceName, sourceLine, stackTrace);
46     }
47     virtual bool canCreatePluginWithoutRenderer(const blink::WebString& mimeType)
48     {
49         using blink::WebString;
50
51         const CR_DEFINE_STATIC_LOCAL(WebString, suffix, ("-can-create-without-renderer"));
52         return mimeType.utf8().find(suffix.utf8()) != std::string::npos;
53     }
54     virtual void loadURLExternally(blink::WebLocalFrame* frame, const blink::WebURLRequest& request, blink::WebNavigationPolicy policy, const blink::WebString& suggested_name)
55     {
56         m_baseProxy->loadURLExternally(frame, request, policy, suggested_name);
57         Base::loadURLExternally(frame, request, policy, suggested_name);
58     }
59     virtual void didStartProvisionalLoad(blink::WebLocalFrame* frame)
60     {
61         m_baseProxy->didStartProvisionalLoad(frame);
62         Base::didStartProvisionalLoad(frame);
63     }
64     virtual void didReceiveServerRedirectForProvisionalLoad(blink::WebLocalFrame* frame)
65     {
66         m_baseProxy->didReceiveServerRedirectForProvisionalLoad(frame);
67         Base::didReceiveServerRedirectForProvisionalLoad(frame);
68     }
69     virtual void didFailProvisionalLoad(blink::WebLocalFrame* frame, const blink::WebURLError& error)
70     {
71         // If the test finished, don't notify the embedder of the failed load,
72         // as we already destroyed the document loader.
73         if (m_baseProxy->didFailProvisionalLoad(frame, error))
74             return;
75         Base::didFailProvisionalLoad(frame, error);
76     }
77     virtual void didCommitProvisionalLoad(blink::WebLocalFrame* frame, const blink::WebHistoryItem& item, blink::WebHistoryCommitType commit_type)
78     {
79         m_baseProxy->didCommitProvisionalLoad(frame, item, commit_type);
80         Base::didCommitProvisionalLoad(frame, item, commit_type);
81     }
82     virtual void didReceiveTitle(blink::WebLocalFrame* frame, const blink::WebString& title, blink::WebTextDirection direction)
83     {
84         m_baseProxy->didReceiveTitle(frame, title, direction);
85         Base::didReceiveTitle(frame, title, direction);
86     }
87     virtual void didChangeIcon(blink::WebLocalFrame* frame, blink::WebIconURL::Type iconType)
88     {
89         m_baseProxy->didChangeIcon(frame, iconType);
90         Base::didChangeIcon(frame, iconType);
91     }
92     virtual void didFinishDocumentLoad(blink::WebLocalFrame* frame)
93     {
94         m_baseProxy->didFinishDocumentLoad(frame);
95         Base::didFinishDocumentLoad(frame);
96     }
97     virtual void didHandleOnloadEvents(blink::WebLocalFrame* frame)
98     {
99         m_baseProxy->didHandleOnloadEvents(frame);
100         Base::didHandleOnloadEvents(frame);
101     }
102     virtual void didFailLoad(blink::WebLocalFrame* frame, const blink::WebURLError& error)
103     {
104         m_baseProxy->didFailLoad(frame, error);
105         Base::didFailLoad(frame, error);
106     }
107     virtual void didFinishLoad(blink::WebLocalFrame* frame)
108     {
109         m_baseProxy->didFinishLoad(frame);
110         Base::didFinishLoad(frame);
111     }
112     virtual blink::WebNotificationPresenter* notificationPresenter()
113     {
114         return m_baseProxy->notificationPresenter();
115     }
116     virtual void didChangeSelection(bool is_selection_empty) {
117         m_baseProxy->didChangeSelection(is_selection_empty);
118         Base::didChangeSelection(is_selection_empty);
119     }
120     virtual blink::WebColorChooser* createColorChooser(
121         blink::WebColorChooserClient* client,
122         const blink::WebColor& initial_color,
123         const blink::WebVector<blink::WebColorSuggestion>& suggestions) {
124       return m_baseProxy->createColorChooser(client, initial_color, suggestions);
125     }
126     virtual void runModalAlertDialog(const blink::WebString& message) {
127         m_baseProxy->m_delegate->printMessage(std::string("ALERT: ") + message.utf8().data() + "\n");
128     }
129     virtual bool runModalConfirmDialog(const blink::WebString& message) {
130         m_baseProxy->m_delegate->printMessage(std::string("CONFIRM: ") + message.utf8().data() + "\n");
131         return true;
132     }
133     virtual bool runModalPromptDialog(const blink::WebString& message, const blink::WebString& defaultValue, blink::WebString*) {
134         m_baseProxy->m_delegate->printMessage(std::string("PROMPT: ") + message.utf8().data() + ", default text: " + defaultValue.utf8().data() + "\n");
135         return true;
136     }
137     virtual bool runModalBeforeUnloadDialog(bool is_reload, const blink::WebString& message) {
138         m_baseProxy->m_delegate->printMessage(std::string("CONFIRM NAVIGATION: ") + message.utf8().data() + "\n");
139         return !m_baseProxy->m_testInterfaces->testRunner()->shouldStayOnPageAfterHandlingBeforeUnload();
140     }
141     virtual void showContextMenu(const blink::WebContextMenuData& contextMenuData) {
142         m_baseProxy->showContextMenu(Base::GetWebFrame()->toWebLocalFrame(), contextMenuData);
143         Base::showContextMenu(contextMenuData);
144     }
145     virtual void didDetectXSS(blink::WebLocalFrame* frame, const blink::WebURL& insecureURL, bool didBlockEntirePage)
146     {
147         // This is not implemented in RenderFrameImpl, so need to explicitly call
148         // into the base proxy.
149         m_baseProxy->didDetectXSS(frame, insecureURL, didBlockEntirePage);
150         Base::didDetectXSS(frame, insecureURL, didBlockEntirePage);
151     }
152     virtual void didDispatchPingLoader(blink::WebLocalFrame* frame, const blink::WebURL& url)
153     {
154         // This is not implemented in RenderFrameImpl, so need to explicitly call
155         // into the base proxy.
156         m_baseProxy->didDispatchPingLoader(frame, url);
157         Base::didDispatchPingLoader(frame, url);
158     }
159     virtual void willRequestResource(blink::WebLocalFrame* frame, const blink::WebCachedURLRequest& request)
160     {
161         // This is not implemented in RenderFrameImpl, so need to explicitly call
162         // into the base proxy.
163         m_baseProxy->willRequestResource(frame, request);
164         Base::willRequestResource(frame, request);
165     }
166     virtual void didCreateDataSource(blink::WebLocalFrame* frame, blink::WebDataSource* ds)
167     {
168         Base::didCreateDataSource(frame, ds);
169     }
170     virtual void willSendRequest(blink::WebLocalFrame* frame, unsigned identifier, blink::WebURLRequest& request, const blink::WebURLResponse& redirectResponse)
171     {
172         m_baseProxy->willSendRequest(frame, identifier, request, redirectResponse);
173         Base::willSendRequest(frame, identifier, request, redirectResponse);
174     }
175     virtual void didReceiveResponse(blink::WebLocalFrame* frame, unsigned identifier, const blink::WebURLResponse& response)
176     {
177         m_baseProxy->didReceiveResponse(frame, identifier, response);
178         Base::didReceiveResponse(frame, identifier, response);
179     }
180     virtual void didChangeResourcePriority(blink::WebLocalFrame* frame, unsigned identifier, const blink::WebURLRequest::Priority& priority, int intra_priority_value)
181     {
182         // This is not implemented in RenderFrameImpl, so need to explicitly call
183         // into the base proxy.
184         m_baseProxy->didChangeResourcePriority(frame, identifier, priority, intra_priority_value);
185         Base::didChangeResourcePriority(frame, identifier, priority, intra_priority_value);
186     }
187     virtual void didFinishResourceLoad(blink::WebLocalFrame* frame, unsigned identifier)
188     {
189         m_baseProxy->didFinishResourceLoad(frame, identifier);
190         Base::didFinishResourceLoad(frame, identifier);
191     }
192     virtual blink::WebNavigationPolicy decidePolicyForNavigation(blink::WebLocalFrame* frame, blink::WebDataSource::ExtraData* extraData, const blink::WebURLRequest& request, blink::WebNavigationType type, blink::WebNavigationPolicy defaultPolicy, bool isRedirect)
193     {
194         blink::WebNavigationPolicy policy = m_baseProxy->decidePolicyForNavigation(frame, extraData, request, type, defaultPolicy, isRedirect);
195         if (policy == blink::WebNavigationPolicyIgnore)
196             return policy;
197
198         return Base::decidePolicyForNavigation(frame, extraData, request, type, defaultPolicy, isRedirect);
199     }
200     virtual void willStartUsingPeerConnectionHandler(blink::WebLocalFrame* frame, blink::WebRTCPeerConnectionHandler* handler)
201     {
202         // RenderFrameImpl::willStartUsingPeerConnectionHandler can not be mocked.
203         // See http://crbug/363285.
204     }
205     virtual blink::WebUserMediaClient* userMediaClient()
206     {
207         return m_baseProxy->userMediaClient();
208     }
209     virtual bool willCheckAndDispatchMessageEvent(blink::WebLocalFrame* sourceFrame, blink::WebFrame* targetFrame, blink::WebSecurityOrigin target, blink::WebDOMMessageEvent event)
210     {
211         if (m_baseProxy->willCheckAndDispatchMessageEvent(sourceFrame, targetFrame, target, event))
212             return true;
213         return Base::willCheckAndDispatchMessageEvent(sourceFrame, targetFrame, target, event);
214     }
215     virtual void didStopLoading()
216     {
217         m_baseProxy->didStopLoading();
218         Base::didStopLoading();
219     }
220
221 private:
222     WebTestProxyBase* m_baseProxy;
223
224     DISALLOW_COPY_AND_ASSIGN(WebFrameTestProxy);
225 };
226
227 }  // namespace content
228
229 #endif // WebTestProxy_h