Skip to content

Commit 5fe6c1e

Browse files
clellandchromium-wpt-export-bot
authored andcommitted
Don't update LCP for video elements switching from poster.
A video element whose rendered contents are a poster image will have a different MediaTiming than when it's contents are the video itself. However, that different object will cause the MediaRecordId to be different, and so the same element can create two distinct LCP candidate records. This change forces the MediaRecordId to not consider the MediaTiming object when calculating the hash for a video element. Bug: 330202431 Change-Id: I56b8c8d54c1a3d64138f8de529fe15695b1df952 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5970217 Reviewed-by: Hao Liu <[email protected]> Commit-Queue: Ian Clelland <[email protected]> Cr-Commit-Position: refs/heads/main@{#1378586}
1 parent 0a5ba65 commit 5fe6c1e

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!doctype html>
2+
<html>
3+
<title>This test verifies a video element only triggers a single LCP entry</title>
4+
<script src="/resources/testharness.js"></script>
5+
<script src="/resources/testharnessreport.js"></script>
6+
7+
<body>
8+
<video muted src="/images/pattern.webm" poster="/images/lcp-16x16.png" width="600"></video>
9+
<script>
10+
const lcp_entries = [];
11+
let unread_lcp_index = 0;
12+
let lcp_resolver = null;
13+
14+
new PerformanceObserver((list, observer) => {
15+
for (const entry of list.getEntries()) {
16+
lcp_entries.push(entry);
17+
}
18+
// If we're currently waiting for an LCP entry, consume it now.
19+
if (lcp_resolver) {
20+
lcp_resolver();
21+
}
22+
}).observe({ type: "largest-contentful-paint", buffered: true });
23+
24+
get_lcp_entry = async () => {
25+
// If there are no unread LCP entries, wait for one to show up.
26+
if (unread_lcp_index == lcp_entries.length) {
27+
await new Promise((resolve) => { lcp_resolver = resolve; });
28+
lcp_resolver = null;
29+
}
30+
// Return the next unread entry.
31+
unread_lcp_index++;
32+
return lcp_entries[unread_lcp_index-1];
33+
};
34+
35+
promise_test(async t => {
36+
// Ensure that the first LCP is the poster image.
37+
lcpEntry = await get_lcp_entry();
38+
assert_true(lcpEntry.url.endsWith('lcp-16x16.png'), "LCP Entry should be poster, but we got " + lcpEntry.url);
39+
40+
// Start the video.
41+
document.querySelector('video').play();
42+
43+
// Race a task to get a second LCP entry with a 500ms timeout.
44+
const second_lcpEntry = await Promise.race([
45+
new Promise(resolve => { t.step_timeout(() => resolve('TIMEOUT'), 500); }),
46+
get_lcp_entry()
47+
]);
48+
assert_equals(second_lcpEntry, 'TIMEOUT', "There should be no further LCP entry, but we got " + second_lcpEntry.url);
49+
}, "Video with poster should not emit a second LCP entry after playing.")
50+
</script>
51+
</body>
52+
53+
</html>

0 commit comments

Comments
 (0)