test_nsIAccessibleImage.html (7214B)
1 <!DOCTYPE html> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=429659 5 --> 6 <head> 7 <title>nsIAccessibleImage chrome tests</title> 8 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" /> 9 10 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 11 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> 20 21 <script type="application/javascript"> 22 function testCoordinates(aID, aAcc, aWidth, aHeight) { 23 var screenX = {}, screenY = {}, windowX = {}, windowY = {}, parentX = {}, 24 parentY = {}; 25 26 // get screen coordinates. 27 aAcc.getImagePosition( 28 nsIAccessibleCoordinateType.COORDTYPE_SCREEN_RELATIVE, 29 screenX, screenY); 30 // get window coordinates. 31 aAcc.getImagePosition( 32 nsIAccessibleCoordinateType.COORDTYPE_WINDOW_RELATIVE, 33 windowX, windowY); 34 // get parent related coordinates. 35 aAcc.getImagePosition( 36 nsIAccessibleCoordinateType.COORDTYPE_PARENT_RELATIVE, 37 parentX, parentY); 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) 42 parentY.value = -1; 43 44 // See if asking image for child at image's screen coordinates gives 45 // correct accessible. getChildAtPoint operates on screen coordinates. 46 var tempAcc = null; 47 try { 48 tempAcc = aAcc.getChildAtPoint(screenX.value, screenY.value); 49 } catch (e) {} 50 is(tempAcc, aAcc, 51 "Wrong accessible returned for position of " + aID + "!"); 52 53 // get image's parent. 54 var imageParentAcc = null; 55 try { 56 imageParentAcc = aAcc.parent; 57 } catch (e) {} 58 ok(imageParentAcc, "no parent accessible for " + aID + "!"); 59 60 if (imageParentAcc) { 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 = {}, 64 parentAccHeight = {}; 65 imageParentAcc.getBounds(parentAccX, parentAccY, parentAccWidth, 66 parentAccHeight); 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 + "!"); 71 } 72 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 + "!"); 78 } 79 80 function testThis(aID, aSRC, aWidth, aHeight, 81 aActionCount, aActionNames) { 82 var acc = getAccessible(aID, [nsIAccessibleImage]); 83 if (!acc) 84 return; 85 86 // Test role 87 testRole(aID, ROLE_GRAPHIC); 88 89 // test coordinates and size 90 testCoordinates(aID, acc, aWidth, aHeight); 91 92 // bug 429659: Make sure the SRC attribute is set for any image 93 var attributes = {"src": aSRC}; 94 testAttrs(acc, attributes, true); 95 96 var actionCount = aActionCount || 0; 97 is(acc.actionCount, actionCount, 98 "Wrong number of actions for " + aID + "!"); 99 if (actionCount) { 100 for (let index = 0; index < aActionNames.length; index++) { 101 is(acc.getActionName(index), aActionNames[index], 102 "Wrong action name for " + aID + ", index " + index + "!"); 103 } 104 } 105 } 106 107 function doTest() { 108 // Test non-linked image 109 testThis("nonLinkedImage", "moz.png", 89, 38); 110 111 // Test linked image 112 var actionNamesArray = ["clickAncestor"]; 113 testThis("linkedImage", "moz.png", 89, 38, 1, 114 actionNamesArray); 115 116 // Image with long desc 117 actionNamesArray = ["showlongdesc"]; 118 testThis("longdesc", "moz.png", 89, 38, 1, 119 actionNamesArray); 120 121 // Image with invalid url in long desc 122 testThis("invalidLongdesc", "moz.png", 89, 38, 0); 123 124 // Image with click and long desc 125 actionNamesArray = null; 126 actionNamesArray = ["click", "showlongdesc"]; 127 testThis("clickAndLongdesc", "moz.png", 128 89, 38, 2, actionNamesArray); 129 130 // Image with click 131 actionNamesArray = null; 132 actionNamesArray = ["click"]; 133 testThis("click", "moz.png", 134 89, 38, 1, actionNamesArray); 135 136 // Image with long desc 137 actionNamesArray = null; 138 actionNamesArray = ["showlongdesc"]; 139 testThis("longdesc2", "moz.png", 140 89, 38, 1, actionNamesArray); 141 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); 147 148 SimpleTest.finish(); 149 } 150 151 SimpleTest.waitForExplicitFinish(); 152 addA11yLoadEvent(doTest); 153 </script> 154 </head> 155 <body> 156 157 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=429659">Mozilla Bug 429659</a> 158 <a target="_blank" 159 href="https://bugzilla.mozilla.org/show_bug.cgi?id=652635" 160 title="fall back missing @longdesc to aria-describedby pointing to a href"> 161 Mozilla Bug 652635 162 </a> 163 164 <p id="display"></p> 165 <div id="content" style="display: none"></div> 166 <pre id="test"> 167 </pre> 168 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!');"/> 182 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> 187 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> 192 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!');"/> 196 197 </body> 198 </html>