Backed out changeset db55605b2a4c (relanding bug 121341)
[wine-gecko.git] / accessible / tests / mochitest / testTextboxes.js
blob41263b34ec1d93041c74d71e328ae70ce4b82bd7
1 const nsIAccessibleRetrieval = Components.interfaces.nsIAccessibleRetrieval;
3 // Mapping needed state flags for easier handling.
4 const state_focusable =
5 Components.interfaces.nsIAccessibleStates.STATE_FOCUSABLE;
6 const state_focused =
7 Components.interfaces.nsIAccessibleStates.STATE_FOCUSED;
8 const state_readonly =
9 Components.interfaces.nsIAccessibleStates.STATE_READONLY;
11 const ext_state_multi_line =
12 Components.interfaces.nsIAccessibleStates.EXT_STATE_MULTI_LINE;
13 const ext_state_editable =
14 Components.interfaces.nsIAccessibleStates.EXT_STATE_EDITABLE;
15 const ext_state_required =
16 Components.interfaces.nsIAccessibleStates.STATE_REQUIRED;
17 const ext_state_invalid =
18 Components.interfaces.nsIAccessibleStates.STATE_INVALID;
20 // Mapping needed final roles
21 const role_entry = Components.interfaces.nsIAccessibleRole.ROLE_ENTRY;
22 const role_password_text =
23 Components.interfaces.nsIAccessibleRole.ROLE_PASSWORD_TEXT;
25 var gAccRetrieval = null;
27 function testValue(aID, aAcc, aValue, aRole)
29 if (aRole == role_password_text) {
30 var value;
31 try {
32 value = aAcc.value;
33 do_throw("We do not want a value on " + aID + "!");
34 } catch(e) {
35 is(e.result, Components.results.NS_ERROR_FAILURE,
36 "Wrong return value for getValue on " + aID + "!");
38 } else
39 is(aAcc.value, aValue, "Wrong value for " + aID + "!");
42 function testStates(aID, aAcc, aState, aExtraState, aAbsentState)
44 var state = {}, extraState = {};
45 aAcc.getFinalState(state, extraState);
46 is(state.value & aState, aState, "wrong state bits for " + aID + "!");
47 is(extraState.value & aExtraState, aExtraState,
48 "wrong extraState bits for " + aID + "!");
49 if (aAbsentState != 0)
50 is(state.value & aAbsentState, 0, "state bits should not be present in ID "
51 + aID + "!");
52 if (state.value & state_readonly)
53 // if state is readonly, ext state must not be ext_state_editable.
54 is(extraState.value & ext_state_editable, 0,
55 "Read-only " + aID + " cannot be editable!");
58 function testAction(aID, aAcc, aNumActions, aActionName, aActionDescription)
60 var numActions = aAcc.numActions;
61 is(numActions, aNumActions, "Wrong number of actions for " + aID + "!");
63 if (numActions != 0) {
64 // Test first action. Normally only 1 should be present.
65 is(aAcc.getActionName(0), aActionName,
66 "Wrong name of action for " + aID + "!");
67 is(aAcc.getActionDescription(0), aActionDescription,
68 "Wrong description of action for " + aID + "!");
72 function testThis(aID, aName, aValue, aDescription, aRole, aState,
73 aExtraState, aAbsentState, aNumActions, aActionName,
74 aActionDescription)
76 var elem = document.getElementById(aID);
77 var acc = null;
78 try {
79 acc = gAccRetrieval.getAccessibleFor(elem);
80 } catch(e) {}
81 ok(acc, "No accessible for " + aID + "!");
83 if (acc) {
84 is(acc.name, aName, "Wrong name for " + aID + "!");
85 testValue(aID, acc, aValue, aRole);
86 is(acc.description, aDescription, "Wrong description for " + aID + "!");
87 is(acc.role, aRole, "Wrong role for " + aID + "!");
89 testStates(aID, acc, aState, aExtraState, aAbsentState);
91 testAction(aID, acc, aNumActions, aActionName, aActionDescription);