blob: 84a49f7ea2220c43c083f91057763ae161035532 [file] [log] [blame]
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Largest Contentful Paint: src change triggers new entry.</title>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<img src='/images/blue.png' id='image_id'/>
<script>
async_test(function (t) {
if (!window.LargestContentfulPaint) {
assert_unreached("LargestContentfulPaint is not implemented");
}
let beforeRender = performance.now();
let firstCallback = true;
const observer = new PerformanceObserver(
t.step_func_done(function(entryList) {
assert_equals(entryList.getEntries().length, 1);
const entry = entryList.getEntries()[0];
assert_equals(entry.entryType, 'largest-contentful-paint');
assert_greater_than_equal(entry.renderTime, beforeRender,
'The rendering timestamp should occur after script starts running.');
assert_greater_than_equal(performance.now(), entry.renderTime,
'The rendering timestamp should occur before the entry is dispatched to the observer.');
assert_equals(entry.startTime, entry.renderTime, 'startTime should equal renderTime');
assert_equals(entry.duration, 0);
if (firstCallback) {
// blue.png is 133 x 106.
assert_equals(entry.size, 14098);
assert_equals(entry.id, 'image_id');
const pathname = window.location.origin + '/images/blue.png';
assert_equals(entry.url, pathname);
// Set the src to trigger another entry.
const img = document.getElementById('image_id');
img.src = '/images/black-rectangle.png';
beforeRender = performance.now();
firstCallback =false;
return;
}
// black-rectangle.png is 100 x 50.
assert_equals(entry.size, 5000);
assert_equals(entry.id, 'image_id');
const pathname = window.location.origin + '/images/black-rectangle.png';
assert_equals(entry.url, pathname);
})
);
observer.observe({type: 'largest-contentful-paint', buffered: true});
}, 'Largest Contentful Paint: changing src causes a new entry to be dispatched.');
</script>
</body>