bug 480294 - Refactor nsIAccessibleHyperLink mochitests, r=surkov

This commit is contained in:
Marco Zehe 2009-02-27 12:23:26 +01:00
Родитель 8479d096c0
Коммит aaeb9e8950
4 изменённых файлов: 142 добавлений и 358 удалений

Просмотреть файл

@ -87,7 +87,7 @@ _TEST_FILES =\
test_nsIAccessibleDocument.html \
test_nsIAccessibleEditableText.html \
test_nsIAccessibleHyperLink.html \
$(warning test_nsIAccessibleHyperLink.xul temporarily disabled) \
test_nsIAccessibleHyperLink.xul \
test_nsIAccessibleHyperText.html \
test_nsIAccessibleImage.html \
test_nsIAccessibleTable_1.html \

Просмотреть файл

@ -60,7 +60,9 @@ const ROLE_FORM = nsIAccessibleRole.ROLE_FORM;
const ROLE_GRAPHIC = nsIAccessibleRole.ROLE_GRAPHIC;
const ROLE_GRID_CELL = nsIAccessibleRole.ROLE_GRID_CELL;
const ROLE_HEADING = nsIAccessibleRole.ROLE_HEADING;
const ROLE_IMAGE_MAP = nsIAccessibleRole.ROLE_IMAGE_MAP;
const ROLE_LABEL = nsIAccessibleRole.ROLE_LABEL;
const ROLE_LINK = nsIAccessibleRole.ROLE_LINK;
const ROLE_LIST = nsIAccessibleRole.ROLE_LIST;
const ROLE_LISTBOX = nsIAccessibleRole.ROLE_LISTBOX;
const ROLE_OPTION = nsIAccessibleRole.ROLE_OPTION;
@ -82,15 +84,18 @@ const STATE_EXTSELECTABLE = nsIAccessibleStates.STATE_EXTSELECTABLE;
const STATE_FOCUSABLE = nsIAccessibleStates.STATE_FOCUSABLE;
const STATE_FOCUSED = nsIAccessibleStates.STATE_FOCUSED;
const STATE_HASPOPUP = nsIAccessibleStates.STATE_HASPOPUP;
const STATE_LINKED = nsIAccessibleStates.STATE_LINKED;
const STATE_MIXED = nsIAccessibleStates.STATE_MIXED;
const STATE_MULTISELECTABLE = nsIAccessibleStates.STATE_MULTISELECTABLE;
const STATE_PRESSED = nsIAccessibleStates.STATE_PRESSED;
const STATE_READONLY = nsIAccessibleStates.STATE_READONLY;
const STATE_SELECTABLE = nsIAccessibleStates.STATE_SELECTABLE;
const STATE_SELECTED = nsIAccessibleStates.STATE_SELECTED;
const STATE_TRAVERSED = nsIAccessibleStates.STATE_TRAVERSED;
const EXT_STATE_EDITABLE = nsIAccessibleStates.EXT_STATE_EDITABLE;
const EXT_STATE_EXPANDABLE = nsIAccessibleStates.EXT_STATE_EXPANDABLE;
const EXT_STATE_HORIZONTAL = nsIAccessibleStates.EXT_STATE_HORIZONTAL;
const EXT_STATE_INVALID = nsIAccessibleStates.STATE_INVALID;
const EXT_STATE_MULTI_LINE = nsIAccessibleStates.EXT_STATE_MULTI_LINE;
const EXT_STATE_REQUIRED = nsIAccessibleStates.STATE_REQUIRED;

Просмотреть файл

@ -7,16 +7,23 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=418368
<title>nsIHyperLinkAccessible chrome tests</title>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
<script type="application/javascript" src="chrome://mochikit/content/MochiKit/packed.js"></script>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/a11y/accessible/common.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/a11y/accessible/role.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/a11y/accessible/nsIAccessible_states.js"></script>
<script type="application/javascript">
var gAccRetrieval = null;
function testThis(aID, aAcc, aRole, aAnchors, aName, aValid, aStartIndex,
aEndIndex)
{
is(aAcc.finalRole, aRole, "Wrong role for ID " + aID + "!");
testRole(aAcc, aRole);
is(aAcc.anchorCount, aAnchors, "Wrong number of anchors for ID "
+ aID + "!");
is(aAcc.getAnchor(0).name, aName, "Wrong name for ID "
@ -38,23 +45,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=418368
"Wrong seleccted state after focus for ID " + aID + "!");
}
function testStates(aID, aAcc, aState, aExtraState, aAbsentState,
aShowStateDebugFlag)
{
var state = {}, extraState = {};
aAcc.getState(state, extraState);
if (aShowStateDebugFlag)
alert(statesToString(state.value, 0));
is(state.value & aState, aState, "Wrong state bits for ID " + aID + "!");
is(extraState.value & aExtraState, aExtraState,
"Wrong extra state bits for ID " + aID + "!");
if (aAbsentState != 0)
is(state.value & aAbsentState, 0, "state bits should not be present in ID "
+ aID + "!");
}
function testAction(aId, aAcc, aActionName)
{
var numActions = aActionName ? 1 : 0;
@ -73,336 +63,182 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=418368
function doTest()
{
// Mapping needed state flags for easier handling.
const state_focusable =
Components.interfaces.nsIAccessibleStates.STATE_FOCUSABLE;
const state_focused =
Components.interfaces.nsIAccessibleStates.STATE_FOCUSED;
const state_selectable =
Components.interfaces.nsIAccessibleStates.STATE_SELECTABLE;
const state_linked =
Components.interfaces.nsIAccessibleStates.STATE_LINKED;
const state_traversed =
Components.interfaces.nsIAccessibleStates.STATE_TRAVERSED;
const ext_state_multi_line =
Components.interfaces.nsIAccessibleStates.EXT_STATE_MULTI_LINE;
const ext_state_horizontal =
Components.interfaces.nsIAccessibleStates.EXT_STATE_HORIZONTAL;
const ext_state_required =
Components.interfaces.nsIAccessibleStates.STATE_REQUIRED;
const ext_state_invalid =
Components.interfaces.nsIAccessibleStates.STATE_INVALID;
gAccRetrieval = Components.classes["@mozilla.org/accessibleRetrieval;1"].
getService(Components.interfaces.nsIAccessibleRetrieval);
//////////////////////////////////////////////////////////////////////////
// normal hyperlink
var normalHyperlinkElement = document.getElementById("NormalHyperlink");
var normalHyperlinkAcc;
try {
normalHyperlinkAcc = gAccRetrieval.getAccessibleFor(normalHyperlinkElement).
QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
} catch(e) {
ok(normalHyperlinkAcc, "no interface for normal hyperlink!");
}
testThis("NormalHyperlink", normalHyperlinkAcc,
Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1,
var normalHyperlinkAcc = getAccessible("NormalHyperlink",
[nsIAccessibleHyperLink]);
testThis("NormalHyperlink", normalHyperlinkAcc, ROLE_LINK, 1,
"Mozilla Foundation", true, 18, 19);
is(normalHyperlinkAcc.getURI(0).spec, "http://www.mozilla.org/",
"URI wrong for normalHyperlinkElement!");
testStates("NormalHyperlink", normalHyperlinkAcc,
(state_focusable | state_linked),
(ext_state_horizontal), (0));
testStates(normalHyperlinkAcc,
(STATE_FOCUSABLE | STATE_LINKED),
(EXT_STATE_HORIZONTAL));
testFocus("NormalHyperlink", normalHyperlinkAcc, false, true);
testStates("NormalHyperlink", normalHyperlinkAcc,
(state_focusable | state_focused | state_linked),
(ext_state_horizontal), (0));
testStates(normalHyperlinkAcc,
(STATE_FOCUSABLE | STATE_FOCUSED | STATE_LINKED),
(EXT_STATE_HORIZONTAL));
//////////////////////////////////////////////////////////////////////////
// ARIA hyperlink
var ariaHyperlinkElement = document.getElementById("AriaHyperlink");
var ariaHyperlinkAcc;
try {
ariaHyperlinkAcc = gAccRetrieval.getAccessibleFor(ariaHyperlinkElement).
QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
} catch(e) {
ok(ariaHyperlinkAcc, "no interface for ARIA Hyperlink!");
}
testThis("AriaHyperlink", ariaHyperlinkAcc,
Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1,
var ariaHyperlinkAcc = getAccessible("AriaHyperlink",
[nsIAccessibleHyperLink]);
testThis("AriaHyperlink", ariaHyperlinkAcc, ROLE_LINK, 1,
"Mozilla Foundation Home", true, 32, 33);
testStates("AriaHyperlink", ariaHyperlinkAcc,
(state_focusable | state_linked),
(ext_state_horizontal), (0));
testStates(ariaHyperlinkAcc,
(STATE_FOCUSABLE | STATE_LINKED),
(EXT_STATE_HORIZONTAL));
testFocus("AriaHyperlink", ariaHyperlinkAcc, false, true);
testStates("AriaHyperlink", ariaHyperlinkAcc,
(state_focusable | state_focused | state_linked),
(ext_state_horizontal), (0));
testStates(ariaHyperlinkAcc,
(STATE_FOCUSABLE | STATE_FOCUSED | STATE_LINKED),
(EXT_STATE_HORIZONTAL));
testAction("AriaHyperlink", ariaHyperlinkAcc, "click");
//////////////////////////////////////////////////////////////////////////
// ARIA hyperlink with status invalid
var invalidAriaHyperlinkElement =
document.getElementById("InvalidAriaHyperlink");
var invalidAriaHyperlinkAcc;
try {
invalidAriaHyperlinkAcc =
gAccRetrieval.getAccessibleFor(invalidAriaHyperlinkElement).
QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
} catch(e) {
ok(invalidAriaHyperlinkAcc, "no interface for invalid ARIA hyperlink!");
}
var invalidAriaHyperlinkAcc = getAccessible("InvalidAriaHyperlink",
[nsIAccessibleHyperLink]);
is(invalidAriaHyperlinkAcc.valid, false, "Should not be valid!");
testStates("InvalidAriaHyperlink", invalidAriaHyperlinkAcc,
(state_linked),
(ext_state_horizontal), (state_focusable));
testStates(invalidAriaHyperlinkAcc,
(STATE_LINKED),
(EXT_STATE_HORIZONTAL), (STATE_FOCUSABLE));
testFocus("InvalidAriaHyperlink", invalidAriaHyperlinkAcc,
false, false);
//////////////////////////////////////////////////////////////////////////
// image map and its link children
var imageMapHyperlinkElement =
document.getElementById("imgmap");
var imageMapHyperlinkAcc;
try {
imageMapHyperlinkAcc =
gAccRetrieval.getAccessibleFor(imageMapHyperlinkElement).
QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
} catch(e) {
ok(imageMapHyperlinkAcc, "no Image Map interface!");
}
testThis("imgmap", imageMapHyperlinkAcc,
Components.interfaces.nsIAccessibleRole.ROLE_IMAGE_MAP, 2,
"b", true, 83, 84);
var imageMapHyperlinkAcc = getAccessible("imgmap",
[nsIAccessibleHyperLink]);
testThis("imgmap", imageMapHyperlinkAcc, ROLE_IMAGE_MAP, 2, "b", true,
83, 84);
is(imageMapHyperlinkAcc.getURI(0).spec,
"http://www.bbc.co.uk/radio4/atoz/index.shtml#b", "URI wrong!");
is(imageMapHyperlinkAcc.getURI(1).spec,
"http://www.bbc.co.uk/radio4/atoz/index.shtml#a", "URI wrong!");
testStates("imgmap", imageMapHyperlinkAcc,
testStates(imageMapHyperlinkAcc,
(0),
(ext_state_horizontal), (0));
(EXT_STATE_HORIZONTAL));
var area1 = imageMapHyperlinkAcc.firstChild;
ok(area1, "no children in image map acc!");
var area1HL;
try {
area1HL =
area1.QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
} catch (e) {
ok(area1HL, "no interface for first child of Image Map!");
}
testThis("Area1", area1HL,
Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1,
"b", true, 0, 1);
is(area1HL.getURI(0).spec,
var area1 = getAccessible(imageMapHyperlinkAcc.firstChild,
[nsIAccessibleHyperLink]);
testThis("Area1", area1, ROLE_LINK, 1, "b", true, 0, 1);
is(area1.getURI(0).spec,
"http://www.bbc.co.uk/radio4/atoz/index.shtml#b", "URI wrong!");
testStates("Area1", area1HL,
(state_linked),
(0), (0));
testStates(area1, (STATE_LINKED));
var area2 = area1.nextSibling;
ok(area2, "no next sibling!");
var area2HL;
try {
area2HL =
area2.QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
} catch (e) {
ok(area2HL, "no interface for second child of Image Map!");
}
testThis("Area2", area2HL,
Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1,
"a", true, 1, 2);
is(area2HL.getURI(0).spec,
var area2 = getAccessible(area1.nextSibling,
[nsIAccessibleHyperLink]);
testThis("Area2", area2, ROLE_LINK, 1, "a", true, 1, 2);
is(area2.getURI(0).spec,
"http://www.bbc.co.uk/radio4/atoz/index.shtml#a", "URI wrong!");
testStates("Area2", area2HL,
(state_linked),
(0), (0));
testStates(area2, (STATE_LINKED));
//////////////////////////////////////////////////////////////////////////
// empty hyperlink
var emptyLinkElement = document.getElementById("emptyLink");
var EmptyHLAcc;
try {
EmptyHLAcc =
gAccRetrieval.getAccessibleFor(emptyLinkElement).
QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
} catch (e) {
ok(EmptyHLAcc, "no interface for empty link!");
}
testThis("emptyLink", EmptyHLAcc,
Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1,
null, true, 98, 99);
testStates("emptyLink", EmptyHLAcc,
(state_focusable | state_linked),
(ext_state_horizontal), (0));
var EmptyHLAcc = getAccessible("emptyLink",
[nsIAccessibleHyperLink]);
testThis("emptyLink", EmptyHLAcc, ROLE_LINK, 1, null, true, 98, 99);
testStates(EmptyHLAcc,
(STATE_FOCUSABLE | STATE_LINKED),
(EXT_STATE_HORIZONTAL));
testAction("emptyLink", EmptyHLAcc, "jump");
//////////////////////////////////////////////////////////////////////////
// normal hyperlink with embedded span
var hyperlinkElementWithSpan = document.getElementById("LinkWithSpan");
var hyperlinkWithSpanAcc;
try {
hyperlinkWithSpanAcc =
gAccRetrieval.getAccessibleFor(hyperlinkElementWithSpan).
QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
} catch(e) {
ok(hyperlinkWithSpanAcc, "no interface for hyperlink with span!");
}
testThis("LinkWithSpan", hyperlinkWithSpanAcc,
Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1,
var hyperlinkWithSpanAcc = getAccessible("LinkWithSpan",
[nsIAccessibleHyperLink]);
testThis("LinkWithSpan", hyperlinkWithSpanAcc, ROLE_LINK, 1,
"Heise Online", true, 124, 125);
is(hyperlinkWithSpanAcc.getURI(0).spec, "http://www.heise.de/",
"URI wrong for hyperlinkElementWithSpan!");
testStates("LinkWithSpan", hyperlinkWithSpanAcc,
(state_focusable | state_linked),
(ext_state_horizontal), (0));
testStates(hyperlinkWithSpanAcc,
(STATE_FOCUSABLE | STATE_LINKED),
(EXT_STATE_HORIZONTAL));
testFocus("LinkWithSpan", hyperlinkWithSpanAcc, false, true);
testStates("LinkWithSpan", hyperlinkWithSpanAcc,
(state_focusable | state_focused | state_linked),
(ext_state_horizontal), (0));
testStates(hyperlinkWithSpanAcc,
(STATE_FOCUSABLE | STATE_FOCUSED | STATE_LINKED),
(EXT_STATE_HORIZONTAL));
testAction("LinkWithSpan", hyperlinkWithSpanAcc, "jump");
//////////////////////////////////////////////////////////////////////////
// Named anchor, should never have state_linked
var namedAnchorElement = document.getElementById("namedAnchor");
var namedAnchorAcc;
try {
namedAnchorAcc = gAccRetrieval.getAccessibleFor(namedAnchorElement).
QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
} catch(e) {
ok(namedAnchorAcc, "no interface for named anchor!");
}
testThis("namedAnchor", namedAnchorAcc,
Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1,
var namedAnchorAcc = getAccessible("namedAnchor",
[nsIAccessibleHyperLink]);
testThis("namedAnchor", namedAnchorAcc, ROLE_LINK, 1,
"This should never be of state_linked", true, 202, 203);
testStates("namedAnchor", namedAnchorAcc,
(state_selectable),
(ext_state_horizontal), (state_focusable | state_linked));
testStates(namedAnchorAcc,
(STATE_SELECTABLE),
(EXT_STATE_HORIZONTAL), (STATE_FOCUSABLE | STATE_LINKED));
testAction("namedAnchor", namedAnchorAcc, "");
//////////////////////////////////////////////////////////////////////////
// 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,
var noLinkAcc = getAccessible("noLink",
[nsIAccessibleHyperLink]);
testThis("noLink", noLinkAcc, ROLE_LINK, 1,
"This should never be of state_linked", true, 262, 263);
testStates("noLink", noLinkAcc,
testStates(noLinkAcc,
0,
(ext_state_horizontal), (state_focusable | state_linked));
(EXT_STATE_HORIZONTAL), (STATE_FOCUSABLE | STATE_LINKED));
testAction("noLink", noLinkAcc, "");
//////////////////////////////////////////////////////////////////////////
// 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,
var linkWithClickAcc = getAccessible("linkWithClick",
[nsIAccessibleHyperLink]);
testThis("linkWithClick", linkWithClickAcc, ROLE_LINK, 1,
"This should have state_linked", true, 301, 302);
testStates("linkWithClick", linkWithClickAcc,
(state_linked),
(ext_state_horizontal), 0);
testStates(linkWithClickAcc,
(STATE_LINKED),
(EXT_STATE_HORIZONTAL));
testAction("linkWithClick", linkWithClickAcc, "click");
//////////////////////////////////////////////////////////////////////////
// Maps to group links (bug 431615).
var linksMapElement = document.getElementById("linksmap");
var linksMapAcc;
try {
linksMapAcc = gAccRetrieval.getAccessibleFor(linksMapElement);
} catch(e) { }
ok(linksMapAcc, "no accessible for map grouping links!");
var linksMapAcc = getAccessible("linksmap");
//////////////////////////////////////////////////////////////////////////
// Link with title attribute, no name from the subtree (bug 438325).
var id = "linkWithTitleNoNameFromSubtree";
var linkElement = document.getElementById(id);
var linkAcc;
try {
linkAcc = gAccRetrieval.getAccessibleFor(linkElement).
QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
} catch(e) {
ok(linkAcc, "no interface for link with ID " + id + "!");
}
testThis(id, linkAcc,
Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1,
"Link with title", true, 354, 355);
testStates(id, linkAcc,
(state_linked),
(ext_state_horizontal), 0);
var linkAcc = getAccessible(id, [nsIAccessibleHyperLink]);
testThis(id, linkAcc, ROLE_LINK, 1, "Link with title", true, 354, 355);
testStates(linkAcc,
(STATE_LINKED),
(EXT_STATE_HORIZONTAL));
testAction(id, linkAcc, "jump");
//////////////////////////////////////////////////////////////////////////
// Link with title attribute, name from the subtree - onsreen name
// Link with title attribute, name from the subtree - onscreen name
// (bug 438325).
id = "linkWithTitleNameFromSubtree";
linkElement = document.getElementById(id);
linkAcc;
try {
linkAcc = gAccRetrieval.getAccessibleFor(linkElement).
QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
} catch(e) {
ok(linkAcc, "no interface for link with ID " + id + "!");
}
testThis(id, linkAcc,
Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1,
"the name from subtree", true, 403, 404);
testStates(id, linkAcc,
(state_linked),
(ext_state_horizontal), 0);
linkAcc = getAccessible(id, [nsIAccessibleHyperLink]);
testThis(id, linkAcc, ROLE_LINK, 1, "the name from subtree", true, 403,
404);
testStates(linkAcc,
(STATE_LINKED),
(EXT_STATE_HORIZONTAL));
testAction(id, linkAcc, "jump");
//////////////////////////////////////////////////////////////////////////
// Link with title attribute, name from the nested html:img (bug 438325).
id = "linkWithTitleNameFromImg";
linkElement = document.getElementById(id);
linkAcc;
try {
linkAcc = gAccRetrieval.getAccessibleFor(linkElement).
QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
} catch(e) {
ok(linkAcc, "no interface for link with ID " + id + "!");
}
testThis(id, linkAcc,
Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1,
"The title for link", true, 458, 459);
testStates(id, linkAcc,
(state_linked),
(ext_state_horizontal), 0);
linkAcc = getAccessible(id, [nsIAccessibleHyperLink]);
testThis(id, linkAcc, ROLE_LINK, 1, "The title for link", true, 458,
459);
testStates(linkAcc,
(STATE_LINKED),
(EXT_STATE_HORIZONTAL));
testAction(id, linkAcc, "jump");
//////////////////////////////////////////////////////////////////////////
// Link with label, no name from the subtree (bug 438325).
id = "linkWithLabelNoNameFromSubtree";
linkElement = document.getElementById(id);
linkAcc;
try {
linkAcc = gAccRetrieval.getAccessibleFor(linkElement).
QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
} catch(e) {
ok(linkAcc, "no interface for link with ID " + id + "!");
}
testThis(id, linkAcc,
Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1,
"Link with label and nested image:", true, 462, 463);
testStates(id, linkAcc,
(state_linked),
(ext_state_horizontal), 0);
linkAcc = getAccessible(id, [nsIAccessibleHyperLink]);
testThis(id, linkAcc, ROLE_LINK, 1, "Link with label and nested image:",
true, 462, 463);
testStates(linkAcc,
(STATE_LINKED),
(EXT_STATE_HORIZONTAL));
testAction(id, linkAcc, "jump");
//////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -10,13 +10,21 @@
src="chrome://mochikit/content/MochiKit/packed.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
<script type="application/javascript"
src="chrome://mochikit/content/a11y/accessible/common.js" />
<script type="application/javascript"
src="chrome://mochikit/content/a11y/accessible/role.js" />
<script type="application/javascript"
src="chrome://mochikit/content/a11y/accessible/nsIAccessible_states.js" />
<script type="application/javascript">
<![CDATA[
function testThis(aID, aAcc, aRole, aAnchorCount, aAnchorName, aURI,
aStartIndex, aEndIndex, aValid, aSelectedBefore,
aSelectedAfter)
{
is(aAcc.finalRole, aRole, "Wrong role for ID " + aID + "!");
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 + "!");
@ -33,96 +41,31 @@
+ aID + "!");
}
function testStates(aID, aAcc, aState, aExtraState, aUndesiredState)
{
var state = {}, extraState = {};
aAcc.getState(state, extraState);
is(state.value & aState, aState, "Wrong state bits for " + aID + "!");
is(extraState.value & aExtraState, aExtraState,
"Wrong extra state bits for " + aID + "!");
if (aUndesiredState != 0)
is(state.value & aUndesiredState, 0, "Bits should not be set for "
+ aID +"!");
}
function doTest()
{
// Mapping needed state flags for easier handling.
const state_focusable =
Components.interfaces.nsIAccessibleStates.STATE_FOCUSABLE;
const state_focused =
Components.interfaces.nsIAccessibleStates.STATE_FOCUSED;
const state_selectable =
Components.interfaces.nsIAccessibleStates.STATE_SELECTABLE;
const state_linked =
Components.interfaces.nsIAccessibleStates.STATE_LINKED;
const state_traversed =
Components.interfaces.nsIAccessibleStates.STATE_TRAVERSED;
var linkedLabelAcc = getAccessible("linkedLabel",
[nsIAccessibleHyperLink]);
testThis("linkedLabel", linkedLabelAcc, ROLE_LINK, 1,
"Mozilla Foundation home", "http://www.mozilla.org/", 1, 2,
true, false, true);
testStates(linkedLabelAcc,
(STATE_FOCUSABLE | STATE_LINKED),
(EXT_STATE_HORIZONTAL));
const ext_state_multi_line =
Components.interfaces.nsIAccessibleStates.EXT_STATE_MULTI_LINE;
const ext_state_horizontal =
Components.interfaces.nsIAccessibleStates.EXT_STATE_HORIZONTAL;
const ext_state_required =
Components.interfaces.nsIAccessibleStates.STATE_REQUIRED;
const ext_state_invalid =
Components.interfaces.nsIAccessibleStates.STATE_INVALID;
// Activate accessibility.
var accRetrieval = Components.classes["@mozilla.org/accessibleRetrieval;1"].
getService(Components.interfaces.nsIAccessibleRetrieval);
var linkLabelElement = document.getElementById("linkedLabel");
var linkedLabelAcc;
try {
linkedLabelAcc = accRetrieval.getAccessibleFor(linkLabelElement).
QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
} catch(e) {
ok(linkedLabelAcc, "no interface for linked label!");
}
testThis("linkedLabel", linkedLabelAcc,
Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1,
"Mozilla Foundation home", "http://www.mozilla.org/", 1, 2, true,
false, true);
testStates("linkedLabel", linkedLabelAcc,
(state_focusable | state_linked),
(ext_state_horizontal), 0);
var labelElementWithValue = document.getElementById("linkLabelWithValue");
var labelWithValueAcc;
try {
labelWithValueAcc = accRetrieval.getAccessibleFor(labelElementWithValue).
QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
} catch(e) {
ok(labelWithValueAcc, "no interface for linked label with value!");
}
testThis("linkLabelWithValue", labelWithValueAcc,
Components.interfaces.nsIAccessibleRole.ROLE_LINK, 1,
var labelWithValueAcc = getAccessible("linkLabelWithValue",
[nsIAccessibleHyperLink]);
testThis("linkLabelWithValue", labelWithValueAcc, ROLE_LINK, 1,
"Mozilla Foundation", "http://www.mozilla.org/", 2, 3, true,
false, true);
testStates("linkLabelWithValue", labelWithValueAcc,
(state_focusable | state_linked),
(ext_state_horizontal), 0);
testStates(labelWithValueAcc,
(STATE_FOCUSABLE | STATE_LINKED),
(EXT_STATE_HORIZONTAL));
var NormalLabelElement = document.getElementById("normalLabel");
var normalLabelAcc;
try {
normalLabelAcc = accRetrieval.getAccessibleFor(NormalLabelElement);
} catch(e) {
}
ok(normalLabelAcc, "no accessible for normalLabel!");
if (normalLabelAcc) {
is(normalLabelAcc.finalRole,
Components.interfaces.nsIAccessibleRole.ROLE_LABEL,
"Wrong role!");
is(normalLabelAcc.name, "This label should not be a link",
"Wrong name for normal label!");
var stateNormal = {}, extraStateNormal = {};
normalLabelAcc.getState(stateNormal, extraStateNormal);
undesiredState = (state_focusable | state_linked);
is(stateNormal.value & undesiredState, 0, "Wrong state bits for normal label!");
}
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);
SimpleTest.finish();
}