1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/tests/mochitest/test_nsIAccessibleImage.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,179 @@ 1.4 +<!DOCTYPE html> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=429659 1.8 +--> 1.9 +<head> 1.10 + <title>nsIAccessibleImage chrome tests</title> 1.11 + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" /> 1.12 + 1.13 + <script type="application/javascript" 1.14 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.15 + 1.16 + <script type="application/javascript" 1.17 + src="common.js"></script> 1.18 + <script type="application/javascript" 1.19 + src="role.js"></script> 1.20 + <script type="application/javascript" 1.21 + src="attributes.js"></script> 1.22 + 1.23 + <script type="application/javascript"> 1.24 + function testCoordinates(aID, aAcc, aWidth, aHeight) 1.25 + { 1.26 + var screenX = {}, screenY = {}, windowX = {}, windowY = {}, parentX = {}, 1.27 + parentY = {}; 1.28 + 1.29 + // get screen coordinates. 1.30 + aAcc.getImagePosition( 1.31 + nsIAccessibleCoordinateType.COORDTYPE_SCREEN_RELATIVE, 1.32 + screenX, screenY); 1.33 + // get window coordinates. 1.34 + aAcc.getImagePosition( 1.35 + nsIAccessibleCoordinateType.COORDTYPE_WINDOW_RELATIVE, 1.36 + windowX, windowY); 1.37 + // get parent related coordinates. 1.38 + aAcc.getImagePosition( 1.39 + nsIAccessibleCoordinateType.COORDTYPE_PARENT_RELATIVE, 1.40 + parentX, parentY); 1.41 + // XXX For linked images, a negative parentY value is returned, and the 1.42 + // screenY coordinate is the link's screenY coordinate minus 1. 1.43 + // Until this is fixed, set parentY to -1 if it's negative. 1.44 + if (parentY.value < 0) 1.45 + parentY.value = -1; 1.46 + 1.47 + // See if asking image for child at image's screen coordinates gives 1.48 + // correct accessible. getChildAtPoint operates on screen coordinates. 1.49 + var tempAcc = null; 1.50 + try { 1.51 + tempAcc = aAcc.getChildAtPoint(screenX.value, screenY.value); 1.52 + } catch(e) {} 1.53 + is(tempAcc, aAcc, 1.54 + "Wrong accessible returned for position of " + aID + "!"); 1.55 + 1.56 + // get image's parent. 1.57 + var imageParentAcc = null; 1.58 + try { 1.59 + imageParentAcc = aAcc.parent; 1.60 + } catch(e) {} 1.61 + ok(imageParentAcc, "no parent accessible for " + aID + "!"); 1.62 + 1.63 + if (imageParentAcc) { 1.64 + // See if parent's screen coordinates plus image's parent relative 1.65 + // coordinates equal to image's screen coordinates. 1.66 + var parentAccX = {}, parentAccY = {}, parentAccWidth = {}, 1.67 + parentAccHeight = {}; 1.68 + imageParentAcc.getBounds(parentAccX, parentAccY, parentAccWidth, 1.69 + parentAccHeight); 1.70 + is(parentAccX.value + parentX.value, screenX.value, 1.71 + "Wrong screen x coordinate for " + aID + "!"); 1.72 +// XXX see bug 456344 is(parentAccY.value + parentY.value, screenY.value, 1.73 +// "Wrong screen y coordinate for " + aID + "!"); 1.74 + } 1.75 + 1.76 + var width = {}, height = {}; 1.77 + aAcc.getImageSize(width, height); 1.78 + is(width.value, aWidth, "Wrong width for " + aID + "!"); 1.79 + is(height.value, aHeight, "wrong height for " + aID + "!"); 1.80 + } 1.81 + 1.82 + function testThis(aID, aSRC, aWidth, aHeight, 1.83 + aActionCount, aActionNames) 1.84 + { 1.85 + var acc = getAccessible(aID, [nsIAccessibleImage]); 1.86 + if (!acc) 1.87 + return; 1.88 + 1.89 + // Test role 1.90 + testRole(aID, ROLE_GRAPHIC); 1.91 + 1.92 + // test coordinates and size 1.93 + testCoordinates(aID, acc, aWidth, aHeight); 1.94 + 1.95 + // bug 429659: Make sure the SRC attribute is set for any image 1.96 + var attributes = {"src": aSRC}; 1.97 + testAttrs(acc, attributes, true); 1.98 + 1.99 + if (aActionCount) { 1.100 + is(acc.actionCount, aActionCount, 1.101 + "Wrong number of actions for " + aID + "!"); 1.102 + 1.103 + for (index = 0; index < aActionNames.length; index++) 1.104 + is(acc.getActionName(index), aActionNames[index], 1.105 + "Wrong action name for " + aID + ", index " + index +"!"); 1.106 + } 1.107 + } 1.108 + 1.109 + function doTest() 1.110 + { 1.111 + // Test non-linked image 1.112 + testThis("nonLinkedImage", "moz.png", 89, 38); 1.113 + 1.114 + // Test linked image 1.115 + testThis("linkedImage", "moz.png", 89, 38); 1.116 + 1.117 + // Image with long desc 1.118 + var actionNamesArray = new Array("showlongdesc"); 1.119 + testThis("longdesc", "moz.png", 89, 38, 1, 1.120 + actionNamesArray); 1.121 + 1.122 + // Image with click and long desc 1.123 + actionNamesArray = null; 1.124 + actionNamesArray = new Array("click", "showlongdesc"); 1.125 + testThis("clickAndLongdesc", "moz.png", 1.126 + 89, 38, 2, actionNamesArray); 1.127 + 1.128 + // Image with click 1.129 + actionNamesArray = null; 1.130 + actionNamesArray = new Array("click"); 1.131 + testThis("click", "moz.png", 1.132 + 89, 38, 1, actionNamesArray); 1.133 + 1.134 + // Image with long desc 1.135 + actionNamesArray = null; 1.136 + actionNamesArray = new Array("showlongdesc"); 1.137 + testThis("longdesc2", "moz.png", 1.138 + 89, 38, 1, actionNamesArray); 1.139 + 1.140 + SimpleTest.finish(); 1.141 + } 1.142 + 1.143 + SimpleTest.waitForExplicitFinish(); 1.144 + addA11yLoadEvent(doTest); 1.145 + </script> 1.146 +</head> 1.147 +<body> 1.148 + 1.149 + <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=429659">Mozilla Bug 429659</a> 1.150 + <a target="_blank" 1.151 + href="https://bugzilla.mozilla.org/show_bug.cgi?id=652635" 1.152 + title="fall back missing @longdesc to aria-describedby pointing to a href"> 1.153 + Mozilla Bug 652635 1.154 + </a> 1.155 + 1.156 + <p id="display"></p> 1.157 + <div id="content" style="display: none"></div> 1.158 + <pre id="test"> 1.159 + </pre> 1.160 + 1.161 + <br>Simple image:<br> 1.162 + <img id="nonLinkedImage" src="moz.png"/> 1.163 + <br>Linked image:<br> 1.164 + <a href="http://www.mozilla.org"><img id="linkedImage" src="moz.png"></a> 1.165 + <br>Image with longdesc:<br> 1.166 + <img id="longdesc" src="moz.png" longdesc="longdesc_src.html" 1.167 + alt="Image of Mozilla logo"/> 1.168 + <br>Image with click and longdesc:<br> 1.169 + <img id="clickAndLongdesc" src="moz.png" longdesc="longdesc_src.html" 1.170 + alt="Another image of Mozilla logo" onclick="alert('Clicked!');"/> 1.171 + 1.172 + <br>image described by a link to be treated as longdesc<br> 1.173 + <img id="longdesc2" src="moz.png" aria-describedby="describing_link" 1.174 + alt="Second Image of Mozilla logo"/> 1.175 + <a id="describing_link" href="longdesc_src.html">link to description of image</a> 1.176 + 1.177 + <br>Image with click:<br> 1.178 + <img id="click" src="moz.png" 1.179 + alt="A third image of Mozilla logo" onclick="alert('Clicked, too!');"/> 1.180 + 1.181 +</body> 1.182 +</html>