1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<!--
XUL Widget Test for scrollbars
-->
<window title="Scrollbar"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml"/>
<hbox>
<scrollbar orient="horizontal"
id="scroller"
curpos="0"
maxpos="600"
pageincrement="400"
width="500"
style="margin:0"/>
</hbox>
<!-- test code goes here -->
<script type="application/javascript"><![CDATA[
/** Test for Scrollbar **/
var scrollbarTester = {
scrollbar: null,
middlePref: false,
startTest: function() {
this.scrollbar = $("scroller");
this.middlePref = this.getMiddlePref();
var self = this;
[0, 1, 2].map(function(button) {
[false, true].map(function(alt) {
[false, true].map(function(shift) {
self.testThumbDragging(button, alt, shift);
})
})
});
SimpleTest.finish();
},
testThumbDragging: function(button, withAlt, withShift) {
this.reset();
var x = 160; // on the right half of the thumb
var y = 5;
var isMac = navigator.platform.indexOf("Mac") != -1;
var runtime = Components.classes["@mozilla.org/xre/app-info;1"]
.getService(Components.interfaces.nsIXULRuntime);
var isGtk = runtime.widgetToolkit.indexOf("gtk") != -1;
// Start the drag.
this.mousedown(x, y, button, withAlt, withShift);
var newPos = this.getPos();
var scrollToClick = (newPos != 0);
if (isMac || isGtk) {
ok(!scrollToClick, "On Linux and Mac OS X, clicking the scrollbar thumb "+
"should never move it.");
} else if (button == 0 && withShift) {
ok(scrollToClick, "On platforms other than Linux and Mac OS X, holding "+
"shift should enable scroll-to-click on the scrollbar thumb.");
} else if (button == 1 && this.middlePref) {
ok(scrollToClick, "When middlemouse.scrollbarPosition is on, clicking the "+
"thumb with the middle mouse button should center it "+
"around the cursor.")
}
// Move one pixel to the right.
this.mousemove(x+1, y, button, withAlt, withShift);
var newPos2 = this.getPos();
if (newPos2 != newPos) {
ok(newPos2 > newPos, "Scrollbar thumb should follow the mouse when dragged.");
ok(newPos2 - newPos < 3, "Scrollbar shouldn't move further than the mouse when dragged.");
ok(button == 0 || (button == 1 && this.middlePref) || (button == 2 && isGtk),
"Dragging the scrollbar should only be possible with the left mouse button.");
} else {
// Dragging had no effect.
if (button == 0) {
ok(false, "Dragging the scrollbar thumb should work.");
} else if (button == 1 && this.middlePref && (!isGtk && !isMac)) {
ok(false, "When middlemouse.scrollbarPosition is on, dragging the "+
"scrollbar thumb should be possible using the middle mouse button.");
} else {
ok(true, "Dragging works correctly.");
}
}
// Release the mouse button.
this.mouseup(x+1, y, button, withAlt, withShift);
var newPos3 = this.getPos();
ok(newPos3 == newPos2,
"Releasing the mouse button after dragging the thumb shouldn't move it.");
},
getMiddlePref: function() {
// It would be better to test with different middlePref settings,
// but the setting is only queried once, at browser startup, so
// changing it here wouldn't have any effect
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService);
var mouseBranch = prefService.getBranch("middlemouse.");
return mouseBranch.getBoolPref("scrollbarPosition");
},
setPos: function(pos) {
this.scrollbar.setAttribute("curpos", pos);
},
getPos: function() {
return this.scrollbar.getAttribute("curpos");
},
reset: function() {
this.setPos(0);
},
mousedown: function(x, y, button, alt, shift) {
synthesizeMouse(this.scrollbar, x, y, { type: "mousedown", 'button': button,
altKey: alt, shiftKey: shift });
},
mousemove: function(x, y, button, alt, shift) {
synthesizeMouse(this.scrollbar, x, y, { type: "mousemove", 'button': button,
altKey: alt, shiftKey: shift });
},
mouseup: function(x, y, button, alt, shift) {
synthesizeMouse(this.scrollbar, x, y, { type: "mouseup", 'button': button,
altKey: alt, shiftKey: shift });
}
}
function doTest() {
setTimeout(function() { scrollbarTester.startTest(); }, 0);
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(doTest);
]]></script>
</window>
|