OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef COMPONENTS_TEST_RUNNER_WEB_FRAME_TEST_PROXY_H_ | |
6 #define COMPONENTS_TEST_RUNNER_WEB_FRAME_TEST_PROXY_H_ | |
7 | |
8 #include <memory> | |
9 #include <utility> | |
10 | |
11 #include "base/logging.h" | |
12 #include "base/macros.h" | |
13 #include "components/test_runner/test_runner_export.h" | |
14 #include "components/test_runner/web_frame_test_client.h" | |
15 #include "third_party/WebKit/public/platform/WebEffectiveConnectionType.h" | |
16 #include "third_party/WebKit/public/platform/WebString.h" | |
17 #include "third_party/WebKit/public/web/WebFrameClient.h" | |
18 #include "third_party/WebKit/public/web/WebLocalFrame.h" | |
19 | |
20 namespace test_runner { | |
21 | |
22 class TEST_RUNNER_EXPORT WebFrameTestProxyBase { | |
23 public: | |
24 void set_test_client(std::unique_ptr<WebFrameTestClient> client) { | |
25 DCHECK(client); | |
26 DCHECK(!test_client_); | |
27 test_client_ = std::move(client); | |
28 } | |
29 | |
30 blink::WebLocalFrame* web_frame() const { return web_frame_; } | |
31 void set_web_frame(blink::WebLocalFrame* frame) { | |
32 DCHECK(frame); | |
33 DCHECK(!web_frame_); | |
34 web_frame_ = frame; | |
35 } | |
36 | |
37 protected: | |
38 WebFrameTestProxyBase(); | |
39 ~WebFrameTestProxyBase(); | |
40 blink::WebFrameClient* test_client() { return test_client_.get(); } | |
41 | |
42 private: | |
43 std::unique_ptr<WebFrameTestClient> test_client_; | |
44 blink::WebLocalFrame* web_frame_; | |
45 | |
46 DISALLOW_COPY_AND_ASSIGN(WebFrameTestProxyBase); | |
47 }; | |
48 | |
49 // WebFrameTestProxy is used during LayoutTests and always instantiated, at time | |
50 // of writing with Base=RenderFrameImpl. It does not directly inherit from it | |
51 // for layering purposes. | |
52 template <class Base, typename P> | |
53 class WebFrameTestProxy : public Base, public WebFrameTestProxyBase { | |
54 public: | |
55 explicit WebFrameTestProxy(P p) : Base(p) {} | |
56 | |
57 virtual ~WebFrameTestProxy() {} | |
58 | |
59 // WebFrameClient implementation. | |
60 blink::WebPlugin* createPlugin( | |
61 blink::WebLocalFrame* frame, | |
62 const blink::WebPluginParams& params) override { | |
63 blink::WebPlugin* plugin = test_client()->createPlugin(frame, params); | |
64 if (plugin) | |
65 return plugin; | |
66 return Base::createPlugin(frame, params); | |
67 } | |
68 | |
69 blink::WebScreenOrientationClient* webScreenOrientationClient() override { | |
70 return test_client()->webScreenOrientationClient(); | |
71 } | |
72 | |
73 void didAddMessageToConsole(const blink::WebConsoleMessage& message, | |
74 const blink::WebString& source_name, | |
75 unsigned source_line, | |
76 const blink::WebString& stack_trace) override { | |
77 test_client()->didAddMessageToConsole(message, source_name, source_line, | |
78 stack_trace); | |
79 Base::didAddMessageToConsole( | |
80 message, source_name, source_line, stack_trace); | |
81 } | |
82 | |
83 bool canCreatePluginWithoutRenderer( | |
84 const blink::WebString& mime_type) override { | |
85 const char suffix[] = "-can-create-without-renderer"; | |
86 return mime_type.utf8().find(suffix) != std::string::npos; | |
87 } | |
88 | |
89 void loadURLExternally(const blink::WebURLRequest& request, | |
90 blink::WebNavigationPolicy policy, | |
91 const blink::WebString& suggested_name, | |
92 bool replaces_current_history_item) override { | |
93 test_client()->loadURLExternally(request, policy, suggested_name, | |
94 replaces_current_history_item); | |
95 Base::loadURLExternally(request, policy, suggested_name, | |
96 replaces_current_history_item); | |
97 } | |
98 | |
99 void didStartProvisionalLoad(blink::WebDataSource* data_source) override { | |
100 test_client()->didStartProvisionalLoad(data_source); | |
101 Base::didStartProvisionalLoad(data_source); | |
102 } | |
103 | |
104 void didReceiveServerRedirectForProvisionalLoad( | |
105 blink::WebLocalFrame* frame) override { | |
106 test_client()->didReceiveServerRedirectForProvisionalLoad(frame); | |
107 Base::didReceiveServerRedirectForProvisionalLoad(frame); | |
108 } | |
109 | |
110 void didFailProvisionalLoad( | |
111 blink::WebLocalFrame* frame, | |
112 const blink::WebURLError& error, | |
113 blink::WebHistoryCommitType commit_type) override { | |
114 test_client()->didFailProvisionalLoad(frame, error, commit_type); | |
115 // If the test finished, don't notify the embedder of the failed load, | |
116 // as we already destroyed the document loader. | |
117 if (!frame->provisionalDataSource()) | |
118 return; | |
119 Base::didFailProvisionalLoad(frame, error, commit_type); | |
120 } | |
121 | |
122 void didCommitProvisionalLoad( | |
123 blink::WebLocalFrame* frame, | |
124 const blink::WebHistoryItem& item, | |
125 blink::WebHistoryCommitType commit_type) override { | |
126 test_client()->didCommitProvisionalLoad(frame, item, commit_type); | |
127 Base::didCommitProvisionalLoad(frame, item, commit_type); | |
128 } | |
129 | |
130 void didReceiveTitle(blink::WebLocalFrame* frame, | |
131 const blink::WebString& title, | |
132 blink::WebTextDirection direction) override { | |
133 test_client()->didReceiveTitle(frame, title, direction); | |
134 Base::didReceiveTitle(frame, title, direction); | |
135 } | |
136 | |
137 void didChangeIcon(blink::WebLocalFrame* frame, | |
138 blink::WebIconURL::Type icon_type) override { | |
139 test_client()->didChangeIcon(frame, icon_type); | |
140 Base::didChangeIcon(frame, icon_type); | |
141 } | |
142 | |
143 void didFinishDocumentLoad(blink::WebLocalFrame* frame) override { | |
144 test_client()->didFinishDocumentLoad(frame); | |
145 Base::didFinishDocumentLoad(frame); | |
146 } | |
147 | |
148 void didHandleOnloadEvents(blink::WebLocalFrame* frame) override { | |
149 test_client()->didHandleOnloadEvents(frame); | |
150 Base::didHandleOnloadEvents(frame); | |
151 } | |
152 | |
153 void didFailLoad(blink::WebLocalFrame* frame, | |
154 const blink::WebURLError& error, | |
155 blink::WebHistoryCommitType commit_type) override { | |
156 test_client()->didFailLoad(frame, error, commit_type); | |
157 Base::didFailLoad(frame, error, commit_type); | |
158 } | |
159 | |
160 void didFinishLoad(blink::WebLocalFrame* frame) override { | |
161 Base::didFinishLoad(frame); | |
162 test_client()->didFinishLoad(frame); | |
163 } | |
164 | |
165 void didNavigateWithinPage(blink::WebLocalFrame* frame, | |
166 const blink::WebHistoryItem& history_item, | |
167 blink::WebHistoryCommitType commit_type, | |
168 bool content_initiated) override { | |
169 Base::didNavigateWithinPage(frame, history_item, commit_type, | |
170 content_initiated); | |
171 test_client()->didNavigateWithinPage(frame, history_item, commit_type, | |
172 content_initiated); | |
173 } | |
174 | |
175 void didStopLoading() override { | |
176 Base::didStopLoading(); | |
177 test_client()->didStopLoading(); | |
178 } | |
179 | |
180 void didChangeSelection(bool is_selection_empty) override { | |
181 test_client()->didChangeSelection(is_selection_empty); | |
182 Base::didChangeSelection(is_selection_empty); | |
183 } | |
184 | |
185 blink::WebColorChooser* createColorChooser( | |
186 blink::WebColorChooserClient* client, | |
187 const blink::WebColor& initial_color, | |
188 const blink::WebVector<blink::WebColorSuggestion>& suggestions) override { | |
189 return test_client()->createColorChooser(client, initial_color, | |
190 suggestions); | |
191 } | |
192 | |
193 blink::WebEffectiveConnectionType getEffectiveConnectionType() override { | |
194 if (test_client()->getEffectiveConnectionType() != | |
195 blink::WebEffectiveConnectionType::TypeUnknown) { | |
196 return test_client()->getEffectiveConnectionType(); | |
197 } | |
198 return Base::getEffectiveConnectionType(); | |
199 } | |
200 | |
201 void runModalAlertDialog(const blink::WebString& message) override { | |
202 test_client()->runModalAlertDialog(message); | |
203 } | |
204 | |
205 bool runModalConfirmDialog(const blink::WebString& message) override { | |
206 return test_client()->runModalConfirmDialog(message); | |
207 } | |
208 | |
209 bool runModalPromptDialog(const blink::WebString& message, | |
210 const blink::WebString& default_value, | |
211 blink::WebString* actual_value) override { | |
212 return test_client()->runModalPromptDialog(message, default_value, | |
213 actual_value); | |
214 } | |
215 | |
216 bool runModalBeforeUnloadDialog(bool is_reload) override { | |
217 return test_client()->runModalBeforeUnloadDialog(is_reload); | |
218 } | |
219 | |
220 void showContextMenu( | |
221 const blink::WebContextMenuData& context_menu_data) override { | |
222 test_client()->showContextMenu(context_menu_data); | |
223 Base::showContextMenu(context_menu_data); | |
224 } | |
225 | |
226 void didDetectXSS(const blink::WebURL& insecure_url, | |
227 bool did_block_entire_page) override { | |
228 // This is not implemented in RenderFrameImpl, so need to explicitly call | |
229 // into the base proxy. | |
230 test_client()->didDetectXSS(insecure_url, did_block_entire_page); | |
231 Base::didDetectXSS(insecure_url, did_block_entire_page); | |
232 } | |
233 | |
234 void didDispatchPingLoader(const blink::WebURL& url) override { | |
235 // This is not implemented in RenderFrameImpl, so need to explicitly call | |
236 // into the base proxy. | |
237 test_client()->didDispatchPingLoader(url); | |
238 Base::didDispatchPingLoader(url); | |
239 } | |
240 | |
241 void willSendRequest(blink::WebLocalFrame* frame, | |
242 blink::WebURLRequest& request) override { | |
243 Base::willSendRequest(frame, request); | |
244 test_client()->willSendRequest(frame, request); | |
245 } | |
246 | |
247 void didReceiveResponse(const blink::WebURLResponse& response) override { | |
248 test_client()->didReceiveResponse(response); | |
249 Base::didReceiveResponse(response); | |
250 } | |
251 | |
252 blink::WebNavigationPolicy decidePolicyForNavigation( | |
253 const blink::WebFrameClient::NavigationPolicyInfo& info) override { | |
254 blink::WebNavigationPolicy policy = | |
255 test_client()->decidePolicyForNavigation(info); | |
256 if (policy == blink::WebNavigationPolicyIgnore) | |
257 return policy; | |
258 | |
259 return Base::decidePolicyForNavigation(info); | |
260 } | |
261 | |
262 void didStartLoading(bool to_different_document) override { | |
263 Base::didStartLoading(to_different_document); | |
264 test_client()->didStartLoading(to_different_document); | |
265 } | |
266 | |
267 void willStartUsingPeerConnectionHandler( | |
268 blink::WebRTCPeerConnectionHandler* handler) override { | |
269 // RenderFrameImpl::willStartUsingPeerConnectionHandler can not be mocked. | |
270 // See http://crbug/363285. | |
271 } | |
272 | |
273 blink::WebUserMediaClient* userMediaClient() override { | |
274 return test_client()->userMediaClient(); | |
275 } | |
276 | |
277 void postAccessibilityEvent(const blink::WebAXObject& object, | |
278 blink::WebAXEvent event) override { | |
279 test_client()->postAccessibilityEvent(object, event); | |
280 Base::postAccessibilityEvent(object, event); | |
281 } | |
282 | |
283 void checkIfAudioSinkExistsAndIsAuthorized( | |
284 const blink::WebString& sink_id, | |
285 const blink::WebSecurityOrigin& security_origin, | |
286 blink::WebSetSinkIdCallbacks* web_callbacks) override { | |
287 test_client()->checkIfAudioSinkExistsAndIsAuthorized( | |
288 sink_id, security_origin, web_callbacks); | |
289 } | |
290 | |
291 void didClearWindowObject(blink::WebLocalFrame* frame) override { | |
292 test_client()->didClearWindowObject(frame); | |
293 Base::didClearWindowObject(frame); | |
294 } | |
295 bool runFileChooser(const blink::WebFileChooserParams& params, | |
296 blink::WebFileChooserCompletion* completion) override { | |
297 return test_client()->runFileChooser(params, completion); | |
298 } | |
299 | |
300 private: | |
301 DISALLOW_COPY_AND_ASSIGN(WebFrameTestProxy); | |
302 }; | |
303 | |
304 } // namespace test_runner | |
305 | |
306 #endif // COMPONENTS_TEST_RUNNER_WEB_FRAME_TEST_PROXY_H_ | |
OLD | NEW |