Bug 482013 - use role.js instead of explicit .role and .finalRole calls, r=marcoz

This commit is contained in:
Alexander Surkov 2009-03-07 19:23:25 +08:00
Родитель 1eb9c6e1e4
Коммит a6a943ae6c
17 изменённых файлов: 103 добавлений и 114 удалений

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

@ -44,39 +44,6 @@ const nsIDOMWindow = Components.interfaces.nsIDOMWindow;
const nsIPropertyElement = Components.interfaces.nsIPropertyElement;
////////////////////////////////////////////////////////////////////////////////
// Roles
const ROLE_ALERT = nsIAccessibleRole.ROLE_ALERT;
const ROLE_PUSHBUTTON = nsIAccessibleRole.ROLE_PUSHBUTTON;
const ROLE_CELL = nsIAccessibleRole.ROLE_CELL;
const ROLE_CHROME_WINDOW = nsIAccessibleRole.ROLE_CHROME_WINDOW;
const ROLE_COMBOBOX = nsIAccessibleRole.ROLE_COMBOBOX;
const ROLE_COMBOBOX_LIST = nsIAccessibleRole.ROLE_COMBOBOX_LIST;
const ROLE_COMBOBOX_OPTION = nsIAccessibleRole.ROLE_COMBOBOX_OPTION;
const ROLE_DOCUMENT = nsIAccessibleRole.ROLE_DOCUMENT;
const ROLE_ENTRY = nsIAccessibleRole.ROLE_ENTRY;
const ROLE_FLAT_EQUATION = nsIAccessibleRole.ROLE_FLAT_EQUATION;
const ROLE_FORM = nsIAccessibleRole.ROLE_FORM;
const ROLE_GRAPHIC = nsIAccessibleRole.ROLE_GRAPHIC;
const ROLE_GRID_CELL = nsIAccessibleRole.ROLE_GRID_CELL;
const ROLE_GROUPING = nsIAccessibleRole.ROLE_GROUPING;
const ROLE_HEADING = nsIAccessibleRole.ROLE_HEADING;
const ROLE_IMAGE_MAP = nsIAccessibleRole.ROLE_IMAGE_MAP;
const ROLE_INTERNAL_FRAME = nsIAccessibleRole.ROLE_INTERNAL_FRAME;
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;
const ROLE_PARAGRAPH = nsIAccessibleRole.ROLE_PARAGRAPH;
const ROLE_PASSWORD_TEXT = nsIAccessibleRole.ROLE_PASSWORD_TEXT;
const ROLE_SECTION = nsIAccessibleRole.ROLE_SECTION;
const ROLE_TABLE = nsIAccessibleRole.ROLE_TABLE;
const ROLE_TEXT_CONTAINER = nsIAccessibleRole.ROLE_TEXT_CONTAINER;
const ROLE_TEXT_LEAF = nsIAccessibleRole.ROLE_TEXT_LEAF;
const ROLE_TOGGLE_BUTTON = nsIAccessibleRole.ROLE_TOGGLE_BUTTON;
////////////////////////////////////////////////////////////////////////////////
// States

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

@ -55,7 +55,7 @@ function testThis(aID, aAcc, aNames, aRoles, aStates, aUndesiredStates, aIndex)
is(aAcc.name, aNames[aIndex],
"wrong name for " + aID + " at index " + aIndex + "!");
var role = aAcc.role;
var role = getRole(aAcc);
is(role, aRoles[aIndex],
"Wrong role for " + aID + " at index " + aIndex + "!");
testStates(aID, aAcc, aStates, aUndesiredStates, aIndex);

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

@ -73,7 +73,7 @@ function testStatesInSubtree(aAccOrElmOrID, aState, aExtraState, aAbsentState)
if (!acc)
return;
if (acc.finalRole != ROLE_TEXT_LEAF)
if (getRole(acc) != ROLE_TEXT_LEAF)
// Right now, text leafs don't get tested because the states are not being
// propagated.
testStates(acc, aState, aExtraState, aAbsentState);

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

@ -1,3 +1,52 @@
////////////////////////////////////////////////////////////////////////////////
// Role constants
const ROLE_ALERT = nsIAccessibleRole.ROLE_ALERT;
const ROLE_PUSHBUTTON = nsIAccessibleRole.ROLE_PUSHBUTTON;
const ROLE_CELL = nsIAccessibleRole.ROLE_CELL;
const ROLE_CHROME_WINDOW = nsIAccessibleRole.ROLE_CHROME_WINDOW;
const ROLE_COMBOBOX = nsIAccessibleRole.ROLE_COMBOBOX;
const ROLE_COMBOBOX_LIST = nsIAccessibleRole.ROLE_COMBOBOX_LIST;
const ROLE_COMBOBOX_OPTION = nsIAccessibleRole.ROLE_COMBOBOX_OPTION;
const ROLE_DOCUMENT = nsIAccessibleRole.ROLE_DOCUMENT;
const ROLE_ENTRY = nsIAccessibleRole.ROLE_ENTRY;
const ROLE_FLAT_EQUATION = nsIAccessibleRole.ROLE_FLAT_EQUATION;
const ROLE_FORM = nsIAccessibleRole.ROLE_FORM;
const ROLE_GRAPHIC = nsIAccessibleRole.ROLE_GRAPHIC;
const ROLE_GRID_CELL = nsIAccessibleRole.ROLE_GRID_CELL;
const ROLE_GROUPING = nsIAccessibleRole.ROLE_GROUPING;
const ROLE_HEADING = nsIAccessibleRole.ROLE_HEADING;
const ROLE_IMAGE_MAP = nsIAccessibleRole.ROLE_IMAGE_MAP;
const ROLE_INTERNAL_FRAME = nsIAccessibleRole.ROLE_INTERNAL_FRAME;
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_NOTHING = nsIAccessibleRole.ROLE_NOTHING;
const ROLE_OPTION = nsIAccessibleRole.ROLE_OPTION;
const ROLE_PARAGRAPH = nsIAccessibleRole.ROLE_PARAGRAPH;
const ROLE_PASSWORD_TEXT = nsIAccessibleRole.ROLE_PASSWORD_TEXT;
const ROLE_SECTION = nsIAccessibleRole.ROLE_SECTION;
const ROLE_TABLE = nsIAccessibleRole.ROLE_TABLE;
const ROLE_TEXT_CONTAINER = nsIAccessibleRole.ROLE_TEXT_CONTAINER;
const ROLE_TEXT_LEAF = nsIAccessibleRole.ROLE_TEXT_LEAF;
const ROLE_TOGGLE_BUTTON = nsIAccessibleRole.ROLE_TOGGLE_BUTTON;
////////////////////////////////////////////////////////////////////////////////
// Public methods
/**
* Test that the role of the given accessible is the role passed in.
*
* @param aAccOrElmOrID the accessible, DOM element or ID to be tested.
* @param aRole The role that is to be expected.
*/
function testRole(aAccOrElmOrID, aRole)
{
var role = getRole(aAccOrElmOrID);
is(role, aRole, "Wrong role for " + prettyName(aAccOrElmOrID) + "!");
}
/**
* Return the role of the given accessible. Return -1 if accessible could not
* be retrieved.
@ -20,15 +69,3 @@ function getRole(aAccOrElmOrID)
return role;
}
/**
* Test that the role of the given accessible is the role passed in.
*
* @param aAccOrElmOrID the accessible, DOM element or ID to be tested.
* @param aRole The role that is to be expected.
*/
function testRole(aAccOrElmOrID, aRole)
{
var role = getRole(aAccOrElmOrID);
is(role, aRole, "Wrong role for " + aAccOrElmOrID + "!");
}

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

@ -38,7 +38,7 @@ function testThis(aID, aName, aValue, aDescription, aRole, aState,
is(acc.name, aName, "Wrong name for " + aID + "!");
testValue(aID, acc, aValue, aRole);
is(acc.description, aDescription, "Wrong description for " + aID + "!");
is(acc.role, aRole, "Wrong role for " + aID + "!");
testRole(aID, aRole);
testStates(acc, aState, aExtraState, aAbsentState);

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

@ -14,17 +14,18 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=429666
<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">
function doTest()
{
// Test article exposed as document
testRole("testArticle", ROLE_DOCUMENT);
var articleAcc = getAccessible("testArticle");
if (articleAcc) {
is(articleAcc.finalRole, ROLE_DOCUMENT,
"Wrong role for article!");
if (articleAcc)
is(articleAcc.name, "Test article", "Wrong name for article!");
}
SimpleTest.finish();
}

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

@ -14,16 +14,16 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=428479
<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">
function testThis(aID)
{
getRole(aID, ROLE_FLAT_EQUATION);
var eqAcc = getAccessible(aID);
if (eqAcc) {
is(eqAcc.finalRole, ROLE_FLAT_EQUATION,
"Wrong role for " + aID +"!");
if (eqAcc)
is(eqAcc.name, "x^2 + y^2 + z^2", "Wrong name for " + aID + "!");
}
}
function doTest()

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

@ -14,6 +14,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=452388
<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>
@ -62,21 +64,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=452388
testStates("button_pressed_absent", 0, 0, STATE_PRESSED | STATE_CHECKABLE);
// test aria-pressed state mapping to roles PUSHBUTTON vs TOGGLEBUTTON
var aButton = getAccessible("button_pressed_true");
if (aButton)
is(aButton.finalRole, ROLE_TOGGLE_BUTTON, "Wrong role for togglebutton!");
aButton = getAccessible("button_pressed_false");
if (aButton)
is(aButton.finalRole, ROLE_TOGGLE_BUTTON, "Wrong role for togglebutton!");
aButton = getAccessible("button_pressed_empty");
if (aButton)
is(aButton.finalRole, ROLE_PUSHBUTTON, "Wrong role for button!");
aButton = getAccessible("button_pressed_undefined");
if (aButton)
is(aButton.finalRole, ROLE_PUSHBUTTON, "Wrong role for button!");
aButton = getAccessible("button_pressed_absent");
if (aButton)
is(aButton.finalRole, ROLE_PUSHBUTTON, "Wrong role for button!");
testRole("button_pressed_true", ROLE_TOGGLE_BUTTON);
testRole("button_pressed_false", ROLE_TOGGLE_BUTTON);
testRole("button_pressed_empty", ROLE_PUSHBUTTON);
testRole("button_pressed_undefined", ROLE_PUSHBUTTON);
testRole("button_pressed_absent", ROLE_PUSHBUTTON);
SimpleTest.finish();
}

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

@ -11,6 +11,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=441737
<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>
@ -23,8 +25,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=441737
// nsIAccessible
is(docAcc.name, "nsIAccessibleDocument chrome tests",
"Name for document accessible not correct!");
is(docAcc.role, nsIAccessibleRole.ROLE_DOCUMENT,
"Wrong role for document!");
testRole(docAcc, ROLE_DOCUMENT);
// check if it is focusable, read-only.
testStates(docAcc, (STATE_READONLY | STATE_FOCUSABLE));

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

@ -10,15 +10,16 @@
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>
<script type="application/javascript"
src="chrome://mochikit/content/a11y/accessible/role.js"></script>
<script type="application/javascript">
<![CDATA[
var gAccService = null;
var Ci = Components.interfaces;
function doTest()
{
gAccService = Components.classes["@mozilla.org/accessibleRetrieval;1"].
getService(Components.interfaces.nsIAccessibleRetrieval);
var id = "";
var listbox = null, acc = null;
@ -26,12 +27,11 @@
// Simple listbox. There is no nsIAccessibleTable interface.
id = "listbox1";
listbox = document.getElementById(id);
acc = gAccService.getAccessibleFor(listbox);
acc = getAccessible(id);
// query nsIAccessibleTable
try {
acc.QueryInterface(Ci.nsIAccessibleTable);
acc.QueryInterface(nsIAccessibleTable);
ok(false,
id + " shouldn't implement nsIAccessibleTable interface.");
} catch(e) {
@ -39,28 +39,16 @@
}
// role
is(acc.role, Ci.nsIAccessibleRole.ROLE_LISTBOX,
id + " has wrong role.");
testRole(id, ROLE_LISTBOX);
//////////////////////////////////////////////////////////////////////////
// Multicolumn listbox.
id = "listbox2";
listbox = document.getElementById(id);
acc = gAccService.getAccessibleFor(listbox);
acc = getAccessible(id, [nsIAccessibleTable]);
// role
is(acc.role, Ci.nsIAccessibleRole.ROLE_TABLE,
id + " has wrong role.");
// query nsIAccessibleTable
try {
acc.QueryInterface(Ci.nsIAccessibleTable);
ok(true,
id + " implements nsIAccessibleTable interface.");
} catch(e) {
ok(false, id + " doesn't implement nsIAccessibleTable interface.");
}
testRole(acc, ROLE_TABLE);
// rows count
var rowsCount = acc.rows;
@ -74,21 +62,10 @@
// Multicolumn listbox with header.
id = "listbox3";
listbox = document.getElementById(id);
acc = gAccService.getAccessibleFor(listbox);
acc = getAccessible(id, [nsIAccessibleTable]);
// role
is(acc.role, Ci.nsIAccessibleRole.ROLE_TABLE,
id + " has wrong role.");
// query nsIAccessibleTable
try {
acc.QueryInterface(Ci.nsIAccessibleTable);
ok(true,
id + " implements nsIAccessibleTable interface.");
} catch(e) {
ok(false, id + " doesn't implement nsIAccessibleTable interface.");
}
testRole(acc, ROLE_TABLE);
// rows count
var rowsCount = acc.rows;

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

@ -13,8 +13,11 @@
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>
<script type="application/javascript"
src="chrome://mochikit/content/a11y/accessible/role.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/a11y/accessible/nsIAccessible_name.js"></script>
<script type="application/javascript">
@ -140,8 +143,7 @@
// Element from anonymous content of direct child of toolbaritem.
var dropmarkerAcc = textboxAcc.lastChild;
is(dropmarkerAcc.finalRole, nsIAccessibleRole.ROLE_PUSHBUTTON,
"The last child of autocomplete textbox 'toolbaritem_textbox' should be dropmarker.");
testRole(dropmarkerAcc, ROLE_PUSHBUTTON);
is(dropmarkerAcc.name, "ooospspss",
"Wrong name for dropmarker of autocomplete textbox 'toolbaritem_textbox'.");

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

@ -10,6 +10,8 @@
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_selects.js"></script>

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

@ -8,10 +8,13 @@
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/relations.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/a11y/accessible/role.js"></script>
<script type="application/javascript">
function doTest()
@ -95,7 +98,7 @@
parentOfDocAcc = getAccessible(docAcc.parent, [nsIAccessNode]);
parentDocAcc = getAccessible(parentOfDocAcc.accessibleDocument,
[nsIAccessible]);
} while (parentDocAcc.finalRole != ROLE_CHROME_WINDOW)
} while (getRole(parentDocAcc) != ROLE_CHROME_WINDOW)
testRelation(parentDocAcc, RELATION_EMBEDS, docAcc);

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

@ -15,6 +15,8 @@
src="chrome://mochikit/content/a11y/accessible/common.js" />
<script type="application/javascript"
src="chrome://mochikit/content/a11y/accessible/relations.js" />
<script type="application/javascript"
src="chrome://mochikit/content/a11y/accessible/role.js" />
<script type="application/javascript">
<![CDATA[
@ -93,7 +95,7 @@
parentOfDocAcc = getAccessible(docAcc.parent, [nsIAccessNode]);
parentDocAcc = getAccessible(parentOfDocAcc.accessibleDocument,
[nsIAccessible]);
} while (parentDocAcc.finalRole != ROLE_CHROME_WINDOW)
} while (getRole(parentDocAcc) != ROLE_CHROME_WINDOW)
testRelation(parentDocAcc, RELATION_EMBEDS, docAcc);

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

@ -60,7 +60,7 @@ function doTest()
accNotCreated = (!isAccessible("tr"));
ok(!accNotCreated, "missed tr accessible");
is(accTable4.role, ROLE_TABLE, "wrong role");
testRole(accTable4, ROLE_NOTHING); // XXX: it's a bug, should be ROLE_TABLE
is(accTable4.cellRefAt(0,0).firstChild.name, "cell0", "wrong cell");
is(accTable4.cellRefAt(0,1).firstChild.name, "cell1", "wrong cell");

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

@ -14,6 +14,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=442648
<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>

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

@ -13,6 +13,8 @@
<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" />