-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[M103] [Paint Preview] Ignore Paint Timing while capturing
WebLocalFrameImpl::CapturePaintPreview can cause LCP to select elements that are off-screen. Avoid this by skipping paint timings while it is running. (cherry picked from commit 3e66b23) Bug: 1323073 Change-Id: I549fd7ae853e656534f2e768454d9bf5f01dedf1 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3661154 Reviewed-by: Calder Kitagawa <ckitagawa@chromium.org> Reviewed-by: Yoav Weiss <yoavweiss@chromium.org> Commit-Queue: Daniel Rubery <drubery@chromium.org> Cr-Original-Commit-Position: refs/heads/main@{#1006953} Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3671535 Reviewed-by: Krishna Govind <govind@chromium.org> Owners-Override: Krishna Govind <govind@chromium.org> Commit-Queue: Krishna Govind <govind@chromium.org> Cr-Commit-Position: refs/branch-heads/5060@{#422} Cr-Branched-From: b83393d-refs/heads/main@{#1002911}
- Loading branch information
Daniel Rubery
authored and
Chromium LUCI CQ
committed
May 31, 2022
1 parent
c4fbea8
commit 50d9535
Showing
3 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
...wser/page_load_metrics/integration_tests/data/largest_contentful_paint_paint_preview.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<script src="resources/testharness.js"></script> | ||
<script> | ||
// Tell testharness.js to not wait for 'real' tests; we only want | ||
// testharness.js for its assertion helpers. | ||
setup({'output': false}); | ||
</script> | ||
|
||
<script> | ||
// 'AsyncBuffer' serves as a helper to buffer LCP reports asynchronously. | ||
class AsyncBuffer { | ||
constructor() { | ||
// 'pending' is an array that will buffer entries reported through the | ||
// PerformanceObserver and can be collected with 'pop'. | ||
this.pending = []; | ||
|
||
// 'resolve_fn' is a reference to the 'resolve' function of a | ||
// Promise that blocks for new entries to arrive via 'push()'. Calling | ||
// the function resolves the promise and unblocks calls to 'pop()'. | ||
this.resolve_fn = null; | ||
} | ||
|
||
// Concatenates the given 'entries' list to this AsyncBuffer. | ||
push(entries) { | ||
if (entries.length == 0) { | ||
throw new Error("Must not push an empty list of entries!"); | ||
} | ||
this.pending = this.pending.concat(entries); | ||
|
||
// If there are calls to 'pop' that are blocked waiting for items, signal | ||
// that they can continue. | ||
if (this.resolve_fn != null) { | ||
this.resolve_fn(); | ||
this.resolve_fn = null; | ||
} | ||
} | ||
|
||
// Takes the current pending entries from this AsyncBuffer. If there are no | ||
// entries queued already, this will block until some show up. | ||
async pop() { | ||
if (this.pending.length == 0) { | ||
// Need to instantiate a promise to block on. The next call to 'push' | ||
// will resolve the promise once it has queued the entries. | ||
await new Promise(resolve => { | ||
this.resolve_fn = resolve; | ||
}); | ||
} | ||
assert_true(this.pending.length > 0); | ||
|
||
const result = this.pending; | ||
this.pending = []; | ||
return result; | ||
} | ||
} | ||
|
||
const buffer = new AsyncBuffer(); | ||
const po = new PerformanceObserver(entryList => { | ||
buffer.push(entryList.getEntries()); | ||
}); | ||
po.observe({type: 'largest-contentful-paint', buffered: true}); | ||
|
||
const block_for_next_lcp = async () => { | ||
const seen_events = await buffer.pop(); | ||
assert_equals(seen_events.length, 1); | ||
return seen_events[0].size; | ||
}; | ||
|
||
const trigger_repaint_and_block_for_next_lcp = async () => { | ||
let new_div = document.createElement("div"); | ||
document.getElementById('firstDiv').appendChild(new_div); | ||
new_div.innerText = "Medium text"; | ||
return await block_for_next_lcp(); | ||
}; | ||
</script> | ||
|
||
<div id="firstDiv" style='width: 600px; height: 10000px'>Short text</div> | ||
<div style='width: 600px; height: 500px'>Loooooooooooong offscreen text that shouldn't count for LCP computation</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters