2008-04-23 06:22:25 -07:00
|
|
|
<!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" />
|
|
|
|
|
2009-02-05 01:06:40 -08:00
|
|
|
<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"
|
2010-09-01 15:09:56 -07:00
|
|
|
src="common.js"></script>
|
2009-02-05 01:06:40 -08:00
|
|
|
<script type="application/javascript"
|
2010-09-01 15:09:56 -07:00
|
|
|
src="role.js"></script>
|
2009-02-05 01:06:40 -08:00
|
|
|
<script type="application/javascript"
|
2010-09-01 15:09:56 -07:00
|
|
|
src="attributes.js"></script>
|
2008-04-23 06:22:25 -07:00
|
|
|
|
|
|
|
<script type="application/javascript">
|
2008-07-07 22:42:11 -07:00
|
|
|
function testCoordinates(aID, aAcc, aWidth, aHeight)
|
2008-04-23 06:22:25 -07:00
|
|
|
{
|
2008-07-07 22:42:11 -07:00
|
|
|
var screenX = {}, screenY = {}, windowX = {}, windowY = {}, parentX = {},
|
|
|
|
parentY = {};
|
2008-04-23 06:22:25 -07:00
|
|
|
|
2008-07-07 22:42:11 -07:00
|
|
|
// get screen coordinates.
|
2009-02-05 01:06:40 -08:00
|
|
|
aAcc.getImagePosition(
|
2008-07-07 22:42:11 -07:00
|
|
|
nsIAccessibleCoordinateType.COORDTYPE_SCREEN_RELATIVE,
|
|
|
|
screenX, screenY);
|
|
|
|
// get window coordinates.
|
2009-02-05 01:06:40 -08:00
|
|
|
aAcc.getImagePosition(
|
2008-07-07 22:42:11 -07:00
|
|
|
nsIAccessibleCoordinateType.COORDTYPE_WINDOW_RELATIVE,
|
|
|
|
windowX, windowY);
|
|
|
|
// get parent related coordinates.
|
2009-02-05 01:06:40 -08:00
|
|
|
aAcc.getImagePosition(
|
2008-07-07 22:42:11 -07:00
|
|
|
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.
|
2009-02-05 01:06:40 -08:00
|
|
|
if (parentY.value < 0)
|
2008-07-07 22:42:11 -07:00
|
|
|
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 {
|
2009-02-05 01:06:40 -08:00
|
|
|
tempAcc = aAcc.getChildAtPoint(screenX.value, screenY.value);
|
2008-07-07 22:42:11 -07:00
|
|
|
} catch(e) {}
|
2009-02-05 01:06:40 -08:00
|
|
|
is(tempAcc, aAcc,
|
2008-07-07 22:42:11 -07:00
|
|
|
"Wrong accessible returned for position of " + aID + "!");
|
|
|
|
|
|
|
|
// get image's parent.
|
|
|
|
var imageParentAcc = null;
|
|
|
|
try {
|
2009-02-05 01:06:40 -08:00
|
|
|
imageParentAcc = aAcc.parent;
|
2008-07-07 22:42:11 -07:00
|
|
|
} 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 + "!");
|
2008-09-22 05:07:08 -07:00
|
|
|
// XXX see bug 456344 is(parentAccY.value + parentY.value, screenY.value,
|
|
|
|
// "Wrong screen y coordinate for " + aID + "!");
|
2008-07-07 22:42:11 -07:00
|
|
|
}
|
2008-04-23 06:22:25 -07:00
|
|
|
|
|
|
|
var width = {}, height = {};
|
2009-02-05 01:06:40 -08:00
|
|
|
aAcc.getImageSize(width, height);
|
2008-04-23 06:22:25 -07:00
|
|
|
is(width.value, aWidth, "Wrong width for " + aID + "!");
|
|
|
|
is(height.value, aHeight, "wrong height for " + aID + "!");
|
|
|
|
}
|
|
|
|
|
2008-08-26 00:39:17 -07:00
|
|
|
function testThis(aID, aName, aSRC, aWidth, aHeight,
|
|
|
|
aNumActions, aActionNames)
|
2008-04-23 06:22:25 -07:00
|
|
|
{
|
2009-02-05 01:06:40 -08:00
|
|
|
var acc = getAccessible(aID, [nsIAccessibleImage]);
|
2008-07-07 22:42:11 -07:00
|
|
|
if (!acc)
|
|
|
|
return;
|
|
|
|
|
2008-04-23 06:22:25 -07:00
|
|
|
is(acc.name, aName, "wrong name for " + aID + "!");
|
|
|
|
|
2009-02-05 01:06:40 -08:00
|
|
|
// Test role
|
|
|
|
testRole(aID, ROLE_GRAPHIC);
|
|
|
|
|
2008-04-23 06:22:25 -07:00
|
|
|
// test coordinates and size
|
2008-07-07 22:42:11 -07:00
|
|
|
testCoordinates(aID, acc, aWidth, aHeight);
|
2008-04-23 06:22:25 -07:00
|
|
|
|
|
|
|
// bug 429659: Make sure the SRC attribute is set for any image
|
2009-02-05 01:06:40 -08:00
|
|
|
var attributes = {"src": aSRC};
|
|
|
|
testAttrs(acc, attributes, true);
|
2008-08-26 00:39:17 -07:00
|
|
|
|
|
|
|
if (aNumActions) {
|
|
|
|
is(acc.numActions, aNumActions,
|
|
|
|
"Wrong number of actions for " + aID + "!");
|
|
|
|
|
2009-02-05 01:06:40 -08:00
|
|
|
for (index = 0; index < aActionNames.length; index++)
|
2008-08-26 00:39:17 -07:00
|
|
|
is(acc.getActionName(index), aActionNames[index],
|
|
|
|
"Wrong action name for " + aID + ", index " + index +"!");
|
|
|
|
}
|
2008-04-23 06:22:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function doTest()
|
|
|
|
{
|
|
|
|
// Test non-linked image
|
2008-07-07 22:42:11 -07:00
|
|
|
testThis("nonLinkedImage", null, "moz.png", 89, 38);
|
2008-04-23 06:22:25 -07:00
|
|
|
|
|
|
|
// Test linked image
|
2010-02-01 23:43:18 -08:00
|
|
|
testThis("linkedImage", null, "moz.png", 89, 38);
|
2008-04-23 06:22:25 -07:00
|
|
|
|
|
|
|
// Test non-linked image with alt attribute
|
2008-07-07 22:42:11 -07:00
|
|
|
testThis("nonLinkedImageWithAlt", "MoFo", "moz.png", 89, 38);
|
2008-04-23 06:22:25 -07:00
|
|
|
|
|
|
|
// Test linked image with alt attribute
|
2010-02-01 23:43:18 -08:00
|
|
|
testThis("linkedImageWithAlt", "MoFo link", "moz.png", 89, 38);
|
2008-04-23 06:22:25 -07:00
|
|
|
|
|
|
|
// Test non-linked image with title attribute
|
2008-07-07 22:42:11 -07:00
|
|
|
testThis("nonLinkedImageWithTitle", "MoFo logo", "moz.png", 89, 38);
|
2008-04-23 06:22:25 -07:00
|
|
|
|
|
|
|
// Test linked image with title attribute
|
2010-02-01 23:43:18 -08:00
|
|
|
testThis("linkedImageWithTitle", "Link to MoFo", "moz.png", 89, 38);
|
2008-04-23 06:22:25 -07:00
|
|
|
|
2008-04-24 23:21:09 -07:00
|
|
|
// Test simple image with empty alt attribute
|
2008-12-16 08:13:49 -08:00
|
|
|
testThis("nonLinkedImageEmptyAlt", "", "moz.png", 89, 38);
|
2008-04-24 23:21:09 -07:00
|
|
|
|
|
|
|
// Test linked image with empty alt attribute
|
2010-02-01 23:43:18 -08:00
|
|
|
testThis("linkedImageEmptyAlt", "", "moz.png", 89, 38);
|
2008-04-24 23:21:09 -07:00
|
|
|
|
|
|
|
// Test simple image with empty alt attribute and title
|
2008-07-07 22:42:11 -07:00
|
|
|
testThis("nonLinkedImageEmptyAltAndTitle", "MozillaFoundation", "moz.png", 89, 38);
|
2008-04-24 23:21:09 -07:00
|
|
|
|
|
|
|
// Test linked image with empty alt attribute and title
|
2010-02-01 23:43:18 -08:00
|
|
|
testThis("linkedImageEmptyAltAndTitle", "Link to Mozilla Foundation", "moz.png", 89, 38);
|
2008-04-24 23:21:09 -07:00
|
|
|
|
2008-08-26 00:39:17 -07:00
|
|
|
// 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);
|
|
|
|
|
2008-04-23 06:22:25 -07:00
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
2009-09-23 07:21:47 -07:00
|
|
|
addA11yLoadEvent(doTest);
|
2008-04-23 06:22:25 -07:00
|
|
|
</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>
|
2008-04-24 23:21:09 -07:00
|
|
|
<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>
|
2008-08-26 00:39:17 -07:00
|
|
|
<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!');"/>
|
2008-04-23 06:22:25 -07:00
|
|
|
</body>
|
|
|
|
</html>
|