2008-07-24 21:07:43 -07:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
|
|
|
<?xml-stylesheet href="/tests/SimpleTest/test.css" type="text/css"?>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=378028
|
|
|
|
-->
|
|
|
|
<window title="Mozilla Bug 378028"
|
|
|
|
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
|
|
|
<script type="application/javascript" src="/MochiKit/packed.js" />
|
|
|
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"/>
|
|
|
|
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"/>
|
|
|
|
|
|
|
|
<!-- test results are displayed in the html:body -->
|
|
|
|
<body xmlns="http://www.w3.org/1999/xhtml">
|
|
|
|
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=378028"
|
|
|
|
target="_blank">Mozilla Bug 378028</a>
|
|
|
|
</body>
|
|
|
|
|
|
|
|
<!-- richlistbox currently has no way of giving us a defined number of
|
|
|
|
rows, so we just choose an arbitrary height limit that should give
|
|
|
|
us plenty of vertical scrollability -->
|
|
|
|
<richlistbox id="richlistbox" style="height:50px;">
|
|
|
|
<richlistitem id="richlistbox_item1"><label value="Item 1"/></richlistitem>
|
|
|
|
<richlistitem id="richlistbox_item2"><label value="Item 2"/></richlistitem>
|
|
|
|
<richlistitem id="richlistbox_item3"><label value="Item 3"/></richlistitem>
|
|
|
|
<richlistitem id="richlistbox_item4"><label value="Item 4"/></richlistitem>
|
|
|
|
<richlistitem id="richlistbox_item5"><label value="Item 5"/></richlistitem>
|
|
|
|
<richlistitem id="richlistbox_item6"><label value="Item 6"/></richlistitem>
|
|
|
|
<richlistitem id="richlistbox_item7"><label value="Item 7"/></richlistitem>
|
|
|
|
<richlistitem id="richlistbox_item8"><label value="Item 8"/></richlistitem>
|
|
|
|
</richlistbox>
|
2010-06-23 10:28:12 -07:00
|
|
|
|
2008-07-24 21:07:43 -07:00
|
|
|
<listbox id="listbox" rows="2">
|
|
|
|
<listitem id="listbox_item1" label="Item 1"/>
|
|
|
|
<listitem id="listbox_item2" label="Item 2"/>
|
|
|
|
<listitem id="listbox_item3" label="Item 3"/>
|
|
|
|
<listitem id="listbox_item4" label="Item 4"/>
|
|
|
|
<listitem id="listbox_item5" label="Item 5"/>
|
|
|
|
<listitem id="listbox_item6" label="Item 6"/>
|
|
|
|
<listitem id="listbox_item7" label="Item 7"/>
|
|
|
|
<listitem id="listbox_item8" label="Item 8"/>
|
|
|
|
</listbox>
|
2010-06-23 10:28:12 -07:00
|
|
|
|
2008-07-24 21:07:43 -07:00
|
|
|
<box orient="horizontal">
|
|
|
|
<arrowscrollbox id="hscrollbox" clicktoscroll="true" orient="horizontal"
|
|
|
|
smoothscroll="false" style="max-width:80px;" flex="1">
|
|
|
|
<hbox style="width:40px; height:20px; background:white;"/>
|
|
|
|
<hbox style="width:40px; height:20px; background:black;"/>
|
|
|
|
<hbox style="width:40px; height:20px; background:white;"/>
|
|
|
|
<hbox style="width:40px; height:20px; background:black;"/>
|
|
|
|
<hbox style="width:40px; height:20px; background:white;"/>
|
|
|
|
<hbox style="width:40px; height:20px; background:black;"/>
|
|
|
|
<hbox style="width:40px; height:20px; background:white;"/>
|
|
|
|
<hbox style="width:40px; height:20px; background:black;"/>
|
|
|
|
</arrowscrollbox>
|
|
|
|
</box>
|
2010-06-23 10:28:12 -07:00
|
|
|
|
2008-07-24 21:07:43 -07:00
|
|
|
<arrowscrollbox id="vscrollbox" clicktoscroll="true" orient="vertical"
|
|
|
|
smoothscroll="false" style="max-height:80px;" flex="1">
|
|
|
|
<vbox style="width:100px; height:40px; background:white;"/>
|
|
|
|
<vbox style="width:100px; height:40px; background:black;"/>
|
|
|
|
<vbox style="width:100px; height:40px; background:white;"/>
|
|
|
|
<vbox style="width:100px; height:40px; background:black;"/>
|
|
|
|
<vbox style="width:100px; height:40px; background:white;"/>
|
|
|
|
<vbox style="width:100px; height:40px; background:black;"/>
|
|
|
|
<vbox style="width:100px; height:40px; background:white;"/>
|
|
|
|
<vbox style="width:100px; height:40px; background:black;"/>
|
|
|
|
<vbox style="width:100px; height:40px; background:white;"/>
|
|
|
|
<vbox style="width:100px; height:40px; background:black;"/>
|
|
|
|
</arrowscrollbox>
|
2010-06-23 10:28:12 -07:00
|
|
|
|
2008-07-24 21:07:43 -07:00
|
|
|
<!-- test code goes here -->
|
|
|
|
<script type="application/javascript"><![CDATA[
|
|
|
|
|
|
|
|
/** Test for Bug 378028 **/
|
2008-09-17 04:27:19 -07:00
|
|
|
/* and for Bug 350471 **/
|
2008-07-24 21:07:43 -07:00
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
2008-09-17 04:27:19 -07:00
|
|
|
/* There are three kinds of scroll events:
|
|
|
|
1. line scrolls without hasPixels
|
|
|
|
2. line scrolls with hasPixels
|
|
|
|
3. pixel scrolls
|
|
|
|
Listboxes and arrowscrollboxes (DOM event scrolling) should only react to
|
|
|
|
line scrolls and ignore hasPixels.
|
|
|
|
Richlistboxes ("native" scrolling) should be scrollable by kind 1 and 3.
|
|
|
|
*/
|
|
|
|
const kinds = [
|
|
|
|
{ eventType: "DOMMouseScroll", hasPixels: false, shouldScrollDOM: true, shouldScrollNative: true },
|
|
|
|
{ eventType: "DOMMouseScroll", hasPixels: true, shouldScrollDOM: true, shouldScrollNative: false },
|
|
|
|
{ eventType: "MozMousePixelScroll", hasPixels: false, shouldScrollDOM: false, shouldScrollNative: true }
|
|
|
|
];
|
|
|
|
|
|
|
|
|
2008-07-24 21:07:43 -07:00
|
|
|
function testListbox(id)
|
|
|
|
{
|
|
|
|
var listbox = document.getElementById(id);
|
2010-06-23 10:28:12 -07:00
|
|
|
|
2008-09-17 04:27:19 -07:00
|
|
|
function helper(aStart, aDelta, aKind)
|
2008-07-24 21:07:43 -07:00
|
|
|
{
|
|
|
|
listbox.scrollToIndex(aStart);
|
|
|
|
synthesizeMouseScroll(listbox, 10, 10,
|
2008-09-17 04:27:19 -07:00
|
|
|
{axis:"vertical", delta:aDelta, type:aKind.eventType,
|
|
|
|
hasPixels:aKind.hasPixels});
|
|
|
|
is(listbox.getIndexOfFirstVisibleRow(), aKind.shouldScrollDOM ? aStart + aDelta : aStart,
|
|
|
|
"mouse-scroll of '" + id + "' vertical starting " + aStart + " delta " + aDelta
|
|
|
|
+ " eventType " + aKind.eventType + " hasPixels " + aKind.hasPixels);
|
2008-07-24 21:07:43 -07:00
|
|
|
|
|
|
|
// Check that horizontal scrolling has no effect
|
|
|
|
listbox.scrollToIndex(aStart);
|
|
|
|
synthesizeMouseScroll(listbox, 10, 10,
|
2008-09-17 04:27:19 -07:00
|
|
|
{axis:"horizontal", delta:aDelta, type:aKind.eventType,
|
|
|
|
hasPixels:aKind.hasPixels});
|
2008-07-24 21:07:43 -07:00
|
|
|
is(listbox.getIndexOfFirstVisibleRow(), aStart,
|
2008-09-17 04:27:19 -07:00
|
|
|
"mouse-scroll of '" + id + "' horizontal starting " + aStart + " delta " + aDelta
|
|
|
|
+ " eventType " + aKind.eventType + " hasPixels " + aKind.hasPixels);
|
2008-07-24 21:07:43 -07:00
|
|
|
}
|
2008-09-17 04:27:19 -07:00
|
|
|
kinds.forEach(function(aKind) {
|
|
|
|
helper(2, -1, aKind);
|
|
|
|
helper(2, 1, aKind);
|
|
|
|
helper(2, -2, aKind);
|
|
|
|
helper(2, 2, aKind);
|
|
|
|
});
|
2008-07-24 21:07:43 -07:00
|
|
|
}
|
|
|
|
|
2008-10-27 12:24:33 -07:00
|
|
|
function testRichListbox(id, andThen)
|
2008-07-24 21:07:43 -07:00
|
|
|
{
|
|
|
|
var listbox = document.getElementById(id);
|
2008-10-27 12:24:33 -07:00
|
|
|
var tests = [];
|
|
|
|
|
|
|
|
function helper()
|
2008-07-24 21:07:43 -07:00
|
|
|
{
|
2009-03-09 04:10:12 -07:00
|
|
|
var [aStart, aDelta, aKind] = tests[0];
|
2008-10-27 12:24:33 -07:00
|
|
|
tests.shift();
|
2008-07-24 21:07:43 -07:00
|
|
|
listbox.scrollToIndex(aStart);
|
|
|
|
synthesizeMouseScroll(listbox, 10, 10,
|
2008-09-17 04:27:19 -07:00
|
|
|
{axis:"vertical", delta:aDelta, type:aKind.eventType,
|
|
|
|
hasPixels:aKind.hasPixels});
|
2008-10-27 12:24:33 -07:00
|
|
|
setTimeout(function() {
|
2009-03-09 04:10:12 -07:00
|
|
|
var change = listbox.getIndexOfFirstVisibleRow() - aStart;
|
|
|
|
var direction = (change > 0) - (change < 0);
|
|
|
|
var expected = aKind.shouldScrollNative && (aDelta > 0) - (aDelta < 0);
|
|
|
|
is(direction, expected,
|
2008-10-27 12:24:33 -07:00
|
|
|
"mouse-scroll of '" + id + "' vertical starting " + aStart + " delta " + aDelta
|
|
|
|
+ " eventType " + aKind.eventType + " hasPixels " + aKind.hasPixels);
|
2009-03-09 04:10:12 -07:00
|
|
|
|
2008-10-27 12:24:33 -07:00
|
|
|
// Check that horizontal scrolling has no effect
|
|
|
|
listbox.scrollToIndex(aStart);
|
|
|
|
synthesizeMouseScroll(listbox, 10, 10,
|
|
|
|
{axis:"horizontal", delta:aDelta, type:aKind.eventType,
|
|
|
|
hasPixels:aKind.hasPixels});
|
|
|
|
setTimeout(function() {
|
|
|
|
is(listbox.getIndexOfFirstVisibleRow(), aStart,
|
|
|
|
"mouse-scroll of '" + id + "' horizontal starting " + aStart + " delta " + aDelta
|
|
|
|
+ " eventType " + aKind.eventType + " hasPixels " + aKind.hasPixels);
|
|
|
|
if (tests.length)
|
|
|
|
helper();
|
|
|
|
else
|
|
|
|
andThen();
|
|
|
|
}, 0);
|
|
|
|
}, 0);
|
2008-07-24 21:07:43 -07:00
|
|
|
}
|
2010-06-23 10:28:12 -07:00
|
|
|
|
2008-07-24 21:07:43 -07:00
|
|
|
// richlistbox currently uses native XUL scrolling, so the "line"
|
|
|
|
// amounts don't necessarily correspond 1-to-1 with listbox items. So
|
2009-03-09 04:10:12 -07:00
|
|
|
// we just check that scrolling up/down scrolls in the right direction.
|
2008-09-17 04:27:19 -07:00
|
|
|
kinds.forEach(function(aKind) {
|
2009-03-09 04:10:12 -07:00
|
|
|
tests.push([2, -100, aKind]);
|
|
|
|
tests.push([2, 100, aKind]);
|
2008-09-17 04:27:19 -07:00
|
|
|
});
|
2008-10-27 12:24:33 -07:00
|
|
|
helper();
|
2008-07-24 21:07:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function testArrowScrollbox(id)
|
|
|
|
{
|
|
|
|
var scrollbox = document.getElementById(id);
|
|
|
|
var scrollBoxObject = scrollbox.scrollBoxObject;
|
|
|
|
var orient = scrollbox.getAttribute("orient");
|
2010-06-23 10:28:12 -07:00
|
|
|
|
2008-09-17 04:27:19 -07:00
|
|
|
function helper(aStart, aDelta, aExpected, aKind)
|
2008-07-24 21:07:43 -07:00
|
|
|
{
|
|
|
|
var xpos = {};
|
|
|
|
var ypos = {};
|
|
|
|
var pos = orient == "horizontal" ? xpos : ypos;
|
|
|
|
|
|
|
|
scrollBoxObject.scrollTo(aStart, aStart);
|
2010-06-23 10:28:12 -07:00
|
|
|
for (var i = (orient == "horizontal") ? 2 : 0; i >= 0; i--) {
|
|
|
|
synthesizeMouseScroll(scrollbox, 5, 5,
|
|
|
|
{axis:"vertical", delta:aDelta, type:aKind.eventType,
|
|
|
|
hasPixels:aKind.hasPixels});
|
|
|
|
scrollBoxObject.getPosition(xpos, ypos);
|
|
|
|
// Note, vertical mouse scrolling is allowed to scroll horizontal
|
|
|
|
// arrowscrollboxes, because many users have no horizontal mouse scroll
|
|
|
|
// capability
|
|
|
|
var expected = (aKind.shouldScrollDOM && !i) ? aExpected : aStart;
|
|
|
|
is(pos.value, expected,
|
|
|
|
"mouse-scroll of '" + id + "' vertical starting " + aStart + " delta " + aDelta
|
|
|
|
+ " eventType " + aKind.eventType + " hasPixels " + aKind.hasPixels);
|
|
|
|
}
|
2008-07-24 21:07:43 -07:00
|
|
|
|
2010-06-23 10:28:12 -07:00
|
|
|
for (var i = (orient == "horizontal") ? 2 : 0; i >= 0; i--) {
|
|
|
|
scrollBoxObject.scrollTo(aStart, aStart);
|
|
|
|
synthesizeMouseScroll(scrollbox, 5, 5,
|
|
|
|
{axis:"horizontal", delta:aDelta, type:aKind.eventType,
|
|
|
|
hasPixels:aKind.hasPixels});
|
|
|
|
// horizontal mouse scrolling is never allowed to scroll vertical
|
|
|
|
// arrowscrollboxes
|
|
|
|
scrollBoxObject.getPosition(xpos, ypos);
|
|
|
|
var expected = (aKind.shouldScrollDOM && !i && (orient == "horizontal")) ? aExpected : aStart;
|
|
|
|
is(pos.value, expected,
|
|
|
|
"mouse-scroll of '" + id + "' horizontal starting " + aStart + " delta " + aDelta
|
|
|
|
+ " eventType " + aKind.eventType + " hasPixels " + aKind.hasPixels);
|
|
|
|
}
|
2008-07-24 21:07:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
var scrolledWidth = {};
|
|
|
|
var scrolledHeight = {};
|
|
|
|
scrollBoxObject.getScrolledSize(scrolledWidth, scrolledHeight);
|
|
|
|
var scrollMaxX = scrolledWidth.value - scrollBoxObject.width;
|
|
|
|
var scrollMaxY = scrolledHeight.value - scrollBoxObject.height;
|
|
|
|
var scrollMax = orient == "horizontal" ? scrollMaxX : scrollMaxY;
|
|
|
|
|
2008-09-17 04:27:19 -07:00
|
|
|
kinds.forEach(function(aKind) {
|
|
|
|
helper(50, -100, 0, aKind);
|
|
|
|
helper(50, 100, scrollMax, aKind);
|
|
|
|
});
|
2008-07-24 21:07:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function runTests()
|
|
|
|
{
|
2008-10-27 12:24:33 -07:00
|
|
|
testRichListbox("richlistbox", function() {
|
|
|
|
testListbox("listbox");
|
|
|
|
testArrowScrollbox("hscrollbox");
|
|
|
|
testArrowScrollbox("vscrollbox");
|
|
|
|
SimpleTest.finish();
|
|
|
|
});
|
2008-07-24 21:07:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
window.onload = function() { setTimeout(runTests, 0); };
|
|
|
|
]]></script>
|
|
|
|
</window>
|