Chromium Code Reviews| 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 title="normal wrap">0123 456</div> | |
| 18 <div title="normal wrap, space overflows">01234 567</div> | |
| 19 <div title="pre-wrap" style="white-space: pre-wrap">0123 45678</div> | |
| 20 <div title="pre-wrap, space overflows" style="white-space: pre-wrap">01234 567 8</div> | |
| 21 <div title="break-word" style="word-wrap: break-word">0123456789</div> | |
| 22 <div title="pre" style="white-space:pre">a | |
| 23 b<span></span>b</div> | |
| 24 </div> | |
| 25 <script> | |
| 26 var range = document.createRange(); | |
| 27 | |
| 28 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
| |
| 29 var name = element.title; | |
| 30 var node = element.firstChild; | |
| 31 for (var i = 0; i < node.textContent.length; i++) { | |
| 32 range.setStart(node, i); | |
| 33 range.setEnd(node, i + 1); | |
| 34 var rects = range.getClientRects(); | |
| 35 var bounds = range.getBoundingClientRect(); | |
| 36 if (rects.length <= 1) | |
| 37 continue; | |
| 38 // If all rects are empty, bounds should be rects[0]. | |
| 39 if (bounds.width == 0 || bounds.height == 0) { | |
| 40 test(function () { | |
| 41 assert_equals_rect(bounds, rects[0]); | |
| 42 }, name + "[" + i + "]isEmpty: " + rectToString(bounds) + " from " + rects ToString(rects)); | |
| 43 } | |
| 44 test(function () { | |
| 45 assert_equals(bounds.height, rects[0].height); | |
| 46 }, name + "[" + i + "].height: " + rectToString(bounds) + " from " + rectsTo String(rects)); | |
| 47 } | |
| 48 }); | |
| 49 | |
| 50 function assert_equals_rect(actual, expected, description) { | |
| 51 for (var prop in expected) | |
| 52 assert_equals(actual[prop], expected[prop], description + "." + prop); | |
| 53 } | |
| 54 function rectsToString(rects) { | |
| 55 return "[" + Array.prototype.map.call(rects, rectToString).join() + "]"; | |
| 56 } | |
| 57 | |
| 58 function rectToString(r) { | |
| 59 return "(" + r.left + "," + r.top + "-" + r.width + "," + r.height + ")"; | |
| 60 } | |
| 61 </script> | |
| OLD | NEW |