\
+ \
+ '},
+ {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);
+ }
+}