Skip to content

Commit

Permalink
[text-box-trim] Test hit-testing
Browse files Browse the repository at this point in the history
This patch adds tests for `getBoundingClientRect()` and
`elementFromPoint()`, two CSSOM View functions that represent
the logic for hit-testing.

This patch has no behavior changes.

Bug: 40254880
Change-Id: I2d416b042ed278a339daeabfe3c8702b020c458d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5587766
Commit-Queue: Kent Tamura <tkent@chromium.org>
Auto-Submit: Koji Ishii <kojii@chromium.org>
Reviewed-by: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1309621}
  • Loading branch information
kojiishi authored and chromium-wpt-export-bot committed Jun 3, 2024
1 parent 1a89780 commit 060cd15
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions css/css-inline/text-box-trim/text-box-trim-om-001.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!DOCTYPE html>
<link rel="help" href="https://drafts.csswg.org/css-inline-3/#propdef-text-box-edge">
<link rel="help" href="https://drafts.csswg.org/css-inline-3/#propdef-text-box-trim">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
@font-face {
font-family: test-font;
src: url(resources/cap-x-height.ttf);
}
.spacer {
background: lightgray;
block-size: 100px;
}
#target {
font-family: test-font;
font-size: 100px;
line-height: 2;
text-box-trim: both;
text-box-edge: ex alphabetic;
}
</style>
<div id="container">
<div class="spacer"></div>
<div id="target">A</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, 100);
}, "getBoundingClientRect.top");
test(() => {
assert_equals(target_bounds.height, 20);
}, "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>

0 comments on commit 060cd15

Please sign in to comment.