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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
content / public / test / mock_web_contents_observer.h [blame]
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_PUBLIC_TEST_MOCK_WEB_CONTENTS_OBSERVER_H_
#define CONTENT_PUBLIC_TEST_MOCK_WEB_CONTENTS_OBSERVER_H_
#include "content/public/browser/web_contents_observer.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/accessibility/ax_updates_and_events.h"
namespace content {
// A mock WebContentsObserver with which tests can set expectations for how
// observer methods are called in response to actions taken in the test.
//
// For example:
// GURL url = ...
// testing::NiceMock<MockWebContentsObserver> observer(web_contents());
// EXPECT_CALL(observer,
// DidStartNavigation(
// testing::Truly([&](NavigationHandle* navigation_handle) {
// return navigation_handle->GetURL() == url;
// })));
// EXPECT_TRUE(NavigateToURL(shell(), url));
//
class MockWebContentsObserver : public WebContentsObserver {
public:
explicit MockWebContentsObserver(WebContents* web_contents);
~MockWebContentsObserver() override;
MOCK_METHOD(void,
RenderFrameCreated,
(RenderFrameHost* render_frame_host),
(override));
MOCK_METHOD(void,
RenderFrameDeleted,
(RenderFrameHost* render_frame_host),
(override));
MOCK_METHOD(void, PrimaryPageChanged, (Page & page), (override));
MOCK_METHOD(void,
RenderFrameHostChanged,
(RenderFrameHost* old_host, RenderFrameHost* new_host),
(override));
MOCK_METHOD(void,
FrameDeleted,
(FrameTreeNodeId frame_tree_node_id),
(override));
MOCK_METHOD(void,
RenderFrameHostStateChanged,
(RenderFrameHost* render_frame_host,
RenderFrameHost::LifecycleState old_state,
RenderFrameHost::LifecycleState new_state),
(override));
MOCK_METHOD(void, CaptureTargetChanged, (), (override));
MOCK_METHOD(void, RenderViewReady, (), (override));
MOCK_METHOD(void,
RenderViewDeleted,
(RenderViewHost* render_view_host),
(override));
MOCK_METHOD(void,
PrimaryMainFrameRenderProcessGone,
(base::TerminationStatus status),
(override));
MOCK_METHOD(void,
RenderViewHostChanged,
(RenderViewHost* old_host, RenderViewHost* new_host),
(override));
MOCK_METHOD(void,
OnRendererUnresponsive,
(RenderProcessHost* render_process_host),
(override));
MOCK_METHOD(void,
OnRendererResponsive,
(RenderProcessHost* render_process_host),
(override));
MOCK_METHOD(void,
DidStartNavigation,
(NavigationHandle* navigation_handle),
(override));
MOCK_METHOD(void,
DidRedirectNavigation,
(NavigationHandle* navigation_handle),
(override));
MOCK_METHOD(void,
ReadyToCommitNavigation,
(NavigationHandle* navigation_handle),
(override));
MOCK_METHOD(void,
DidFinishNavigation,
(NavigationHandle* navigation_handle),
(override));
MOCK_METHOD(void, DidStartLoading, (), (override));
MOCK_METHOD(void, DidStopLoading, (), (override));
MOCK_METHOD(void, LoadProgressChanged, (double progress), (override));
MOCK_METHOD(void, PrimaryMainDocumentElementAvailable, (), (override));
MOCK_METHOD(void, DocumentOnLoadCompletedInPrimaryMainFrame, (), (override));
MOCK_METHOD(void,
DOMContentLoaded,
(RenderFrameHost* render_frame_host),
(override));
MOCK_METHOD(void,
DidFinishLoad,
(RenderFrameHost* render_frame_host, const GURL& validated_url),
(override));
MOCK_METHOD(void,
DidFailLoad,
(RenderFrameHost* render_frame_host,
const GURL& validated_url,
int error_code),
(override));
MOCK_METHOD(void, DidChangeVisibleSecurityState, (), (override));
MOCK_METHOD(void,
DidLoadResourceFromMemoryCache,
(RenderFrameHost* render_frame_host,
const GURL& url,
const std::string& mime_type,
network::mojom::RequestDestination request_destination),
(override));
MOCK_METHOD(void,
ResourceLoadComplete,
(RenderFrameHost* render_frame_host,
const GlobalRequestID& request_id,
const blink::mojom::ResourceLoadInfo& resource_load_info),
(override));
MOCK_METHOD(void,
OnCookiesAccessed,
(RenderFrameHost* render_frame_host,
const CookieAccessDetails& details),
(override));
MOCK_METHOD(void,
OnCookiesAccessed,
(NavigationHandle* navigation_handle,
const CookieAccessDetails& details),
(override));
MOCK_METHOD(void,
NavigationEntryCommitted,
(const LoadCommittedDetails& load_details),
(override));
MOCK_METHOD(void,
NavigationListPruned,
(const PrunedDetails& pruned_details),
(override));
MOCK_METHOD(void, NavigationEntriesDeleted, (), (override));
MOCK_METHOD(void,
NavigationEntryChanged,
(const EntryChangedDetails& change_details),
(override));
MOCK_METHOD(void,
DidOpenRequestedURL,
(WebContents* new_contents,
RenderFrameHost* source_render_frame_host,
const GURL& url,
const Referrer& referrer,
WindowOpenDisposition disposition,
ui::PageTransition transition,
bool started_from_context_menu,
bool renderer_initiated),
(override));
MOCK_METHOD(void, DidFirstVisuallyNonEmptyPaint, (), (override));
MOCK_METHOD(void, NavigationStopped, (), (override));
MOCK_METHOD(void,
DidGetUserInteraction,
(const blink::WebInputEvent& event),
(override));
MOCK_METHOD(void, DidGetIgnoredUIEvent, (), (override));
MOCK_METHOD(void, OnVisibilityChanged, (Visibility visibility), (override));
MOCK_METHOD(void,
PrimaryMainFrameWasResized,
(bool width_changed),
(override));
MOCK_METHOD(void,
FrameNameChanged,
(RenderFrameHost* render_frame_host, const std::string& name),
(override));
MOCK_METHOD(void,
FrameReceivedUserActivation,
(RenderFrameHost* render_frame_host),
(override));
MOCK_METHOD(void,
FrameDisplayStateChanged,
(RenderFrameHost* render_frame_host, bool is_display_none),
(override));
MOCK_METHOD(void,
FrameSizeChanged,
(RenderFrameHost* render_frame_host,
const gfx::Size& frame_size),
(override));
MOCK_METHOD(void, TitleWasSet, (NavigationEntry * entry), (override));
MOCK_METHOD(void, PepperInstanceCreated, (), (override));
MOCK_METHOD(void, PepperInstanceDeleted, (), (override));
MOCK_METHOD(void,
ViewportFitChanged,
(blink::mojom::ViewportFit value),
(override));
MOCK_METHOD(void,
PluginCrashed,
(const base::FilePath& plugin_path, base::ProcessId plugin_pid),
(override));
MOCK_METHOD(void,
PluginHungStatusChanged,
(int plugin_child_id,
const base::FilePath& plugin_path,
bool is_hung),
(override));
MOCK_METHOD(void,
InnerWebContentsCreated,
(WebContents* inner_web_contents),
(override));
MOCK_METHOD(void,
InnerWebContentsAttached,
(WebContents* inner_web_contents,
RenderFrameHost* render_frame_host),
(override));
MOCK_METHOD(void,
DidCloneToNewWebContents,
(WebContents* old_web_contents, WebContents* new_web_contents),
(override));
MOCK_METHOD(void, WebContentsDestroyed, (), (override));
MOCK_METHOD(void,
UserAgentOverrideSet,
(const blink::UserAgentOverride& ua_override),
(override));
MOCK_METHOD(void,
DidUpdateFaviconURL,
(RenderFrameHost* render_frame_host,
const std::vector<blink::mojom::FaviconURLPtr>& candidates),
(override));
MOCK_METHOD(void, OnAudioStateChanged, (bool audible), (override));
MOCK_METHOD(void,
OnFrameAudioStateChanged,
(RenderFrameHost* rfh, bool audible),
(override));
MOCK_METHOD(void,
OnDeviceConnectionTypesChanged,
(DeviceConnectionType connection_type, bool used),
(override));
MOCK_METHOD(void, DidUpdateAudioMutingState, (bool muted), (override));
MOCK_METHOD(void,
DidToggleFullscreenModeForTab,
(bool entered_fullscreen, bool will_cause_resize),
(override));
MOCK_METHOD(void, DidAcquireFullscreen, (RenderFrameHost* rfh), (override));
MOCK_METHOD(void,
DidChangeVerticalScrollDirection,
(viz::VerticalScrollDirection scroll_direction),
(override));
MOCK_METHOD(void, BeforeFormRepostWarningShow, (), (override));
MOCK_METHOD(void, BeforeUnloadFired, (bool proceed), (override));
MOCK_METHOD(void, BeforeUnloadDialogCancelled, (), (override));
MOCK_METHOD(void, AXTreeIDForMainFrameHasChanged, (), (override));
MOCK_METHOD(void,
AccessibilityEventReceived,
(const ui::AXUpdatesAndEvents& details),
(override));
MOCK_METHOD(void,
AccessibilityLocationChangesReceived,
(const ui::AXTreeID& tree_id,
ui::AXLocationAndScrollUpdates& details),
(override));
MOCK_METHOD(void, DidChangeThemeColor, (), (override));
MOCK_METHOD(void, OnBackgroundColorChanged, (), (override));
MOCK_METHOD(void,
OnDidAddMessageToConsole,
(RenderFrameHost * source_frame,
blink::mojom::ConsoleMessageLevel log_level,
const std::u16string& message,
int32_t line_no,
const std::u16string& source_id,
const std::optional<std::u16string>& untrusted_stack_trace),
(override));
MOCK_METHOD(void,
MediaStartedPlaying,
(const MediaPlayerInfo& video_type, const MediaPlayerId& id),
(override));
MOCK_METHOD(void,
MediaStoppedPlaying,
(const MediaPlayerInfo& video_type,
const MediaPlayerId& id,
WebContentsObserver::MediaStoppedReason reason),
(override));
MOCK_METHOD(void,
MediaResized,
(const gfx::Size& size, const MediaPlayerId& id),
(override));
MOCK_METHOD(void,
MediaEffectivelyFullscreenChanged,
(bool is_fullscreen),
(override));
MOCK_METHOD(void,
MediaPictureInPictureChanged,
(bool is_picture_in_picture),
(override));
MOCK_METHOD(void,
MediaMutedStatusChanged,
(const MediaPlayerId& id, bool muted),
(override));
MOCK_METHOD(void, MediaDestroyed, (const MediaPlayerId& id), (override));
MOCK_METHOD(void,
OnPageScaleFactorChanged,
(float page_scale_factor),
(override));
MOCK_METHOD(void, OnPaste, (), (override));
MOCK_METHOD(void,
OnWebContentsFocused,
(RenderWidgetHost* render_widget_host),
(override));
MOCK_METHOD(void,
OnWebContentsLostFocus,
(RenderWidgetHost* render_widget_host),
(override));
MOCK_METHOD(void,
OnFocusChangedInPage,
(FocusedNodeDetails* details),
(override));
MOCK_METHOD(void,
DidUpdateWebManifestURL,
(RenderFrameHost * target_frame, const GURL& manifest_url),
(override));
MOCK_METHOD(void,
AudioContextPlaybackStarted,
(const AudioContextId& audio_context_id),
(override));
MOCK_METHOD(void,
AudioContextPlaybackStopped,
(const AudioContextId& audio_context_id),
(override));
MOCK_METHOD(void,
OnServiceWorkerAccessed,
(RenderFrameHost* render_frame_host,
const GURL& scope,
AllowServiceWorkerResult allowed),
(override));
MOCK_METHOD(void,
OnServiceWorkerAccessed,
(NavigationHandle* navigation_handle,
const GURL& scope,
AllowServiceWorkerResult allowed),
(override));
MOCK_METHOD(void,
AboutToBeDiscarded,
(WebContents * new_contents),
(override));
MOCK_METHOD(void, WasDiscarded, (), (override));
};
} // namespace content
#endif // CONTENT_PUBLIC_TEST_MOCK_WEB_CONTENTS_OBSERVER_H_