4 https://bugzilla.mozilla.org/show_bug.cgi?id=429659
7 <title>nsIAccessibleImage chrome tests
</title>
8 <link rel=
"stylesheet" type=
"text/css" href=
"chrome://mochikit/content/tests/SimpleTest/test.css" />
10 <script src=
"chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
12 <script type=
"application/javascript"
13 src=
"common.js"></script>
14 <script type=
"application/javascript"
15 src=
"role.js"></script>
16 <script type=
"application/javascript"
17 src=
"attributes.js"></script>
18 <script type=
"application/javascript"
19 src=
"layout.js"></script>
21 <script type=
"application/javascript">
22 function testCoordinates(aID, aAcc, aWidth, aHeight) {
23 var screenX = {}, screenY = {}, windowX = {}, windowY = {}, parentX = {},
26 // get screen coordinates.
27 aAcc.getImagePosition(
28 nsIAccessibleCoordinateType.COORDTYPE_SCREEN_RELATIVE,
30 // get window coordinates.
31 aAcc.getImagePosition(
32 nsIAccessibleCoordinateType.COORDTYPE_WINDOW_RELATIVE,
34 // get parent related coordinates.
35 aAcc.getImagePosition(
36 nsIAccessibleCoordinateType.COORDTYPE_PARENT_RELATIVE,
38 // XXX For linked images, a negative parentY value is returned, and the
39 // screenY coordinate is the link's screenY coordinate minus
1.
40 // Until this is fixed, set parentY to -
1 if it's negative.
41 if (parentY.value <
0)
44 // See if asking image for child at image's screen coordinates gives
45 // correct accessible. getChildAtPoint operates on screen coordinates.
48 tempAcc = aAcc.getChildAtPoint(screenX.value, screenY.value);
51 "Wrong accessible returned for position of " + aID +
"!");
53 // get image's parent.
54 var imageParentAcc = null;
56 imageParentAcc = aAcc.parent;
58 ok(imageParentAcc,
"no parent accessible for " + aID +
"!");
61 // See if parent's screen coordinates plus image's parent relative
62 // coordinates equal to image's screen coordinates.
63 var parentAccX = {}, parentAccY = {}, parentAccWidth = {},
65 imageParentAcc.getBounds(parentAccX, parentAccY, parentAccWidth,
67 is(parentAccX.value + parentX.value, screenX.value,
68 "Wrong screen x coordinate for " + aID +
"!");
69 // XXX see bug
456344 is(parentAccY.value + parentY.value, screenY.value,
70 //
"Wrong screen y coordinate for " + aID +
"!");
73 var [expected_w, expected_h] = CSSToDevicePixels(window, aWidth, aHeight);
74 var width = {}, height = {};
75 aAcc.getImageSize(width, height);
76 is(width.value, expected_w,
"Wrong width for " + aID +
"!");
77 is(height.value, expected_h,
"wrong height for " + aID +
"!");
80 function testThis(aID, aSRC, aWidth, aHeight,
81 aActionCount, aActionNames) {
82 var acc = getAccessible(aID, [nsIAccessibleImage]);
87 testRole(aID, ROLE_GRAPHIC);
89 // test coordinates and size
90 testCoordinates(aID, acc, aWidth, aHeight);
92 // bug
429659: Make sure the SRC attribute is set for any image
93 var attributes = {
"src": aSRC};
94 testAttrs(acc, attributes, true);
96 var actionCount = aActionCount ||
0;
97 is(acc.actionCount, actionCount,
98 "Wrong number of actions for " + aID +
"!");
100 for (let index =
0; index < aActionNames.length; index++) {
101 is(acc.getActionName(index), aActionNames[index],
102 "Wrong action name for " + aID +
", index " + index +
"!");
108 // Test non-linked image
109 testThis(
"nonLinkedImage",
"moz.png",
89,
38);
112 var actionNamesArray = [
"click ancestor"];
113 testThis(
"linkedImage",
"moz.png",
89,
38,
1,
116 // Image with long desc
117 actionNamesArray = [
"showlongdesc"];
118 testThis(
"longdesc",
"moz.png",
89,
38,
1,
121 // Image with invalid url in long desc
122 testThis(
"invalidLongdesc",
"moz.png",
89,
38,
0);
124 // Image with click and long desc
125 actionNamesArray = null;
126 actionNamesArray = [
"click",
"showlongdesc"];
127 testThis(
"clickAndLongdesc",
"moz.png",
128 89,
38,
2, actionNamesArray);
131 actionNamesArray = null;
132 actionNamesArray = [
"click"];
133 testThis(
"click",
"moz.png",
134 89,
38,
1, actionNamesArray);
136 // Image with long desc
137 actionNamesArray = null;
138 actionNamesArray = [
"showlongdesc"];
139 testThis(
"longdesc2",
"moz.png",
140 89,
38,
1, actionNamesArray);
142 // Image described by HTML:a@href with whitespaces
143 actionNamesArray = null;
144 actionNamesArray = [
"showlongdesc"];
145 testThis(
"longdesc3",
"moz.png",
146 89,
38,
1, actionNamesArray);
151 SimpleTest.waitForExplicitFinish();
152 addA11yLoadEvent(doTest);
157 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=429659">Mozilla Bug
429659</a>
159 href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=652635"
160 title=
"fall back missing @longdesc to aria-describedby pointing to a href">
165 <div id=
"content" style=
"display: none"></div>
169 <br>Simple image:
<br>
170 <img id=
"nonLinkedImage" src=
"moz.png"/>
171 <br>Linked image:
<br>
172 <a href=
"http://www.mozilla.org"><img id=
"linkedImage" src=
"moz.png"></a>
173 <br>Image with longdesc:
<br>
174 <img id=
"longdesc" src=
"moz.png" longdesc=
"longdesc_src.html"
175 alt=
"Image of Mozilla logo"/>
176 <br>Image with invalid url in longdesc:
<br>
177 <img id=
"invalidLongdesc" src=
"moz.png" longdesc=
"longdesc src.html"
178 alt=
"Image of Mozilla logo"/>
179 <br>Image with click and longdesc:
<br>
180 <img id=
"clickAndLongdesc" src=
"moz.png" longdesc=
"longdesc_src.html"
181 alt=
"Another image of Mozilla logo" onclick=
"alert('Clicked!');"/>
183 <br>image described by a link to be treated as longdesc
<br>
184 <img id=
"longdesc2" src=
"moz.png" aria-describedby=
"describing_link"
185 alt=
"Second Image of Mozilla logo"/>
186 <a id=
"describing_link" href=
"longdesc_src.html">link to description of image
</a>
188 <br>Image described by a link to be treated as longdesc with whitespaces
<br>
189 <img id=
"longdesc3" src=
"moz.png" aria-describedby=
"describing_link2"
190 alt=
"Second Image of Mozilla logo"/>
191 <a id=
"describing_link2" href=
"longdesc src.html">link to description of image
</a>
193 <br>Image with click:
<br>
194 <img id=
"click" src=
"moz.png"
195 alt=
"A third image of Mozilla logo" onclick=
"alert('Clicked, too!');"/>