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