Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: components/test_runner/web_frame_test_proxy.h

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

Powered by Google App Engine
This is Rietveld 408576698