toolkit/content/tests/chrome/test_mousescroll.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <?xml version="1.0"?>
michael@0 2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
michael@0 3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
michael@0 4 <!--
michael@0 5 https://bugzilla.mozilla.org/show_bug.cgi?id=378028
michael@0 6 -->
michael@0 7 <window title="Mozilla Bug 378028"
michael@0 8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
michael@0 9 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
michael@0 10 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
michael@0 11
michael@0 12 <!-- test results are displayed in the html:body -->
michael@0 13 <body xmlns="http://www.w3.org/1999/xhtml">
michael@0 14 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=378028"
michael@0 15 target="_blank">Mozilla Bug 378028</a>
michael@0 16 </body>
michael@0 17
michael@0 18 <!-- richlistbox currently has no way of giving us a defined number of
michael@0 19 rows, so we just choose an arbitrary height limit that should give
michael@0 20 us plenty of vertical scrollability -->
michael@0 21 <richlistbox id="richlistbox" style="height:50px;">
michael@0 22 <richlistitem id="richlistbox_item0" hidden="true"><label value="Item 0"/></richlistitem>
michael@0 23 <richlistitem id="richlistbox_item1"><label value="Item 1"/></richlistitem>
michael@0 24 <richlistitem id="richlistbox_item2"><label value="Item 2"/></richlistitem>
michael@0 25 <richlistitem id="richlistbox_item3"><label value="Item 3"/></richlistitem>
michael@0 26 <richlistitem id="richlistbox_item4"><label value="Item 4"/></richlistitem>
michael@0 27 <richlistitem id="richlistbox_item5"><label value="Item 5"/></richlistitem>
michael@0 28 <richlistitem id="richlistbox_item6"><label value="Item 6"/></richlistitem>
michael@0 29 <richlistitem id="richlistbox_item7"><label value="Item 7"/></richlistitem>
michael@0 30 <richlistitem id="richlistbox_item8"><label value="Item 8"/></richlistitem>
michael@0 31 </richlistbox>
michael@0 32
michael@0 33 <listbox id="listbox" rows="2">
michael@0 34 <listitem id="listbox_item0" label="Item 0" hidden="true"/>
michael@0 35 <listitem id="listbox_item1" label="Item 1"/>
michael@0 36 <listitem id="listbox_item2" label="Item 2"/>
michael@0 37 <listitem id="listbox_item3" label="Item 3"/>
michael@0 38 <listitem id="listbox_item4" label="Item 4"/>
michael@0 39 <listitem id="listbox_item5" label="Item 5"/>
michael@0 40 <listitem id="listbox_item6" label="Item 6"/>
michael@0 41 <listitem id="listbox_item7" label="Item 7"/>
michael@0 42 <listitem id="listbox_item8" label="Item 8"/>
michael@0 43 </listbox>
michael@0 44
michael@0 45 <box orient="horizontal">
michael@0 46 <arrowscrollbox id="hscrollbox" clicktoscroll="true" orient="horizontal"
michael@0 47 smoothscroll="false" style="max-width:80px;" flex="1">
michael@0 48 <hbox style="width:40px; height:20px; background:black;" hidden="true"/>
michael@0 49 <hbox style="width:40px; height:20px; background:white;"/>
michael@0 50 <hbox style="width:40px; height:20px; background:black;"/>
michael@0 51 <hbox style="width:40px; height:20px; background:white;"/>
michael@0 52 <hbox style="width:40px; height:20px; background:black;"/>
michael@0 53 <hbox style="width:40px; height:20px; background:white;"/>
michael@0 54 <hbox style="width:40px; height:20px; background:black;"/>
michael@0 55 <hbox style="width:40px; height:20px; background:white;"/>
michael@0 56 <hbox style="width:40px; height:20px; background:black;"/>
michael@0 57 </arrowscrollbox>
michael@0 58 </box>
michael@0 59
michael@0 60 <arrowscrollbox id="vscrollbox" clicktoscroll="true" orient="vertical"
michael@0 61 smoothscroll="false" style="max-height:80px;" flex="1">
michael@0 62 <vbox style="width:100px; height:40px; background:black;" hidden="true"/>
michael@0 63 <vbox style="width:100px; height:40px; background:white;"/>
michael@0 64 <vbox style="width:100px; height:40px; background:black;"/>
michael@0 65 <vbox style="width:100px; height:40px; background:white;"/>
michael@0 66 <vbox style="width:100px; height:40px; background:black;"/>
michael@0 67 <vbox style="width:100px; height:40px; background:white;"/>
michael@0 68 <vbox style="width:100px; height:40px; background:black;"/>
michael@0 69 <vbox style="width:100px; height:40px; background:white;"/>
michael@0 70 <vbox style="width:100px; height:40px; background:black;"/>
michael@0 71 <vbox style="width:100px; height:40px; background:white;"/>
michael@0 72 <vbox style="width:100px; height:40px; background:black;"/>
michael@0 73 </arrowscrollbox>
michael@0 74
michael@0 75 <!-- test code goes here -->
michael@0 76 <script type="application/javascript"><![CDATA[
michael@0 77
michael@0 78 /** Test for Bug 378028 **/
michael@0 79 /* and for Bug 350471 **/
michael@0 80 var smoothScrollPref = "general.smoothScroll";
michael@0 81 SpecialPowers.setBoolPref(smoothScrollPref, false);
michael@0 82 SimpleTest.waitForExplicitFinish();
michael@0 83
michael@0 84 const deltaModes = [
michael@0 85 WheelEvent.DOM_DELTA_PIXEL, // 0
michael@0 86 WheelEvent.DOM_DELTA_LINE, // 1
michael@0 87 WheelEvent.DOM_DELTA_PAGE // 2
michael@0 88 ];
michael@0 89
michael@0 90 function testListbox(id)
michael@0 91 {
michael@0 92 var listbox = document.getElementById(id);
michael@0 93
michael@0 94 function helper(aStart, aDelta, aIntDelta, aDeltaMode)
michael@0 95 {
michael@0 96 listbox.scrollToIndex(aStart);
michael@0 97 synthesizeWheel(listbox, 10, 10,
michael@0 98 { deltaMode: aDeltaMode, deltaY: aDelta,
michael@0 99 lineOrPageDeltaY: aIntDelta });
michael@0 100 var expectedPos = aStart;
michael@0 101 if (aIntDelta) {
michael@0 102 if (aDeltaMode == WheelEvent.DOM_DELTA_PAGE) {
michael@0 103 expectedPos += aIntDelta > 0 ? listbox.getNumberOfVisibleRows() :
michael@0 104 -listbox.getNumberOfVisibleRows();
michael@0 105 } else {
michael@0 106 expectedPos += aIntDelta;
michael@0 107 }
michael@0 108 }
michael@0 109 is(listbox.getIndexOfFirstVisibleRow(), expectedPos,
michael@0 110 "testListbox(" + id + "): vertical, starting " + aStart +
michael@0 111 " delta " + aDelta + " lineOrPageDelta " + aIntDelta +
michael@0 112 " aDeltaMode " + aDeltaMode);
michael@0 113
michael@0 114 // Check that horizontal scrolling has no effect
michael@0 115 listbox.scrollToIndex(aStart);
michael@0 116 synthesizeWheel(listbox, 10, 10,
michael@0 117 { deltaMode: aDeltaMode, deltaX: aDelta,
michael@0 118 lineOrPageDeltaX: aIntDelta });
michael@0 119 is(listbox.getIndexOfFirstVisibleRow(), aStart,
michael@0 120 "testListbox(" + id + "): horizontal, starting " + aStart +
michael@0 121 " delta " + aDelta + " lineOrPageDelta " + aIntDelta +
michael@0 122 " aDeltaMode " + aDeltaMode);
michael@0 123 }
michael@0 124 deltaModes.forEach(function(aDeltaMode) {
michael@0 125 let delta = (aDeltaMode == WheelEvent.DOM_DELTA_PIXEL) ? 5.0 : 0.3;
michael@0 126 helper(5, -delta, 0, aDeltaMode);
michael@0 127 helper(5, -delta, -1, aDeltaMode);
michael@0 128 helper(5, delta, 1, aDeltaMode);
michael@0 129 helper(5, delta, 0, aDeltaMode);
michael@0 130 });
michael@0 131 }
michael@0 132
michael@0 133 function testRichListbox(id, andThen)
michael@0 134 {
michael@0 135 var listbox = document.getElementById(id);
michael@0 136 var tests = [];
michael@0 137
michael@0 138 var winUtils = SpecialPowers.getDOMWindowUtils(window);
michael@0 139 winUtils.advanceTimeAndRefresh(100);
michael@0 140
michael@0 141 function helper()
michael@0 142 {
michael@0 143 var [aStart, aDelta, aIntDelta, aDeltaMode] = tests[0];
michael@0 144 tests.shift();
michael@0 145 listbox.scrollToIndex(aStart);
michael@0 146 synthesizeWheel(listbox, 10, 10,
michael@0 147 { deltaMode: aDeltaMode, deltaY: aDelta,
michael@0 148 lineOrPageDeltaY: aIntDelta });
michael@0 149
michael@0 150 winUtils.advanceTimeAndRefresh(100);
michael@0 151
michael@0 152 var change = listbox.getIndexOfFirstVisibleRow() - aStart;
michael@0 153 var direction = (change > 0) - (change < 0);
michael@0 154 var expected = (aDelta > 0) - (aDelta < 0);
michael@0 155 is(direction, expected,
michael@0 156 "testRichListbox(" + id + "): vertical, starting " + aStart +
michael@0 157 " delta " + aDelta + " lineOrPageDelta " + aIntDelta +
michael@0 158 " aDeltaMode " + aDeltaMode);
michael@0 159
michael@0 160 // Check that horizontal scrolling has no effect
michael@0 161 listbox.scrollToIndex(aStart);
michael@0 162 synthesizeWheel(listbox, 10, 10,
michael@0 163 { deltaMode: aDeltaMode, deltaX: aDelta,
michael@0 164 lineOrPageDeltaX: aIntDelta });
michael@0 165
michael@0 166 winUtils.advanceTimeAndRefresh(100);
michael@0 167
michael@0 168 is(listbox.getIndexOfFirstVisibleRow(), aStart,
michael@0 169 "testRichListbox(" + id + "): horizontal, starting " + aStart +
michael@0 170 " delta " + aDelta + " lineOrPageDelta " + aIntDelta +
michael@0 171 " aDeltaMode " + aDeltaMode);
michael@0 172
michael@0 173 if (tests.length) {
michael@0 174 winUtils.advanceTimeAndRefresh(100);
michael@0 175 helper();
michael@0 176 } else {
michael@0 177 winUtils.restoreNormalRefresh();
michael@0 178 andThen();
michael@0 179 }
michael@0 180 }
michael@0 181
michael@0 182 // richlistbox currently uses native XUL scrolling, so the "line"
michael@0 183 // amounts don't necessarily correspond 1-to-1 with listbox items. So
michael@0 184 // we just check that scrolling up/down scrolls in the right direction.
michael@0 185 deltaModes.forEach(function(aDeltaMode) {
michael@0 186 let delta = (aDeltaMode == WheelEvent.DOM_DELTA_PIXEL) ? 32.0 : 2.0;
michael@0 187 tests.push([5, -delta, -1, aDeltaMode]);
michael@0 188 tests.push([5, -delta, 0, aDeltaMode]);
michael@0 189 tests.push([5, delta, 1, aDeltaMode]);
michael@0 190 tests.push([5, delta, 0, aDeltaMode]);
michael@0 191 });
michael@0 192 helper();
michael@0 193 }
michael@0 194
michael@0 195 function testArrowScrollbox(id)
michael@0 196 {
michael@0 197 var scrollbox = document.getElementById(id);
michael@0 198 var scrollBoxObject = scrollbox.scrollBoxObject;
michael@0 199 var orient = scrollbox.getAttribute("orient");
michael@0 200
michael@0 201 function helper(aStart, aDelta, aIntDelta, aDeltaMode, aExpected)
michael@0 202 {
michael@0 203 var xpos = {};
michael@0 204 var ypos = {};
michael@0 205 var orientIsHorizontal = (orient == "horizontal");
michael@0 206 var pos = orientIsHorizontal ? xpos : ypos;
michael@0 207
michael@0 208 scrollBoxObject.scrollTo(aStart, aStart);
michael@0 209
michael@0 210 for (var i = orientIsHorizontal ? 2 : 0; i >= 0; i--) {
michael@0 211 synthesizeWheel(scrollbox, 5, 5,
michael@0 212 { deltaMode: aDeltaMode, deltaY: aDelta,
michael@0 213 lineOrPageDeltaY: aIntDelta });
michael@0 214 scrollBoxObject.getPosition(xpos, ypos);
michael@0 215 // Note, vertical mouse scrolling is allowed to scroll horizontal
michael@0 216 // arrowscrollboxes, because many users have no horizontal mouse scroll
michael@0 217 // capability
michael@0 218 let expected = !i ? aExpected : aStart;
michael@0 219 is(pos.value, expected,
michael@0 220 "testArrowScrollbox(" + id + "): vertical, starting " + aStart +
michael@0 221 " delta " + aDelta + " lineOrPageDelta " + aIntDelta +
michael@0 222 " aDeltaMode " + aDeltaMode);
michael@0 223 }
michael@0 224
michael@0 225 scrollBoxObject.scrollTo(aStart, aStart);
michael@0 226 for (var i = orientIsHorizontal ? 2 : 0; i >= 0; i--) {
michael@0 227 synthesizeWheel(scrollbox, 5, 5,
michael@0 228 { deltaMode: aDeltaMode, deltaX: aDelta,
michael@0 229 lineOrPageDeltaX: aIntDelta });
michael@0 230 // horizontal mouse scrolling is never allowed to scroll vertical
michael@0 231 // arrowscrollboxes
michael@0 232 scrollBoxObject.getPosition(xpos, ypos);
michael@0 233 let expected = (!i && orientIsHorizontal) ? aExpected : aStart;
michael@0 234 is(pos.value, expected,
michael@0 235 "testArrowScrollbox(" + id + "): horizontal, starting " + aStart +
michael@0 236 " delta " + aDelta + " lineOrPageDelta " + aIntDelta +
michael@0 237 " aDeltaMode " + aDeltaMode);
michael@0 238 }
michael@0 239 }
michael@0 240
michael@0 241 var scrolledWidth = {};
michael@0 242 var scrolledHeight = {};
michael@0 243 scrollBoxObject.getScrolledSize(scrolledWidth, scrolledHeight);
michael@0 244 var scrollMaxX = scrolledWidth.value - scrollBoxObject.width;
michael@0 245 var scrollMaxY = scrolledHeight.value - scrollBoxObject.height;
michael@0 246 var scrollMax = orient == "horizontal" ? scrollMaxX : scrollMaxY;
michael@0 247
michael@0 248 deltaModes.forEach(function(aDeltaMode) {
michael@0 249 // These lineOrPageDelta values are not realistic. However, it's enough to
michael@0 250 // test if it's scrolled by the lineOrPageDelta value.
michael@0 251 let delta = (aDeltaMode == WheelEvent.DOM_DELTA_PIXEL) ? 5.0 : 0.3;
michael@0 252 helper(50, -delta, -100, aDeltaMode, 0);
michael@0 253 helper(50, delta, 100, aDeltaMode, scrollMax);
michael@0 254 helper(50, -delta, 0, aDeltaMode, 50);
michael@0 255 helper(50, delta, 0, aDeltaMode, 50);
michael@0 256 });
michael@0 257 }
michael@0 258
michael@0 259 function runTests()
michael@0 260 {
michael@0 261 testRichListbox("richlistbox", function() {
michael@0 262 testListbox("listbox");
michael@0 263 testArrowScrollbox("hscrollbox");
michael@0 264 testArrowScrollbox("vscrollbox");
michael@0 265 SpecialPowers.clearUserPref(smoothScrollPref);
michael@0 266 SimpleTest.finish();
michael@0 267 });
michael@0 268 }
michael@0 269
michael@0 270 window.onload = function() { setTimeout(runTests, 0); };
michael@0 271 ]]></script>
michael@0 272 </window>

mercurial