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