1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/content/tests/browser/browser_bug295977_autoscroll_overflow.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,155 @@ 1.4 +function test() 1.5 +{ 1.6 + const kPrefName_AutoScroll = "general.autoScroll"; 1.7 + Services.prefs.setBoolPref(kPrefName_AutoScroll, true); 1.8 + 1.9 + gBrowser.selectedTab = gBrowser.addTab(); 1.10 + 1.11 + const expectScrollNone = 0; 1.12 + const expectScrollVert = 1; 1.13 + const expectScrollHori = 2; 1.14 + const expectScrollBoth = 3; 1.15 + 1.16 + var allTests = [ 1.17 + {dataUri: 'data:text/html,<html><head><meta charset="utf-8"></head><body><style type="text/css">div { display: inline-block; }</style>\ 1.18 + <div id="a" style="width: 100px; height: 100px; overflow: hidden;"><div style="width: 200px; height: 200px;"></div></div>\ 1.19 + <div id="b" style="width: 100px; height: 100px; overflow: auto;"><div style="width: 200px; height: 200px;"></div></div>\ 1.20 + <div id="c" style="width: 100px; height: 100px; overflow-x: auto; overflow-y: hidden;"><div style="width: 200px; height: 200px;"></div></div>\ 1.21 + <div id="d" style="width: 100px; height: 100px; overflow-y: auto; overflow-x: hidden;"><div style="width: 200px; height: 200px;"></div></div>\ 1.22 + <select id="e" style="width: 100px; height: 100px;" multiple="multiple"><option>aaaaaaaaaaaaaaaaaaaaaaaa</option><option>a</option><option>a</option>\ 1.23 + <option>a</option><option>a</option><option>a</option><option>a</option><option>a</option><option>a</option><option>a</option>\ 1.24 + <option>a</option><option>a</option><option>a</option><option>a</option><option>a</option><option>a</option><option>a</option></select>\ 1.25 + <select id="f" style="width: 100px; height: 100px;"><option>a</option><option>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</option><option>a</option>\ 1.26 + <option>a</option><option>a</option><option>a</option><option>a</option><option>a</option><option>a</option><option>a</option>\ 1.27 + <option>a</option><option>a</option><option>a</option><option>a</option><option>a</option><option>a</option><option>a</option></select>\ 1.28 + <div id="g" style="width: 99px; height: 99px; border: 10px solid black; margin: 10px; overflow: auto;"><div style="width: 100px; height: 100px;"></div></div>\ 1.29 + <div id="h" style="width: 100px; height: 100px; overflow: -moz-hidden-unscrollable;"><div style="width: 200px; height: 200px;"></div></div>\ 1.30 + <iframe id="iframe" style="display: none;"></iframe>\ 1.31 + </body></html>'}, 1.32 + {elem: 'a', expected: expectScrollNone}, 1.33 + {elem: 'b', expected: expectScrollBoth}, 1.34 + {elem: 'c', expected: expectScrollHori}, 1.35 + {elem: 'd', expected: expectScrollVert}, 1.36 + {elem: 'e', expected: expectScrollVert}, 1.37 + {elem: 'f', expected: expectScrollNone}, 1.38 + {elem: 'g', expected: expectScrollBoth}, 1.39 + {elem: 'h', expected: expectScrollNone}, 1.40 + {dataUri: 'data:text/html,<html><head><meta charset="utf-8"></head><body id="i" style="overflow-y: scroll"><div style="height: 2000px"></div>\ 1.41 + <iframe id="iframe" style="display: none;"></iframe>\ 1.42 + </body></html>'}, 1.43 + {elem: 'i', expected: expectScrollVert}, // bug 695121 1.44 + {dataUri: 'data:text/html,<html><head><meta charset="utf-8"></head><style>html, body { width: 100%; height: 100%; overflow-x: hidden; overflow-y: scroll; }</style>\ 1.45 + <body id="j"><div style="height: 2000px"></div>\ 1.46 + <iframe id="iframe" style="display: none;"></iframe>\ 1.47 + </body></html>'}, 1.48 + {elem: 'j', expected: expectScrollVert} // bug 914251 1.49 + ]; 1.50 + 1.51 + var doc; 1.52 + 1.53 + function nextTest() { 1.54 + var test = allTests.shift(); 1.55 + if (!test) { 1.56 + endTest(); 1.57 + return; 1.58 + } 1.59 + 1.60 + if (test.dataUri) { 1.61 + startLoad(test.dataUri); 1.62 + return; 1.63 + } 1.64 + 1.65 + var elem = doc.getElementById(test.elem); 1.66 + 1.67 + let firstTimestamp = undefined; 1.68 + function checkScroll(timestamp) { 1.69 + if (firstTimestamp === undefined) { 1.70 + firstTimestamp = timestamp; 1.71 + } 1.72 + 1.73 + // This value is calculated similarly to the value of the same name in 1.74 + // ClickEventHandler.autoscrollLoop, except here it's cumulative across 1.75 + // all frames after the first one instead of being based only on the 1.76 + // current frame. 1.77 + let timeCompensation = (timestamp - firstTimestamp) / 20; 1.78 + info("timestamp=" + timestamp + " firstTimestamp=" + firstTimestamp + 1.79 + " timeCompensation=" + timeCompensation); 1.80 + 1.81 + // Try to wait until enough time has passed to allow the scroll to happen. 1.82 + // autoscrollLoop incrementally scrolls during each animation frame, but 1.83 + // due to how its calculations work, when a frame is very close to the 1.84 + // previous frame, no scrolling may actually occur during that frame. 1.85 + // After 20ms's worth of frames, timeCompensation will be 1, making it 1.86 + // more likely that the accumulated scroll in autoscrollLoop will be >= 1, 1.87 + // although it also depends on acceleration, which here in this test 1.88 + // should be > 1 due to how it synthesizes mouse events below. 1.89 + if (timeCompensation < 1) { 1.90 + window.mozRequestAnimationFrame(checkScroll); 1.91 + return; 1.92 + } 1.93 + 1.94 + // Close the autoscroll popup by synthesizing Esc. 1.95 + EventUtils.synthesizeKey("VK_ESCAPE", {}, gBrowser.contentWindow); 1.96 + var scrollVert = test.expected & expectScrollVert; 1.97 + ok((scrollVert && elem.scrollTop > 0) || 1.98 + (!scrollVert && elem.scrollTop == 0), 1.99 + test.elem+' should'+(scrollVert ? '' : ' not')+' have scrolled vertically'); 1.100 + var scrollHori = test.expected & expectScrollHori; 1.101 + ok((scrollHori && elem.scrollLeft > 0) || 1.102 + (!scrollHori && elem.scrollLeft == 0), 1.103 + test.elem+' should'+(scrollHori ? '' : ' not')+' have scrolled horizontally'); 1.104 + 1.105 + // Before continuing the test, we need to ensure that the IPC 1.106 + // message that stops autoscrolling has had time to arrive. 1.107 + executeSoon(nextTest); 1.108 + }; 1.109 + EventUtils.synthesizeMouse(elem, 50, 50, { button: 1 }, 1.110 + gBrowser.contentWindow); 1.111 + 1.112 + // This ensures bug 605127 is fixed: pagehide in an unrelated document 1.113 + // should not cancel the autoscroll. 1.114 + var iframe = gBrowser.contentDocument.getElementById("iframe"); 1.115 + var e = iframe.contentDocument.createEvent("pagetransition"); 1.116 + e.initPageTransitionEvent("pagehide", true, true, false); 1.117 + iframe.contentDocument.dispatchEvent(e); 1.118 + iframe.contentDocument.documentElement.dispatchEvent(e); 1.119 + 1.120 + EventUtils.synthesizeMouse(elem, 100, 100, 1.121 + { type: "mousemove", clickCount: "0" }, 1.122 + gBrowser.contentWindow); 1.123 + 1.124 + // Start checking for the scroll. 1.125 + window.mozRequestAnimationFrame(checkScroll); 1.126 + } 1.127 + 1.128 + waitForExplicitFinish(); 1.129 + 1.130 + nextTest(); 1.131 + 1.132 + function startLoad(dataUri) { 1.133 + gBrowser.selectedBrowser.addEventListener("pageshow", onLoad, false); 1.134 + gBrowser.loadURI(dataUri); 1.135 + } 1.136 + 1.137 + function onLoad() { 1.138 + gBrowser.selectedBrowser.removeEventListener("pageshow", onLoad, false); 1.139 + waitForFocus(onFocus, content); 1.140 + } 1.141 + 1.142 + function onFocus() { 1.143 + doc = gBrowser.contentDocument; 1.144 + nextTest(); 1.145 + } 1.146 + 1.147 + function endTest() { 1.148 + // restore the changed prefs 1.149 + if (Services.prefs.prefHasUserValue(kPrefName_AutoScroll)) 1.150 + Services.prefs.clearUserPref(kPrefName_AutoScroll); 1.151 + 1.152 + // cleaning-up 1.153 + gBrowser.removeCurrentTab(); 1.154 + 1.155 + // waitForFocus() fixes a failure in the next test if the latter runs too soon. 1.156 + waitForFocus(finish); 1.157 + } 1.158 +}