servo/tests/wpt/web-platform-tests/element-timing/observe-large-image.html

46 lines
1.7 KiB
HTML

<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Element Timing: observe large elements</title>
<body>
<style>
body {
margin: 0;
}
</style>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/element-timing-helpers.js"></script>
<script>
let beforeRender;
async_test(function (t) {
const observer = new PerformanceObserver(
t.step_func_done(function(entryList) {
assert_equals(entryList.getEntries().length, 1);
const entry = entryList.getEntries()[0];
const index = window.location.href.lastIndexOf('/');
const pathname = window.location.href.substring(0, index) +
'/resources/square20.jpg';
checkElement(entry, pathname, '', 'large_one', beforeRender);
// Assume viewport hasn't changed, so the element occupies all of it.
checkRect(entry,
[0, document.documentElement.clientWidth, 0, document.documentElement.clientHeight]);
checkNaturalSize(entry, 20, 20);
})
);
observer.observe({entryTypes: ['element']});
// We add the image during onload to be sure that the observer is registered
// in time for it to observe the element timing.
window.onload = () => {
// Add an image setting width and height equal to viewport.
const img = document.createElement('img');
img.src = 'resources/square20.jpg';
img.width = document.documentElement.clientWidth;
img.height = document.documentElement.clientHeight;
img.setAttribute('id', 'large_one');
document.body.appendChild(img);
beforeRender = performance.now();
};
}, 'Large img element is observable.');
</script>
</body>