forked from rnewman/services-central-old
/
test_nsIAccessibleImage.html
223 lines (188 loc) · 8.37 KB
/
test_nsIAccessibleImage.html
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<!DOCTYPE html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=429659
-->
<head>
<title>nsIAccessibleImage chrome tests</title>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
<script type="application/javascript" src="chrome://mochikit/content/MochiKit/packed.js"></script>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript">
const nsIAccessibleImage = Components.interfaces.nsIAccessibleImage;
const nsIAccessibleCoordinateType =
Components.interfaces.nsIAccessibleCoordinateType;
var gAccRetrieval;
function testCoordinates(aID, aAcc, aWidth, aHeight)
{
var screenX = {}, screenY = {}, windowX = {}, windowY = {}, parentX = {},
parentY = {};
var imageAcc = null;
try {
imageAcc = aAcc.QueryInterface(nsIAccessibleImage);
} catch(e) {}
ok(imageAcc, "no image interface for " + aID + "!");
if (!imageAcc)
return;
// get screen coordinates.
imageAcc.getImagePosition(
nsIAccessibleCoordinateType.COORDTYPE_SCREEN_RELATIVE,
screenX, screenY);
// get window coordinates.
imageAcc.getImagePosition(
nsIAccessibleCoordinateType.COORDTYPE_WINDOW_RELATIVE,
windowX, windowY);
// get parent related coordinates.
imageAcc.getImagePosition(
nsIAccessibleCoordinateType.COORDTYPE_PARENT_RELATIVE,
parentX, parentY);
// XXX For linked images, a negative parentY value is returned, and the
// screenY coordinate is the link's screenY coordinate minus 1.
// Until this is fixed, set parentY to -1 if it's negative.
if (parentY.value < 0) {
parentY.value = -1;
}
// See if asking image for child at image's screen coordinates gives
// correct accessible. getChildAtPoint operates on screen coordinates.
var tempAcc = null;
try {
tempAcc = imageAcc.getChildAtPoint(screenX.value, screenY.value);
} catch(e) {}
is(tempAcc, imageAcc,
"Wrong accessible returned for position of " + aID + "!");
// get image's parent.
var imageParentAcc = null;
try {
imageParentAcc = imageAcc.parent;
} catch(e) {}
ok(imageParentAcc, "no parent accessible for " + aID + "!");
if (imageParentAcc) {
// See if parent's screen coordinates plus image's parent relative
// coordinates equal to image's screen coordinates.
var parentAccX = {}, parentAccY = {}, parentAccWidth = {},
parentAccHeight = {};
imageParentAcc.getBounds(parentAccX, parentAccY, parentAccWidth,
parentAccHeight);
is(parentAccX.value + parentX.value, screenX.value,
"Wrong screen x coordinate for " + aID + "!");
// XXX see bug 456344 is(parentAccY.value + parentY.value, screenY.value,
// "Wrong screen y coordinate for " + aID + "!");
}
var width = {}, height = {};
imageAcc.getImageSize(width, height);
is(width.value, aWidth, "Wrong width for " + aID + "!");
is(height.value, aHeight, "wrong height for " + aID + "!");
}
function testThis(aID, aName, aSRC, aWidth, aHeight,
aNumActions, aActionNames)
{
var elem = document.getElementById(aID);
var acc;
try {
acc = gAccRetrieval.getAccessibleFor(elem);
} catch(e) {}
ok(acc, "No accessible for " + aID + "!");
if (!acc)
return;
is(acc.name, aName, "wrong name for " + aID + "!");
// test coordinates and size
testCoordinates(aID, acc, aWidth, aHeight);
// bug 429659: Make sure the SRC attribute is set for any image
var attributes;
try {
attributes = acc.attributes;
} catch(e) {}
ok(attributes, "no attributes on " + aID + "!");
is(attributes.getStringProperty("src"), aSRC,
"no correct src attribute for " + aID + "!");
if (aNumActions) {
is(acc.numActions, aNumActions,
"Wrong number of actions for " + aID + "!");
for (index = 0; index < aActionNames.length; index++) {
is(acc.getActionName(index), aActionNames[index],
"Wrong action name for " + aID + ", index " + index +"!");
}
}
}
function doTest()
{
gAccRetrieval = Components.classes["@mozilla.org/accessibleRetrieval;1"].
getService(Components.interfaces.nsIAccessibleRetrieval);
// Test non-linked image
testThis("nonLinkedImage", null, "moz.png", 89, 38);
// Test linked image
testThis("linkedImage", null, "moz.png", 93, 42);
// Test non-linked image with alt attribute
testThis("nonLinkedImageWithAlt", "MoFo", "moz.png", 89, 38);
// Test linked image with alt attribute
testThis("linkedImageWithAlt", "MoFo link", "moz.png", 93, 42);
// Test non-linked image with title attribute
testThis("nonLinkedImageWithTitle", "MoFo logo", "moz.png", 89, 38);
// Test linked image with title attribute
testThis("linkedImageWithTitle", "Link to MoFo", "moz.png", 93, 42);
// Test simple image with empty alt attribute
testThis("nonLinkedImageEmptyAlt", "", "moz.png", 89, 38);
// Test linked image with empty alt attribute
testThis("linkedImageEmptyAlt", "", "moz.png", 93, 42);
// Test simple image with empty alt attribute and title
testThis("nonLinkedImageEmptyAltAndTitle", "MozillaFoundation", "moz.png", 89, 38);
// Test linked image with empty alt attribute and title
testThis("linkedImageEmptyAltAndTitle", "Link to Mozilla Foundation", "moz.png", 93, 42);
// Image with long desc
var actionNamesArray = new Array("showlongdesc");
testThis("longdesc", "Image of Mozilla logo", "moz.png", 89, 38, 1,
actionNamesArray);
// Image with click and long desc
actionNamesArray = null;
actionNamesArray = new Array("click", "showlongdesc");
testThis("clickAndLongdesc", "Another image of Mozilla logo", "moz.png",
89, 38, 2, actionNamesArray);
// Image with click
actionNamesArray = null;
actionNamesArray = new Array("click");
testThis("click", "A third image of Mozilla logo", "moz.png",
89, 38, 1, actionNamesArray);
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(doTest);
</script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=429659">Mozilla Bug 429659</a>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test">
</pre>
<br>Simple image:<br>
<img id="nonLinkedImage" src="moz.png"/>
<br>Linked image:<br>
<a href="http://www.mozilla.org"><img id="linkedImage" src="moz.png"></a>
<br>Simple image with alt:<br>
<img id="nonLinkedImageWithAlt" src="moz.png" alt="MoFo"/>
<br>Linked image with alt:<br>
<a href="http://www.mozilla.org"><img id="linkedImageWithAlt" src="moz.png" alt="MoFo link"/></a>
<br>Simple image with title:<br>
<img id="nonLinkedImageWithTitle" src="moz.png" title="MoFo logo"/>
<br>Linked image with title:<br>
<a href="http://www.mozilla.org"><img id="linkedImageWithTitle" src="moz.png" title="Link to MoFo"/></a>
<br>Simple image with empty alt:<br>
<img id="nonLinkedImageEmptyAlt" src="moz.png" alt=""/>
<br>Linked image with empty alt:<br>
<a href="http://www.mozilla.org"><img id="linkedImageEmptyAlt" src="moz.png" alt=""/></a>
<br>Simple image with empty alt and title:<br>
<img id="nonLinkedImageEmptyAltAndTitle" src="moz.png" alt="" title="MozillaFoundation"/>
<br>Linked image with empty alt and title:<br>
<a href="http://www.mozilla.org"><img id="linkedImageEmptyAltAndTitle" src="moz.png" alt=""
title="Link to Mozilla Foundation"/></a>
<br>Image with longdesc:<br>
<img id="longdesc" src="moz.png" longdesc="longdesc_src.html"
alt="Image of Mozilla logo"/>
<br>Image with click and longdesc:<br>
<img id="clickAndLongdesc" src="moz.png" longdesc="longdesc_src.html"
alt="Another image of Mozilla logo" onclick="alert('Clicked!');"/>
<br>Image with click:<br>
<img id="click" src="moz.png"
alt="A third image of Mozilla logo" onclick="alert('Clicked, too!');"/>
</body>
</html>