OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <meta charset="utf-8"> |
| 5 <title>Test rendering of sub-pixel borders</title> |
| 6 <style> |
| 7 .test { |
| 8 box-sizing: content-box; |
| 9 display: inline-block; |
| 10 margin: 5px; |
| 11 width: 80px; |
| 12 height: 80px; |
| 13 border: 1px solid green; |
| 14 background: lightgreen; |
| 15 text-align: center; |
| 16 line-height: 80px; |
| 17 } |
| 18 </style> |
| 19 <script src="../../resources/testharness.js"></script> |
| 20 <script src="../../resources/testharnessreport.js"></script> |
| 21 </head> |
| 22 <body> |
| 23 <div class="test" style="border-width: 0.25px">0.25px</div> |
| 24 <div class="test" style="border-width: 0.5px">0.5px</div> |
| 25 <div class="test" style="border-width: 0.75px">0.75px</div> |
| 26 <div class="test" style="border-width: 1px">1px</div> |
| 27 <div class="test" style="border-width: 1.25px">1.25px</div> |
| 28 <div class="test" style="border-width: 1.5px">1.5px</div> |
| 29 <p> |
| 30 Border thickness should be rounded, not floored, with the exception of |
| 31 values below 1px where it should always round up. |
| 32 </p> |
| 33 <script> |
| 34 var testElements = {}; |
| 35 var elements = document.getElementsByClassName('test'); |
| 36 for (var element, i = 0; element = elements[i]; i++) { |
| 37 testElements[element.firstChild.nodeValue] = element; |
| 38 } |
| 39 |
| 40 function sizeAsString(element) { |
| 41 var rect = element.getBoundingClientRect(); |
| 42 return rect.width.toFixed(2) + 'x' + rect.height.toFixed(2); |
| 43 } |
| 44 |
| 45 function borderAsString(element) { |
| 46 var style = window.getComputedStyle(element); |
| 47 return style.borderTopWidth + ' ' + style.borderRightWidth + ' ' + |
| 48 style.borderBottomWidth + ' ' + style.borderLeftWidth; |
| 49 } |
| 50 |
| 51 test(function() { |
| 52 var referenceSize = sizeAsString(testElements['1px']); |
| 53 assert_equals(sizeAsString(testElements['0.25px']), referenceSize, |
| 54 'Size of 0.25px box should match 1px reference.'); |
| 55 assert_equals(sizeAsString(testElements['0.5px']), referenceSize, |
| 56 'Size of 0.5px box should match 1px reference.'); |
| 57 assert_equals(sizeAsString(testElements['0.75px']), referenceSize, |
| 58 'Size of 0.75px box should match 1px reference.'); |
| 59 |
| 60 var refSize = testElements['1px'].getBoundingClientRect(); |
| 61 var testSize = testElements['1.25px'].getBoundingClientRect(); |
| 62 assert_greater_than(testSize.width, refSize.width, |
| 63 'Size of 1.25px box should be larger than 1px box.'); |
| 64 assert_greater_than(testSize.height, refSize.height, |
| 65 'Size of 1.25px box should be larger than 1px box.'); |
| 66 }, 'Size of all elements are correct.'); |
| 67 |
| 68 test(function() { |
| 69 assert_equals(borderAsString(testElements['0.25px']), |
| 70 '1px 1px 1px 1px', |
| 71 'Border thickness of 0.25px box should be 1px.'); |
| 72 assert_equals(borderAsString(testElements['0.5px']), |
| 73 '1px 1px 1px 1px', |
| 74 'Border thickness of 0.5px box should be 1px.'); |
| 75 assert_equals(borderAsString(testElements['0.75px']), |
| 76 '1px 1px 1px 1px', |
| 77 'Border thickness of 0.75px box should be 1px.'); |
| 78 assert_equals(borderAsString(testElements['1.25px']), |
| 79 '1.25px 1.25px 1.25px 1.25px', |
| 80 'Border thickness of 1.25px box should retain decimals.'); |
| 81 assert_equals(borderAsString(testElements['1.5px']), |
| 82 '1.5px 1.5px 1.5px 1.5px', |
| 83 'Border thickness of 1.5px box should retain decimals.'); |
| 84 }, 'All elements should have correctly sized borders.'); |
| 85 </script> |
| 86 </body> |
| 87 </html> |
OLD | NEW |