OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <meta charset="utf-8"> | 4 <meta charset="utf-8"> |
5 <title>Tests text range bounds</title> | 5 <title>Tests text range bounds</title> |
6 <style> | 6 <style> |
7 div { text-rendering: optimizeLegibility; } | 7 div { text-rendering: optimizeLegibility; visibility: hidden; } |
8 </style> | 8 </style> |
9 <script src="../../resources/testharness.js"></script> | 9 <script src="../../resources/testharness.js"></script> |
10 <script src="../../resources/testharnessreport.js"></script> | 10 <script src="../../resources/testharnessreport.js"></script> |
11 </head> | 11 </head> |
12 <body> | 12 <body> |
13 <div id="test">Tests caret position reporting using ranges.</div> | 13 <div id="test">Tests caret position reporting using ranges.</div> |
14 <script> | 14 <script> |
15 var el = document.getElementById('test'); | 15 var el = document.getElementById('test'); |
16 var len = el.firstChild.textContent.length; | 16 var len = el.firstChild.textContent.length; |
17 | 17 |
18 function posForOffset(offset) { | 18 function posForOffset(offset) { |
19 var r = document.createRange(); | 19 var r = document.createRange(); |
20 r.setStart(el.firstChild, offset); | 20 r.setStart(el.firstChild, offset); |
21 r.setEnd(el.firstChild, offset); | 21 r.setEnd(el.firstChild, offset); |
22 return r.getClientRects()[0].left; | 22 return r.getClientRects()[0].left; |
23 } | 23 } |
24 | 24 |
25 test(function() { | 25 test(function() { |
26 assert_true(posForOffset(len) > posForOffset(len - 1), | 26 assert_true(posForOffset(len) > posForOffset(len - 1), |
27 'Last caret position should be higher than second to last.')
; | 27 'Last caret position should be higher than second to last.')
; |
28 assert_true(posForOffset(len) != posForOffset(0), | 28 assert_true(posForOffset(len) != posForOffset(0), |
29 'Last caret position should not match first.'); | 29 'Last caret position should not match first.'); |
30 }, 'Caret positions reported correctly.'); | 30 }, 'Caret positions reported correctly.'); |
31 </script> | 31 </script> |
32 </body> | 32 </body> |
33 </html> | 33 </html> |
OLD | NEW |