| OLD | NEW |
| (Empty) | |
| 1 <!DOCTPYE html> |
| 2 <script src="../../../resources/testharness.js"></script> |
| 3 <script src="../../../resources/testharnessreport.js"></script> |
| 4 <style> |
| 5 html, body { |
| 6 margin: 0; |
| 7 } |
| 8 |
| 9 #container > div { |
| 10 font-size: 10px; |
| 11 width: 5ch; |
| 12 border: thin solid black; |
| 13 } |
| 14 </style> |
| 15 <div id="log"></div> |
| 16 <div id="container"> |
| 17 <div id="normal-wrap">0123 456</div> |
| 18 <div id="normal-wrap-with-overflow-space">01234 567</div> |
| 19 <div id="pre-wrap" style="white-space: pre-wrap">0123 45678</div> |
| 20 <div id="pre-wrap-with-overflow-space" style="white-space: pre-wrap">01234 567
8</div> |
| 21 <div id="break-word" style="word-wrap: break-word">0123456789</div> |
| 22 <div id="pre" style="white-space:pre">a |
| 23 b<span></span>b</div> |
| 24 </div> |
| 25 <script> |
| 26 var range = document.createRange(); |
| 27 |
| 28 testWhenFirstRectIsEmpty("normal-wrap", [4]); |
| 29 testWhenFirstRectIsEmpty("normal-wrap-with-overflow-space", [5]); |
| 30 testWhenFirstRectIsEmpty("pre-wrap", [3, 4, 5]); |
| 31 testWhenFirstRectIsEmpty("pre-wrap-with-overflow-space", [4, 5, 6]); |
| 32 testWhenFirstRectIsEmpty("break-word", [4, 5]); |
| 33 testWhenFirstRectIsEmpty("pre", [0, 1, 2]); |
| 34 |
| 35 function testWhenFirstRectIsEmpty(id, offsets) { |
| 36 let element = document.getElementById(id); |
| 37 let node = element.firstChild; |
| 38 for (let offset of offsets) { |
| 39 range.setStart(node, offset); |
| 40 range.setEnd(node, offset + 1); |
| 41 let rects = range.getClientRects(); |
| 42 let bounds = range.getBoundingClientRect(); |
| 43 if (rects.length <= 1) |
| 44 continue; |
| 45 |
| 46 if (!bounds.width || !bounds.height) { |
| 47 // If all rects are empty, bounds should be equal to rects[0]. |
| 48 test(() => assert_equals_rect(bounds, rects[0]), |
| 49 `${name}[${offset}]: ${rectToString(bounds)} should be equal to the firs
t of ${rectsToString(rects)}`); |
| 50 } else { |
| 51 // Otherwise, it should be the union of rects excluding empty ones. |
| 52 // Since we measure one character, it should have the same height as rects
[0]. |
| 53 test(() => assert_equals(bounds.height, rects[0].height), |
| 54 `${name}[${offset}]: Height of ${rectToString(bounds)} should match to t
he first of ${rectsToString(rects)}`); |
| 55 } |
| 56 } |
| 57 } |
| 58 |
| 59 function assert_equals_rect(actual, expected, description) { |
| 60 for (let prop in expected) |
| 61 assert_equals(actual[prop], expected[prop], description + "." + prop); |
| 62 } |
| 63 function rectsToString(rects) { |
| 64 return "[" + Array.prototype.map.call(rects, rectToString).join() + "]"; |
| 65 } |
| 66 |
| 67 function rectToString(r) { |
| 68 return "(" + r.left + "," + r.top + "-" + r.width + "," + r.height + ")"; |
| 69 } |
| 70 </script> |
| OLD | NEW |