Commit 08bb68ed authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

Improve fast/dom/Range/get-bounding-client-rect-empty-and-non-empty.html

The layout has unclear test flow, as it uses a big test function with
different branches with different assertions for all test cases. As a
result, the expectations for the test cases are unclear.

This patch removes all branching from the test flow, so that it becomes
clear what we expect on each test case. It also reveals that LayoutNG
has different behavior and should be marked failure here.

Bug: 755750
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_layout_ng
Change-Id: I7d1a22a5805cc7ad031bf3c7bc24f0b822a3a0da
Reviewed-on: https://chromium-review.googlesource.com/1142573
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576289}
parent dc4eddf6
...@@ -545,7 +545,8 @@ crbug.com/591099 fast/css3-text/css3-text-indent/negative-text-indent-leading-ou ...@@ -545,7 +545,8 @@ crbug.com/591099 fast/css3-text/css3-text-indent/negative-text-indent-leading-ou
crbug.com/591099 fast/css3-text/css3-text-indent/text-indent-leading-out-of-flow.html [ Failure ] crbug.com/591099 fast/css3-text/css3-text-indent/text-indent-leading-out-of-flow.html [ Failure ]
crbug.com/591099 fast/css3-text/css3-text-indent/text-indent-out-of-flow-each-line-hanging.html [ Failure ] crbug.com/591099 fast/css3-text/css3-text-indent/text-indent-out-of-flow-each-line-hanging.html [ Failure ]
crbug.com/591099 fast/dom/HTMLAreaElement/area-download.html [ Failure ] crbug.com/591099 fast/dom/HTMLAreaElement/area-download.html [ Failure ]
crbug.com/714962 fast/dom/Range/getBoundingClientRect-linebreak-character.html [ Failure ] crbug.com/755750 fast/dom/Range/get-bounding-client-rect-empty-and-non-empty.html [ Failure ]
crbug.com/755750 fast/dom/Range/getBoundingClientRect-linebreak-character.html [ Failure ]
crbug.com/591099 fast/dom/nodesFromRect/nodesFromRect-basic.html [ Failure ] crbug.com/591099 fast/dom/nodesFromRect/nodesFromRect-basic.html [ Failure ]
crbug.com/591099 fast/dynamic/first-letter-after-list-marker.html [ Failure ] crbug.com/591099 fast/dynamic/first-letter-after-list-marker.html [ Failure ]
crbug.com/591099 fast/dynamic/text-combine.html [ Failure ] crbug.com/591099 fast/dynamic/text-combine.html [ Failure ]
......
...@@ -23,48 +23,60 @@ html, body { ...@@ -23,48 +23,60 @@ html, body {
b<span></span>b</div> b<span></span>b</div>
</div> </div>
<script> <script>
var range = document.createRange(); testEmptyBoundsEqualFirstRect('normal-wrap', 4);
testEmptyBoundsEqualFirstRect('normal-wrap-with-overflow-space', 5);
testWhenFirstRectIsEmpty("normal-wrap", [4]); testUniqueRectAt('pre-wrap', 3);
testWhenFirstRectIsEmpty("normal-wrap-with-overflow-space", [5]); testUniqueRectAt('pre-wrap', 4);
testWhenFirstRectIsEmpty("pre-wrap", [3, 4, 5]); testUniqueRectAt('pre-wrap', 5);
testWhenFirstRectIsEmpty("pre-wrap-with-overflow-space", [4, 5, 6]);
testWhenFirstRectIsEmpty("break-word", [4, 5]);
testWhenFirstRectIsEmpty("pre", [0, 1, 2]);
function testWhenFirstRectIsEmpty(id, offsets) { testUniqueRectAt('pre-wrap-with-overflow-space', 4);
let element = document.getElementById(id); testUniqueRectAt('pre-wrap-with-overflow-space', 5);
let node = element.firstChild; testUniqueRectAt('pre-wrap-with-overflow-space', 6);
for (let offset of offsets) {
range.setStart(node, offset);
range.setEnd(node, offset + 1);
let rects = range.getClientRects();
let bounds = range.getBoundingClientRect();
if (rects.length <= 1)
continue;
if (!bounds.width || !bounds.height) { testUniqueRectAt('break-word', 4);
// If all rects are empty, bounds should be equal to rects[0]. testUniqueRectAt('break-word', 5);
test(() => assert_equals_rect(bounds, rects[0]),
`${name}[${offset}]: ${rectToString(bounds)} should be equal to the first of ${rectsToString(rects)}`); testUniqueRectAt('pre', 0);
} else { testUniqueRectAt('pre', 1);
// Otherwise, it should be the union of rects excluding empty ones. testUniqueRectAt('pre', 2);
// Since we measure one character, it should have the same height as rects[0].
test(() => assert_equals(bounds.height, rects[0].height), function getRectsAndBoundsAt(id, offset) {
`${name}[${offset}]: Height of ${rectToString(bounds)} should match to the first of ${rectsToString(rects)}`); const element = document.getElementById(id);
} const node = element.firstChild;
} const range = document.createRange();
range.setStart(node, offset);
range.setEnd(node, offset + 1);
return {rects: range.getClientRects(), bounds: range.getBoundingClientRect()}
}
function testEmptyBoundsEqualFirstRect(id, offset) {
const rectsAndBounds = getRectsAndBoundsAt(id, offset);
const rects = rectsAndBounds.rects;
const bounds = rectsAndBounds.bounds;
// All rects are empty, and bounds should be equal to rects[0].
test(() => {
assert_equals(bounds.width, 0);
assert_greater_than(rects.length, 0);
assert_equals_rect(bounds, rects[0]);
}, `${id}[${offset}]: ${rectToString(bounds)} should be equal to the first of ${rectsToString(rects)}`);
}
function testUniqueRectAt(id, offset) {
test(() => assert_equals(getRectsAndBoundsAt(id, offset).rects.length, 1),
`${id}[${offset}]: Only one unique client rect`);
} }
function assert_equals_rect(actual, expected, description) { function assert_equals_rect(actual, expected) {
for (let prop in expected) for (let prop in expected)
assert_equals(actual[prop], expected[prop], description + "." + prop); assert_equals(actual[prop], expected[prop]);
} }
function rectsToString(rects) { function rectsToString(rects) {
return "[" + Array.prototype.map.call(rects, rectToString).join() + "]"; return '[' + Array.prototype.map.call(rects, rectToString).join() + ']';
} }
function rectToString(r) { function rectToString(r) {
return "(" + r.left + "," + r.top + "-" + r.width + "," + r.height + ")"; return '(' + r.left + ',' + r.top + '-' + r.width + ',' + r.height + ')';
} }
</script> </script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment