Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!DOCTYPE HTML>
<head>
<meta charset=utf-8>
<title>Element Timing: observe element with a content image in a pseudo element</title>
<style>
body {
margin: 20px;
}
#target {
font-size: 12px;
}
#target::before {
content: 'This is text I care about';
}
</style>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/element-timing-helpers.js"></script>
<script>
let beforeRender = performance.now();
async_test(function (t) {
assert_implements(window.PerformanceElementTiming, "PerformanceElementTiming is not implemented");
const observer = new PerformanceObserver(
t.step_func_done(function(entryList) {
assert_equals(entryList.getEntries().length, 1);
const entry = entryList.getEntries()[0];
checkTextElement(entry, 'my_div', 'target', beforeRender,
document.getElementById('target'));
assert_equals(entry.intersectionRect.left, 20, 'left should be 20.');
// Text box size will vary from device to device, so try lower bounding height by 12, width by 100.
assert_greater_than_equal(entry.intersectionRect.right, 120);
assert_equals(entry.intersectionRect.top, 20, 'top should be 20.');
assert_greater_than_equal(entry.intersectionRect.bottom, 32);
})
);
observer.observe({entryTypes: ['element']});
}, 'Element with elementtiming attribute and a ::before content image is observable.');
</script>
</head>
<body>
<p id='target' elementtiming='my_div'></p>
</body>