1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/content/tests/browser/browser_autoscroll_disabled.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,78 @@ 1.4 +function test() 1.5 +{ 1.6 + const kPrefName_AutoScroll = "general.autoScroll"; 1.7 + Services.prefs.setBoolPref(kPrefName_AutoScroll, false); 1.8 + 1.9 + gBrowser.selectedTab = gBrowser.addTab(); 1.10 + 1.11 + var doc; 1.12 + 1.13 + function startLoad(dataUri) { 1.14 + gBrowser.selectedBrowser.addEventListener("pageshow", onLoad, false); 1.15 + gBrowser.loadURI(dataUri); 1.16 + } 1.17 + 1.18 + function onLoad() { 1.19 + gBrowser.selectedBrowser.removeEventListener("pageshow", onLoad, false); 1.20 + waitForFocus(onFocus, content); 1.21 + } 1.22 + 1.23 + function onFocus() { 1.24 + doc = gBrowser.contentDocument; 1.25 + runChecks(); 1.26 + } 1.27 + 1.28 + function endTest() { 1.29 + // restore the changed prefs 1.30 + if (Services.prefs.prefHasUserValue(kPrefName_AutoScroll)) 1.31 + Services.prefs.clearUserPref(kPrefName_AutoScroll); 1.32 + 1.33 + // cleaning-up 1.34 + gBrowser.removeCurrentTab(); 1.35 + 1.36 + // waitForFocus() fixes a failure in the next test if the latter runs too soon. 1.37 + waitForFocus(finish); 1.38 + } 1.39 + 1.40 + waitForExplicitFinish(); 1.41 + 1.42 + let dataUri = 'data:text/html,<html><body id="i" style="overflow-y: scroll"><div style="height: 2000px"></div>\ 1.43 + <iframe id="iframe" style="display: none;"></iframe>\ 1.44 +</body></html>'; 1.45 + startLoad(dataUri); 1.46 + 1.47 + function runChecks() { 1.48 + var elem = doc.getElementById('i'); 1.49 + // Skip the first callback as it's the same callback that the browser 1.50 + // uses to kick off the scrolling. 1.51 + var skipFrames = 1; 1.52 + var checkScroll = function () { 1.53 + if (skipFrames--) { 1.54 + window.mozRequestAnimationFrame(checkScroll); 1.55 + return; 1.56 + } 1.57 + ok(elem.scrollTop == 0, "element should not have scrolled vertically"); 1.58 + ok(elem.scrollLeft == 0, "element should not have scrolled horizontally"); 1.59 + 1.60 + endTest(); 1.61 + }; 1.62 + EventUtils.synthesizeMouse(elem, 50, 50, { button: 1 }, 1.63 + gBrowser.contentWindow); 1.64 + 1.65 + var iframe = gBrowser.contentDocument.getElementById("iframe"); 1.66 + var e = iframe.contentDocument.createEvent("pagetransition"); 1.67 + e.initPageTransitionEvent("pagehide", true, true, false); 1.68 + iframe.contentDocument.dispatchEvent(e); 1.69 + iframe.contentDocument.documentElement.dispatchEvent(e); 1.70 + 1.71 + EventUtils.synthesizeMouse(elem, 100, 100, 1.72 + { type: "mousemove", clickCount: "0" }, 1.73 + gBrowser.contentWindow); 1.74 + /* 1.75 + * if scrolling didn’t work, we wouldn’t do any redraws and thus time out. 1.76 + * so request and force redraws to get the chance to check for scrolling at 1.77 + * all. 1.78 + */ 1.79 + window.mozRequestAnimationFrame(checkScroll); 1.80 + } 1.81 +}