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_WEBFRAMETESTPROXY_H_
6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBFRAMETESTPROXY_H_
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"
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
{
22 WebFrameTestProxy(P p
, R r
)
26 virtual ~WebFrameTestProxy() { }
28 void setBaseProxy(WebTestProxyBase
* proxy
)
33 blink::WebPlugin
* createPlugin(blink::WebLocalFrame
* frame
, const blink::WebPluginParams
& params
)
35 blink::WebPlugin
* plugin
= m_baseProxy
->createPlugin(frame
, params
);
38 return Base::createPlugin(frame
, params
);
41 // WebFrameClient implementation.
42 virtual void didAddMessageToConsole(const blink::WebConsoleMessage
& message
, const blink::WebString
& sourceName
, unsigned sourceLine
, const blink::WebString
& stackTrace
)
44 m_baseProxy
->didAddMessageToConsole(message
, sourceName
, sourceLine
);
45 Base::didAddMessageToConsole(message
, sourceName
, sourceLine
, stackTrace
);
47 virtual bool canCreatePluginWithoutRenderer(const blink::WebString
& mimeType
)
49 using blink::WebString
;
51 const CR_DEFINE_STATIC_LOCAL(WebString
, suffix
, ("-can-create-without-renderer"));
52 return mimeType
.utf8().find(suffix
.utf8()) != std::string::npos
;
54 virtual void loadURLExternally(blink::WebLocalFrame
* frame
, const blink::WebURLRequest
& request
, blink::WebNavigationPolicy policy
, const blink::WebString
& suggested_name
)
56 m_baseProxy
->loadURLExternally(frame
, request
, policy
, suggested_name
);
57 Base::loadURLExternally(frame
, request
, policy
, suggested_name
);
59 virtual void didStartProvisionalLoad(blink::WebLocalFrame
* frame
)
61 m_baseProxy
->didStartProvisionalLoad(frame
);
62 Base::didStartProvisionalLoad(frame
);
64 virtual void didReceiveServerRedirectForProvisionalLoad(blink::WebLocalFrame
* frame
)
66 m_baseProxy
->didReceiveServerRedirectForProvisionalLoad(frame
);
67 Base::didReceiveServerRedirectForProvisionalLoad(frame
);
69 virtual void didFailProvisionalLoad(blink::WebLocalFrame
* frame
, const blink::WebURLError
& error
)
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
))
75 Base::didFailProvisionalLoad(frame
, error
);
77 virtual void didCommitProvisionalLoad(blink::WebLocalFrame
* frame
, const blink::WebHistoryItem
& item
, blink::WebHistoryCommitType commit_type
)
79 m_baseProxy
->didCommitProvisionalLoad(frame
, item
, commit_type
);
80 Base::didCommitProvisionalLoad(frame
, item
, commit_type
);
82 virtual void didReceiveTitle(blink::WebLocalFrame
* frame
, const blink::WebString
& title
, blink::WebTextDirection direction
)
84 m_baseProxy
->didReceiveTitle(frame
, title
, direction
);
85 Base::didReceiveTitle(frame
, title
, direction
);
87 virtual void didChangeIcon(blink::WebLocalFrame
* frame
, blink::WebIconURL::Type iconType
)
89 m_baseProxy
->didChangeIcon(frame
, iconType
);
90 Base::didChangeIcon(frame
, iconType
);
92 virtual void didFinishDocumentLoad(blink::WebLocalFrame
* frame
)
94 m_baseProxy
->didFinishDocumentLoad(frame
);
95 Base::didFinishDocumentLoad(frame
);
97 virtual void didHandleOnloadEvents(blink::WebLocalFrame
* frame
)
99 m_baseProxy
->didHandleOnloadEvents(frame
);
100 Base::didHandleOnloadEvents(frame
);
102 virtual void didFailLoad(blink::WebLocalFrame
* frame
, const blink::WebURLError
& error
)
104 m_baseProxy
->didFailLoad(frame
, error
);
105 Base::didFailLoad(frame
, error
);
107 virtual void didFinishLoad(blink::WebLocalFrame
* frame
)
109 m_baseProxy
->didFinishLoad(frame
);
110 Base::didFinishLoad(frame
);
112 virtual blink::WebNotificationPresenter
* notificationPresenter()
114 return m_baseProxy
->notificationPresenter();
116 virtual void didChangeSelection(bool is_selection_empty
) {
117 m_baseProxy
->didChangeSelection(is_selection_empty
);
118 Base::didChangeSelection(is_selection_empty
);
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
);
126 virtual void runModalAlertDialog(const blink::WebString
& message
) {
127 m_baseProxy
->m_delegate
->printMessage(std::string("ALERT: ") + message
.utf8().data() + "\n");
129 virtual bool runModalConfirmDialog(const blink::WebString
& message
) {
130 m_baseProxy
->m_delegate
->printMessage(std::string("CONFIRM: ") + message
.utf8().data() + "\n");
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");
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();
141 virtual void showContextMenu(const blink::WebContextMenuData
& contextMenuData
) {
142 m_baseProxy
->showContextMenu(Base::GetWebFrame()->toWebLocalFrame(), contextMenuData
);
143 Base::showContextMenu(contextMenuData
);
145 virtual void didDetectXSS(blink::WebLocalFrame
* frame
, const blink::WebURL
& insecureURL
, bool didBlockEntirePage
)
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
);
152 virtual void didDispatchPingLoader(blink::WebLocalFrame
* frame
, const blink::WebURL
& url
)
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
);
159 virtual void willRequestResource(blink::WebLocalFrame
* frame
, const blink::WebCachedURLRequest
& request
)
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
);
166 virtual void didCreateDataSource(blink::WebLocalFrame
* frame
, blink::WebDataSource
* ds
)
168 Base::didCreateDataSource(frame
, ds
);
170 virtual void willSendRequest(blink::WebLocalFrame
* frame
, unsigned identifier
, blink::WebURLRequest
& request
, const blink::WebURLResponse
& redirectResponse
)
172 m_baseProxy
->willSendRequest(frame
, identifier
, request
, redirectResponse
);
173 Base::willSendRequest(frame
, identifier
, request
, redirectResponse
);
175 virtual void didReceiveResponse(blink::WebLocalFrame
* frame
, unsigned identifier
, const blink::WebURLResponse
& response
)
177 m_baseProxy
->didReceiveResponse(frame
, identifier
, response
);
178 Base::didReceiveResponse(frame
, identifier
, response
);
180 virtual void didChangeResourcePriority(blink::WebLocalFrame
* frame
, unsigned identifier
, const blink::WebURLRequest::Priority
& priority
, int intra_priority_value
)
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
);
187 virtual void didFinishResourceLoad(blink::WebLocalFrame
* frame
, unsigned identifier
)
189 m_baseProxy
->didFinishResourceLoad(frame
, identifier
);
190 Base::didFinishResourceLoad(frame
, identifier
);
192 virtual blink::WebNavigationPolicy
decidePolicyForNavigation(blink::WebLocalFrame
* frame
, blink::WebDataSource::ExtraData
* extraData
, const blink::WebURLRequest
& request
, blink::WebNavigationType type
, blink::WebNavigationPolicy defaultPolicy
, bool isRedirect
)
194 blink::WebNavigationPolicy policy
= m_baseProxy
->decidePolicyForNavigation(frame
, extraData
, request
, type
, defaultPolicy
, isRedirect
);
195 if (policy
== blink::WebNavigationPolicyIgnore
)
198 return Base::decidePolicyForNavigation(frame
, extraData
, request
, type
, defaultPolicy
, isRedirect
);
200 virtual void willStartUsingPeerConnectionHandler(blink::WebLocalFrame
* frame
, blink::WebRTCPeerConnectionHandler
* handler
)
202 // RenderFrameImpl::willStartUsingPeerConnectionHandler can not be mocked.
203 // See http://crbug/363285.
205 virtual bool willCheckAndDispatchMessageEvent(blink::WebLocalFrame
* sourceFrame
, blink::WebFrame
* targetFrame
, blink::WebSecurityOrigin target
, blink::WebDOMMessageEvent event
)
207 if (m_baseProxy
->willCheckAndDispatchMessageEvent(sourceFrame
, targetFrame
, target
, event
))
209 return Base::willCheckAndDispatchMessageEvent(sourceFrame
, targetFrame
, target
, event
);
211 virtual void didStopLoading()
213 m_baseProxy
->didStopLoading();
214 Base::didStopLoading();
218 WebTestProxyBase
* m_baseProxy
;
220 DISALLOW_COPY_AND_ASSIGN(WebFrameTestProxy
);
223 } // namespace content
225 #endif // WebTestProxy_h