accessible/tests/mochitest/test_nsIAccessibleImage.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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" />
    10   <script type="application/javascript"
    11           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    13   <script type="application/javascript"
    14           src="common.js"></script>
    15   <script type="application/javascript"
    16           src="role.js"></script>
    17   <script type="application/javascript"
    18           src="attributes.js"></script>
    20   <script type="application/javascript">
    21     function testCoordinates(aID, aAcc, aWidth, aHeight)
    22     {
    23       var screenX = {}, screenY = {}, windowX = {}, windowY = {}, parentX = {},
    24           parentY = {};
    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;
    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 + "!");
    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 + "!");
    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       }
    73       var width = {}, height = {};
    74       aAcc.getImageSize(width, height);
    75       is(width.value, aWidth, "Wrong width for " + aID + "!");
    76       is(height.value, aHeight, "wrong height for " + aID + "!");
    77     }
    79     function testThis(aID, aSRC, aWidth, aHeight,
    80                       aActionCount, aActionNames)
    81     {
    82       var acc = getAccessible(aID, [nsIAccessibleImage]);
    83       if (!acc)
    84         return;
    86       // Test role
    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       if (aActionCount) {
    97         is(acc.actionCount, aActionCount,
    98            "Wrong number of actions for " + aID + "!");
   100         for (index = 0; index < aActionNames.length; index++)
   101           is(acc.getActionName(index), aActionNames[index],
   102              "Wrong action name for " + aID + ", index " + index +"!");
   103       }
   104     }
   106     function doTest()
   107     {
   108       // Test non-linked image
   109       testThis("nonLinkedImage", "moz.png", 89, 38);
   111       // Test linked image
   112       testThis("linkedImage", "moz.png", 89, 38);
   114       // Image with long desc
   115       var actionNamesArray = new Array("showlongdesc");
   116       testThis("longdesc", "moz.png", 89, 38, 1,
   117                actionNamesArray);
   119       // Image with click and long desc
   120       actionNamesArray = null;
   121       actionNamesArray = new Array("click", "showlongdesc");
   122       testThis("clickAndLongdesc", "moz.png",
   123                89, 38, 2, actionNamesArray);
   125       // Image with click
   126       actionNamesArray = null;
   127       actionNamesArray = new Array("click");
   128       testThis("click", "moz.png",
   129                89, 38, 1, actionNamesArray);
   131       // Image with long desc
   132       actionNamesArray = null;
   133       actionNamesArray = new Array("showlongdesc");
   134       testThis("longdesc2", "moz.png",
   135                89, 38, 1, actionNamesArray);
   137       SimpleTest.finish();
   138     }
   140     SimpleTest.waitForExplicitFinish();
   141     addA11yLoadEvent(doTest);
   142   </script>
   143 </head>
   144 <body>
   146   <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=429659">Mozilla Bug 429659</a>
   147   <a target="_blank"
   148     href="https://bugzilla.mozilla.org/show_bug.cgi?id=652635"
   149     title="fall back missing @longdesc to aria-describedby pointing to a href">
   150      Mozilla Bug 652635
   151   </a>
   153   <p id="display"></p>
   154   <div id="content" style="display: none"></div>
   155   <pre id="test">
   156   </pre>
   158   <br>Simple image:<br>
   159   <img id="nonLinkedImage" src="moz.png"/>
   160   <br>Linked image:<br>
   161   <a href="http://www.mozilla.org"><img id="linkedImage" src="moz.png"></a>
   162   <br>Image with longdesc:<br>
   163   <img id="longdesc" src="moz.png" longdesc="longdesc_src.html"
   164        alt="Image of Mozilla logo"/>
   165   <br>Image with click and longdesc:<br>
   166   <img id="clickAndLongdesc" src="moz.png" longdesc="longdesc_src.html"
   167        alt="Another image of Mozilla logo" onclick="alert('Clicked!');"/>
   169   <br>image described by a link to be treated as longdesc<br>
   170   <img id="longdesc2" src="moz.png" aria-describedby="describing_link"
   171        alt="Second Image of Mozilla logo"/>
   172   <a id="describing_link" href="longdesc_src.html">link to description of image</a>
   174   <br>Image with click:<br>
   175   <img id="click" src="moz.png"
   176        alt="A third image of Mozilla logo" onclick="alert('Clicked, too!');"/>
   178 </body>
   179 </html>

mercurial