forked from nwjs/chromium.src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb_frame_test_proxy.cc
More file actions
289 lines (241 loc) · 10.7 KB
/
web_frame_test_proxy.cc
File metadata and controls
289 lines (241 loc) · 10.7 KB
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 2016 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.
#include "content/shell/test_runner/web_frame_test_proxy.h"
#include "content/public/renderer/render_frame_observer.h"
#include "content/shell/test_runner/test_interfaces.h"
#include "content/shell/test_runner/test_runner.h"
#include "content/shell/test_runner/web_frame_test_client.h"
#include "content/shell/test_runner/web_test_delegate.h"
#include "content/shell/test_runner/web_test_interfaces.h"
#include "content/shell/test_runner/web_view_test_proxy.h"
#include "third_party/blink/public/web/web_user_gesture_indicator.h"
namespace test_runner {
namespace {
void PrintFrameUserGestureStatus(WebTestDelegate* delegate,
blink::WebLocalFrame* frame,
const char* msg) {
bool is_user_gesture =
blink::WebUserGestureIndicator::IsProcessingUserGesture(frame);
delegate->PrintMessage(std::string("Frame with user gesture \"") +
(is_user_gesture ? "true" : "false") + "\"" + msg);
}
class TestRenderFrameObserver : public content::RenderFrameObserver {
public:
TestRenderFrameObserver(content::RenderFrame* frame, WebViewTestProxy* proxy)
: RenderFrameObserver(frame), web_view_test_proxy_(proxy) {}
~TestRenderFrameObserver() override {}
private:
TestRunner* test_runner() {
return web_view_test_proxy_->test_interfaces()->GetTestRunner();
}
WebTestDelegate* delegate() { return web_view_test_proxy_->delegate(); }
// content::RenderFrameObserver overrides.
void OnDestruct() override { delete this; }
void DidStartProvisionalLoad(blink::WebDocumentLoader* document_loader,
bool is_content_initiated) override {
// A provisional load notification is received when a frame navigation is
// sent to the browser. We don't want to log it again during commit.
if (delegate()->IsNavigationInitiatedByRenderer(
document_loader->GetRequest())) {
return;
}
if (test_runner()->shouldDumpFrameLoadCallbacks()) {
WebFrameTestClient::PrintFrameDescription(delegate(),
render_frame()->GetWebFrame());
delegate()->PrintMessage(" - didStartProvisionalLoadForFrame\n");
}
if (test_runner()->shouldDumpUserGestureInFrameLoadCallbacks()) {
PrintFrameUserGestureStatus(delegate(), render_frame()->GetWebFrame(),
" - in didStartProvisionalLoadForFrame\n");
}
}
void DidFailProvisionalLoad(const blink::WebURLError& error) override {
if (test_runner()->shouldDumpFrameLoadCallbacks()) {
WebFrameTestClient::PrintFrameDescription(delegate(),
render_frame()->GetWebFrame());
delegate()->PrintMessage(" - didFailProvisionalLoadWithError\n");
}
}
void DidCommitProvisionalLoad(bool is_same_document_navigation,
ui::PageTransition transition) override {
if (test_runner()->shouldDumpFrameLoadCallbacks()) {
WebFrameTestClient::PrintFrameDescription(delegate(),
render_frame()->GetWebFrame());
delegate()->PrintMessage(" - didCommitLoadForFrame\n");
}
}
void DidFinishDocumentLoad() override {
if (test_runner()->shouldDumpFrameLoadCallbacks()) {
WebFrameTestClient::PrintFrameDescription(delegate(),
render_frame()->GetWebFrame());
delegate()->PrintMessage(" - didFinishDocumentLoadForFrame\n");
}
}
void DidFinishLoad() override {
if (test_runner()->shouldDumpFrameLoadCallbacks()) {
WebFrameTestClient::PrintFrameDescription(delegate(),
render_frame()->GetWebFrame());
delegate()->PrintMessage(" - didFinishLoadForFrame\n");
}
}
void DidHandleOnloadEvents() override {
if (test_runner()->shouldDumpFrameLoadCallbacks()) {
WebFrameTestClient::PrintFrameDescription(delegate(),
render_frame()->GetWebFrame());
delegate()->PrintMessage(" - didHandleOnloadEventsForFrame\n");
}
}
WebViewTestProxy* web_view_test_proxy_;
DISALLOW_COPY_AND_ASSIGN(TestRenderFrameObserver);
};
} // namespace
WebFrameTestProxy::~WebFrameTestProxy() = default;
void WebFrameTestProxy::Initialize(
WebTestInterfaces* interfaces,
content::RenderViewImpl* render_view_for_frame) {
// The RenderViewImpl will also be a test proxy type.
auto* view_proxy_for_frame =
static_cast<WebViewTestProxy*>(render_view_for_frame);
test_client_ =
interfaces->CreateWebFrameTestClient(view_proxy_for_frame, this);
new TestRenderFrameObserver(this, view_proxy_for_frame); // deletes itself.
}
// WebLocalFrameClient implementation.
blink::WebPlugin* WebFrameTestProxy::CreatePlugin(
const blink::WebPluginParams& params) {
blink::WebPlugin* plugin = test_client_->CreatePlugin(params);
if (plugin)
return plugin;
return RenderFrameImpl::CreatePlugin(params);
}
void WebFrameTestProxy::DidAddMessageToConsole(
const blink::WebConsoleMessage& message,
const blink::WebString& source_name,
unsigned source_line,
const blink::WebString& stack_trace) {
test_client_->DidAddMessageToConsole(message, source_name, source_line,
stack_trace);
RenderFrameImpl::DidAddMessageToConsole(message, source_name, source_line,
stack_trace);
}
void WebFrameTestProxy::DownloadURL(
const blink::WebURLRequest& request,
blink::WebLocalFrameClient::CrossOriginRedirects
cross_origin_redirect_behavior,
mojo::ScopedMessagePipeHandle blob_url_token) {
test_client_->DownloadURL(request, cross_origin_redirect_behavior,
mojo::ScopedMessagePipeHandle());
RenderFrameImpl::DownloadURL(request, cross_origin_redirect_behavior,
std::move(blob_url_token));
}
void WebFrameTestProxy::DidReceiveTitle(const blink::WebString& title,
blink::WebTextDirection direction) {
test_client_->DidReceiveTitle(title, direction);
RenderFrameImpl::DidReceiveTitle(title, direction);
}
void WebFrameTestProxy::DidChangeIcon(blink::WebIconURL::Type icon_type) {
test_client_->DidChangeIcon(icon_type);
RenderFrameImpl::DidChangeIcon(icon_type);
}
void WebFrameTestProxy::DidFailLoad(const blink::WebURLError& error,
blink::WebHistoryCommitType commit_type) {
test_client_->DidFailLoad(error, commit_type);
RenderFrameImpl::DidFailLoad(error, commit_type);
}
void WebFrameTestProxy::DidStartLoading() {
test_client_->DidStartLoading();
RenderFrameImpl::DidStartLoading();
}
void WebFrameTestProxy::DidStopLoading() {
RenderFrameImpl::DidStopLoading();
test_client_->DidStopLoading();
}
void WebFrameTestProxy::DidChangeSelection(bool is_selection_empty) {
test_client_->DidChangeSelection(is_selection_empty);
RenderFrameImpl::DidChangeSelection(is_selection_empty);
}
void WebFrameTestProxy::DidChangeContents() {
test_client_->DidChangeContents();
RenderFrameImpl::DidChangeContents();
}
blink::WebEffectiveConnectionType
WebFrameTestProxy::GetEffectiveConnectionType() {
if (test_client_->GetEffectiveConnectionType() !=
blink::WebEffectiveConnectionType::kTypeUnknown) {
return test_client_->GetEffectiveConnectionType();
}
return RenderFrameImpl::GetEffectiveConnectionType();
}
void WebFrameTestProxy::RunModalAlertDialog(const blink::WebString& message) {
test_client_->RunModalAlertDialog(message);
}
bool WebFrameTestProxy::RunModalConfirmDialog(const blink::WebString& message) {
return test_client_->RunModalConfirmDialog(message);
}
bool WebFrameTestProxy::RunModalPromptDialog(
const blink::WebString& message,
const blink::WebString& default_value,
blink::WebString* actual_value) {
return test_client_->RunModalPromptDialog(message, default_value,
actual_value);
}
bool WebFrameTestProxy::RunModalBeforeUnloadDialog(bool is_reload) {
return test_client_->RunModalBeforeUnloadDialog(is_reload);
}
void WebFrameTestProxy::ShowContextMenu(
const blink::WebContextMenuData& context_menu_data) {
test_client_->ShowContextMenu(context_menu_data);
RenderFrameImpl::ShowContextMenu(context_menu_data);
}
void WebFrameTestProxy::DidDispatchPingLoader(const blink::WebURL& url) {
// This is not implemented in RenderFrameImpl, so need to explicitly call
// into the base proxy.
test_client_->DidDispatchPingLoader(url);
RenderFrameImpl::DidDispatchPingLoader(url);
}
void WebFrameTestProxy::WillSendRequest(blink::WebURLRequest& request) {
RenderFrameImpl::WillSendRequest(request);
test_client_->WillSendRequest(request);
}
void WebFrameTestProxy::DidReceiveResponse(
const blink::WebURLResponse& response) {
test_client_->DidReceiveResponse(response);
RenderFrameImpl::DidReceiveResponse(response);
}
void WebFrameTestProxy::BeginNavigation(
std::unique_ptr<blink::WebNavigationInfo> info) {
if (test_client_->ShouldContinueNavigation(*info))
RenderFrameImpl::BeginNavigation(std::move(info));
}
void WebFrameTestProxy::PostAccessibilityEvent(const blink::WebAXObject& object,
ax::mojom::Event event) {
test_client_->PostAccessibilityEvent(object, event);
// Guard against the case where |this| was deleted as a result of an
// accessibility listener detaching a frame. If that occurs, the
// WebAXObject will be detached.
if (object.IsDetached())
return; // |this| is invalid.
RenderFrameImpl::PostAccessibilityEvent(object, event);
}
void WebFrameTestProxy::MarkWebAXObjectDirty(const blink::WebAXObject& object,
bool subtree) {
test_client_->MarkWebAXObjectDirty(object, subtree);
// Guard against the case where |this| was deleted as a result of an
// accessibility listener detaching a frame. If that occurs, the
// WebAXObject will be detached.
if (object.IsDetached())
return; // |this| is invalid.
RenderFrameImpl::MarkWebAXObjectDirty(object, subtree);
}
void WebFrameTestProxy::CheckIfAudioSinkExistsAndIsAuthorized(
const blink::WebString& sink_id,
std::unique_ptr<blink::WebSetSinkIdCallbacks> web_callbacks) {
test_client_->CheckIfAudioSinkExistsAndIsAuthorized(sink_id,
std::move(web_callbacks));
}
void WebFrameTestProxy::DidClearWindowObject() {
test_client_->DidClearWindowObject();
RenderFrameImpl::DidClearWindowObject();
}
} // namespace test_runner