1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/content/tests/chrome/test_mousescroll.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,272 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> 1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?> 1.7 +<!-- 1.8 +https://bugzilla.mozilla.org/show_bug.cgi?id=378028 1.9 +--> 1.10 +<window title="Mozilla Bug 378028" 1.11 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.12 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 1.13 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> 1.14 + 1.15 + <!-- test results are displayed in the html:body --> 1.16 + <body xmlns="http://www.w3.org/1999/xhtml"> 1.17 + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=378028" 1.18 + target="_blank">Mozilla Bug 378028</a> 1.19 + </body> 1.20 + 1.21 + <!-- richlistbox currently has no way of giving us a defined number of 1.22 + rows, so we just choose an arbitrary height limit that should give 1.23 + us plenty of vertical scrollability --> 1.24 + <richlistbox id="richlistbox" style="height:50px;"> 1.25 + <richlistitem id="richlistbox_item0" hidden="true"><label value="Item 0"/></richlistitem> 1.26 + <richlistitem id="richlistbox_item1"><label value="Item 1"/></richlistitem> 1.27 + <richlistitem id="richlistbox_item2"><label value="Item 2"/></richlistitem> 1.28 + <richlistitem id="richlistbox_item3"><label value="Item 3"/></richlistitem> 1.29 + <richlistitem id="richlistbox_item4"><label value="Item 4"/></richlistitem> 1.30 + <richlistitem id="richlistbox_item5"><label value="Item 5"/></richlistitem> 1.31 + <richlistitem id="richlistbox_item6"><label value="Item 6"/></richlistitem> 1.32 + <richlistitem id="richlistbox_item7"><label value="Item 7"/></richlistitem> 1.33 + <richlistitem id="richlistbox_item8"><label value="Item 8"/></richlistitem> 1.34 + </richlistbox> 1.35 + 1.36 + <listbox id="listbox" rows="2"> 1.37 + <listitem id="listbox_item0" label="Item 0" hidden="true"/> 1.38 + <listitem id="listbox_item1" label="Item 1"/> 1.39 + <listitem id="listbox_item2" label="Item 2"/> 1.40 + <listitem id="listbox_item3" label="Item 3"/> 1.41 + <listitem id="listbox_item4" label="Item 4"/> 1.42 + <listitem id="listbox_item5" label="Item 5"/> 1.43 + <listitem id="listbox_item6" label="Item 6"/> 1.44 + <listitem id="listbox_item7" label="Item 7"/> 1.45 + <listitem id="listbox_item8" label="Item 8"/> 1.46 + </listbox> 1.47 + 1.48 + <box orient="horizontal"> 1.49 + <arrowscrollbox id="hscrollbox" clicktoscroll="true" orient="horizontal" 1.50 + smoothscroll="false" style="max-width:80px;" flex="1"> 1.51 + <hbox style="width:40px; height:20px; background:black;" hidden="true"/> 1.52 + <hbox style="width:40px; height:20px; background:white;"/> 1.53 + <hbox style="width:40px; height:20px; background:black;"/> 1.54 + <hbox style="width:40px; height:20px; background:white;"/> 1.55 + <hbox style="width:40px; height:20px; background:black;"/> 1.56 + <hbox style="width:40px; height:20px; background:white;"/> 1.57 + <hbox style="width:40px; height:20px; background:black;"/> 1.58 + <hbox style="width:40px; height:20px; background:white;"/> 1.59 + <hbox style="width:40px; height:20px; background:black;"/> 1.60 + </arrowscrollbox> 1.61 + </box> 1.62 + 1.63 + <arrowscrollbox id="vscrollbox" clicktoscroll="true" orient="vertical" 1.64 + smoothscroll="false" style="max-height:80px;" flex="1"> 1.65 + <vbox style="width:100px; height:40px; background:black;" hidden="true"/> 1.66 + <vbox style="width:100px; height:40px; background:white;"/> 1.67 + <vbox style="width:100px; height:40px; background:black;"/> 1.68 + <vbox style="width:100px; height:40px; background:white;"/> 1.69 + <vbox style="width:100px; height:40px; background:black;"/> 1.70 + <vbox style="width:100px; height:40px; background:white;"/> 1.71 + <vbox style="width:100px; height:40px; background:black;"/> 1.72 + <vbox style="width:100px; height:40px; background:white;"/> 1.73 + <vbox style="width:100px; height:40px; background:black;"/> 1.74 + <vbox style="width:100px; height:40px; background:white;"/> 1.75 + <vbox style="width:100px; height:40px; background:black;"/> 1.76 + </arrowscrollbox> 1.77 + 1.78 + <!-- test code goes here --> 1.79 + <script type="application/javascript"><![CDATA[ 1.80 + 1.81 +/** Test for Bug 378028 **/ 1.82 +/* and for Bug 350471 **/ 1.83 +var smoothScrollPref = "general.smoothScroll"; 1.84 +SpecialPowers.setBoolPref(smoothScrollPref, false); 1.85 +SimpleTest.waitForExplicitFinish(); 1.86 + 1.87 +const deltaModes = [ 1.88 + WheelEvent.DOM_DELTA_PIXEL, // 0 1.89 + WheelEvent.DOM_DELTA_LINE, // 1 1.90 + WheelEvent.DOM_DELTA_PAGE // 2 1.91 +]; 1.92 + 1.93 +function testListbox(id) 1.94 +{ 1.95 + var listbox = document.getElementById(id); 1.96 + 1.97 + function helper(aStart, aDelta, aIntDelta, aDeltaMode) 1.98 + { 1.99 + listbox.scrollToIndex(aStart); 1.100 + synthesizeWheel(listbox, 10, 10, 1.101 + { deltaMode: aDeltaMode, deltaY: aDelta, 1.102 + lineOrPageDeltaY: aIntDelta }); 1.103 + var expectedPos = aStart; 1.104 + if (aIntDelta) { 1.105 + if (aDeltaMode == WheelEvent.DOM_DELTA_PAGE) { 1.106 + expectedPos += aIntDelta > 0 ? listbox.getNumberOfVisibleRows() : 1.107 + -listbox.getNumberOfVisibleRows(); 1.108 + } else { 1.109 + expectedPos += aIntDelta; 1.110 + } 1.111 + } 1.112 + is(listbox.getIndexOfFirstVisibleRow(), expectedPos, 1.113 + "testListbox(" + id + "): vertical, starting " + aStart + 1.114 + " delta " + aDelta + " lineOrPageDelta " + aIntDelta + 1.115 + " aDeltaMode " + aDeltaMode); 1.116 + 1.117 + // Check that horizontal scrolling has no effect 1.118 + listbox.scrollToIndex(aStart); 1.119 + synthesizeWheel(listbox, 10, 10, 1.120 + { deltaMode: aDeltaMode, deltaX: aDelta, 1.121 + lineOrPageDeltaX: aIntDelta }); 1.122 + is(listbox.getIndexOfFirstVisibleRow(), aStart, 1.123 + "testListbox(" + id + "): horizontal, starting " + aStart + 1.124 + " delta " + aDelta + " lineOrPageDelta " + aIntDelta + 1.125 + " aDeltaMode " + aDeltaMode); 1.126 + } 1.127 + deltaModes.forEach(function(aDeltaMode) { 1.128 + let delta = (aDeltaMode == WheelEvent.DOM_DELTA_PIXEL) ? 5.0 : 0.3; 1.129 + helper(5, -delta, 0, aDeltaMode); 1.130 + helper(5, -delta, -1, aDeltaMode); 1.131 + helper(5, delta, 1, aDeltaMode); 1.132 + helper(5, delta, 0, aDeltaMode); 1.133 + }); 1.134 +} 1.135 + 1.136 +function testRichListbox(id, andThen) 1.137 +{ 1.138 + var listbox = document.getElementById(id); 1.139 + var tests = []; 1.140 + 1.141 + var winUtils = SpecialPowers.getDOMWindowUtils(window); 1.142 + winUtils.advanceTimeAndRefresh(100); 1.143 + 1.144 + function helper() 1.145 + { 1.146 + var [aStart, aDelta, aIntDelta, aDeltaMode] = tests[0]; 1.147 + tests.shift(); 1.148 + listbox.scrollToIndex(aStart); 1.149 + synthesizeWheel(listbox, 10, 10, 1.150 + { deltaMode: aDeltaMode, deltaY: aDelta, 1.151 + lineOrPageDeltaY: aIntDelta }); 1.152 + 1.153 + winUtils.advanceTimeAndRefresh(100); 1.154 + 1.155 + var change = listbox.getIndexOfFirstVisibleRow() - aStart; 1.156 + var direction = (change > 0) - (change < 0); 1.157 + var expected = (aDelta > 0) - (aDelta < 0); 1.158 + is(direction, expected, 1.159 + "testRichListbox(" + id + "): vertical, starting " + aStart + 1.160 + " delta " + aDelta + " lineOrPageDelta " + aIntDelta + 1.161 + " aDeltaMode " + aDeltaMode); 1.162 + 1.163 + // Check that horizontal scrolling has no effect 1.164 + listbox.scrollToIndex(aStart); 1.165 + synthesizeWheel(listbox, 10, 10, 1.166 + { deltaMode: aDeltaMode, deltaX: aDelta, 1.167 + lineOrPageDeltaX: aIntDelta }); 1.168 + 1.169 + winUtils.advanceTimeAndRefresh(100); 1.170 + 1.171 + is(listbox.getIndexOfFirstVisibleRow(), aStart, 1.172 + "testRichListbox(" + id + "): horizontal, starting " + aStart + 1.173 + " delta " + aDelta + " lineOrPageDelta " + aIntDelta + 1.174 + " aDeltaMode " + aDeltaMode); 1.175 + 1.176 + if (tests.length) { 1.177 + winUtils.advanceTimeAndRefresh(100); 1.178 + helper(); 1.179 + } else { 1.180 + winUtils.restoreNormalRefresh(); 1.181 + andThen(); 1.182 + } 1.183 + } 1.184 + 1.185 + // richlistbox currently uses native XUL scrolling, so the "line" 1.186 + // amounts don't necessarily correspond 1-to-1 with listbox items. So 1.187 + // we just check that scrolling up/down scrolls in the right direction. 1.188 + deltaModes.forEach(function(aDeltaMode) { 1.189 + let delta = (aDeltaMode == WheelEvent.DOM_DELTA_PIXEL) ? 32.0 : 2.0; 1.190 + tests.push([5, -delta, -1, aDeltaMode]); 1.191 + tests.push([5, -delta, 0, aDeltaMode]); 1.192 + tests.push([5, delta, 1, aDeltaMode]); 1.193 + tests.push([5, delta, 0, aDeltaMode]); 1.194 + }); 1.195 + helper(); 1.196 +} 1.197 + 1.198 +function testArrowScrollbox(id) 1.199 +{ 1.200 + var scrollbox = document.getElementById(id); 1.201 + var scrollBoxObject = scrollbox.scrollBoxObject; 1.202 + var orient = scrollbox.getAttribute("orient"); 1.203 + 1.204 + function helper(aStart, aDelta, aIntDelta, aDeltaMode, aExpected) 1.205 + { 1.206 + var xpos = {}; 1.207 + var ypos = {}; 1.208 + var orientIsHorizontal = (orient == "horizontal"); 1.209 + var pos = orientIsHorizontal ? xpos : ypos; 1.210 + 1.211 + scrollBoxObject.scrollTo(aStart, aStart); 1.212 + 1.213 + for (var i = orientIsHorizontal ? 2 : 0; i >= 0; i--) { 1.214 + synthesizeWheel(scrollbox, 5, 5, 1.215 + { deltaMode: aDeltaMode, deltaY: aDelta, 1.216 + lineOrPageDeltaY: aIntDelta }); 1.217 + scrollBoxObject.getPosition(xpos, ypos); 1.218 + // Note, vertical mouse scrolling is allowed to scroll horizontal 1.219 + // arrowscrollboxes, because many users have no horizontal mouse scroll 1.220 + // capability 1.221 + let expected = !i ? aExpected : aStart; 1.222 + is(pos.value, expected, 1.223 + "testArrowScrollbox(" + id + "): vertical, starting " + aStart + 1.224 + " delta " + aDelta + " lineOrPageDelta " + aIntDelta + 1.225 + " aDeltaMode " + aDeltaMode); 1.226 + } 1.227 + 1.228 + scrollBoxObject.scrollTo(aStart, aStart); 1.229 + for (var i = orientIsHorizontal ? 2 : 0; i >= 0; i--) { 1.230 + synthesizeWheel(scrollbox, 5, 5, 1.231 + { deltaMode: aDeltaMode, deltaX: aDelta, 1.232 + lineOrPageDeltaX: aIntDelta }); 1.233 + // horizontal mouse scrolling is never allowed to scroll vertical 1.234 + // arrowscrollboxes 1.235 + scrollBoxObject.getPosition(xpos, ypos); 1.236 + let expected = (!i && orientIsHorizontal) ? aExpected : aStart; 1.237 + is(pos.value, expected, 1.238 + "testArrowScrollbox(" + id + "): horizontal, starting " + aStart + 1.239 + " delta " + aDelta + " lineOrPageDelta " + aIntDelta + 1.240 + " aDeltaMode " + aDeltaMode); 1.241 + } 1.242 + } 1.243 + 1.244 + var scrolledWidth = {}; 1.245 + var scrolledHeight = {}; 1.246 + scrollBoxObject.getScrolledSize(scrolledWidth, scrolledHeight); 1.247 + var scrollMaxX = scrolledWidth.value - scrollBoxObject.width; 1.248 + var scrollMaxY = scrolledHeight.value - scrollBoxObject.height; 1.249 + var scrollMax = orient == "horizontal" ? scrollMaxX : scrollMaxY; 1.250 + 1.251 + deltaModes.forEach(function(aDeltaMode) { 1.252 + // These lineOrPageDelta values are not realistic. However, it's enough to 1.253 + // test if it's scrolled by the lineOrPageDelta value. 1.254 + let delta = (aDeltaMode == WheelEvent.DOM_DELTA_PIXEL) ? 5.0 : 0.3; 1.255 + helper(50, -delta, -100, aDeltaMode, 0); 1.256 + helper(50, delta, 100, aDeltaMode, scrollMax); 1.257 + helper(50, -delta, 0, aDeltaMode, 50); 1.258 + helper(50, delta, 0, aDeltaMode, 50); 1.259 + }); 1.260 +} 1.261 + 1.262 +function runTests() 1.263 +{ 1.264 + testRichListbox("richlistbox", function() { 1.265 + testListbox("listbox"); 1.266 + testArrowScrollbox("hscrollbox"); 1.267 + testArrowScrollbox("vscrollbox"); 1.268 + SpecialPowers.clearUserPref(smoothScrollPref); 1.269 + SimpleTest.finish(); 1.270 + }); 1.271 +} 1.272 + 1.273 +window.onload = function() { setTimeout(runTests, 0); }; 1.274 + ]]></script> 1.275 +</window>