2 <?xml-stylesheet href=
"chrome://global/skin" type=
"text/css"?>
3 <?xml-stylesheet href=
"chrome://mochikit/content/tests/SimpleTest/test.css"
6 <window xmlns=
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
7 title=
"test for nsIAccessibleHyperLink interface on XUL:label elements">
9 <script type=
"application/javascript"
10 src=
"chrome://mochikit/content/MochiKit/packed.js"></script>
11 <script type=
"application/javascript"
12 src=
"chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
13 <script type=
"application/javascript">
15 function testThis(aID, aAcc, aRole, aAnchorCount, aAnchorName, aURI,
16 aStartIndex, aEndIndex, aValid, aSelectedBefore,
19 is(aAcc.finalRole, aRole,
"Wrong role for ID " + aID +
"!");
20 is(aAcc.anchorCount, aAnchorCount,
"Wrong number of anchors for ID "
22 is(aAcc.getAnchor(
0).name, aAnchorName,
"Wrong name for ID " + aID +
"!");
23 is(aAcc.getURI(
0).spec, aURI,
"URI wrong for ID " + aID +
"!");
24 is(aAcc.startIndex, aStartIndex,
"Wrong startIndex value for ID " + aID
26 is(aAcc.endIndex, aEndIndex,
"Wrong endIndex value for ID " + aID +
"!");
27 is(aAcc.valid, aValid,
"Wrong valid state for ID " + aID +
"!");
29 is(aAcc.selected, aSelectedBefore,
"Wrong focused state before focus for "
31 document.getElementById(aID).focus();
32 is(aAcc.selected, aSelectedAfter,
"Wrong selected state after focus for "
36 function testStates(aID, aAcc, aState, aExtraState, aUndesiredState)
38 var state = {}, extraState = {};
39 aAcc.getFinalState(state, extraState);
40 is(state.value & aState, aState,
"Wrong state bits for " + aID +
"!");
41 is(extraState.value & aExtraState, aExtraState,
42 "Wrong extra state bits for " + aID +
"!");
43 if (aUndesiredState !=
0)
44 is(state.value & aUndesiredState,
0,
"Bits should not be set for "
50 // Mapping needed state flags for easier handling.
51 const state_focusable =
52 Components.interfaces.nsIAccessibleStates.STATE_FOCUSABLE;
54 Components.interfaces.nsIAccessibleStates.STATE_FOCUSED;
55 const state_selectable =
56 Components.interfaces.nsIAccessibleStates.STATE_SELECTABLE;
58 Components.interfaces.nsIAccessibleStates.STATE_LINKED;
59 const state_traversed =
60 Components.interfaces.nsIAccessibleStates.STATE_TRAVERSED;
62 const ext_state_multi_line =
63 Components.interfaces.nsIAccessibleStates.EXT_STATE_MULTI_LINE;
64 const ext_state_horizontal =
65 Components.interfaces.nsIAccessibleStates.EXT_STATE_HORIZONTAL;
66 const ext_state_required =
67 Components.interfaces.nsIAccessibleStates.STATE_REQUIRED;
68 const ext_state_invalid =
69 Components.interfaces.nsIAccessibleStates.STATE_INVALID;
71 // Activate accessibility.
72 var accRetrieval = Components.classes[
"@mozilla.org/accessibleRetrieval;1"].
73 getService(Components.interfaces.nsIAccessibleRetrieval);
75 var linkLabelElement = document.getElementById(
"linkedLabel");
78 linkedLabelAcc = accRetrieval.getAccessibleFor(linkLabelElement).
79 QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
81 ok(linkedLabelAcc,
"no interface for linked label!");
83 testThis(
"linkedLabel", linkedLabelAcc,
84 Components.interfaces.nsIAccessibleRole.ROLE_LINK,
1,
85 "Mozilla Foundation home",
"http://www.mozilla.org/",
1,
2, true,
87 testStates(
"linkedLabel", linkedLabelAcc,
88 (state_focusable | state_linked),
89 (ext_state_horizontal),
0);
91 var labelElementWithValue = document.getElementById(
"linkLabelWithValue");
92 var labelWithValueAcc;
94 labelWithValueAcc = accRetrieval.getAccessibleFor(labelElementWithValue).
95 QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
97 ok(labelWithValueAcc,
"no interface for linked label with value!");
99 testThis(
"linkLabelWithValue", labelWithValueAcc,
100 Components.interfaces.nsIAccessibleRole.ROLE_LINK,
1,
101 "Mozilla Foundation",
"http://www.mozilla.org/",
2,
3, true,
103 testStates(
"linkLabelWithValue", labelWithValueAcc,
104 (state_focusable | state_linked),
105 (ext_state_horizontal),
0);
107 var NormalLabelElement = document.getElementById(
"normalLabel");
110 normalLabelAcc = accRetrieval.getAccessibleFor(NormalLabelElement);
113 ok(normalLabelAcc,
"no accessible for normalLabel!");
114 if (normalLabelAcc) {
115 is(normalLabelAcc.finalRole,
116 Components.interfaces.nsIAccessibleRole.ROLE_LABEL,
118 is(normalLabelAcc.name,
"This label should not be a link",
119 "Wrong name for normal label!");
121 var stateNormal = {}, extraStateNormal = {};
122 normalLabelAcc.getFinalState(stateNormal, extraStateNormal);
123 undesiredState = (state_focusable | state_linked);
124 is(stateNormal.value & undesiredState,
0,
"Wrong state bits for normal label!");
130 SimpleTest.waitForExplicitFinish();
131 addLoadEvent(doTest);
135 <body xmlns=
"http://www.w3.org/1999/xhtml">
137 href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=421066"
138 title=
"Implement Mochitests for the nsIAccessibleHyperLink interface on XUL:label elements">
142 <div id=
"content" style=
"display: none">
148 <label id=
"linkedLabel" class=
"text-link" href=
"http://www.mozilla.org/">
149 Mozilla Foundation home
</label>
150 <label id=
"linkLabelWithValue" value=
"Mozilla Foundation" class=
"text-link"
151 href=
"http://www.mozilla.org/" />
152 <label id=
"normalLabel" value=
"This label should not be a link" />