1 // Copyright 2014 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 COMPONENTS_TEST_RUNNER_WEB_FRAME_TEST_PROXY_H_
6 #define COMPONENTS_TEST_RUNNER_WEB_FRAME_TEST_PROXY_H_
8 #include "base/basictypes.h"
9 #include "components/test_runner/mock_screen_orientation_client.h"
10 #include "components/test_runner/web_test_delegate.h"
11 #include "components/test_runner/web_test_interfaces.h"
12 #include "components/test_runner/web_test_proxy.h"
13 #include "components/test_runner/web_test_runner.h"
14 #include "third_party/WebKit/public/platform/WebString.h"
16 namespace test_runner
{
18 // Templetized wrapper around RenderFrameImpl objects, which implement
19 // the WebFrameClient interface.
20 template <class Base
, typename P
>
21 class WebFrameTestProxy
: public Base
{
23 explicit WebFrameTestProxy(P p
) : Base(p
), base_proxy_(NULL
) {}
25 virtual ~WebFrameTestProxy() {}
27 void set_base_proxy(WebTestProxyBase
* proxy
) { base_proxy_
= proxy
; }
29 // WebFrameClient implementation.
30 virtual blink::WebPlugin
* createPlugin(blink::WebLocalFrame
* frame
,
31 const blink::WebPluginParams
& params
) {
32 blink::WebPlugin
* plugin
= base_proxy_
->CreatePlugin(frame
, params
);
35 return Base::createPlugin(frame
, params
);
38 virtual blink::WebScreenOrientationClient
* webScreenOrientationClient() {
39 return base_proxy_
->GetScreenOrientationClientMock();
42 virtual void didAddMessageToConsole(const blink::WebConsoleMessage
& message
,
43 const blink::WebString
& source_name
,
45 const blink::WebString
& stack_trace
) {
46 base_proxy_
->DidAddMessageToConsole(message
, source_name
, source_line
);
47 Base::didAddMessageToConsole(
48 message
, source_name
, source_line
, stack_trace
);
51 virtual bool canCreatePluginWithoutRenderer(
52 const blink::WebString
& mime_type
) {
53 using blink::WebString
;
55 const CR_DEFINE_STATIC_LOCAL(
56 WebString
, suffix
, ("-can-create-without-renderer"));
57 return mime_type
.utf8().find(suffix
.utf8()) != std::string::npos
;
60 virtual void loadURLExternally(blink::WebLocalFrame
* frame
,
61 const blink::WebURLRequest
& request
,
62 blink::WebNavigationPolicy policy
,
63 const blink::WebString
& suggested_name
) {
64 base_proxy_
->LoadURLExternally(frame
, request
, policy
, suggested_name
);
65 Base::loadURLExternally(frame
, request
, policy
, suggested_name
);
68 virtual void didStartProvisionalLoad(blink::WebLocalFrame
* frame
,
69 double triggeringEventTime
) {
70 base_proxy_
->DidStartProvisionalLoad(frame
);
71 Base::didStartProvisionalLoad(
72 frame
, triggeringEventTime
);
75 virtual void didReceiveServerRedirectForProvisionalLoad(
76 blink::WebLocalFrame
* frame
) {
77 base_proxy_
->DidReceiveServerRedirectForProvisionalLoad(frame
);
78 Base::didReceiveServerRedirectForProvisionalLoad(frame
);
81 virtual void didFailProvisionalLoad(
82 blink::WebLocalFrame
* frame
,
83 const blink::WebURLError
& error
,
84 blink::WebHistoryCommitType commit_type
) {
85 // If the test finished, don't notify the embedder of the failed load,
86 // as we already destroyed the document loader.
87 if (base_proxy_
->DidFailProvisionalLoad(frame
, error
, commit_type
))
89 Base::didFailProvisionalLoad(frame
, error
, commit_type
);
92 virtual void didCommitProvisionalLoad(
93 blink::WebLocalFrame
* frame
,
94 const blink::WebHistoryItem
& item
,
95 blink::WebHistoryCommitType commit_type
) {
96 base_proxy_
->DidCommitProvisionalLoad(frame
, item
, commit_type
);
97 Base::didCommitProvisionalLoad(frame
, item
, commit_type
);
100 virtual void didReceiveTitle(blink::WebLocalFrame
* frame
,
101 const blink::WebString
& title
,
102 blink::WebTextDirection direction
) {
103 base_proxy_
->DidReceiveTitle(frame
, title
, direction
);
104 Base::didReceiveTitle(frame
, title
, direction
);
107 virtual void didChangeIcon(blink::WebLocalFrame
* frame
,
108 blink::WebIconURL::Type icon_type
) {
109 base_proxy_
->DidChangeIcon(frame
, icon_type
);
110 Base::didChangeIcon(frame
, icon_type
);
113 virtual void didFinishDocumentLoad(blink::WebLocalFrame
* frame
) {
114 base_proxy_
->DidFinishDocumentLoad(frame
);
115 Base::didFinishDocumentLoad(frame
);
118 virtual void didHandleOnloadEvents(blink::WebLocalFrame
* frame
) {
119 base_proxy_
->DidHandleOnloadEvents(frame
);
120 Base::didHandleOnloadEvents(frame
);
123 virtual void didFailLoad(blink::WebLocalFrame
* frame
,
124 const blink::WebURLError
& error
,
125 blink::WebHistoryCommitType commit_type
) {
126 base_proxy_
->DidFailLoad(frame
, error
, commit_type
);
127 Base::didFailLoad(frame
, error
, commit_type
);
130 virtual void didFinishLoad(blink::WebLocalFrame
* frame
) {
131 Base::didFinishLoad(frame
);
132 base_proxy_
->DidFinishLoad(frame
);
135 virtual void didChangeSelection(bool is_selection_empty
) {
136 base_proxy_
->DidChangeSelection(is_selection_empty
);
137 Base::didChangeSelection(is_selection_empty
);
140 virtual blink::WebColorChooser
* createColorChooser(
141 blink::WebColorChooserClient
* client
,
142 const blink::WebColor
& initial_color
,
143 const blink::WebVector
<blink::WebColorSuggestion
>& suggestions
) {
144 return base_proxy_
->CreateColorChooser(client
, initial_color
, suggestions
);
147 virtual void runModalAlertDialog(const blink::WebString
& message
) {
148 base_proxy_
->GetDelegate()->PrintMessage(std::string("ALERT: ") +
149 message
.utf8().data() + "\n");
152 virtual bool runModalConfirmDialog(const blink::WebString
& message
) {
153 base_proxy_
->GetDelegate()->PrintMessage(std::string("CONFIRM: ") +
154 message
.utf8().data() + "\n");
158 virtual bool runModalPromptDialog(const blink::WebString
& message
,
159 const blink::WebString
& default_value
,
161 base_proxy_
->GetDelegate()->PrintMessage(
162 std::string("PROMPT: ") + message
.utf8().data() + ", default text: " +
163 default_value
.utf8().data() + "\n");
167 virtual bool runModalBeforeUnloadDialog(bool is_reload
,
168 const blink::WebString
& message
) {
169 base_proxy_
->GetDelegate()->PrintMessage(
170 std::string("CONFIRM NAVIGATION: ") + message
.utf8().data() + "\n");
171 return !base_proxy_
->GetInterfaces()
173 ->ShouldStayOnPageAfterHandlingBeforeUnload();
176 virtual void showContextMenu(
177 const blink::WebContextMenuData
& context_menu_data
) {
178 base_proxy_
->ShowContextMenu(context_menu_data
);
179 Base::showContextMenu(context_menu_data
);
182 virtual void didDetectXSS(blink::WebLocalFrame
* frame
,
183 const blink::WebURL
& insecure_url
,
184 bool did_block_entire_page
) {
185 // This is not implemented in RenderFrameImpl, so need to explicitly call
186 // into the base proxy.
187 base_proxy_
->DidDetectXSS(frame
, insecure_url
, did_block_entire_page
);
188 Base::didDetectXSS(frame
, insecure_url
, did_block_entire_page
);
191 virtual void didDispatchPingLoader(blink::WebLocalFrame
* frame
,
192 const blink::WebURL
& url
) {
193 // This is not implemented in RenderFrameImpl, so need to explicitly call
194 // into the base proxy.
195 base_proxy_
->DidDispatchPingLoader(frame
, url
);
196 Base::didDispatchPingLoader(frame
, url
);
199 virtual void willRequestResource(blink::WebLocalFrame
* frame
,
200 const blink::WebCachedURLRequest
& request
) {
201 // This is not implemented in RenderFrameImpl, so need to explicitly call
202 // into the base proxy.
203 base_proxy_
->WillRequestResource(frame
, request
);
204 Base::willRequestResource(frame
, request
);
207 virtual void didCreateDataSource(blink::WebLocalFrame
* frame
,
208 blink::WebDataSource
* ds
) {
209 Base::didCreateDataSource(frame
, ds
);
212 virtual void willSendRequest(blink::WebLocalFrame
* frame
,
214 blink::WebURLRequest
& request
,
215 const blink::WebURLResponse
& redirect_response
) {
216 Base::willSendRequest(frame
, identifier
, request
, redirect_response
);
217 base_proxy_
->WillSendRequest(frame
, identifier
, request
, redirect_response
);
220 virtual void didReceiveResponse(blink::WebLocalFrame
* frame
,
222 const blink::WebURLResponse
& response
) {
223 base_proxy_
->DidReceiveResponse(frame
, identifier
, response
);
224 Base::didReceiveResponse(frame
, identifier
, response
);
227 virtual void didChangeResourcePriority(
228 blink::WebLocalFrame
* frame
,
230 const blink::WebURLRequest::Priority
& priority
,
231 int intra_priority_value
) {
232 // This is not implemented in RenderFrameImpl, so need to explicitly call
233 // into the base proxy.
234 base_proxy_
->DidChangeResourcePriority(
235 frame
, identifier
, priority
, intra_priority_value
);
236 Base::didChangeResourcePriority(
237 frame
, identifier
, priority
, intra_priority_value
);
240 virtual void didFinishResourceLoad(blink::WebLocalFrame
* frame
,
241 unsigned identifier
) {
242 base_proxy_
->DidFinishResourceLoad(frame
, identifier
);
243 Base::didFinishResourceLoad(frame
, identifier
);
246 virtual blink::WebNavigationPolicy
decidePolicyForNavigation(
247 const blink::WebFrameClient::NavigationPolicyInfo
& info
) {
248 blink::WebNavigationPolicy policy
= base_proxy_
->DecidePolicyForNavigation(
250 if (policy
== blink::WebNavigationPolicyIgnore
)
253 return Base::decidePolicyForNavigation(info
);
256 virtual void willStartUsingPeerConnectionHandler(
257 blink::WebLocalFrame
* frame
,
258 blink::WebRTCPeerConnectionHandler
* handler
) {
259 // RenderFrameImpl::willStartUsingPeerConnectionHandler can not be mocked.
260 // See http://crbug/363285.
263 virtual blink::WebUserMediaClient
* userMediaClient() {
264 return base_proxy_
->GetUserMediaClient();
267 virtual bool willCheckAndDispatchMessageEvent(
268 blink::WebLocalFrame
* source_frame
,
269 blink::WebFrame
* target_frame
,
270 blink::WebSecurityOrigin target
,
271 blink::WebDOMMessageEvent event
) {
272 if (base_proxy_
->WillCheckAndDispatchMessageEvent(
273 source_frame
, target_frame
, target
, event
))
275 return Base::willCheckAndDispatchMessageEvent(
276 source_frame
, target_frame
, target
, event
);
279 virtual void didStopLoading() {
280 base_proxy_
->DidStopLoading();
281 Base::didStopLoading();
284 virtual void postAccessibilityEvent(const blink::WebAXObject
& object
,
285 blink::WebAXEvent event
) {
286 base_proxy_
->PostAccessibilityEvent(object
, event
);
287 Base::postAccessibilityEvent(object
, event
);
291 WebTestProxyBase
* base_proxy_
;
293 DISALLOW_COPY_AND_ASSIGN(WebFrameTestProxy
);
296 } // namespace test_runner
298 #endif // COMPONENTS_TEST_RUNNER_WEB_FRAME_TEST_PROXY_H_