Commit 425d0481 authored by Nicolás Peña Moreno's avatar Nicolás Peña Moreno Committed by Commit Bot

[PaintTiming] Add form control test for FCP

This CL adds a test to ensure that FCP is not triggered when there's a
textfield with no text but is triggered when there's text. Spec issue:
https://github.com/w3c/paint-timing/issues/52

Bug: 1059427
Change-Id: I4cf4f961d43bfa92d6be2abd519a9d8acfde8141
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2091968
Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
Reviewed-by: default avatarAnnie Sullivan <sullivan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748243}
parent 6700d124
<!DOCTYPE html>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/utils.js"></script>
<form>
<input type="text" id='myInput'>
</form>
<script>
promise_test(async () => {
const onload = new Promise(r => window.addEventListener('load', r));
await onload;
return assertNoFirstContentfulPaint().then(() => {
document.getElementById('myInput').value = 'default text';
return assertFirstContentfulPaint();
})
});
</script>
</body>
// We use requestAnimationFrame() calls to force the user agent to paint. Hence, set
// |numFramesWaiting| to 3 and use that constant whenever the test needs to wait for
// the next paint to occur.
const numFramesWaiting = 3;
function waitForAnimationFrames(count) {
return new Promise(resolve => {
if (count-- <= 0) {
resolve();
} else {
requestAnimationFrame(() => {
waitForAnimationFrames(count).then(resolve);
});
}
});
}
function assertNoFirstContentfulPaint() {
return waitForAnimationFrames(numFramesWaiting).then(() => {
return new Promise((resolve, reject) => {
const observer = new PerformanceObserver(entryList =>{
const entries = entryList.getEntriesByName('first-contentful-paint');
observer.disconnect();
if (entries.length > 0)
reject('Received a first contentful paint entry.');
else
resolve();
});
observer.observe({type: 'paint', buffered: true});
observer.observe({type: 'mark'});
performance.mark('flush');
});
});
}
function assertFirstContentfulPaint() {
return waitForAnimationFrames(numFramesWaiting).then(() => {
return new Promise((resolve, reject) => {
const observer = new PerformanceObserver(entryList =>{
const entries = entryList.getEntriesByName('first-contentful-paint');
observer.disconnect();
if (entries.length === 0)
reject('Did not receive a first contentful paint entry.');
else {
resolve();
}
});
observer.observe({type: 'paint', buffered: true});
observer.observe({type: 'mark'});
performance.mark('flush');
});
});
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment