test_bug549262.html (5288B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=549262 5 --> 6 <head> 7 <title>Test for Bug 549262</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 10 <script src="/tests/SimpleTest/EventUtils.js"></script> 11 <script type="text/javascript" src="/tests/gfx/layers/apz/test/mochitest/apz_test_utils.js"></script> 12 </head> 13 <body> 14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=549262">Mozilla Bug 549262</a> 15 <p id="display"></p> 16 <div id="content"> 17 </div> 18 <pre id="test"> 19 <script type="application/javascript"> 20 21 /** Test for Bug 549262 */ 22 23 var smoothScrollPref = "general.smoothScroll"; 24 SimpleTest.waitForExplicitFinish(); 25 var win = window.open("file_bug549262.html", "_blank", 26 "width=600,height=600,scrollbars=yes"); 27 28 function waitForScrollEvent(aWindow) { 29 return new Promise(resolve => { 30 aWindow.addEventListener("scroll", () => { SimpleTest.executeSoon(resolve); }, {once: true, capture: true}); 31 }); 32 } 33 34 function waitAndCheckNoScrollEvent(aWindow) { 35 let gotScroll = false; 36 function recordScroll() { 37 gotScroll = true; 38 } 39 aWindow.addEventListener("scroll", recordScroll, {capture: true}); 40 return waitToClearOutAnyPotentialScrolls(aWindow).then(function() { 41 aWindow.removeEventListener("scroll", recordScroll, {capture: true}); 42 is(gotScroll, false, "check that we didn't get a scroll"); 43 }); 44 } 45 46 SimpleTest.waitForFocus(function() { 47 SpecialPowers.pushPrefEnv({"set": [[smoothScrollPref, false]]}, startTest); 48 }, win); 49 async function startTest() { 50 // Make sure that pressing Space when a contenteditable element is not focused 51 // will scroll the page. 52 var ed = win.document.getElementById("editor"); 53 var sc = win.document.querySelector("a"); 54 sc.focus(); 55 await waitToClearOutAnyPotentialScrolls(win); 56 is(win.scrollY, 0, "Sanity check"); 57 let waitForScrolling = waitForScrollEvent(win); 58 synthesizeKey(" ", {}, win); 59 60 await waitForScrolling; 61 62 isnot(win.scrollY, 0, "Page is scrolled down"); 63 is(ed.textContent, "abc", "The content of the editable element has not changed"); 64 var oldY = win.scrollY; 65 waitForScrolling = waitForScrollEvent(win); 66 synthesizeKey(" ", {shiftKey: true}, win); 67 68 await waitForScrolling; 69 70 ok(win.scrollY < oldY, "Page is scrolled up"); 71 is(ed.textContent, "abc", "The content of the editable element has not changed"); 72 73 // Make sure that pressing Space when a contenteditable element is focused 74 // will not scroll the page, and will edit the element. 75 ed.focus(); 76 win.getSelection().collapse(ed.firstChild, 1); 77 await waitToClearOutAnyPotentialScrolls(win); 78 oldY = win.scrollY; 79 let waitForNoScroll = waitAndCheckNoScrollEvent(win); 80 synthesizeKey(" ", {}, win); 81 82 await waitForNoScroll; 83 84 ok(win.scrollY <= oldY, "Page is not scrolled down"); 85 is(ed.textContent, "a bc", "The content of the editable element has changed"); 86 sc.focus(); 87 await waitToClearOutAnyPotentialScrolls(win); 88 waitForScrolling = waitForScrollEvent(win); 89 synthesizeKey(" ", {}, win); 90 91 await waitForScrolling; 92 93 isnot(win.scrollY, 0, "Page is scrolled down"); 94 is(ed.textContent, "a bc", "The content of the editable element has not changed"); 95 ed.focus(); 96 win.getSelection().collapse(ed.firstChild, 3); 97 await waitToClearOutAnyPotentialScrolls(win); 98 waitForNoScroll = waitAndCheckNoScrollEvent(win); 99 synthesizeKey(" ", {shiftKey: true}, win); 100 101 await waitForNoScroll; 102 103 isnot(win.scrollY, 0, "Page is not scrolled up"); 104 is(ed.textContent, "a b c", "The content of the editable element has changed"); 105 106 // Now let's test the down/up keys 107 sc = document.body; 108 109 ed.blur(); 110 sc.focus(); 111 await waitToClearOutAnyPotentialScrolls(win); 112 oldY = win.scrollY; 113 waitForScrolling = waitForScrollEvent(win); 114 synthesizeKey("VK_UP", {}, win); 115 116 await waitForScrolling; 117 118 ok(win.scrollY < oldY, "Page is scrolled up"); 119 oldY = win.scrollY; 120 ed.focus(); 121 win.getSelection().collapse(ed.firstChild, 3); 122 await waitToClearOutAnyPotentialScrolls(win); 123 waitForNoScroll = waitAndCheckNoScrollEvent(win); 124 synthesizeKey("VK_UP", {}, win); 125 126 await waitForNoScroll; 127 128 is(win.scrollY, oldY, "Page is not scrolled up"); 129 is(win.getSelection().focusNode, ed.firstChild, "Correct element selected"); 130 is(win.getSelection().focusOffset, 0, "Selection should be moved to the beginning"); 131 win.getSelection().removeAllRanges(); 132 await waitToClearOutAnyPotentialScrolls(win); 133 waitForScrolling = waitForScrollEvent(win); 134 synthesizeMouse(sc, 300, 300, {}, win); 135 synthesizeKey("VK_DOWN", {}, win); 136 137 await waitForScrolling; 138 139 ok(win.scrollY > oldY, "Page is scrolled down"); 140 ed.focus(); 141 win.getSelection().collapse(ed.firstChild, 3); 142 await waitToClearOutAnyPotentialScrolls(win); 143 oldY = win.scrollY; 144 waitForNoScroll = waitAndCheckNoScrollEvent(win); 145 synthesizeKey("VK_DOWN", {}, win); 146 147 await waitForNoScroll; 148 149 is(win.scrollY, oldY, "Page is not scrolled down"); 150 is(win.getSelection().focusNode, ed.firstChild, "Correct element selected"); 151 is(win.getSelection().focusOffset, ed.textContent.length, "Selection should be moved to the end"); 152 153 win.close(); 154 155 SimpleTest.finish(); 156 } 157 </script> 158 </pre> 159 </body> 160 </html>