diff -r 000000000000 -r 6474c204b198 toolkit/content/tests/browser/browser_bug295977_autoscroll_overflow.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/toolkit/content/tests/browser/browser_bug295977_autoscroll_overflow.js Wed Dec 31 06:09:35 2014 +0100 @@ -0,0 +1,155 @@ +function test() +{ + const kPrefName_AutoScroll = "general.autoScroll"; + Services.prefs.setBoolPref(kPrefName_AutoScroll, true); + + gBrowser.selectedTab = gBrowser.addTab(); + + const expectScrollNone = 0; + const expectScrollVert = 1; + const expectScrollHori = 2; + const expectScrollBoth = 3; + + var allTests = [ + {dataUri: 'data:text/html,\ +
\ +
\ +
\ +
\ + \ + \ +
\ +
\ + \ + '}, + {elem: 'a', expected: expectScrollNone}, + {elem: 'b', expected: expectScrollBoth}, + {elem: 'c', expected: expectScrollHori}, + {elem: 'd', expected: expectScrollVert}, + {elem: 'e', expected: expectScrollVert}, + {elem: 'f', expected: expectScrollNone}, + {elem: 'g', expected: expectScrollBoth}, + {elem: 'h', expected: expectScrollNone}, + {dataUri: 'data:text/html,
\ + \ + '}, + {elem: 'i', expected: expectScrollVert}, // bug 695121 + {dataUri: 'data:text/html,\ +
\ + \ + '}, + {elem: 'j', expected: expectScrollVert} // bug 914251 + ]; + + var doc; + + function nextTest() { + var test = allTests.shift(); + if (!test) { + endTest(); + return; + } + + if (test.dataUri) { + startLoad(test.dataUri); + return; + } + + var elem = doc.getElementById(test.elem); + + let firstTimestamp = undefined; + function checkScroll(timestamp) { + if (firstTimestamp === undefined) { + firstTimestamp = timestamp; + } + + // This value is calculated similarly to the value of the same name in + // ClickEventHandler.autoscrollLoop, except here it's cumulative across + // all frames after the first one instead of being based only on the + // current frame. + let timeCompensation = (timestamp - firstTimestamp) / 20; + info("timestamp=" + timestamp + " firstTimestamp=" + firstTimestamp + + " timeCompensation=" + timeCompensation); + + // Try to wait until enough time has passed to allow the scroll to happen. + // autoscrollLoop incrementally scrolls during each animation frame, but + // due to how its calculations work, when a frame is very close to the + // previous frame, no scrolling may actually occur during that frame. + // After 20ms's worth of frames, timeCompensation will be 1, making it + // more likely that the accumulated scroll in autoscrollLoop will be >= 1, + // although it also depends on acceleration, which here in this test + // should be > 1 due to how it synthesizes mouse events below. + if (timeCompensation < 1) { + window.mozRequestAnimationFrame(checkScroll); + return; + } + + // Close the autoscroll popup by synthesizing Esc. + EventUtils.synthesizeKey("VK_ESCAPE", {}, gBrowser.contentWindow); + var scrollVert = test.expected & expectScrollVert; + ok((scrollVert && elem.scrollTop > 0) || + (!scrollVert && elem.scrollTop == 0), + test.elem+' should'+(scrollVert ? '' : ' not')+' have scrolled vertically'); + var scrollHori = test.expected & expectScrollHori; + ok((scrollHori && elem.scrollLeft > 0) || + (!scrollHori && elem.scrollLeft == 0), + test.elem+' should'+(scrollHori ? '' : ' not')+' have scrolled horizontally'); + + // Before continuing the test, we need to ensure that the IPC + // message that stops autoscrolling has had time to arrive. + executeSoon(nextTest); + }; + EventUtils.synthesizeMouse(elem, 50, 50, { button: 1 }, + gBrowser.contentWindow); + + // This ensures bug 605127 is fixed: pagehide in an unrelated document + // should not cancel the autoscroll. + var iframe = gBrowser.contentDocument.getElementById("iframe"); + var e = iframe.contentDocument.createEvent("pagetransition"); + e.initPageTransitionEvent("pagehide", true, true, false); + iframe.contentDocument.dispatchEvent(e); + iframe.contentDocument.documentElement.dispatchEvent(e); + + EventUtils.synthesizeMouse(elem, 100, 100, + { type: "mousemove", clickCount: "0" }, + gBrowser.contentWindow); + + // Start checking for the scroll. + window.mozRequestAnimationFrame(checkScroll); + } + + waitForExplicitFinish(); + + nextTest(); + + function startLoad(dataUri) { + gBrowser.selectedBrowser.addEventListener("pageshow", onLoad, false); + gBrowser.loadURI(dataUri); + } + + function onLoad() { + gBrowser.selectedBrowser.removeEventListener("pageshow", onLoad, false); + waitForFocus(onFocus, content); + } + + function onFocus() { + doc = gBrowser.contentDocument; + nextTest(); + } + + function endTest() { + // restore the changed prefs + if (Services.prefs.prefHasUserValue(kPrefName_AutoScroll)) + Services.prefs.clearUserPref(kPrefName_AutoScroll); + + // cleaning-up + gBrowser.removeCurrentTab(); + + // waitForFocus() fixes a failure in the next test if the latter runs too soon. + waitForFocus(finish); + } +}