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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
content / browser / renderer_host / input / event_latency_aura_browsertest.cc [blame]
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/test/metrics/histogram_tester.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/hit_test_region_observer.h"
#include "content/shell/browser/shell.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/events/test/event_generator.h"
namespace content {
class EventLatencyBrowserTest : public ContentBrowserTest {
public:
EventLatencyBrowserTest() = default;
~EventLatencyBrowserTest() override = default;
EventLatencyBrowserTest(const EventLatencyBrowserTest&) = delete;
EventLatencyBrowserTest& operator=(const EventLatencyBrowserTest&) = delete;
protected:
RenderWidgetHostImpl* GetWidgetHost() {
return RenderWidgetHostImpl::From(shell()
->web_contents()
->GetPrimaryMainFrame()
->GetRenderViewHost()
->GetWidget());
}
// Starts the test server and navigates to the test page. Returns after the
// navigation is complete.
void LoadTestPage() {
ASSERT_TRUE(embedded_test_server()->Start());
// Navigate to the test page which has a rAF animation and a main thread
// animation running.
GURL test_url =
embedded_test_server()->GetURL("/event-latency-animation.html");
EXPECT_TRUE(NavigateToURL(shell(), test_url));
aura::Window* content = shell()->web_contents()->GetContentNativeView();
content->GetHost()->SetBoundsInPixels(gfx::Rect(800, 600));
RenderWidgetHostImpl* host = GetWidgetHost();
HitTestRegionObserver observer(host->GetFrameSinkId());
// Wait for the hit test data to be ready.
observer.WaitForHitTestData();
}
void FocusButton() const { ASSERT_TRUE(ExecJs(shell(), "focusButton()")); }
void FocusInput() const { ASSERT_TRUE(ExecJs(shell(), "focusInput()")); }
void StartAnimations() const {
ASSERT_TRUE(ExecJs(shell(), "startAnimations()"));
}
};
// Tests that if a key-press on a page causes a visual update, appropriate event
// latency metrics are reported.
// TODO(crbug.com/40132021): flaky test.
IN_PROC_BROWSER_TEST_F(EventLatencyBrowserTest, DISABLED_KeyPressOnButton) {
base::HistogramTester histogram_tester;
ASSERT_NO_FATAL_FAILURE(LoadTestPage());
FocusButton();
ui::test::EventGenerator generator(shell()
->web_contents()
->GetRenderWidgetHostView()
->GetNativeView()
->GetRootWindow());
// Press and release the space key. Since the button on the test page is
// focused, this should change the visuals of the button and generate
// compositor frames with appropriate event latency metrics.
generator.PressKey(ui::VKEY_SPACE, 0);
generator.ReleaseKey(ui::VKEY_SPACE, 0);
RunUntilInputProcessed(GetWidgetHost());
FetchHistogramsFromChildProcesses();
base::HistogramTester::CountsMap expected_counts = {
{"EventLatency.KeyPressed.BrowserToRendererCompositor", 1},
{"EventLatency.KeyPressed.BeginImplFrameToSendBeginMainFrame", 1},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit", 1},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit.HandleInputEvents",
1},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit.Animate", 1},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit.StyleUpdate", 1},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit.LayoutUpdate", 1},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit.Prepaint", 1},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit.Composite", 1},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit.Paint", 1},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit."
"ScrollingCoordinator",
1},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit.CompositeCommit", 1},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit.UpdateLayers", 1},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit."
"BeginMainSentToStarted",
1},
{"EventLatency.KeyPressed.Commit", 1},
{"EventLatency.KeyPressed.EndCommitToActivation", 1},
{"EventLatency.KeyPressed.Activation", 1},
{"EventLatency.KeyPressed.EndActivateToSubmitCompositorFrame", 1},
{"EventLatency.KeyPressed."
"SubmitCompositorFrameToPresentationCompositorFrame",
1},
{"EventLatency.KeyPressed."
"SubmitCompositorFrameToPresentationCompositorFrame."
"SubmitToReceiveCompositorFrame",
1},
{"EventLatency.KeyPressed."
"SubmitCompositorFrameToPresentationCompositorFrame."
"ReceivedCompositorFrameToStartDraw",
1},
{"EventLatency.KeyPressed."
"SubmitCompositorFrameToPresentationCompositorFrame."
"StartDrawToSwapStart",
1},
{"EventLatency.KeyPressed."
"SubmitCompositorFrameToPresentationCompositorFrame.SwapStartToSwapEnd",
1},
{"EventLatency.KeyPressed."
"SubmitCompositorFrameToPresentationCompositorFrame."
"SwapEndToPresentationCompositorFrame",
1},
{"EventLatency.KeyPressed.TotalLatency", 1},
{"EventLatency.KeyReleased.BrowserToRendererCompositor", 1},
{"EventLatency.KeyReleased.BeginImplFrameToSendBeginMainFrame", 1},
{"EventLatency.KeyReleased.SendBeginMainFrameToCommit", 1},
{"EventLatency.KeyReleased.SendBeginMainFrameToCommit.HandleInputEvents",
1},
{"EventLatency.KeyReleased.SendBeginMainFrameToCommit.Animate", 1},
{"EventLatency.KeyReleased.SendBeginMainFrameToCommit.StyleUpdate", 1},
{"EventLatency.KeyReleased.SendBeginMainFrameToCommit.LayoutUpdate", 1},
{"EventLatency.KeyReleased.SendBeginMainFrameToCommit.Prepaint", 1},
{"EventLatency.KeyReleased.SendBeginMainFrameToCommit.Composite", 1},
{"EventLatency.KeyReleased.SendBeginMainFrameToCommit.Paint", 1},
{"EventLatency.KeyReleased.SendBeginMainFrameToCommit."
"ScrollingCoordinator",
1},
{"EventLatency.KeyReleased.SendBeginMainFrameToCommit.CompositeCommit",
1},
{"EventLatency.KeyReleased.SendBeginMainFrameToCommit.UpdateLayers", 1},
{"EventLatency.KeyReleased.SendBeginMainFrameToCommit."
"BeginMainSentToStarted",
1},
{"EventLatency.KeyReleased.Commit", 1},
{"EventLatency.KeyReleased.EndCommitToActivation", 1},
{"EventLatency.KeyReleased.Activation", 1},
{"EventLatency.KeyReleased.EndActivateToSubmitCompositorFrame", 1},
{"EventLatency.KeyReleased."
"SubmitCompositorFrameToPresentationCompositorFrame",
1},
{"EventLatency.KeyReleased."
"SubmitCompositorFrameToPresentationCompositorFrame."
"SubmitToReceiveCompositorFrame",
1},
{"EventLatency.KeyReleased."
"SubmitCompositorFrameToPresentationCompositorFrame."
"ReceivedCompositorFrameToStartDraw",
1},
{"EventLatency.KeyReleased."
"SubmitCompositorFrameToPresentationCompositorFrame."
"StartDrawToSwapStart",
1},
{"EventLatency.KeyReleased."
"SubmitCompositorFrameToPresentationCompositorFrame.SwapStartToSwapEnd",
1},
{"EventLatency.KeyReleased."
"SubmitCompositorFrameToPresentationCompositorFrame."
"SwapEndToPresentationCompositorFrame",
1},
{"EventLatency.KeyReleased.TotalLatency", 1},
{"EventLatency.TotalLatency", 2},
};
EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix("EventLatency."),
testing::ContainerEq(expected_counts));
}
// Tests that if a key-press on a page with an animation causes a visual update,
// appropriate event latency metrics are reported.
// TODO(crbug.com/40128555): Test is flaky.
IN_PROC_BROWSER_TEST_F(EventLatencyBrowserTest,
DISABLED_KeyPressOnButtonWithAnimation) {
base::HistogramTester histogram_tester;
ASSERT_NO_FATAL_FAILURE(LoadTestPage());
StartAnimations();
FocusButton();
ui::test::EventGenerator generator(shell()
->web_contents()
->GetRenderWidgetHostView()
->GetNativeView()
->GetRootWindow());
// Press and release the space key. Since the button on the test page is
// focused, this should change the visuals of the button and generate
// compositor frames with appropriate event latency metrics.
generator.PressKey(ui::VKEY_SPACE, 0);
generator.ReleaseKey(ui::VKEY_SPACE, 0);
RunUntilInputProcessed(GetWidgetHost());
FetchHistogramsFromChildProcesses();
base::HistogramTester::CountsMap expected_counts = {
{"EventLatency.KeyPressed.BrowserToRendererCompositor", 1},
{"EventLatency.KeyPressed.BeginImplFrameToSendBeginMainFrame", 1},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit", 1},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit.HandleInputEvents",
1},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit.Animate", 1},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit.StyleUpdate", 1},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit.LayoutUpdate", 1},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit.Prepaint", 1},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit.Composite", 1},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit.Paint", 1},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit."
"ScrollingCoordinator",
1},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit.CompositeCommit", 1},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit.UpdateLayers", 1},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit."
"BeginMainSentToStarted",
1},
{"EventLatency.KeyPressed.Commit", 1},
{"EventLatency.KeyPressed.EndCommitToActivation", 1},
{"EventLatency.KeyPressed.Activation", 1},
{"EventLatency.KeyPressed.EndActivateToSubmitCompositorFrame", 1},
{"EventLatency.KeyPressed."
"SubmitCompositorFrameToPresentationCompositorFrame",
1},
{"EventLatency.KeyPressed.TotalLatency", 1},
{"EventLatency.KeyPressed."
"SubmitCompositorFrameToPresentationCompositorFrame."
"SubmitToReceiveCompositorFrame",
1},
{"EventLatency.KeyPressed."
"SubmitCompositorFrameToPresentationCompositorFrame."
"ReceivedCompositorFrameToStartDraw",
1},
{"EventLatency.KeyPressed."
"SubmitCompositorFrameToPresentationCompositorFrame."
"StartDrawToSwapStart",
1},
{"EventLatency.KeyPressed."
"SubmitCompositorFrameToPresentationCompositorFrame.SwapStartToSwapEnd",
1},
{"EventLatency.KeyPressed."
"SubmitCompositorFrameToPresentationCompositorFrame."
"SwapEndToPresentationCompositorFrame",
1},
{"EventLatency.KeyReleased.BrowserToRendererCompositor", 1},
{"EventLatency.KeyReleased.BeginImplFrameToSendBeginMainFrame", 1},
{"EventLatency.KeyReleased.SendBeginMainFrameToCommit", 1},
{"EventLatency.KeyReleased.SendBeginMainFrameToCommit.HandleInputEvents",
1},
{"EventLatency.KeyReleased.SendBeginMainFrameToCommit.Animate", 1},
{"EventLatency.KeyReleased.SendBeginMainFrameToCommit.StyleUpdate", 1},
{"EventLatency.KeyReleased.SendBeginMainFrameToCommit.LayoutUpdate", 1},
{"EventLatency.KeyReleased.SendBeginMainFrameToCommit.Prepaint", 1},
{"EventLatency.KeyReleased.SendBeginMainFrameToCommit.Composite", 1},
{"EventLatency.KeyReleased.SendBeginMainFrameToCommit.Paint", 1},
{"EventLatency.KeyReleased.SendBeginMainFrameToCommit."
"ScrollingCoordinator",
1},
{"EventLatency.KeyReleased.SendBeginMainFrameToCommit.CompositeCommit",
1},
{"EventLatency.KeyReleased.SendBeginMainFrameToCommit.UpdateLayers", 1},
{"EventLatency.KeyReleased.SendBeginMainFrameToCommit."
"BeginMainSentToStarted",
1},
{"EventLatency.KeyReleased.Commit", 1},
{"EventLatency.KeyReleased.EndCommitToActivation", 1},
{"EventLatency.KeyReleased.Activation", 1},
{"EventLatency.KeyReleased.EndActivateToSubmitCompositorFrame", 1},
{"EventLatency.KeyReleased."
"SubmitCompositorFrameToPresentationCompositorFrame",
1},
{"EventLatency.KeyReleased."
"SubmitCompositorFrameToPresentationCompositorFrame."
"SubmitToReceiveCompositorFrame",
1},
{"EventLatency.KeyReleased."
"SubmitCompositorFrameToPresentationCompositorFrame."
"ReceivedCompositorFrameToStartDraw",
1},
{"EventLatency.KeyReleased."
"SubmitCompositorFrameToPresentationCompositorFrame."
"StartDrawToSwapStart",
1},
{"EventLatency.KeyReleased."
"SubmitCompositorFrameToPresentationCompositorFrame.SwapStartToSwapEnd",
1},
{"EventLatency.KeyReleased."
"SubmitCompositorFrameToPresentationCompositorFrame."
"SwapEndToPresentationCompositorFrame",
1},
{"EventLatency.KeyReleased.TotalLatency", 1},
{"EventLatency.TotalLatency", 2},
};
EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix("EventLatency."),
testing::ContainerEq(expected_counts));
}
// Tests that entering a character in a textbox leads to appropriate event
// latency metrics being reported even though the page has an animation running.
//
// Disabled due to flakiness on several platforms. See crbug.com/1072340
IN_PROC_BROWSER_TEST_F(EventLatencyBrowserTest,
DISABLED_KeyPressInInputWithAnimation) {
base::HistogramTester histogram_tester;
ASSERT_NO_FATAL_FAILURE(LoadTestPage());
StartAnimations();
FocusInput();
ui::test::EventGenerator generator(shell()
->web_contents()
->GetRenderWidgetHostView()
->GetNativeView()
->GetRootWindow());
// Enter a character into the focused textbox. This should generate compositor
// frames with appropriate event latency metrics.
generator.PressKey(ui::VKEY_A, 0);
generator.ReleaseKey(ui::VKEY_A, 0);
RunUntilInputProcessed(GetWidgetHost());
FetchHistogramsFromChildProcesses();
// TODO(crbug.com/40126863): Since this is this first key-press after the
// textbox is focused, there would be two reports, one for the RawKeyDown that
// causes some style changes (due to :focus-visible behavior) and one for the
// Char that inserts the actual character. These should be reported
// separately.
base::HistogramTester::CountsMap expected_counts = {
{"EventLatency.KeyPressed.BrowserToRendererCompositor", 2},
{"EventLatency.KeyPressed.BeginImplFrameToSendBeginMainFrame", 2},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit", 2},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit.HandleInputEvents",
2},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit.Animate", 2},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit.StyleUpdate", 2},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit.LayoutUpdate", 2},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit.Prepaint", 2},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit.Composite", 2},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit.Paint", 2},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit."
"ScrollingCoordinator",
2},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit.CompositeCommit", 2},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit.UpdateLayers", 2},
{"EventLatency.KeyPressed.SendBeginMainFrameToCommit."
"BeginMainSentToStarted",
2},
{"EventLatency.KeyPressed.Commit", 2},
{"EventLatency.KeyPressed.EndCommitToActivation", 2},
{"EventLatency.KeyPressed.Activation", 2},
{"EventLatency.KeyPressed.EndActivateToSubmitCompositorFrame", 2},
{"EventLatency.KeyPressed."
"SubmitCompositorFrameToPresentationCompositorFrame",
2},
{"EventLatency.KeyPressed."
"SubmitCompositorFrameToPresentationCompositorFrame."
"SubmitToReceiveCompositorFrame",
2},
{"EventLatency.KeyPressed."
"SubmitCompositorFrameToPresentationCompositorFrame."
"ReceivedCompositorFrameToStartDraw",
2},
{"EventLatency.KeyPressed."
"SubmitCompositorFrameToPresentationCompositorFrame."
"StartDrawToSwapStart",
2},
{"EventLatency.KeyPressed."
"SubmitCompositorFrameToPresentationCompositorFrame.SwapStartToSwapEnd",
2},
{"EventLatency.KeyPressed."
"SubmitCompositorFrameToPresentationCompositorFrame."
"SwapEndToPresentationCompositorFrame",
2},
{"EventLatency.KeyPressed.TotalLatency", 2},
{"EventLatency.TotalLatency", 2},
};
EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix("EventLatency."),
testing::ContainerEq(expected_counts));
}
} // namespace content