diff options
Diffstat (limited to 'accessible/tests/mochitest/hyperlink')
-rw-r--r-- | accessible/tests/mochitest/hyperlink/a11y.ini | 7 | ||||
-rw-r--r-- | accessible/tests/mochitest/hyperlink/hyperlink.js | 46 | ||||
-rw-r--r-- | accessible/tests/mochitest/hyperlink/test_general.html | 279 | ||||
-rw-r--r-- | accessible/tests/mochitest/hyperlink/test_general.xhtml | 98 |
4 files changed, 430 insertions, 0 deletions
diff --git a/accessible/tests/mochitest/hyperlink/a11y.ini b/accessible/tests/mochitest/hyperlink/a11y.ini new file mode 100644 index 0000000000..60804a70c8 --- /dev/null +++ b/accessible/tests/mochitest/hyperlink/a11y.ini @@ -0,0 +1,7 @@ +[DEFAULT] +support-files = hyperlink.js + !/accessible/tests/mochitest/*.js + !/accessible/tests/mochitest/letters.gif + +[test_general.html] +[test_general.xhtml] diff --git a/accessible/tests/mochitest/hyperlink/hyperlink.js b/accessible/tests/mochitest/hyperlink/hyperlink.js new file mode 100644 index 0000000000..93caa9090c --- /dev/null +++ b/accessible/tests/mochitest/hyperlink/hyperlink.js @@ -0,0 +1,46 @@ +/* import-globals-from ../common.js */ +/* import-globals-from ../events.js */ +/* import-globals-from ../states.js */ + +/** + * Focus hyperlink invoker. + * + * @param aID [in] hyperlink identifier + * @param aSelectedAfter [in] specifies if hyperlink is selected/focused after + * the focus + */ +function focusLink(aID, aSelectedAfter) { + this.node = getNode(aID); + this.accessible = getAccessible(this.node); + + this.eventSeq = []; + this.unexpectedEventSeq = []; + + var checker = new invokerChecker(EVENT_FOCUS, this.accessible); + if (aSelectedAfter) { + this.eventSeq.push(checker); + } else { + this.unexpectedEventSeq.push(checker); + } + + this.invoke = function focusLink_invoke() { + var expectedStates = aSelectedAfter ? STATE_FOCUSABLE : 0; + var unexpectedStates = + (!aSelectedAfter ? STATE_FOCUSABLE : 0) | STATE_FOCUSED; + testStates(aID, expectedStates, 0, unexpectedStates, 0); + + this.node.focus(); + }; + + this.finalCheck = function focusLink_finalCheck() { + var expectedStates = aSelectedAfter ? STATE_FOCUSABLE | STATE_FOCUSED : 0; + var unexpectedStates = !aSelectedAfter + ? STATE_FOCUSABLE | STATE_FOCUSED + : 0; + testStates(aID, expectedStates, 0, unexpectedStates, 0); + }; + + this.getID = function focusLink_getID() { + return "focus hyperlink " + prettyName(aID); + }; +} diff --git a/accessible/tests/mochitest/hyperlink/test_general.html b/accessible/tests/mochitest/hyperlink/test_general.html new file mode 100644 index 0000000000..c652f1d962 --- /dev/null +++ b/accessible/tests/mochitest/hyperlink/test_general.html @@ -0,0 +1,279 @@ +<!DOCTYPE html> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=418368 +--> +<head> + <title>nsIHyperLinkAccessible chrome tests</title> + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" /> + + <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> + + <script type="application/javascript" + src="../common.js"></script> + <script type="application/javascript" + src="../role.js"></script> + <script type="application/javascript" + src="../states.js"></script> + <script type="application/javascript" + src="../events.js"></script> + + <script type="application/javascript" + src="hyperlink.js"></script> + + <script type="application/javascript"> + function testThis(aID, aAcc, aRole, aAnchors, aName, aValid, aStartIndex, + aEndIndex) { + testRole(aAcc, aRole); + is(aAcc.anchorCount, aAnchors, "Wrong number of anchors for ID " + + aID + "!"); + is(aAcc.getAnchor(0).name, aName, "Wrong name for ID " + + aID + "!"); + is(aAcc.valid, aValid, "No correct valid state for ID " + + aID + "!"); + is(aAcc.startIndex, aStartIndex, "Wrong startIndex value for ID " + + aID + "!"); + is(aAcc.endIndex, aEndIndex, "Wrong endIndex value for ID " + + aID + "!"); + } + + function testAction(aId, aAcc, aActionName) { + var actionCount = aActionName ? 1 : 0; + is(aAcc.actionCount, actionCount, + "Wrong actions number for ID " + aId); + try { + is(aAcc.getActionName(0), aActionName, + "Wrong action name for ID " + aId); + } catch (e) { + if (actionCount) + ok(false, "Exception on action name getting for ID " + aId); + else + ok(true, "Correct action name for ID " + aId); + } + } + + // gA11yEventDumpToConsole = true; // debug stuff + function doPreTest() { + waitForImageMap("imgmap", doTest); + } + + var gQueue = null; + function doTest() { + // //////////////////////////////////////////////////////////////////////// + // normal hyperlink + var normalHyperlinkAcc = getAccessible("NormalHyperlink", + [nsIAccessibleHyperLink]); + testThis("NormalHyperlink", normalHyperlinkAcc, ROLE_LINK, 1, + "Mozilla Foundation", true, 17, 18); + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + is(normalHyperlinkAcc.getURI(0).spec, "http://www.mozilla.org/", + "URI wrong for normalHyperlinkElement!"); + testStates(normalHyperlinkAcc, STATE_LINKED, 0); + + // //////////////////////////////////////////////////////////////////////// + // ARIA hyperlink + var ariaHyperlinkAcc = getAccessible("AriaHyperlink", + [nsIAccessibleHyperLink]); + testThis("AriaHyperlink", ariaHyperlinkAcc, ROLE_LINK, 1, + "Mozilla Foundation Home", true, 30, 31); + testStates(ariaHyperlinkAcc, STATE_LINKED, 0); + testAction("AriaHyperlink", ariaHyperlinkAcc, "click"); + + // //////////////////////////////////////////////////////////////////////// + // ARIA hyperlink with status invalid + var invalidAriaHyperlinkAcc = getAccessible("InvalidAriaHyperlink", + [nsIAccessibleHyperLink]); + is(invalidAriaHyperlinkAcc.valid, false, "Should not be valid!"); + testStates(invalidAriaHyperlinkAcc, STATE_LINKED, 0); + + // //////////////////////////////////////////////////////////////////////// + // image map and its link children + + var imageMapHyperlinkAcc = getAccessible("imgmap", + [nsIAccessibleHyperLink]); + testThis("imgmap", imageMapHyperlinkAcc, ROLE_IMAGE_MAP, 2, "b", true, + 79, 80); + is(imageMapHyperlinkAcc.getURI(0).spec, + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + "http://www.bbc.co.uk/radio4/atoz/index.shtml#b", "URI wrong!"); + is(imageMapHyperlinkAcc.getURI(1).spec, + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + "http://www.bbc.co.uk/radio4/atoz/index.shtml#a", "URI wrong!"); + testStates(imageMapHyperlinkAcc, 0, 0); + + var area1 = getAccessible(imageMapHyperlinkAcc.firstChild, + [nsIAccessibleHyperLink]); + testThis("Area1", area1, ROLE_LINK, 1, "b", true, 0, 1); + is(area1.getURI(0).spec, + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + "http://www.bbc.co.uk/radio4/atoz/index.shtml#b", "URI wrong!"); + testStates(area1, (STATE_LINKED)); + + var area2 = getAccessible(area1.nextSibling, + [nsIAccessibleHyperLink]); + testThis("Area2", area2, ROLE_LINK, 1, "a", true, 1, 2); + is(area2.getURI(0).spec, + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + "http://www.bbc.co.uk/radio4/atoz/index.shtml#a", "URI wrong!"); + testStates(area2, (STATE_LINKED)); + + // //////////////////////////////////////////////////////////////////////// + // empty hyperlink + var EmptyHLAcc = getAccessible("emptyLink", + [nsIAccessibleHyperLink]); + testThis("emptyLink", EmptyHLAcc, ROLE_LINK, 1, null, true, 93, 94); + testStates(EmptyHLAcc, (STATE_FOCUSABLE | STATE_LINKED), 0); + testAction("emptyLink", EmptyHLAcc, "jump"); + + // //////////////////////////////////////////////////////////////////////// + // normal hyperlink with embedded span + var hyperlinkWithSpanAcc = getAccessible("LinkWithSpan", + [nsIAccessibleHyperLink]); + testThis("LinkWithSpan", hyperlinkWithSpanAcc, ROLE_LINK, 1, + "Heise Online", true, 119, 120); + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + is(hyperlinkWithSpanAcc.getURI(0).spec, "http://www.heise.de/", + "URI wrong for hyperlinkElementWithSpan!"); + testStates(hyperlinkWithSpanAcc, STATE_LINKED, 0); + testAction("LinkWithSpan", hyperlinkWithSpanAcc, "jump"); + + // //////////////////////////////////////////////////////////////////////// + // Named anchor, should never have state_linked + var namedAnchorAcc = getAccessible("namedAnchor", + [nsIAccessibleHyperLink]); + testThis("namedAnchor", namedAnchorAcc, ROLE_LINK, 1, + "This should never be of state_linked", true, 196, 197); + testStates(namedAnchorAcc, STATE_SELECTABLE, + 0, (STATE_FOCUSABLE | STATE_LINKED)); + testAction("namedAnchor", namedAnchorAcc, ""); + + // //////////////////////////////////////////////////////////////////////// + // No link (hasn't any attribute), should never have state_linked + var noLinkAcc = getAccessible("noLink", + [nsIAccessibleHyperLink]); + testThis("noLink", noLinkAcc, ROLE_LINK, 1, + "This should never be of state_linked", true, 254, 255); + testStates(noLinkAcc, 0, 0, (STATE_FOCUSABLE | STATE_LINKED)); + testAction("noLink", noLinkAcc, ""); + + // //////////////////////////////////////////////////////////////////////// + // Link with registered 'click' event, should have state_linked + var linkWithClickAcc = getAccessible("linkWithClick", + [nsIAccessibleHyperLink]); + testThis("linkWithClick", linkWithClickAcc, ROLE_LINK, 1, + "This should have state_linked", true, 292, 293); + testStates(linkWithClickAcc, STATE_LINKED, 0); + testAction("linkWithClick", linkWithClickAcc, "click"); + + // //////////////////////////////////////////////////////////////////////// + // Maps to group links (bug 431615). + // var linksMapAcc = getAccessible("linksmap"); + + // //////////////////////////////////////////////////////////////////////// + // Link with title attribute, no name from the subtree (bug 438325). + var id = "linkWithTitleNoNameFromSubtree"; + var linkAcc = getAccessible(id, [nsIAccessibleHyperLink]); + testThis(id, linkAcc, ROLE_LINK, 1, "Link with title", true, 344, 345); + testStates(linkAcc, STATE_LINKED, 0); + testAction(id, linkAcc, "jump"); + + // //////////////////////////////////////////////////////////////////////// + // Link with title attribute, name from the subtree - onscreen name + // (bug 438325). + id = "linkWithTitleNameFromSubtree"; + linkAcc = getAccessible(id, [nsIAccessibleHyperLink]); + testThis(id, linkAcc, ROLE_LINK, 1, "the name from subtree", true, 393, + 394); + testStates(linkAcc, STATE_LINKED, 0); + testAction(id, linkAcc, "jump"); + + // //////////////////////////////////////////////////////////////////////// + // Link with title attribute, name from the nested html:img (bug 438325). + id = "linkWithTitleNameFromImg"; + linkAcc = getAccessible(id, [nsIAccessibleHyperLink]); + testThis(id, linkAcc, ROLE_LINK, 1, "The title for link", true, 447, + 448); + testStates(linkAcc, STATE_LINKED, 0); + testAction(id, linkAcc, "jump"); + + // //////////////////////////////////////////////////////////////////////// + // Text accessible shouldn't implement nsIAccessibleHyperLink + var res = isAccessible(getNode("namedAnchor").firstChild, + [nsIAccessibleHyperLink]); + ok(!res, "Text accessible shouldn't implement nsIAccessibleHyperLink"); + + // //////////////////////////////////////////////////////////////////////// + // Test focus + gQueue = new eventQueue(); + + gQueue.push(new focusLink("NormalHyperlink", true)); + gQueue.push(new focusLink("AriaHyperlink", true)); + gQueue.push(new focusLink("InvalidAriaHyperlink", false)); + gQueue.push(new focusLink("LinkWithSpan", true)); + + gQueue.invoke(); // Will call SimpleTest.finish(); + } + + SimpleTest.waitForExplicitFinish(); + addA11yLoadEvent(doPreTest); + </script> + +</head> +<body><a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=418368">Mozilla Bug 418368</a + ><p id="display"></p + ><div id="content" style="display: none"></div + ><pre id="test"> + </pre + ><br + >Simple link:<br + ><a id="NormalHyperlink" href="http://www.mozilla.org">Mozilla Foundation</a + ><br>ARIA link:<br + ><span id="AriaHyperlink" role="link" + onclick="window.open('http://www.mozilla.org/');" + tabindex="0">Mozilla Foundation Home</span + ><br + >Invalid, non-focusable hyperlink:<br + ><span id="InvalidAriaHyperlink" role="link" aria-invalid="true" + onclick="window.open('http:/www.mozilla.org/');">Invalid link</span + ><br>Image map:<br + ><map name="atoz_map" + ><area href="http://www.bbc.co.uk/radio4/atoz/index.shtml#b" + coords="17,0,30,14" + alt="b" + shape="rect"></area + ><area href="http://www.bbc.co.uk/radio4/atoz/index.shtml#a" + coords="0,0,13,14" + alt="a" + shape="rect"></area + ></map + ><img width="447" id="imgmap" + height="15" + usemap="#atoz_map" + src="../letters.gif"><br>Empty link:<br + ><a id="emptyLink" href=""><img src=""></a + ><br>Link with embedded span<br + ><a id="LinkWithSpan" href="http://www.heise.de/"><span lang="de">Heise Online</span></a + ><br>Named anchor, must not have "linked" state for it to be exposed correctly:<br + ><a id="namedAnchor" name="named_anchor">This should never be of state_linked</a + ><br>Link having no attributes, must not have "linked" state:<a id="noLink" + >This should never be of state_linked</a + ><br>Link with registered 'click' event: <a id="linkWithClick" onclick="var clicked = true;" + >This should have state_linked</a + ><br>Link with title attribute (no name from subtree): <a + id="linkWithTitleNoNameFromSubtree" href="http://www.heise.de/" + title="Link with title"><img src=""/></a + ><br>Link with title attribute (name from subtree): <a + id="linkWithTitleNameFromSubtree" href="http://www.heise.de/" + title="Link with title">the name from subtree</a + ><br>Link with title attribute (name from nested image): <a + id="linkWithTitleNameFromImg" href="http://www.heise.de/" + title="Link with title"><img src="" alt="The title for link"/></a + ><br><br>Map that is used to group links (www.w3.org/TR/WCAG10-HTML-TECHS/#group-bypass), also see the bug 431615:<br + ><map id="linksmap" title="Site navigation"><ul + ><li><a href="http://mozilla.org">About the project</a></li + ><li><a href="http://mozilla.org">Sites and sounds</a></li + ></ul + ></map +></body> +</html> diff --git a/accessible/tests/mochitest/hyperlink/test_general.xhtml b/accessible/tests/mochitest/hyperlink/test_general.xhtml new file mode 100644 index 0000000000..b006e58ef4 --- /dev/null +++ b/accessible/tests/mochitest/hyperlink/test_general.xhtml @@ -0,0 +1,98 @@ +<?xml version="1.0"?> +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" + type="text/css"?> + +<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + title="test for nsIAccessibleHyperLink interface on XUL:label elements"> + + <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> + + <script type="application/javascript" + src="../common.js" /> + <script type="application/javascript" + src="../role.js" /> + <script type="application/javascript" + src="../states.js" /> + <script type="application/javascript" + src="../events.js" /> + + <script type="application/javascript" + src="hyperlink.js" /> + + <script type="application/javascript"> + <![CDATA[ + function testThis(aID, aAcc, aRole, aAnchorCount, aAnchorName, aURI, + aStartIndex, aEndIndex, aValid) + { + testRole(aID, aRole); + is(aAcc.anchorCount, aAnchorCount, "Wrong number of anchors for ID " + + aID + "!"); + is(aAcc.getAnchor(0).name, aAnchorName, "Wrong name for ID " + aID + "!"); + is(aAcc.getURI(0).spec, aURI, "URI wrong for ID " + aID + "!"); + is(aAcc.startIndex, aStartIndex, "Wrong startIndex value for ID " + aID + + "!"); + is(aAcc.endIndex, aEndIndex, "Wrong endIndex value for ID " + aID + "!"); + is(aAcc.valid, aValid, "Wrong valid state for ID " + aID + "!"); + } + + var gQueue = null; + function doTest() + { + var linkedLabelAcc = getAccessible("linkedLabel", + [nsIAccessibleHyperLink]); + testThis("linkedLabel", linkedLabelAcc, ROLE_LINK, 1, + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + "Mozilla Foundation home", "http://www.mozilla.org/", 1, 2, + true); + testStates(linkedLabelAcc, STATE_LINKED, 0); + + var labelWithValueAcc = getAccessible("linkLabelWithValue", + [nsIAccessibleHyperLink]); + testThis("linkLabelWithValue", labelWithValueAcc, ROLE_LINK, 1, + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + "Mozilla Foundation", "http://www.mozilla.org/", 2, 3, true, + false, true); + testStates(labelWithValueAcc, STATE_LINKED, 0); + + var normalLabelAcc = getAccessible("normalLabel"); + testRole(normalLabelAcc, ROLE_LABEL); + is(normalLabelAcc.name, "This label should not be a link", + "Wrong name for normal label!"); + testStates(normalLabelAcc, 0, 0, (STATE_FOCUSABLE | STATE_LINKED)); + + ////////////////////////////////////////////////////////////////////////// + // Test focus + + gQueue = new eventQueue(); + + gQueue.push(new focusLink("linkedLabel", true)); + gQueue.push(new focusLink("linkLabelWithValue", true)); + + gQueue.invoke(); // Will call SimpleTest.finish(); + } + + SimpleTest.waitForExplicitFinish(); + addA11yLoadEvent(doTest); + ]]> + </script> + + <body xmlns="http://www.w3.org/1999/xhtml"> + <a target="_blank" + href="https://bugzilla.mozilla.org/show_bug.cgi?id=421066" + title="Implement Mochitests for the nsIAccessibleHyperLink interface on XUL:label elements"> + Mozilla Bug 421066 + </a> + <p id="display"></p> + <div id="content" style="display: none"> + </div> + <pre id="test"> + </pre> + </body> + + <label id="linkedLabel" href="http://www.mozilla.org/" is="text-link"> + Mozilla Foundation home</label> + <label id="linkLabelWithValue" value="Mozilla Foundation" is="text-link" + href="http://www.mozilla.org/" /> + <label id="normalLabel" value="This label should not be a link" /> +</window> |