Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE html>
<link rel="stylesheet" href="/fonts/baseline-diagnostic/baseline-diagnostic-font.css">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
.spacer {
background: lightgray;
block-size: 200px;
}
#target {
font: 200px/2 BaselineDiagnosticAlphabeticZero;
text-box: trim-both ex alphabetic;
}
</style>
<div id="container">
<div class="spacer"></div>
<div id="target">X</div>
<div class="spacer"></div>
</div>
<script>
function run_tests(test_names) {
const container = document.getElementById('container');
const container_bounds = container.getBoundingClientRect();
const target = document.getElementById('target');
const target_bounds = target.getBoundingClientRect();
// Test `getBoundingClientRect()` returns the trimmed box size.
test(() => {
assert_equals(target_bounds.top - container_bounds.top, 200);
}, "getBoundingClientRect.top");
test(() => {
assert_equals(target_bounds.height, 50);
}, "getBoundingClientRect.height");
// Test `elementFromPoint()` hits `target` even if the point is above/below
// the client rect, because the inner line box overflows the box.
test(() => {
const result = document.elementFromPoint(10, 90 + container_bounds.top);
assert_equals(result, target);
}, "elementFromPoint: 10px above the client rect");
test(() => {
const result = document.elementFromPoint(10, 130 + container_bounds.top);
assert_equals(result, target);
}, "elementFromPoint: 10px below the client rect");
}
setup({explicit_done: true});
document.fonts.ready.then(() => {
run_tests();
done();
});
</script>