tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_general.html (12913B)


      1 <!DOCTYPE html>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=418368
      5 -->
      6 <head>
      7  <title>nsIHyperLinkAccessible 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  <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
     12 
     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="../states.js"></script>
     19  <script type="application/javascript"
     20          src="../events.js"></script>
     21 
     22  <script type="application/javascript"
     23          src="hyperlink.js"></script>
     24 
     25  <script type="application/javascript">
     26    function testThis(aID, aAcc, aRole, aAnchors, aName, aValid, aStartIndex,
     27                      aEndIndex) {
     28      testRole(aAcc, aRole);
     29      is(aAcc.anchorCount, aAnchors, "Wrong number of anchors for ID "
     30                                      + aID + "!");
     31      is(aAcc.getAnchor(0).name, aName, "Wrong name for ID "
     32                                        + aID + "!");
     33      is(aAcc.valid, aValid, "No correct valid state for ID "
     34                             + aID + "!");
     35      is(aAcc.startIndex, aStartIndex, "Wrong startIndex value for ID "
     36                                       + aID + "!");
     37      is(aAcc.endIndex, aEndIndex, "Wrong endIndex value for ID "
     38                                   + aID + "!");
     39    }
     40 
     41    function testAction(aId, aAcc, aActionName) {
     42      var actionCount = aActionName ? 1 : 0;
     43      is(aAcc.actionCount, actionCount,
     44         "Wrong actions number for ID " + aId);
     45      try {
     46        is(aAcc.getActionName(0), aActionName,
     47           "Wrong action name for ID " + aId);
     48      } catch (e) {
     49        if (actionCount)
     50          ok(false, "Exception on action name getting for ID " + aId);
     51        else
     52          ok(true, "Correct action name for ID " + aId);
     53      }
     54    }
     55 
     56    // gA11yEventDumpToConsole = true; // debug stuff
     57    function doPreTest() {
     58      waitForImageMap("imgmap", doTest);
     59    }
     60 
     61    var gQueue = null;
     62    function doTest() {
     63      // ////////////////////////////////////////////////////////////////////////
     64      // normal hyperlink
     65      var normalHyperlinkAcc = getAccessible("NormalHyperlink",
     66                                             [nsIAccessibleHyperLink]);
     67      testThis("NormalHyperlink", normalHyperlinkAcc, ROLE_LINK, 1,
     68               "Mozilla Foundation", true, 17, 18);
     69      // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     70      is(normalHyperlinkAcc.getURI(0).spec, "http://www.mozilla.org/",
     71         "URI wrong for normalHyperlinkElement!");
     72      testStates(normalHyperlinkAcc, STATE_LINKED, 0);
     73 
     74      // ////////////////////////////////////////////////////////////////////////
     75      // ARIA hyperlink
     76      var ariaHyperlinkAcc = getAccessible("AriaHyperlink",
     77                                           [nsIAccessibleHyperLink]);
     78      testThis("AriaHyperlink", ariaHyperlinkAcc, ROLE_LINK, 1,
     79               "Mozilla Foundation Home", true, 30, 31);
     80      testStates(ariaHyperlinkAcc, STATE_LINKED, 0);
     81      testAction("AriaHyperlink", ariaHyperlinkAcc, "click");
     82 
     83      // ////////////////////////////////////////////////////////////////////////
     84      // ARIA hyperlink with status invalid
     85      var invalidAriaHyperlinkAcc = getAccessible("InvalidAriaHyperlink",
     86                                                  [nsIAccessibleHyperLink]);
     87      is(invalidAriaHyperlinkAcc.valid, false, "Should not be valid!");
     88      testStates(invalidAriaHyperlinkAcc, STATE_LINKED, 0);
     89 
     90      // ////////////////////////////////////////////////////////////////////////
     91      // image map and its link children
     92 
     93      var imageMapHyperlinkAcc = getAccessible("imgmap",
     94                                               [nsIAccessibleHyperLink]);
     95      testThis("imgmap", imageMapHyperlinkAcc, ROLE_IMAGE_MAP, 2, "b", true,
     96               79, 80);
     97      is(imageMapHyperlinkAcc.getURI(0).spec,
     98         // eslint-disable-next-line @microsoft/sdl/no-insecure-url
     99         "http://www.bbc.co.uk/radio4/atoz/index.shtml#b", "URI wrong!");
    100      is(imageMapHyperlinkAcc.getURI(1).spec,
    101         // eslint-disable-next-line @microsoft/sdl/no-insecure-url
    102         "http://www.bbc.co.uk/radio4/atoz/index.shtml#a", "URI wrong!");
    103      testStates(imageMapHyperlinkAcc, 0, 0);
    104 
    105      var area1 = getAccessible(imageMapHyperlinkAcc.firstChild,
    106                                [nsIAccessibleHyperLink]);
    107      testThis("Area1", area1, ROLE_LINK, 1, "b", true, 0, 1);
    108      is(area1.getURI(0).spec,
    109         // eslint-disable-next-line @microsoft/sdl/no-insecure-url
    110         "http://www.bbc.co.uk/radio4/atoz/index.shtml#b", "URI wrong!");
    111      testStates(area1, (STATE_LINKED));
    112 
    113      var area2 = getAccessible(area1.nextSibling,
    114                                [nsIAccessibleHyperLink]);
    115      testThis("Area2", area2, ROLE_LINK, 1, "a", true, 1, 2);
    116      is(area2.getURI(0).spec,
    117         // eslint-disable-next-line @microsoft/sdl/no-insecure-url
    118         "http://www.bbc.co.uk/radio4/atoz/index.shtml#a", "URI wrong!");
    119      testStates(area2, (STATE_LINKED));
    120 
    121      // ////////////////////////////////////////////////////////////////////////
    122      // empty hyperlink
    123      var EmptyHLAcc = getAccessible("emptyLink",
    124                                     [nsIAccessibleHyperLink]);
    125      testThis("emptyLink", EmptyHLAcc, ROLE_LINK, 1, null, true, 93, 94);
    126      testStates(EmptyHLAcc, (STATE_FOCUSABLE | STATE_LINKED), 0);
    127      testAction("emptyLink", EmptyHLAcc, "jump");
    128 
    129      // ////////////////////////////////////////////////////////////////////////
    130      // normal hyperlink with embedded span
    131      var hyperlinkWithSpanAcc = getAccessible("LinkWithSpan",
    132                                               [nsIAccessibleHyperLink]);
    133      testThis("LinkWithSpan", hyperlinkWithSpanAcc, ROLE_LINK, 1,
    134               "Heise Online", true, 119, 120);
    135      // eslint-disable-next-line @microsoft/sdl/no-insecure-url
    136      is(hyperlinkWithSpanAcc.getURI(0).spec, "http://www.heise.de/",
    137         "URI wrong for hyperlinkElementWithSpan!");
    138      testStates(hyperlinkWithSpanAcc, STATE_LINKED, 0);
    139      testAction("LinkWithSpan", hyperlinkWithSpanAcc, "jump");
    140 
    141      // ////////////////////////////////////////////////////////////////////////
    142      // Named anchor, should never have state_linked
    143      var namedAnchorAcc = getAccessible("namedAnchor",
    144                                         [nsIAccessibleHyperLink]);
    145      testThis("namedAnchor", namedAnchorAcc, ROLE_TEXT, 1,
    146               null, true, 196, 197);
    147      testStates(namedAnchorAcc, 0, 0, (STATE_FOCUSABLE | STATE_LINKED));
    148      testAction("namedAnchor", namedAnchorAcc, "");
    149 
    150      // ////////////////////////////////////////////////////////////////////////
    151      // No link (hasn't any attribute), should never have state_linked
    152      var noLinkAcc = getAccessible("noLink",
    153                                    [nsIAccessibleHyperLink]);
    154      testThis("noLink", noLinkAcc, ROLE_TEXT, 1,
    155               null, true, 254, 255);
    156      testStates(noLinkAcc, 0, 0, (STATE_FOCUSABLE | STATE_LINKED));
    157      testAction("noLink", noLinkAcc, "");
    158 
    159      // ////////////////////////////////////////////////////////////////////////
    160      // Link with registered 'click' event, should have state_linked
    161      var linkWithClickAcc = getAccessible("linkWithClick",
    162                                           [nsIAccessibleHyperLink]);
    163      testThis("linkWithClick", linkWithClickAcc, ROLE_LINK, 1,
    164               "This should have state_linked", true, 292, 293);
    165      testStates(linkWithClickAcc, STATE_LINKED, 0);
    166      testAction("linkWithClick", linkWithClickAcc, "click");
    167 
    168      // ////////////////////////////////////////////////////////////////////////
    169      // Maps to group links (bug 431615).
    170      // var linksMapAcc = getAccessible("linksmap");
    171 
    172      // ////////////////////////////////////////////////////////////////////////
    173      // Link with title attribute, no name from the subtree (bug 438325).
    174      var id = "linkWithTitleNoNameFromSubtree";
    175      var linkAcc = getAccessible(id, [nsIAccessibleHyperLink]);
    176      testThis(id, linkAcc, ROLE_LINK, 1, "Link with title", true, 344, 345);
    177      testStates(linkAcc, STATE_LINKED, 0);
    178      testAction(id, linkAcc, "jump");
    179 
    180      // ////////////////////////////////////////////////////////////////////////
    181      // Link with title attribute, name from the subtree - onscreen name
    182      // (bug 438325).
    183      id = "linkWithTitleNameFromSubtree";
    184      linkAcc = getAccessible(id, [nsIAccessibleHyperLink]);
    185      testThis(id, linkAcc, ROLE_LINK, 1, "the name from subtree", true, 393,
    186               394);
    187      testStates(linkAcc, STATE_LINKED, 0);
    188      testAction(id, linkAcc, "jump");
    189 
    190      // ////////////////////////////////////////////////////////////////////////
    191      // Link with title attribute, name from the nested html:img (bug 438325).
    192      id = "linkWithTitleNameFromImg";
    193      linkAcc = getAccessible(id, [nsIAccessibleHyperLink]);
    194      testThis(id, linkAcc, ROLE_LINK, 1, "The title for link", true, 447,
    195               448);
    196      testStates(linkAcc, STATE_LINKED, 0);
    197      testAction(id, linkAcc, "jump");
    198 
    199      // ////////////////////////////////////////////////////////////////////////
    200      // Text accessible shouldn't implement nsIAccessibleHyperLink
    201      var res = isAccessible(getNode("namedAnchor").firstChild,
    202                             [nsIAccessibleHyperLink]);
    203      ok(!res, "Text accessible shouldn't implement nsIAccessibleHyperLink");
    204 
    205      // ////////////////////////////////////////////////////////////////////////
    206      // Test focus
    207      gQueue = new eventQueue();
    208 
    209      gQueue.push(new focusLink("NormalHyperlink", true));
    210      gQueue.push(new focusLink("AriaHyperlink", true));
    211      gQueue.push(new focusLink("InvalidAriaHyperlink", false));
    212      gQueue.push(new focusLink("LinkWithSpan", true));
    213 
    214      gQueue.invoke(); // Will call SimpleTest.finish();
    215    }
    216 
    217    SimpleTest.waitForExplicitFinish();
    218    addA11yLoadEvent(doPreTest);
    219  </script>
    220 
    221 </head>
    222 <body><a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=418368">Mozilla Bug 418368</a
    223  ><p id="display"></p
    224  ><div id="content" style="display: none"></div
    225  ><pre id="test">
    226  </pre
    227  ><br
    228  >Simple link:<br
    229  ><a id="NormalHyperlink" href="http://www.mozilla.org">Mozilla Foundation</a
    230  ><br>ARIA link:<br
    231  ><span id="AriaHyperlink" role="link"
    232         onclick="window.open('http://www.mozilla.org/');"
    233         tabindex="0">Mozilla Foundation Home</span
    234  ><br
    235  >Invalid, non-focusable hyperlink:<br
    236  ><span id="InvalidAriaHyperlink" role="link" aria-invalid="true"
    237         onclick="window.open('http:/www.mozilla.org/');">Invalid link</span
    238  ><br>Image map:<br
    239  ><map name="atoz_map"
    240    ><area href="http://www.bbc.co.uk/radio4/atoz/index.shtml#b"
    241          coords="17,0,30,14"
    242          alt="b"
    243          shape="rect"></area
    244    ><area href="http://www.bbc.co.uk/radio4/atoz/index.shtml#a"
    245           coords="0,0,13,14"
    246           alt="a"
    247           shape="rect"></area
    248    ></map
    249  ><img width="447" id="imgmap"
    250        height="15"
    251        usemap="#atoz_map"
    252        src="../letters.gif"><br>Empty link:<br
    253  ><a id="emptyLink" href=""><img src=""></a
    254  ><br>Link with embedded span<br
    255  ><a id="LinkWithSpan" href="http://www.heise.de/"><span lang="de">Heise Online</span></a
    256  ><br>Named anchor, must not have "linked" state for it to be exposed correctly:<br
    257  ><a id="namedAnchor" name="named_anchor">This should never be of state_linked</a
    258  ><br>Link having no attributes, must not have "linked" state:<a id="noLink"
    259  >This should never be of state_linked</a
    260  ><br>Link with registered 'click' event: <a id="linkWithClick" onclick="var clicked = true;"
    261  >This should have state_linked</a
    262  ><br>Link with title attribute (no name from subtree): <a
    263      id="linkWithTitleNoNameFromSubtree" href="http://www.heise.de/"
    264      title="Link with title"><img src=""/></a
    265  ><br>Link with title attribute (name from subtree): <a
    266      id="linkWithTitleNameFromSubtree" href="http://www.heise.de/"
    267      title="Link with title">the name from subtree</a
    268  ><br>Link with title attribute (name from nested image): <a
    269      id="linkWithTitleNameFromImg" href="http://www.heise.de/"
    270      title="Link with title"><img src="" alt="The title for link"/></a
    271  ><br><br>Map that is used to group links (www.w3.org/TR/WCAG10-HTML-TECHS/#group-bypass), also see the bug 431615:<br
    272  ><map id="linksmap" title="Site navigation"><ul
    273    ><li><a href="http://mozilla.org">About the project</a></li
    274    ><li><a href="http://mozilla.org">Sites and sounds</a></li
    275    ></ul
    276  ></map
    277 ></body>
    278 </html>