test_bug791616.html (2121B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Test bug 791616</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <script src="/tests/SimpleTest/EventUtils.js"></script> 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 8 <style> 9 #t { 10 overflow: auto; 11 position: absolute; 12 left: 200px; 13 top: 100px; 14 font: 14px/1.3em "Consolas","Bitstream Vera Sans Mono","Courier New",Courier,monospace; 15 } 16 </style> 17 </head> 18 <body> 19 <p id="display"></p> 20 <div id="t" contenteditable> 21 <div>66666666666666</div> 22 <div id="target">777777777777777777777777777777777777777</div> 23 </div> 24 </div> 25 <pre id="test"> 26 <script class="testbody"> 27 var t = document.getElementById("t"); 28 var target = document.getElementById("target"); 29 var sel = window.getSelection(); 30 var smoothScrollPref = "general.smoothScroll"; 31 32 SimpleTest.waitForExplicitFinish(); 33 t.scrollTop = 0; 34 var targetY = target.getBoundingClientRect().top; 35 36 SimpleTest.waitForFocus(function() { 37 SpecialPowers.pushPrefEnv({"set":[[smoothScrollPref, false]]}, runTest); 38 }); 39 function runTest() { 40 is(target.getBoundingClientRect().top, targetY, "Target should not have scrolled due to waitForFocus"); 41 t.focus(); 42 is(target.getBoundingClientRect().top, targetY, "Target should not have scrolled due to focus change"); 43 44 // Move the caret to scroll it into view 45 sel.collapse(target.firstChild, 2); 46 synthesizeKey("KEY_ArrowLeft"); 47 48 // Delay until next repaint in case stuff is asynchronous. Also 49 // take a trip through the event loop. 50 setTimeout(function() { 51 window.requestAnimationFrame(function() { 52 is(sel.anchorNode, target.firstChild, "Should have selected 'target' text node"); 53 is(sel.anchorOffset, 1, "Selection should have moved left one character"); 54 // We should not have needed to scroll the caret into view 55 is(target.getBoundingClientRect().top, targetY, "Target should not have scrolled"); 56 SimpleTest.finish(); 57 }); 58 // Make sure repainting actually happens. 59 target.style.background = "yellow"; 60 }); 61 } 62 </script> 63 </pre> 64 </body> 65 </html>