blob: 87246b6e07da9927f63fd6f54da6edacda059809 [file] [log] [blame]
[email protected]a1640e42014-05-14 13:43:321// 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.
4
jochen73e711c2015-06-03 10:01:465#ifndef COMPONENTS_TEST_RUNNER_WEB_FRAME_TEST_PROXY_H_
6#define COMPONENTS_TEST_RUNNER_WEB_FRAME_TEST_PROXY_H_
[email protected]a1640e42014-05-14 13:43:327
8#include "base/basictypes.h"
jochen73e711c2015-06-03 10:01:469#include "components/test_runner/mock_screen_orientation_client.h"
jochen73e711c2015-06-03 10:01:4610#include "components/test_runner/web_test_delegate.h"
jochen746754c52015-06-05 16:40:4111#include "components/test_runner/web_test_interfaces.h"
jochen73e711c2015-06-03 10:01:4612#include "components/test_runner/web_test_proxy.h"
jochen746754c52015-06-05 16:40:4113#include "components/test_runner/web_test_runner.h"
[email protected]a1640e42014-05-14 13:43:3214#include "third_party/WebKit/public/platform/WebString.h"
15
jochenf5f31752015-06-03 12:06:3416namespace test_runner {
[email protected]a1640e42014-05-14 13:43:3217
18// Templetized wrapper around RenderFrameImpl objects, which implement
19// the WebFrameClient interface.
jochen664198b2015-06-25 14:13:0020template <class Base, typename P>
[email protected]a1640e42014-05-14 13:43:3221class WebFrameTestProxy : public Base {
22 public:
jochen664198b2015-06-25 14:13:0023 explicit WebFrameTestProxy(P p) : Base(p), base_proxy_(NULL) {}
[email protected]a1640e42014-05-14 13:43:3224
25 virtual ~WebFrameTestProxy() {}
26
27 void set_base_proxy(WebTestProxyBase* proxy) { base_proxy_ = proxy; }
28
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);
[email protected]67ca3c62014-07-22 23:44:1433 if (plugin)
34 return plugin;
[email protected]a1640e42014-05-14 13:43:3235 return Base::createPlugin(frame, params);
36 }
37
[email protected]a2ca0032014-06-27 02:28:0838 virtual blink::WebScreenOrientationClient* webScreenOrientationClient() {
39 return base_proxy_->GetScreenOrientationClientMock();
40 }
41
[email protected]a1640e42014-05-14 13:43:3242 virtual void didAddMessageToConsole(const blink::WebConsoleMessage& message,
[email protected]67ca3c62014-07-22 23:44:1443 const blink::WebString& source_name,
44 unsigned source_line,
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);
[email protected]a1640e42014-05-14 13:43:3249 }
50
51 virtual bool canCreatePluginWithoutRenderer(
[email protected]67ca3c62014-07-22 23:44:1452 const blink::WebString& mime_type) {
[email protected]a1640e42014-05-14 13:43:3253 using blink::WebString;
54
[email protected]67ca3c62014-07-22 23:44:1455 const CR_DEFINE_STATIC_LOCAL(
56 WebString, suffix, ("-can-create-without-renderer"));
57 return mime_type.utf8().find(suffix.utf8()) != std::string::npos;
[email protected]a1640e42014-05-14 13:43:3258 }
59
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);
66 }
67
[email protected]0c3c54f2014-07-31 01:29:0068 virtual void didStartProvisionalLoad(blink::WebLocalFrame* frame,
japhet69a06302014-12-12 19:37:1469 double triggeringEventTime) {
[email protected]a1640e42014-05-14 13:43:3270 base_proxy_->DidStartProvisionalLoad(frame);
japhet69a06302014-12-12 19:37:1471 Base::didStartProvisionalLoad(
dglazkovcd24f7e2015-05-18 20:00:0072 frame, triggeringEventTime);
[email protected]a1640e42014-05-14 13:43:3273 }
74
75 virtual void didReceiveServerRedirectForProvisionalLoad(
76 blink::WebLocalFrame* frame) {
77 base_proxy_->DidReceiveServerRedirectForProvisionalLoad(frame);
78 Base::didReceiveServerRedirectForProvisionalLoad(frame);
79 }
80
avi31b6fa42015-03-31 16:09:0981 virtual void didFailProvisionalLoad(
82 blink::WebLocalFrame* frame,
83 const blink::WebURLError& error,
84 blink::WebHistoryCommitType commit_type) {
[email protected]a1640e42014-05-14 13:43:3285 // If the test finished, don't notify the embedder of the failed load,
86 // as we already destroyed the document loader.
avi31b6fa42015-03-31 16:09:0987 if (base_proxy_->DidFailProvisionalLoad(frame, error, commit_type))
[email protected]67ca3c62014-07-22 23:44:1488 return;
avi31b6fa42015-03-31 16:09:0989 Base::didFailProvisionalLoad(frame, error, commit_type);
[email protected]a1640e42014-05-14 13:43:3290 }
91
92 virtual void didCommitProvisionalLoad(
[email protected]67ca3c62014-07-22 23:44:1493 blink::WebLocalFrame* frame,
94 const blink::WebHistoryItem& item,
[email protected]a1640e42014-05-14 13:43:3295 blink::WebHistoryCommitType commit_type) {
96 base_proxy_->DidCommitProvisionalLoad(frame, item, commit_type);
97 Base::didCommitProvisionalLoad(frame, item, commit_type);
98 }
99
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);
105 }
106
107 virtual void didChangeIcon(blink::WebLocalFrame* frame,
[email protected]67ca3c62014-07-22 23:44:14108 blink::WebIconURL::Type icon_type) {
109 base_proxy_->DidChangeIcon(frame, icon_type);
110 Base::didChangeIcon(frame, icon_type);
[email protected]a1640e42014-05-14 13:43:32111 }
112
japhet0ee02e6e52015-07-17 18:27:37113 virtual void didFinishDocumentLoad(blink::WebLocalFrame* frame, bool empty) {
[email protected]a1640e42014-05-14 13:43:32114 base_proxy_->DidFinishDocumentLoad(frame);
japhet0ee02e6e52015-07-17 18:27:37115 Base::didFinishDocumentLoad(frame, empty);
[email protected]a1640e42014-05-14 13:43:32116 }
117
118 virtual void didHandleOnloadEvents(blink::WebLocalFrame* frame) {
119 base_proxy_->DidHandleOnloadEvents(frame);
120 Base::didHandleOnloadEvents(frame);
121 }
122
123 virtual void didFailLoad(blink::WebLocalFrame* frame,
avi31b6fa42015-03-31 16:09:09124 const blink::WebURLError& error,
125 blink::WebHistoryCommitType commit_type) {
126 base_proxy_->DidFailLoad(frame, error, commit_type);
127 Base::didFailLoad(frame, error, commit_type);
[email protected]a1640e42014-05-14 13:43:32128 }
129
130 virtual void didFinishLoad(blink::WebLocalFrame* frame) {
[email protected]a1640e42014-05-14 13:43:32131 Base::didFinishLoad(frame);
[email protected]3b397acb2014-06-05 21:13:23132 base_proxy_->DidFinishLoad(frame);
[email protected]a1640e42014-05-14 13:43:32133 }
134
[email protected]a1640e42014-05-14 13:43:32135 virtual void didChangeSelection(bool is_selection_empty) {
136 base_proxy_->DidChangeSelection(is_selection_empty);
137 Base::didChangeSelection(is_selection_empty);
138 }
139
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);
145 }
146
147 virtual void runModalAlertDialog(const blink::WebString& message) {
jochen746754c52015-06-05 16:40:41148 base_proxy_->GetDelegate()->PrintMessage(std::string("ALERT: ") +
149 message.utf8().data() + "\n");
[email protected]a1640e42014-05-14 13:43:32150 }
151
152 virtual bool runModalConfirmDialog(const blink::WebString& message) {
jochen746754c52015-06-05 16:40:41153 base_proxy_->GetDelegate()->PrintMessage(std::string("CONFIRM: ") +
154 message.utf8().data() + "\n");
[email protected]a1640e42014-05-14 13:43:32155 return true;
156 }
157
158 virtual bool runModalPromptDialog(const blink::WebString& message,
[email protected]67ca3c62014-07-22 23:44:14159 const blink::WebString& default_value,
[email protected]a1640e42014-05-14 13:43:32160 blink::WebString*) {
jochen746754c52015-06-05 16:40:41161 base_proxy_->GetDelegate()->PrintMessage(
[email protected]a1640e42014-05-14 13:43:32162 std::string("PROMPT: ") + message.utf8().data() + ", default text: " +
[email protected]67ca3c62014-07-22 23:44:14163 default_value.utf8().data() + "\n");
[email protected]a1640e42014-05-14 13:43:32164 return true;
165 }
166
167 virtual bool runModalBeforeUnloadDialog(bool is_reload,
168 const blink::WebString& message) {
jochen746754c52015-06-05 16:40:41169 base_proxy_->GetDelegate()->PrintMessage(
170 std::string("CONFIRM NAVIGATION: ") + message.utf8().data() + "\n");
171 return !base_proxy_->GetInterfaces()
172 ->TestRunner()
173 ->ShouldStayOnPageAfterHandlingBeforeUnload();
[email protected]a1640e42014-05-14 13:43:32174 }
175
176 virtual void showContextMenu(
[email protected]67ca3c62014-07-22 23:44:14177 const blink::WebContextMenuData& context_menu_data) {
jochenea29d8ad2015-07-02 15:15:01178 base_proxy_->ShowContextMenu(context_menu_data);
[email protected]67ca3c62014-07-22 23:44:14179 Base::showContextMenu(context_menu_data);
[email protected]a1640e42014-05-14 13:43:32180 }
181
182 virtual void didDetectXSS(blink::WebLocalFrame* frame,
[email protected]67ca3c62014-07-22 23:44:14183 const blink::WebURL& insecure_url,
184 bool did_block_entire_page) {
[email protected]a1640e42014-05-14 13:43:32185 // This is not implemented in RenderFrameImpl, so need to explicitly call
186 // into the base proxy.
[email protected]67ca3c62014-07-22 23:44:14187 base_proxy_->DidDetectXSS(frame, insecure_url, did_block_entire_page);
188 Base::didDetectXSS(frame, insecure_url, did_block_entire_page);
[email protected]a1640e42014-05-14 13:43:32189 }
190
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);
197 }
198
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);
205 }
206
207 virtual void didCreateDataSource(blink::WebLocalFrame* frame,
208 blink::WebDataSource* ds) {
209 Base::didCreateDataSource(frame, ds);
210 }
211
[email protected]67ca3c62014-07-22 23:44:14212 virtual void willSendRequest(blink::WebLocalFrame* frame,
213 unsigned identifier,
[email protected]a1640e42014-05-14 13:43:32214 blink::WebURLRequest& request,
[email protected]67ca3c62014-07-22 23:44:14215 const blink::WebURLResponse& redirect_response) {
216 Base::willSendRequest(frame, identifier, request, redirect_response);
217 base_proxy_->WillSendRequest(frame, identifier, request, redirect_response);
[email protected]a1640e42014-05-14 13:43:32218 }
219
220 virtual void didReceiveResponse(blink::WebLocalFrame* frame,
221 unsigned identifier,
222 const blink::WebURLResponse& response) {
223 base_proxy_->DidReceiveResponse(frame, identifier, response);
224 Base::didReceiveResponse(frame, identifier, response);
225 }
226
227 virtual void didChangeResourcePriority(
[email protected]67ca3c62014-07-22 23:44:14228 blink::WebLocalFrame* frame,
229 unsigned identifier,
[email protected]a1640e42014-05-14 13:43:32230 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.
[email protected]67ca3c62014-07-22 23:44:14234 base_proxy_->DidChangeResourcePriority(
235 frame, identifier, priority, intra_priority_value);
236 Base::didChangeResourcePriority(
237 frame, identifier, priority, intra_priority_value);
[email protected]a1640e42014-05-14 13:43:32238 }
239
240 virtual void didFinishResourceLoad(blink::WebLocalFrame* frame,
241 unsigned identifier) {
242 base_proxy_->DidFinishResourceLoad(frame, identifier);
[email protected]a1640e42014-05-14 13:43:32243 }
244
245 virtual blink::WebNavigationPolicy decidePolicyForNavigation(
[email protected]0c3c54f2014-07-31 01:29:00246 const blink::WebFrameClient::NavigationPolicyInfo& info) {
[email protected]a1640e42014-05-14 13:43:32247 blink::WebNavigationPolicy policy = base_proxy_->DecidePolicyForNavigation(
[email protected]0c3c54f2014-07-31 01:29:00248 info);
[email protected]67ca3c62014-07-22 23:44:14249 if (policy == blink::WebNavigationPolicyIgnore)
250 return policy;
[email protected]a1640e42014-05-14 13:43:32251
[email protected]0c3c54f2014-07-31 01:29:00252 return Base::decidePolicyForNavigation(info);
[email protected]a1640e42014-05-14 13:43:32253 }
254
255 virtual void willStartUsingPeerConnectionHandler(
256 blink::WebLocalFrame* frame,
257 blink::WebRTCPeerConnectionHandler* handler) {
258 // RenderFrameImpl::willStartUsingPeerConnectionHandler can not be mocked.
259 // See http://crbug/363285.
260 }
261
262 virtual blink::WebUserMediaClient* userMediaClient() {
263 return base_proxy_->GetUserMediaClient();
264 }
265
[email protected]a1640e42014-05-14 13:43:32266 virtual bool willCheckAndDispatchMessageEvent(
[email protected]67ca3c62014-07-22 23:44:14267 blink::WebLocalFrame* source_frame,
268 blink::WebFrame* target_frame,
269 blink::WebSecurityOrigin target,
270 blink::WebDOMMessageEvent event) {
271 if (base_proxy_->WillCheckAndDispatchMessageEvent(
272 source_frame, target_frame, target, event))
[email protected]a1640e42014-05-14 13:43:32273 return true;
[email protected]67ca3c62014-07-22 23:44:14274 return Base::willCheckAndDispatchMessageEvent(
275 source_frame, target_frame, target, event);
[email protected]a1640e42014-05-14 13:43:32276 }
277
278 virtual void didStopLoading() {
279 base_proxy_->DidStopLoading();
280 Base::didStopLoading();
281 }
282
jochen56b353612015-07-02 15:57:53283 virtual void postAccessibilityEvent(const blink::WebAXObject& object,
284 blink::WebAXEvent event) {
285 base_proxy_->PostAccessibilityEvent(object, event);
286 Base::postAccessibilityEvent(object, event);
287 }
288
[email protected]a1640e42014-05-14 13:43:32289 private:
[email protected]a1640e42014-05-14 13:43:32290 WebTestProxyBase* base_proxy_;
291
[email protected]a1640e42014-05-14 13:43:32292 DISALLOW_COPY_AND_ASSIGN(WebFrameTestProxy);
293};
294
jochenf5f31752015-06-03 12:06:34295} // namespace test_runner
[email protected]a1640e42014-05-14 13:43:32296
jochen73e711c2015-06-03 10:01:46297#endif // COMPONENTS_TEST_RUNNER_WEB_FRAME_TEST_PROXY_H_