Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Container Timing: lastPaintedElement is selected by the element's own area</title>
<body>
<style>
body {
margin: 0;
}
</style>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/container-timing/resources/container-timing-helpers.js"></script>
<script>
promise_test(async t => {
assert_implements(window.PerformanceContainerTiming, "PerformanceContainerTiming is not implemented");
const div = addContainerRoot(document.body, 'div_ct');
function addPositionedImage(id, left, top, width, height) {
addSquare100Image(div, {
id,
style: `position: absolute; left: ${left}px; top: ${top}px; ` +
`width: ${width}px; height: ${height}px;`
});
}
addPositionedImage('first_id', 0, 0, 100, 100);
const beforeRender = performance.now();
const entries = await getContainerEntries(t);
assert_equals(entries.length, 1);
checkContainerEntry(entries[0], 'div_ct', 'first_id', beforeRender);
checkContainerSize(entries[0], 10000);
// Two more images, in a later frame and sharing the already loaded
// resource, so that they paint together:
// - 100x120 covering all of the first image, so it contributes only
// a 100x20 strip: 2000 of new area, but 12000 of its own.
// - 60x60 of entirely new area: 3600 either way.
// Selecting by the newly contributed area would report the smaller
// one; selecting by the element's own area reports the larger one.
addPositionedImage('overlapping_id', 0, 0, 100, 120);
addPositionedImage('fresh_id', 200, 200, 60, 60);
const allEntries = await getContainerEntries(t, 2);
assert_equals(allEntries.length, 2);
checkContainerEntry(allEntries[1], 'div_ct', 'overlapping_id', beforeRender);
checkContainerSize(allEntries[1], 15600);
checkContainerIntersectionRect(allEntries[1], [0, 260, 0, 260]);
}, 'lastPaintedElement is the element with the largest area of its own, not the largest newly painted area.');
</script>
</body>