зеркало из https://github.com/mozilla/gecko-dev.git
Bug 439077 – Anchor tags with no attributes should not expose linked accessible state, r=MarcoZ
This commit is contained in:
Родитель
10661f4ec3
Коммит
a044334304
|
@ -102,8 +102,13 @@ nsHTMLLinkAccessible::GetState(PRUint32 *aState, PRUint32 *aExtraState)
|
|||
|
||||
nsLinkState linkState;
|
||||
link->GetLinkState(linkState);
|
||||
if (linkState == eLinkState_NotLink) {
|
||||
// This is a named anchor, not a link with also a name attribute. bail out.
|
||||
if (linkState == eLinkState_NotLink || linkState == eLinkState_Unknown) {
|
||||
// This is a either named anchor (a link with also a name attribute) or
|
||||
// it doesn't have any attributes. Check if 'click' event handler is
|
||||
// registered, otherwise bail out.
|
||||
PRBool isOnclick = nsAccUtils::HasListener(content,
|
||||
NS_LITERAL_STRING("click"));
|
||||
if (!isOnclick)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=418368
|
|||
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
|
||||
<script type="application/javascript">
|
||||
var gAccRetrieval = null;
|
||||
|
||||
function testThis(aID, aAcc, aRole, aAnchors, aName, aValid, aStartIndex,
|
||||
aEndIndex)
|
||||
{
|
||||
|
@ -36,10 +38,22 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=418368
|
|||
"Wrong seleccted state after focus for ID " + aID + "!");
|
||||
}
|
||||
|
||||
function testStates(aID, aAcc, aState, aExtraState, aAbsentState)
|
||||
function testStates(aID, aAcc, aState, aExtraState, aAbsentState,
|
||||
aShowStateDebugFlag)
|
||||
{
|
||||
var state = {}, extraState = {};
|
||||
aAcc.getFinalState(state, extraState);
|
||||
|
||||
if (aShowStateDebugFlag) {
|
||||
var list = gAccRetrieval.getStringStates(state.value, 0);
|
||||
|
||||
var str = "";
|
||||
for (var i = 0; i < list.length; i++)
|
||||
str += list.item(i) + "\n";
|
||||
|
||||
alert(str);
|
||||
}
|
||||
|
||||
is(state.value & aState, aState, "Wrong state bits for ID " + aID + "!");
|
||||
is(extraState.value & aExtraState, aExtraState,
|
||||
"Wrong extra state bits for ID " + aID + "!");
|
||||
|
@ -71,7 +85,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=418368
|
|||
const ext_state_invalid =
|
||||
Components.interfaces.nsIAccessibleStates.STATE_INVALID;
|
||||
|
||||
var accService = Components.classes["@mozilla.org/accessibleRetrieval;1"].
|
||||
gAccRetrieval = Components.classes["@mozilla.org/accessibleRetrieval;1"].
|
||||
getService(Components.interfaces.nsIAccessibleRetrieval);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
@ -79,7 +93,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=418368
|
|||
var normalHyperlinkElement = document.getElementById("NormalHyperlink");
|
||||
var normalHyperlinkAcc;
|
||||
try {
|
||||
normalHyperlinkAcc = accService.getAccessibleFor(normalHyperlinkElement).
|
||||
normalHyperlinkAcc = gAccRetrieval.getAccessibleFor(normalHyperlinkElement).
|
||||
QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
|
||||
} catch(e) {
|
||||
ok(normalHyperlinkAcc, "no interface for normal hyperlink!");
|
||||
|
@ -102,7 +116,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=418368
|
|||
var ariaHyperlinkElement = document.getElementById("AriaHyperlink");
|
||||
var ariaHyperlinkAcc;
|
||||
try {
|
||||
ariaHyperlinkAcc = accService.getAccessibleFor(ariaHyperlinkElement).
|
||||
ariaHyperlinkAcc = gAccRetrieval.getAccessibleFor(ariaHyperlinkElement).
|
||||
QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
|
||||
} catch(e) {
|
||||
ok(ariaHyperlinkAcc, "no interface for ARIA Hyperlink!");
|
||||
|
@ -125,7 +139,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=418368
|
|||
var invalidAriaHyperlinkAcc;
|
||||
try {
|
||||
invalidAriaHyperlinkAcc =
|
||||
accService.getAccessibleFor(invalidAriaHyperlinkElement).
|
||||
gAccRetrieval.getAccessibleFor(invalidAriaHyperlinkElement).
|
||||
QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
|
||||
} catch(e) {
|
||||
ok(invalidAriaHyperlinkAcc, "no interface for invalid ARIA hyperlink!");
|
||||
|
@ -144,7 +158,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=418368
|
|||
var imageMapHyperlinkAcc;
|
||||
try {
|
||||
imageMapHyperlinkAcc =
|
||||
accService.getAccessibleFor(imageMapHyperlinkElement).
|
||||
gAccRetrieval.getAccessibleFor(imageMapHyperlinkElement).
|
||||
QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
|
||||
} catch(e) {
|
||||
ok(imageMapHyperlinkAcc, "no Image Map interface!");
|
||||
|
@ -202,7 +216,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=418368
|
|||
var EmptyHLAcc;
|
||||
try {
|
||||
EmptyHLAcc =
|
||||
accService.getAccessibleFor(emptyLinkElement).
|
||||
gAccRetrieval.getAccessibleFor(emptyLinkElement).
|
||||
QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
|
||||
} catch (e) {
|
||||
ok(EmptyHLAcc, "no interface for empty link!");
|
||||
|
@ -220,7 +234,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=418368
|
|||
var hyperlinkWithSpanAcc;
|
||||
try {
|
||||
hyperlinkWithSpanAcc =
|
||||
accService.getAccessibleFor(hyperlinkElementWithSpan).
|
||||
gAccRetrieval.getAccessibleFor(hyperlinkElementWithSpan).
|
||||
QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
|
||||
} catch(e) {
|
||||
ok(hyperlinkWithSpanAcc, "no interface for hyperlink with span!");
|
||||
|
@ -243,7 +257,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=418368
|
|||
var namedAnchorElement = document.getElementById("namedAnchor");
|
||||
var namedAnchorAcc;
|
||||
try {
|
||||
namedAnchorAcc = accService.getAccessibleFor(namedAnchorElement).
|
||||
namedAnchorAcc = gAccRetrieval.getAccessibleFor(namedAnchorElement).
|
||||
QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
|
||||
} catch(e) {
|
||||
ok(namedAnchorAcc, "no interface for named anchor!");
|
||||
|
@ -255,12 +269,46 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=418368
|
|||
(state_selectable),
|
||||
(ext_state_horizontal), (state_focusable | state_linked));
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// No link (hasn't any attribute), should never have state_linked
|
||||
var noLinkElement = document.getElementById("noLink");
|
||||
var noLinkAcc;
|
||||
try {
|
||||
noLinkAcc = gAccRetrieval.getAccessibleFor(noLinkElement).
|
||||
QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
|
||||
} catch(e) {
|
||||
ok(noLinkAcc, "no interface for named anchor!");
|
||||
}
|
||||
testThis("noLink", noLinkAcc,
|
||||
Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1,
|
||||
"This should never be of state_linked", true, 262, 263);
|
||||
testStates("noLink", noLinkAcc,
|
||||
0,
|
||||
(ext_state_horizontal), (state_focusable | state_linked));
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Link with registered 'click' event, should have state_linked
|
||||
var linkWithClickElement = document.getElementById("linkWithClick");
|
||||
var linkWithClickAcc;
|
||||
try {
|
||||
linkWithClickAcc = gAccRetrieval.getAccessibleFor(linkWithClickElement).
|
||||
QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
|
||||
} catch(e) {
|
||||
ok(linkWithClickAcc, "no interface for named anchor!");
|
||||
}
|
||||
testThis("linkWithClick", linkWithClickAcc,
|
||||
Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1,
|
||||
"This should have state_linked", true, 301, 302);
|
||||
testStates("linkWithClick", linkWithClickAcc,
|
||||
(state_linked),
|
||||
(ext_state_horizontal), 0);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Maps to group links (bug 431615).
|
||||
var linksMapElement = document.getElementById("linksmap");
|
||||
var linksMapAcc;
|
||||
try {
|
||||
linksMapAcc = accService.getAccessibleFor(linksMapElement);
|
||||
linksMapAcc = gAccRetrieval.getAccessibleFor(linksMapElement);
|
||||
} catch(e) { }
|
||||
|
||||
ok(linksMapAcc, "no accessible for map grouping links!");
|
||||
|
@ -278,6 +326,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=418368
|
|||
<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>
|
||||
|
@ -308,6 +357,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=418368
|
|||
<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:</br>
|
||||
<a id="noLink">This should never be of state_linked</a>
|
||||
<br>Link with registered 'click' event: </br>
|
||||
<a id="linkWithClick" onclick="var clicked = true;">This should have state_linked</a>
|
||||
|
||||
<br>Map that is used to group links (www.w3.org/TR/WCAG10-HTML-TECHS/#group-bypass),
|
||||
also see the bug 431615:<br>
|
||||
|
|
Загрузка…
Ссылка в новой задаче