Backed out changeset db55605b2a4c (relanding bug 121341)
[wine-gecko.git] / accessible / tests / mochitest / test_nsIAccessibleHyperLink.xul
blob44c809127ca9b7c939a2aa28015feccad896506b
1 <?xml version="1.0"?>
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
4 type="text/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">
14 <![CDATA[
15 function testThis(aID, aAcc, aRole, aAnchorCount, aAnchorName, aURI,
16 aStartIndex, aEndIndex, aValid, aSelectedBefore,
17 aSelectedAfter)
19 is(aAcc.finalRole, aRole, "Wrong role for ID " + aID + "!");
20 is(aAcc.anchorCount, aAnchorCount, "Wrong number of anchors for ID "
21 + aID + "!");
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
25 + "!");
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 "
30 + aID + "!");
31 document.getElementById(aID).focus();
32 is(aAcc.selected, aSelectedAfter, "Wrong selected state after focus for "
33 + aID + "!");
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 "
45 + aID +"!");
48 function doTest()
50 // Mapping needed state flags for easier handling.
51 const state_focusable =
52 Components.interfaces.nsIAccessibleStates.STATE_FOCUSABLE;
53 const state_focused =
54 Components.interfaces.nsIAccessibleStates.STATE_FOCUSED;
55 const state_selectable =
56 Components.interfaces.nsIAccessibleStates.STATE_SELECTABLE;
57 const state_linked =
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");
76 var linkedLabelAcc;
77 try {
78 linkedLabelAcc = accRetrieval.getAccessibleFor(linkLabelElement).
79 QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
80 } catch(e) {
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,
86 false, true);
87 testStates("linkedLabel", linkedLabelAcc,
88 (state_focusable | state_linked),
89 (ext_state_horizontal), 0);
91 var labelElementWithValue = document.getElementById("linkLabelWithValue");
92 var labelWithValueAcc;
93 try {
94 labelWithValueAcc = accRetrieval.getAccessibleFor(labelElementWithValue).
95 QueryInterface(Components.interfaces.nsIAccessibleHyperLink);
96 } catch(e) {
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,
102 false, true);
103 testStates("linkLabelWithValue", labelWithValueAcc,
104 (state_focusable | state_linked),
105 (ext_state_horizontal), 0);
107 var NormalLabelElement = document.getElementById("normalLabel");
108 var normalLabelAcc;
109 try {
110 normalLabelAcc = accRetrieval.getAccessibleFor(NormalLabelElement);
111 } catch(e) {
113 ok(normalLabelAcc, "no accessible for normalLabel!");
114 if (normalLabelAcc) {
115 is(normalLabelAcc.finalRole,
116 Components.interfaces.nsIAccessibleRole.ROLE_LABEL,
117 "Wrong role!");
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!");
127 SimpleTest.finish();
130 SimpleTest.waitForExplicitFinish();
131 addLoadEvent(doTest);
133 </script>
135 <body xmlns="http://www.w3.org/1999/xhtml">
136 <a target="_blank"
137 href="https://bugzilla.mozilla.org/show_bug.cgi?id=421066"
138 title="Implement Mochitests for the nsIAccessibleHyperLink interface on XUL:label elements">
139 Mozilla Bug 421066
140 </a>
141 <p id="display"></p>
142 <div id="content" style="display: none">
143 </div>
144 <pre id="test">
145 </pre>
146 </body>
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" />
153 </window>