OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_TEST_RUNNER_WEB_FRAME_TEST_PROXY_H_ | 5 #ifndef COMPONENTS_TEST_RUNNER_WEB_FRAME_TEST_PROXY_H_ |
6 #define COMPONENTS_TEST_RUNNER_WEB_FRAME_TEST_PROXY_H_ | 6 #define COMPONENTS_TEST_RUNNER_WEB_FRAME_TEST_PROXY_H_ |
7 | 7 |
| 8 #include "base/logging.h" |
8 #include "base/macros.h" | 9 #include "base/macros.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" | 10 #include "third_party/WebKit/public/platform/WebString.h" |
| 11 #include "third_party/WebKit/public/web/WebFrameClient.h" |
| 12 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
15 | 13 |
16 namespace test_runner { | 14 namespace test_runner { |
17 | 15 |
18 // Templetized wrapper around RenderFrameImpl objects, which implement | 16 class WebFrameTestProxyBase { |
19 // the WebFrameClient interface. | 17 public: |
| 18 void set_test_client(blink::WebFrameClient* client) { |
| 19 DCHECK(client); |
| 20 DCHECK(!test_client_); |
| 21 test_client_ = client; |
| 22 } |
| 23 |
| 24 protected: |
| 25 WebFrameTestProxyBase() : test_client_(nullptr) {} |
| 26 blink::WebFrameClient* test_client() { return test_client_; } |
| 27 |
| 28 private: |
| 29 blink::WebFrameClient* test_client_; |
| 30 |
| 31 DISALLOW_COPY_AND_ASSIGN(WebFrameTestProxyBase); |
| 32 }; |
| 33 |
| 34 // WebTestProxy is used during LayoutTests and always instantiated, at time of |
| 35 // writing with Base=RenderFrameImpl. It does not directly inherit from it for |
| 36 // layering purposes. |
20 template <class Base, typename P> | 37 template <class Base, typename P> |
21 class WebFrameTestProxy : public Base { | 38 class WebFrameTestProxy : public Base, public WebFrameTestProxyBase { |
22 public: | 39 public: |
23 explicit WebFrameTestProxy(P p) : Base(p), base_proxy_(NULL) {} | 40 explicit WebFrameTestProxy(P p) : Base(p) {} |
24 | 41 |
25 virtual ~WebFrameTestProxy() {} | 42 virtual ~WebFrameTestProxy() {} |
26 | 43 |
27 void set_base_proxy(WebTestProxyBase* proxy) { base_proxy_ = proxy; } | |
28 | |
29 // WebFrameClient implementation. | 44 // WebFrameClient implementation. |
30 blink::WebPlugin* createPlugin( | 45 blink::WebPlugin* createPlugin( |
31 blink::WebLocalFrame* frame, | 46 blink::WebLocalFrame* frame, |
32 const blink::WebPluginParams& params) override { | 47 const blink::WebPluginParams& params) override { |
33 blink::WebPlugin* plugin = base_proxy_->CreatePlugin(frame, params); | 48 blink::WebPlugin* plugin = test_client()->createPlugin(frame, params); |
34 if (plugin) | 49 if (plugin) |
35 return plugin; | 50 return plugin; |
36 return Base::createPlugin(frame, params); | 51 return Base::createPlugin(frame, params); |
37 } | 52 } |
38 | 53 |
39 blink::WebScreenOrientationClient* webScreenOrientationClient() override { | 54 blink::WebScreenOrientationClient* webScreenOrientationClient() override { |
40 return base_proxy_->GetScreenOrientationClientMock(); | 55 return test_client()->webScreenOrientationClient(); |
41 } | 56 } |
42 | 57 |
43 void didAddMessageToConsole(const blink::WebConsoleMessage& message, | 58 void didAddMessageToConsole(const blink::WebConsoleMessage& message, |
44 const blink::WebString& source_name, | 59 const blink::WebString& source_name, |
45 unsigned source_line, | 60 unsigned source_line, |
46 const blink::WebString& stack_trace) override { | 61 const blink::WebString& stack_trace) override { |
47 base_proxy_->DidAddMessageToConsole(message, source_name, source_line); | 62 test_client()->didAddMessageToConsole(message, source_name, source_line, |
| 63 stack_trace); |
48 Base::didAddMessageToConsole( | 64 Base::didAddMessageToConsole( |
49 message, source_name, source_line, stack_trace); | 65 message, source_name, source_line, stack_trace); |
50 } | 66 } |
51 | 67 |
52 bool canCreatePluginWithoutRenderer( | 68 bool canCreatePluginWithoutRenderer( |
53 const blink::WebString& mime_type) override { | 69 const blink::WebString& mime_type) override { |
54 using blink::WebString; | 70 const char suffix[] = "-can-create-without-renderer"; |
55 | 71 return mime_type.utf8().find(suffix) != std::string::npos; |
56 const CR_DEFINE_STATIC_LOCAL( | |
57 WebString, suffix, ("-can-create-without-renderer")); | |
58 return mime_type.utf8().find(suffix.utf8()) != std::string::npos; | |
59 } | 72 } |
60 | 73 |
61 void loadURLExternally(const blink::WebURLRequest& request, | 74 void loadURLExternally(const blink::WebURLRequest& request, |
62 blink::WebNavigationPolicy policy, | 75 blink::WebNavigationPolicy policy, |
63 const blink::WebString& suggested_name, | 76 const blink::WebString& suggested_name, |
64 bool replaces_current_history_item) override { | 77 bool replaces_current_history_item) override { |
65 base_proxy_->LoadURLExternally(request, policy, suggested_name, | 78 test_client()->loadURLExternally(request, policy, suggested_name, |
66 replaces_current_history_item); | 79 replaces_current_history_item); |
67 Base::loadURLExternally(request, policy, suggested_name, | 80 Base::loadURLExternally(request, policy, suggested_name, |
68 replaces_current_history_item); | 81 replaces_current_history_item); |
69 } | 82 } |
70 | 83 |
71 void didStartProvisionalLoad(blink::WebLocalFrame* frame, | 84 void didStartProvisionalLoad(blink::WebLocalFrame* frame, |
72 double triggeringEventTime) override { | 85 double triggeringEventTime) override { |
73 base_proxy_->DidStartProvisionalLoad(frame); | 86 test_client()->didStartProvisionalLoad(frame, triggeringEventTime); |
74 Base::didStartProvisionalLoad( | 87 Base::didStartProvisionalLoad( |
75 frame, triggeringEventTime); | 88 frame, triggeringEventTime); |
76 } | 89 } |
77 | 90 |
78 void didReceiveServerRedirectForProvisionalLoad( | 91 void didReceiveServerRedirectForProvisionalLoad( |
79 blink::WebLocalFrame* frame) override { | 92 blink::WebLocalFrame* frame) override { |
80 base_proxy_->DidReceiveServerRedirectForProvisionalLoad(frame); | 93 test_client()->didReceiveServerRedirectForProvisionalLoad(frame); |
81 Base::didReceiveServerRedirectForProvisionalLoad(frame); | 94 Base::didReceiveServerRedirectForProvisionalLoad(frame); |
82 } | 95 } |
83 | 96 |
84 void didFailProvisionalLoad( | 97 void didFailProvisionalLoad( |
85 blink::WebLocalFrame* frame, | 98 blink::WebLocalFrame* frame, |
86 const blink::WebURLError& error, | 99 const blink::WebURLError& error, |
87 blink::WebHistoryCommitType commit_type) override { | 100 blink::WebHistoryCommitType commit_type) override { |
| 101 test_client()->didFailProvisionalLoad(frame, error, commit_type); |
88 // If the test finished, don't notify the embedder of the failed load, | 102 // If the test finished, don't notify the embedder of the failed load, |
89 // as we already destroyed the document loader. | 103 // as we already destroyed the document loader. |
90 if (base_proxy_->DidFailProvisionalLoad(frame, error, commit_type)) | 104 if (!frame->provisionalDataSource()) |
91 return; | 105 return; |
92 Base::didFailProvisionalLoad(frame, error, commit_type); | 106 Base::didFailProvisionalLoad(frame, error, commit_type); |
93 } | 107 } |
94 | 108 |
95 void didCommitProvisionalLoad( | 109 void didCommitProvisionalLoad( |
96 blink::WebLocalFrame* frame, | 110 blink::WebLocalFrame* frame, |
97 const blink::WebHistoryItem& item, | 111 const blink::WebHistoryItem& item, |
98 blink::WebHistoryCommitType commit_type) override { | 112 blink::WebHistoryCommitType commit_type) override { |
99 base_proxy_->DidCommitProvisionalLoad(frame, item, commit_type); | 113 test_client()->didCommitProvisionalLoad(frame, item, commit_type); |
100 Base::didCommitProvisionalLoad(frame, item, commit_type); | 114 Base::didCommitProvisionalLoad(frame, item, commit_type); |
101 } | 115 } |
102 | 116 |
103 void didReceiveTitle(blink::WebLocalFrame* frame, | 117 void didReceiveTitle(blink::WebLocalFrame* frame, |
104 const blink::WebString& title, | 118 const blink::WebString& title, |
105 blink::WebTextDirection direction) override { | 119 blink::WebTextDirection direction) override { |
106 base_proxy_->DidReceiveTitle(frame, title, direction); | 120 test_client()->didReceiveTitle(frame, title, direction); |
107 Base::didReceiveTitle(frame, title, direction); | 121 Base::didReceiveTitle(frame, title, direction); |
108 } | 122 } |
109 | 123 |
110 void didChangeIcon(blink::WebLocalFrame* frame, | 124 void didChangeIcon(blink::WebLocalFrame* frame, |
111 blink::WebIconURL::Type icon_type) override { | 125 blink::WebIconURL::Type icon_type) override { |
112 base_proxy_->DidChangeIcon(frame, icon_type); | 126 test_client()->didChangeIcon(frame, icon_type); |
113 Base::didChangeIcon(frame, icon_type); | 127 Base::didChangeIcon(frame, icon_type); |
114 } | 128 } |
115 | 129 |
116 void didFinishDocumentLoad(blink::WebLocalFrame* frame) override { | 130 void didFinishDocumentLoad(blink::WebLocalFrame* frame) override { |
117 base_proxy_->DidFinishDocumentLoad(frame); | 131 test_client()->didFinishDocumentLoad(frame); |
118 Base::didFinishDocumentLoad(frame); | 132 Base::didFinishDocumentLoad(frame); |
119 } | 133 } |
120 | 134 |
121 void didHandleOnloadEvents(blink::WebLocalFrame* frame) override { | 135 void didHandleOnloadEvents(blink::WebLocalFrame* frame) override { |
122 base_proxy_->DidHandleOnloadEvents(frame); | 136 test_client()->didHandleOnloadEvents(frame); |
123 Base::didHandleOnloadEvents(frame); | 137 Base::didHandleOnloadEvents(frame); |
124 } | 138 } |
125 | 139 |
126 void didFailLoad(blink::WebLocalFrame* frame, | 140 void didFailLoad(blink::WebLocalFrame* frame, |
127 const blink::WebURLError& error, | 141 const blink::WebURLError& error, |
128 blink::WebHistoryCommitType commit_type) override { | 142 blink::WebHistoryCommitType commit_type) override { |
129 base_proxy_->DidFailLoad(frame, error, commit_type); | 143 test_client()->didFailLoad(frame, error, commit_type); |
130 Base::didFailLoad(frame, error, commit_type); | 144 Base::didFailLoad(frame, error, commit_type); |
131 } | 145 } |
132 | 146 |
133 void didFinishLoad(blink::WebLocalFrame* frame) override { | 147 void didFinishLoad(blink::WebLocalFrame* frame) override { |
134 Base::didFinishLoad(frame); | 148 Base::didFinishLoad(frame); |
135 base_proxy_->DidFinishLoad(frame); | 149 test_client()->didFinishLoad(frame); |
136 } | 150 } |
137 | 151 |
138 void didChangeSelection(bool is_selection_empty) override { | 152 void didChangeSelection(bool is_selection_empty) override { |
139 base_proxy_->DidChangeSelection(is_selection_empty); | 153 test_client()->didChangeSelection(is_selection_empty); |
140 Base::didChangeSelection(is_selection_empty); | 154 Base::didChangeSelection(is_selection_empty); |
141 } | 155 } |
142 | 156 |
143 blink::WebColorChooser* createColorChooser( | 157 blink::WebColorChooser* createColorChooser( |
144 blink::WebColorChooserClient* client, | 158 blink::WebColorChooserClient* client, |
145 const blink::WebColor& initial_color, | 159 const blink::WebColor& initial_color, |
146 const blink::WebVector<blink::WebColorSuggestion>& suggestions) override { | 160 const blink::WebVector<blink::WebColorSuggestion>& suggestions) override { |
147 return base_proxy_->CreateColorChooser(client, initial_color, suggestions); | 161 return test_client()->createColorChooser(client, initial_color, |
| 162 suggestions); |
148 } | 163 } |
149 | 164 |
150 void runModalAlertDialog(const blink::WebString& message) override { | 165 void runModalAlertDialog(const blink::WebString& message) override { |
151 base_proxy_->RunModalAlertDialog(message); | 166 test_client()->runModalAlertDialog(message); |
152 } | 167 } |
153 | 168 |
154 bool runModalConfirmDialog(const blink::WebString& message) override { | 169 bool runModalConfirmDialog(const blink::WebString& message) override { |
155 return base_proxy_->RunModalConfirmDialog(message); | 170 return test_client()->runModalConfirmDialog(message); |
156 } | 171 } |
157 | 172 |
158 bool runModalPromptDialog(const blink::WebString& message, | 173 bool runModalPromptDialog(const blink::WebString& message, |
159 const blink::WebString& default_value, | 174 const blink::WebString& default_value, |
160 blink::WebString* actual_value) override { | 175 blink::WebString* actual_value) override { |
161 return base_proxy_->RunModalPromptDialog(message, default_value, | 176 return test_client()->runModalPromptDialog(message, default_value, |
162 actual_value); | 177 actual_value); |
163 } | 178 } |
164 | 179 |
165 bool runModalBeforeUnloadDialog(bool is_reload) override { | 180 bool runModalBeforeUnloadDialog(bool is_reload) override { |
166 return base_proxy_->RunModalBeforeUnloadDialog(is_reload); | 181 return test_client()->runModalBeforeUnloadDialog(is_reload); |
167 } | 182 } |
168 | 183 |
169 void showContextMenu( | 184 void showContextMenu( |
170 const blink::WebContextMenuData& context_menu_data) override { | 185 const blink::WebContextMenuData& context_menu_data) override { |
171 base_proxy_->ShowContextMenu(context_menu_data); | 186 test_client()->showContextMenu(context_menu_data); |
172 Base::showContextMenu(context_menu_data); | 187 Base::showContextMenu(context_menu_data); |
173 } | 188 } |
174 | 189 |
175 void didDetectXSS(const blink::WebURL& insecure_url, | 190 void didDetectXSS(const blink::WebURL& insecure_url, |
176 bool did_block_entire_page) override { | 191 bool did_block_entire_page) override { |
177 // This is not implemented in RenderFrameImpl, so need to explicitly call | 192 // This is not implemented in RenderFrameImpl, so need to explicitly call |
178 // into the base proxy. | 193 // into the base proxy. |
179 base_proxy_->DidDetectXSS(insecure_url, did_block_entire_page); | 194 test_client()->didDetectXSS(insecure_url, did_block_entire_page); |
180 Base::didDetectXSS(insecure_url, did_block_entire_page); | 195 Base::didDetectXSS(insecure_url, did_block_entire_page); |
181 } | 196 } |
182 | 197 |
183 void didDispatchPingLoader(const blink::WebURL& url) override { | 198 void didDispatchPingLoader(const blink::WebURL& url) override { |
184 // This is not implemented in RenderFrameImpl, so need to explicitly call | 199 // This is not implemented in RenderFrameImpl, so need to explicitly call |
185 // into the base proxy. | 200 // into the base proxy. |
186 base_proxy_->DidDispatchPingLoader(url); | 201 test_client()->didDispatchPingLoader(url); |
187 Base::didDispatchPingLoader(url); | 202 Base::didDispatchPingLoader(url); |
188 } | 203 } |
189 | 204 |
190 void didCreateDataSource(blink::WebLocalFrame* frame, | |
191 blink::WebDataSource* ds) override { | |
192 Base::didCreateDataSource(frame, ds); | |
193 } | |
194 | |
195 void willSendRequest( | 205 void willSendRequest( |
196 blink::WebLocalFrame* frame, | 206 blink::WebLocalFrame* frame, |
197 unsigned identifier, | 207 unsigned identifier, |
198 blink::WebURLRequest& request, | 208 blink::WebURLRequest& request, |
199 const blink::WebURLResponse& redirect_response) override { | 209 const blink::WebURLResponse& redirect_response) override { |
200 Base::willSendRequest(frame, identifier, request, redirect_response); | 210 Base::willSendRequest(frame, identifier, request, redirect_response); |
201 base_proxy_->WillSendRequest(frame, identifier, request, redirect_response); | 211 test_client()->willSendRequest(frame, identifier, request, |
| 212 redirect_response); |
202 } | 213 } |
203 | 214 |
204 void didReceiveResponse(unsigned identifier, | 215 void didReceiveResponse(unsigned identifier, |
205 const blink::WebURLResponse& response) override { | 216 const blink::WebURLResponse& response) override { |
206 base_proxy_->DidReceiveResponse(identifier, response); | 217 test_client()->didReceiveResponse(identifier, response); |
207 Base::didReceiveResponse(identifier, response); | 218 Base::didReceiveResponse(identifier, response); |
208 } | 219 } |
209 | 220 |
210 void didChangeResourcePriority(unsigned identifier, | 221 void didChangeResourcePriority(unsigned identifier, |
211 const blink::WebURLRequest::Priority& priority, | 222 const blink::WebURLRequest::Priority& priority, |
212 int intra_priority_value) override { | 223 int intra_priority_value) override { |
213 // This is not implemented in RenderFrameImpl, so need to explicitly call | 224 // This is not implemented in RenderFrameImpl, so need to explicitly call |
214 // into the base proxy. | 225 // into the base proxy. |
215 base_proxy_->DidChangeResourcePriority( | 226 test_client()->didChangeResourcePriority(identifier, priority, |
216 identifier, priority, intra_priority_value); | 227 intra_priority_value); |
217 Base::didChangeResourcePriority( | 228 Base::didChangeResourcePriority( |
218 identifier, priority, intra_priority_value); | 229 identifier, priority, intra_priority_value); |
219 } | 230 } |
220 | 231 |
221 void didFinishResourceLoad(blink::WebLocalFrame* frame, | 232 void didFinishResourceLoad(blink::WebLocalFrame* frame, |
222 unsigned identifier) override { | 233 unsigned identifier) override { |
223 base_proxy_->DidFinishResourceLoad(frame, identifier); | 234 test_client()->didFinishResourceLoad(frame, identifier); |
224 } | 235 } |
225 | 236 |
226 blink::WebNavigationPolicy decidePolicyForNavigation( | 237 blink::WebNavigationPolicy decidePolicyForNavigation( |
227 const blink::WebFrameClient::NavigationPolicyInfo& info) override { | 238 const blink::WebFrameClient::NavigationPolicyInfo& info) override { |
228 blink::WebNavigationPolicy policy = base_proxy_->DecidePolicyForNavigation( | 239 blink::WebNavigationPolicy policy = |
229 info); | 240 test_client()->decidePolicyForNavigation(info); |
230 if (policy == blink::WebNavigationPolicyIgnore) | 241 if (policy == blink::WebNavigationPolicyIgnore) |
231 return policy; | 242 return policy; |
232 | 243 |
233 return Base::decidePolicyForNavigation(info); | 244 return Base::decidePolicyForNavigation(info); |
234 } | 245 } |
235 | 246 |
236 void willStartUsingPeerConnectionHandler( | 247 void willStartUsingPeerConnectionHandler( |
237 blink::WebRTCPeerConnectionHandler* handler) override { | 248 blink::WebRTCPeerConnectionHandler* handler) override { |
238 // RenderFrameImpl::willStartUsingPeerConnectionHandler can not be mocked. | 249 // RenderFrameImpl::willStartUsingPeerConnectionHandler can not be mocked. |
239 // See http://crbug/363285. | 250 // See http://crbug/363285. |
240 } | 251 } |
241 | 252 |
242 blink::WebUserMediaClient* userMediaClient() override { | 253 blink::WebUserMediaClient* userMediaClient() override { |
243 return base_proxy_->GetUserMediaClient(); | 254 return test_client()->userMediaClient(); |
244 } | 255 } |
245 | 256 |
246 bool willCheckAndDispatchMessageEvent( | 257 bool willCheckAndDispatchMessageEvent( |
247 blink::WebLocalFrame* source_frame, | 258 blink::WebLocalFrame* source_frame, |
248 blink::WebFrame* target_frame, | 259 blink::WebFrame* target_frame, |
249 blink::WebSecurityOrigin target, | 260 blink::WebSecurityOrigin target, |
250 blink::WebDOMMessageEvent event) override { | 261 blink::WebDOMMessageEvent event) override { |
251 if (base_proxy_->WillCheckAndDispatchMessageEvent( | 262 if (test_client()->willCheckAndDispatchMessageEvent( |
252 source_frame, target_frame, target, event)) | 263 source_frame, target_frame, target, event)) |
253 return true; | 264 return true; |
254 return Base::willCheckAndDispatchMessageEvent( | 265 return Base::willCheckAndDispatchMessageEvent( |
255 source_frame, target_frame, target, event); | 266 source_frame, target_frame, target, event); |
256 } | 267 } |
257 | 268 |
258 void postAccessibilityEvent(const blink::WebAXObject& object, | 269 void postAccessibilityEvent(const blink::WebAXObject& object, |
259 blink::WebAXEvent event) override { | 270 blink::WebAXEvent event) override { |
260 base_proxy_->PostAccessibilityEvent(object, event); | 271 test_client()->postAccessibilityEvent(object, event); |
261 Base::postAccessibilityEvent(object, event); | 272 Base::postAccessibilityEvent(object, event); |
262 } | 273 } |
263 | 274 |
264 void checkIfAudioSinkExistsAndIsAuthorized( | 275 void checkIfAudioSinkExistsAndIsAuthorized( |
265 const blink::WebString& sink_id, | 276 const blink::WebString& sink_id, |
266 const blink::WebSecurityOrigin& security_origin, | 277 const blink::WebSecurityOrigin& security_origin, |
267 blink::WebSetSinkIdCallbacks* web_callbacks) override { | 278 blink::WebSetSinkIdCallbacks* web_callbacks) override { |
268 base_proxy_->CheckIfAudioSinkExistsAndIsAuthorized(sink_id, security_origin, | 279 test_client()->checkIfAudioSinkExistsAndIsAuthorized( |
269 web_callbacks); | 280 sink_id, security_origin, web_callbacks); |
270 } | 281 } |
271 | 282 |
272 private: | 283 private: |
273 WebTestProxyBase* base_proxy_; | |
274 | |
275 DISALLOW_COPY_AND_ASSIGN(WebFrameTestProxy); | 284 DISALLOW_COPY_AND_ASSIGN(WebFrameTestProxy); |
276 }; | 285 }; |
277 | 286 |
278 } // namespace test_runner | 287 } // namespace test_runner |
279 | 288 |
280 #endif // COMPONENTS_TEST_RUNNER_WEB_FRAME_TEST_PROXY_H_ | 289 #endif // COMPONENTS_TEST_RUNNER_WEB_FRAME_TEST_PROXY_H_ |
OLD | NEW |