Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/fast/dom/Range/get-bounding-client-rect-empty-and-non-empty.html |
| diff --git a/third_party/WebKit/LayoutTests/fast/dom/Range/get-bounding-client-rect-empty-and-non-empty.html b/third_party/WebKit/LayoutTests/fast/dom/Range/get-bounding-client-rect-empty-and-non-empty.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ce1b00cd4ac7249cf33fa14da25621da00bb927a |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/fast/dom/Range/get-bounding-client-rect-empty-and-non-empty.html |
| @@ -0,0 +1,61 @@ |
| +<!DOCTPYE html> |
| +<script src="../../../resources/testharness.js"></script> |
| +<script src="../../../resources/testharnessreport.js"></script> |
| +<style> |
| +html, body { |
| + margin: 0; |
| +} |
| + |
| +#container > div { |
| + font-size: 10px; |
| + width: 5ch; |
| + border: thin solid black; |
| +} |
| +</style> |
| +<div id="log"></div> |
| +<div id="container"> |
| + <div title="normal wrap">0123 456</div> |
| + <div title="normal wrap, space overflows">01234 567</div> |
| + <div title="pre-wrap" style="white-space: pre-wrap">0123 45678</div> |
| + <div title="pre-wrap, space overflows" style="white-space: pre-wrap">01234 5678</div> |
| + <div title="break-word" style="word-wrap: break-word">0123456789</div> |
| + <div title="pre" style="white-space:pre">a |
| +b<span></span>b</div> |
| +</div> |
| +<script> |
| +var range = document.createRange(); |
| + |
| +Array.prototype.forEach.call(container.children, function (element) { |
|
eae
2016/05/05 13:28:29
Please don't do this. Data driven tests like this
kojii
2016/05/06 06:11:02
Done, I'm not certain if I understand this correct
|
| + var name = element.title; |
| + var node = element.firstChild; |
| + for (var i = 0; i < node.textContent.length; i++) { |
| + range.setStart(node, i); |
| + range.setEnd(node, i + 1); |
| + var rects = range.getClientRects(); |
| + var bounds = range.getBoundingClientRect(); |
| + if (rects.length <= 1) |
| + continue; |
| + // If all rects are empty, bounds should be rects[0]. |
| + if (bounds.width == 0 || bounds.height == 0) { |
| + test(function () { |
| + assert_equals_rect(bounds, rects[0]); |
| + }, name + "[" + i + "]isEmpty: " + rectToString(bounds) + " from " + rectsToString(rects)); |
| + } |
| + test(function () { |
| + assert_equals(bounds.height, rects[0].height); |
| + }, name + "[" + i + "].height: " + rectToString(bounds) + " from " + rectsToString(rects)); |
| + } |
| +}); |
| + |
| +function assert_equals_rect(actual, expected, description) { |
| + for (var prop in expected) |
| + assert_equals(actual[prop], expected[prop], description + "." + prop); |
| +} |
| +function rectsToString(rects) { |
| + return "[" + Array.prototype.map.call(rects, rectToString).join() + "]"; |
| +} |
| + |
| +function rectToString(r) { |
| + return "(" + r.left + "," + r.top + "-" + r.width + "," + r.height + ")"; |
| +} |
| +</script> |