servo/tests/wpt/web-platform-tests/largest-contentful-paint/observe-image.html

43 lines
2 KiB
HTML

<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Largest Contentful Paint: observe image.</title>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
async_test(function (t) {
if (!window.LargestContentfulPaint) {
assert_unreached("LargestContentfulPaint is not implemented");
}
const beforeRender = performance.now();
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);
// blue.png is 133 x 106.
assert_equals(entry.size, 14098);
assert_equals(entry.id, 'image_id');
// 25 is the length of "largest-contentful-paint/".
const index = window.location.href.lastIndexOf('/') - 25;
const pathname = window.location.href.substring(0, index) + '/images/blue.png';
assert_equals(entry.url, pathname);
assert_greater_than(entry.loadTime, beforeRender,
'The load timestamp should occur after script starts running.');
assert_less_than(entry.loadTime, entry.renderTime,
'The load timestamp should occur before the render timestamp.')
assert_equals(entry.element, document.getElementById('image_id'));
})
);
observer.observe({type: 'largest-contentful-paint', buffered: true});
}, 'Same-origin image is observable.');
</script>
<img src='/images/blue.png' id='image_id'/>
</body>