michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // Role constants michael@0: michael@0: const ROLE_ALERT = nsIAccessibleRole.ROLE_ALERT; michael@0: const ROLE_ANIMATION = nsIAccessibleRole.ROLE_ANIMATION; michael@0: const ROLE_APPLICATION = nsIAccessibleRole.ROLE_APPLICATION; michael@0: const ROLE_APP_ROOT = nsIAccessibleRole.ROLE_APP_ROOT; michael@0: const ROLE_AUTOCOMPLETE = nsIAccessibleRole.ROLE_AUTOCOMPLETE; michael@0: const ROLE_BUTTONDROPDOWNGRID = nsIAccessibleRole.ROLE_BUTTONDROPDOWNGRID; michael@0: const ROLE_CANVAS = nsIAccessibleRole.ROLE_CANVAS; michael@0: const ROLE_CAPTION = nsIAccessibleRole.ROLE_CAPTION; michael@0: const ROLE_CELL = nsIAccessibleRole.ROLE_CELL; michael@0: const ROLE_CHECKBUTTON = nsIAccessibleRole.ROLE_CHECKBUTTON; michael@0: const ROLE_CHECK_MENU_ITEM = nsIAccessibleRole.ROLE_CHECK_MENU_ITEM; michael@0: const ROLE_CHROME_WINDOW = nsIAccessibleRole.ROLE_CHROME_WINDOW; michael@0: const ROLE_COMBOBOX = nsIAccessibleRole.ROLE_COMBOBOX; michael@0: const ROLE_COMBOBOX_LIST = nsIAccessibleRole.ROLE_COMBOBOX_LIST; michael@0: const ROLE_COMBOBOX_OPTION = nsIAccessibleRole.ROLE_COMBOBOX_OPTION; michael@0: const ROLE_COLUMNHEADER = nsIAccessibleRole.ROLE_COLUMNHEADER; michael@0: const ROLE_DEFINITION = nsIAccessibleRole.ROLE_DEFINITION; michael@0: const ROLE_DEFINITION_LIST = nsIAccessibleRole.ROLE_DEFINITION_LIST; michael@0: const ROLE_DIAGRAM = nsIAccessibleRole.ROLE_DIAGRAM; michael@0: const ROLE_DIALOG = nsIAccessibleRole.ROLE_DIALOG; michael@0: const ROLE_DOCUMENT = nsIAccessibleRole.ROLE_DOCUMENT; michael@0: const ROLE_EMBEDDED_OBJECT = nsIAccessibleRole.ROLE_EMBEDDED_OBJECT; michael@0: const ROLE_ENTRY = nsIAccessibleRole.ROLE_ENTRY; michael@0: const ROLE_EQUATION = nsIAccessibleRole.ROLE_EQUATION; michael@0: const ROLE_FIGURE = nsIAccessibleRole.ROLE_FIGURE; michael@0: const ROLE_FOOTER = nsIAccessibleRole.ROLE_FOOTER; michael@0: const ROLE_FLAT_EQUATION = nsIAccessibleRole.ROLE_FLAT_EQUATION; michael@0: const ROLE_FORM = nsIAccessibleRole.ROLE_FORM; michael@0: const ROLE_GRAPHIC = nsIAccessibleRole.ROLE_GRAPHIC; michael@0: const ROLE_GRID_CELL = nsIAccessibleRole.ROLE_GRID_CELL; michael@0: const ROLE_GROUPING = nsIAccessibleRole.ROLE_GROUPING; michael@0: const ROLE_HEADER = nsIAccessibleRole.ROLE_HEADER; michael@0: const ROLE_HEADING = nsIAccessibleRole.ROLE_HEADING; michael@0: const ROLE_IMAGE_MAP = nsIAccessibleRole.ROLE_IMAGE_MAP; michael@0: const ROLE_INTERNAL_FRAME = nsIAccessibleRole.ROLE_INTERNAL_FRAME; michael@0: const ROLE_LABEL = nsIAccessibleRole.ROLE_LABEL; michael@0: const ROLE_LINK = nsIAccessibleRole.ROLE_LINK; michael@0: const ROLE_LIST = nsIAccessibleRole.ROLE_LIST; michael@0: const ROLE_LISTBOX = nsIAccessibleRole.ROLE_LISTBOX; michael@0: const ROLE_LISTITEM = nsIAccessibleRole.ROLE_LISTITEM; michael@0: const ROLE_MENUBAR = nsIAccessibleRole.ROLE_MENUBAR; michael@0: const ROLE_MENUITEM = nsIAccessibleRole.ROLE_MENUITEM; michael@0: const ROLE_MENUPOPUP = nsIAccessibleRole.ROLE_MENUPOPUP; michael@0: const ROLE_NOTHING = nsIAccessibleRole.ROLE_NOTHING; michael@0: const ROLE_NOTE = nsIAccessibleRole.ROLE_NOTE; michael@0: const ROLE_OPTION = nsIAccessibleRole.ROLE_OPTION; michael@0: const ROLE_OUTLINE = nsIAccessibleRole.ROLE_OUTLINE; michael@0: const ROLE_OUTLINEITEM = nsIAccessibleRole.ROLE_OUTLINEITEM; michael@0: const ROLE_PAGETAB = nsIAccessibleRole.ROLE_PAGETAB; michael@0: const ROLE_PAGETABLIST = nsIAccessibleRole.ROLE_PAGETABLIST; michael@0: const ROLE_PANE = nsIAccessibleRole.ROLE_PANE; michael@0: const ROLE_PARAGRAPH = nsIAccessibleRole.ROLE_PARAGRAPH; michael@0: const ROLE_PARENT_MENUITEM = nsIAccessibleRole.ROLE_PARENT_MENUITEM; michael@0: const ROLE_PASSWORD_TEXT = nsIAccessibleRole.ROLE_PASSWORD_TEXT; michael@0: const ROLE_PROGRESSBAR = nsIAccessibleRole.ROLE_PROGRESSBAR; michael@0: const ROLE_PROPERTYPAGE = nsIAccessibleRole.ROLE_PROPERTYPAGE; michael@0: const ROLE_PUSHBUTTON = nsIAccessibleRole.ROLE_PUSHBUTTON; michael@0: const ROLE_RADIOBUTTON = nsIAccessibleRole.ROLE_RADIOBUTTON; michael@0: const ROLE_RADIO_MENU_ITEM = nsIAccessibleRole.ROLE_RADIO_MENU_ITEM; michael@0: const ROLE_RICH_OPTION = nsIAccessibleRole.ROLE_RICH_OPTION; michael@0: const ROLE_ROW = nsIAccessibleRole.ROLE_ROW; michael@0: const ROLE_ROWHEADER = nsIAccessibleRole.ROLE_ROWHEADER; michael@0: const ROLE_SCROLLBAR = nsIAccessibleRole.ROLE_SCROLLBAR; michael@0: const ROLE_SECTION = nsIAccessibleRole.ROLE_SECTION; michael@0: const ROLE_SEPARATOR = nsIAccessibleRole.ROLE_SEPARATOR; michael@0: const ROLE_SLIDER = nsIAccessibleRole.ROLE_SLIDER; michael@0: const ROLE_SPINBUTTON = nsIAccessibleRole.ROLE_SPINBUTTON; michael@0: const ROLE_STATICTEXT = nsIAccessibleRole.ROLE_STATICTEXT; michael@0: const ROLE_STATUSBAR = nsIAccessibleRole.ROLE_STATUSBAR; michael@0: const ROLE_TABLE = nsIAccessibleRole.ROLE_TABLE; michael@0: const ROLE_TERM = nsIAccessibleRole.ROLE_TERM; michael@0: const ROLE_TEXT_CONTAINER = nsIAccessibleRole.ROLE_TEXT_CONTAINER; michael@0: const ROLE_TEXT_LEAF = nsIAccessibleRole.ROLE_TEXT_LEAF; michael@0: const ROLE_TOGGLE_BUTTON = nsIAccessibleRole.ROLE_TOGGLE_BUTTON; michael@0: const ROLE_TOOLBAR = nsIAccessibleRole.ROLE_TOOLBAR; michael@0: const ROLE_TOOLTIP = nsIAccessibleRole.ROLE_TOOLTIP; michael@0: const ROLE_TREE_TABLE = nsIAccessibleRole.ROLE_TREE_TABLE; michael@0: const ROLE_WHITESPACE = nsIAccessibleRole.ROLE_WHITESPACE; michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // Public methods michael@0: michael@0: /** michael@0: * Test that the role of the given accessible is the role passed in. michael@0: * michael@0: * @param aAccOrElmOrID the accessible, DOM element or ID to be tested. michael@0: * @param aRole The role that is to be expected. michael@0: */ michael@0: function testRole(aAccOrElmOrID, aRole) michael@0: { michael@0: var role = getRole(aAccOrElmOrID); michael@0: is(role, aRole, "Wrong role for " + prettyName(aAccOrElmOrID) + "!"); michael@0: } michael@0: michael@0: /** michael@0: * Return the role of the given accessible. Return -1 if accessible could not michael@0: * be retrieved. michael@0: * michael@0: * @param aAccOrElmOrID [in] The accessible, DOM element or element ID the michael@0: * accessible role is being requested for. michael@0: */ michael@0: function getRole(aAccOrElmOrID) michael@0: { michael@0: var acc = getAccessible(aAccOrElmOrID); michael@0: if (!acc) michael@0: return -1; michael@0: michael@0: var role = -1; michael@0: try { michael@0: role = acc.role; michael@0: } catch(e) { michael@0: ok(false, "Role for " + aAccOrElmOrID + " could not be retrieved!"); michael@0: } michael@0: michael@0: return role; michael@0: } michael@0: michael@0: /** michael@0: * Analogy of SimpleTest.is function used to check the role. michael@0: */ michael@0: function isRole(aIdentifier, aRole, aMsg) michael@0: { michael@0: var role = getRole(aIdentifier); michael@0: if (role == - 1) michael@0: return; michael@0: michael@0: if (role == aRole) { michael@0: ok(true, aMsg); michael@0: return; michael@0: } michael@0: michael@0: var got = roleToString(role); michael@0: var expected = roleToString(aRole); michael@0: michael@0: ok(false, aMsg + "got '" + got + "', expected '" + expected + "'"); michael@0: }