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