/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ "use strict"; /* import-globals-from ../../mochitest/role.js */ loadScripts({ name: "role.js", dir: MOCHITESTS_DIR }); /** * Test ARIA role map */ addAccessibleTask( `
hello
hello
hello
hello
`, async function testARIARoleMap(browser, accDoc) { let getAcc = id => findAccessibleChildByID(accDoc, id); testRole(getAcc("aria_alert"), ROLE_ALERT); testRole(getAcc("aria_alert_mixed"), ROLE_ALERT); testRole(getAcc("aria_alertdialog"), ROLE_DIALOG); testRole(getAcc("aria_alertdialog_mixed"), ROLE_DIALOG); testRole(getAcc("aria_application"), ROLE_APPLICATION); testRole(getAcc("aria_application_mixed"), ROLE_APPLICATION); testRole(getAcc("aria_article"), ROLE_ARTICLE); testRole(getAcc("aria_article_mixed"), ROLE_ARTICLE); testRole(getAcc("aria_blockquote"), ROLE_BLOCKQUOTE); testRole(getAcc("aria_blockquote_mixed"), ROLE_BLOCKQUOTE); testRole(getAcc("aria_button"), ROLE_PUSHBUTTON); testRole(getAcc("aria_button_mixed"), ROLE_PUSHBUTTON); testRole(getAcc("aria_caption"), ROLE_CAPTION); testRole(getAcc("aria_caption_mixed"), ROLE_CAPTION); testRole(getAcc("aria_checkbox"), ROLE_CHECKBUTTON); testRole(getAcc("aria_checkbox_mixed"), ROLE_CHECKBUTTON); testRole(getAcc("aria_code"), ROLE_CODE); testRole(getAcc("aria_code_mixed"), ROLE_CODE); testRole(getAcc("aria_combobox"), ROLE_EDITCOMBOBOX); testRole(getAcc("aria_combobox_mixed"), ROLE_EDITCOMBOBOX); testRole(getAcc("aria_comment"), ROLE_COMMENT); testRole(getAcc("aria_comment_mixed"), ROLE_COMMENT); testRole(getAcc("aria_deletion"), ROLE_CONTENT_DELETION); testRole(getAcc("aria_deletion_mixed"), ROLE_CONTENT_DELETION); testRole(getAcc("aria_dialog"), ROLE_DIALOG); testRole(getAcc("aria_dialog_mixed"), ROLE_DIALOG); testRole(getAcc("aria_directory"), ROLE_LIST); testRole(getAcc("aria_directory_mixed"), ROLE_LIST); testRole(getAcc("aria_document"), ROLE_NON_NATIVE_DOCUMENT); testRole(getAcc("aria_document_mixed"), ROLE_NON_NATIVE_DOCUMENT); testRole(getAcc("aria_form"), ROLE_TEXT); testRole(getAcc("aria_form_mixed"), ROLE_TEXT); testRole(getAcc("aria_form_with_label"), ROLE_FORM); testRole(getAcc("aria_form_with_label_mixed"), ROLE_FORM); testRole(getAcc("aria_feed"), ROLE_GROUPING); testRole(getAcc("aria_feed_mixed"), ROLE_GROUPING); testRole(getAcc("aria_figure"), ROLE_FIGURE); testRole(getAcc("aria_figure_mixed"), ROLE_FIGURE); testRole(getAcc("aria_grid"), ROLE_GRID); testRole(getAcc("aria_grid_mixed"), ROLE_GRID); testRole(getAcc("aria_group"), ROLE_GROUPING); testRole(getAcc("aria_group_mixed"), ROLE_GROUPING); testRole(getAcc("aria_heading"), ROLE_HEADING); testRole(getAcc("aria_heading_mixed"), ROLE_HEADING); testRole(getAcc("aria_img"), ROLE_GRAPHIC); testRole(getAcc("aria_img_mixed"), ROLE_GRAPHIC); testRole(getAcc("aria_insertion"), ROLE_CONTENT_INSERTION); testRole(getAcc("aria_insertion_mixed"), ROLE_CONTENT_INSERTION); testRole(getAcc("aria_link"), ROLE_LINK); testRole(getAcc("aria_link_mixed"), ROLE_LINK); testRole(getAcc("aria_list"), ROLE_LIST); testRole(getAcc("aria_list_mixed"), ROLE_LIST); testRole(getAcc("aria_listbox"), ROLE_LISTBOX); testRole(getAcc("aria_listbox_mixed"), ROLE_LISTBOX); testRole(getAcc("aria_log"), ROLE_TEXT); // weak role testRole(getAcc("aria_log_mixed"), ROLE_TEXT); // weak role testRole(getAcc("aria_mark"), ROLE_MARK); testRole(getAcc("aria_mark_mixed"), ROLE_MARK); testRole(getAcc("aria_marquee"), ROLE_ANIMATION); testRole(getAcc("aria_marquee_mixed"), ROLE_ANIMATION); testRole(getAcc("aria_math"), ROLE_FLAT_EQUATION); testRole(getAcc("aria_math_mixed"), ROLE_FLAT_EQUATION); testRole(getAcc("aria_menu"), ROLE_MENUPOPUP); testRole(getAcc("aria_menu_mixed"), ROLE_MENUPOPUP); testRole(getAcc("aria_menubar"), ROLE_MENUBAR); testRole(getAcc("aria_menubar_mixed"), ROLE_MENUBAR); testRole(getAcc("aria_meter"), ROLE_METER); testRole(getAcc("aria_meter_mixed"), ROLE_METER); testRole(getAcc("aria_note"), ROLE_NOTE); testRole(getAcc("aria_note_mixed"), ROLE_NOTE); testRole(getAcc("aria_paragraph"), ROLE_PARAGRAPH); testRole(getAcc("aria_paragraph_mixed"), ROLE_PARAGRAPH); testRole(getAcc("aria_presentation"), ROLE_TEXT); // weak role testRole(getAcc("aria_presentation_mixed"), ROLE_TEXT); // weak role testRole(getAcc("aria_progressbar"), ROLE_PROGRESSBAR); testRole(getAcc("aria_progressbar_mixed"), ROLE_PROGRESSBAR); testRole(getAcc("aria_radio"), ROLE_RADIOBUTTON); testRole(getAcc("aria_radio_mixed"), ROLE_RADIOBUTTON); testRole(getAcc("aria_radiogroup"), ROLE_RADIO_GROUP); testRole(getAcc("aria_radiogroup_mixed"), ROLE_RADIO_GROUP); testRole(getAcc("aria_region_no_name"), ROLE_TEXT); testRole(getAcc("aria_region_no_name_mixed"), ROLE_TEXT); testRole(getAcc("aria_region_has_label"), ROLE_REGION); testRole(getAcc("aria_region_has_label_mixed"), ROLE_REGION); testRole(getAcc("aria_region_has_labelledby"), ROLE_REGION); testRole(getAcc("aria_region_has_labelledby_mixed"), ROLE_REGION); testRole(getAcc("aria_region_has_title"), ROLE_REGION); testRole(getAcc("aria_region_has_title_mixed"), ROLE_REGION); testRole(getAcc("aria_region_empty_name"), ROLE_TEXT); testRole(getAcc("aria_region_empty_name_mixed"), ROLE_TEXT); testRole(getAcc("aria_region_as_table_with_caption"), ROLE_REGION); testRole(getAcc("aria_region_as_table_with_caption_mixed"), ROLE_REGION); testRole(getAcc("aria_region_as_table_with_miscaption"), ROLE_TABLE); testRole(getAcc("aria_region_as_table_with_miscaption_mixed"), ROLE_TABLE); testRole(getAcc("aria_scrollbar"), ROLE_SCROLLBAR); testRole(getAcc("aria_scrollbar_mixed"), ROLE_SCROLLBAR); testRole(getAcc("aria_searchbox"), ROLE_SEARCHBOX); testRole(getAcc("aria_searchbox_mixed"), ROLE_SEARCHBOX); testRole(getAcc("aria_separator"), ROLE_SEPARATOR); testRole(getAcc("aria_separator_mixed"), ROLE_SEPARATOR); testRole(getAcc("aria_slider"), ROLE_SLIDER); testRole(getAcc("aria_slider_mixed"), ROLE_SLIDER); testRole(getAcc("aria_spinbutton"), ROLE_SPINBUTTON); testRole(getAcc("aria_spinbutton_mixed"), ROLE_SPINBUTTON); testRole(getAcc("aria_status"), ROLE_STATUSBAR); testRole(getAcc("aria_status_mixed"), ROLE_STATUSBAR); testRole(getAcc("aria_subscript"), ROLE_SUBSCRIPT); testRole(getAcc("aria_subscript_mixed"), ROLE_SUBSCRIPT); testRole(getAcc("aria_suggestion"), ROLE_SUGGESTION); testRole(getAcc("aria_suggestion_mixed"), ROLE_SUGGESTION); testRole(getAcc("aria_superscript"), ROLE_SUPERSCRIPT); testRole(getAcc("aria_superscript_mixed"), ROLE_SUPERSCRIPT); testRole(getAcc("aria_switch"), ROLE_SWITCH); testRole(getAcc("aria_switch_mixed"), ROLE_SWITCH); testRole(getAcc("aria_tablist"), ROLE_PAGETABLIST); testRole(getAcc("aria_tablist_mixed"), ROLE_PAGETABLIST); testRole(getAcc("aria_tabpanel"), ROLE_PROPERTYPAGE); testRole(getAcc("aria_tabpanel_mixed"), ROLE_PROPERTYPAGE); testRole(getAcc("aria_term"), ROLE_TERM); testRole(getAcc("aria_term_mixed"), ROLE_TERM); testRole(getAcc("aria_textbox"), ROLE_ENTRY); testRole(getAcc("aria_textbox_mixed"), ROLE_ENTRY); testRole(getAcc("aria_timer"), ROLE_TEXT); // weak role testRole(getAcc("aria_timer_mixed"), ROLE_TEXT); // weak role testRole(getAcc("aria_toolbar"), ROLE_TOOLBAR); testRole(getAcc("aria_toolbar_mixed"), ROLE_TOOLBAR); testRole(getAcc("aria_tooltip"), ROLE_TOOLTIP); testRole(getAcc("aria_tooltip_mixed"), ROLE_TOOLTIP); testRole(getAcc("aria_tree"), ROLE_OUTLINE); testRole(getAcc("aria_tree_mixed"), ROLE_OUTLINE); testRole(getAcc("aria_treegrid"), ROLE_TREE_TABLE); testRole(getAcc("aria_treegrid_mixed"), ROLE_TREE_TABLE); }, { chrome: true, topLevel: true } ); /** * Test ARIA landmarks */ addAccessibleTask( `
a main area
a main area
a form area
a form area
a form area
a form area

This is a paragraph inside the article.

This is a paragraph inside the article.

Table based log
Table based log

marquee

marquee

timer
timer
application
application
form
form
form
form
complementary
contentinfo
main
main
search
application table
hi
application table
hi
banner table banner table complementary table complementary table
hi
contentinfo table contentinfo table
hi
main table
hi
main table
hi
navigation table navigation table search table search table
hi
`, async function testLandMarks(browser, accDoc) { let getAcc = id => findAccessibleChildByID(accDoc, id); // Note: // The phrase "weak foo" here means that there is no good foo-to-gecko // role mapping. Similarly "strong foo" means there is a good foo-to- // gecko role mapping. testRole(getAcc("articlemain"), ROLE_LANDMARK); testRole(getAcc("articlemain_mixed"), ROLE_LANDMARK); testRole(getAcc("articleform"), ROLE_ARTICLE); testRole(getAcc("articleform_mixed"), ROLE_ARTICLE); testRole(getAcc("articleform_label"), ROLE_FORM); testRole(getAcc("articleform_label_mixed"), ROLE_FORM); // Test article exposed as article testRole(getAcc("testArticle"), ROLE_ARTICLE); testRole(getAcc("testArticle_mixed"), ROLE_ARTICLE); // weak roles that are forms of "live regions" testRole(getAcc("log_table"), ROLE_TABLE); testRole(getAcc("log_table_mixed"), ROLE_TABLE); testRole(getAcc("timer_div"), ROLE_SECTION); testRole(getAcc("timer_div_mixed"), ROLE_SECTION); // other roles that are forms of "live regions" testRole(getAcc("marquee_h1"), ROLE_ANIMATION); testRole(getAcc("marquee_h1_mixed"), ROLE_ANIMATION); // strong landmark testRole(getAcc("application"), ROLE_APPLICATION); testRole(getAcc("application_mixed"), ROLE_APPLICATION); testRole(getAcc("form"), ROLE_SECTION); testRole(getAcc("form_mixed"), ROLE_SECTION); testRole(getAcc("form_label"), ROLE_FORM); testRole(getAcc("form_label_mixed"), ROLE_FORM); testRole(getAcc("application_table"), ROLE_APPLICATION); testRole(getAcc("application_table_mixed"), ROLE_APPLICATION); function testLandmark(landmarkId) { testRole(getAcc(landmarkId), ROLE_LANDMARK); testRole(getAcc(`${landmarkId}_mixed`), ROLE_LANDMARK); let landmarkTable = getAcc(`${landmarkId}_table`); testRole(landmarkTable, ROLE_LANDMARK); ok( !!landmarkTable.QueryInterface(nsIAccessibleTable), "landmarked table should have nsIAccessibleTable" ); let landmarkTableMixed = getAcc(`${landmarkId}_table_mixed`); testRole(landmarkTableMixed, ROLE_LANDMARK); ok( !!landmarkTableMixed.QueryInterface(nsIAccessibleTable), "landmarked table should have nsIAccessibleTable" ); is(landmarkTableMixed.getCellAt(0, 0).firstChild.name, "hi", "no cell"); } testLandmark("banner"); testLandmark("complementary"); testLandmark("contentinfo"); testLandmark("main"); testLandmark("navigation"); testLandmark("search"); }, { chrome: true, topLevel: true } ); /** * Test abstract roles. * User agents must not map abstract roles to anything but a generic "section" gecko role. */ addAccessibleTask( `
composite
composite
landmark
landmark
roletype
roletype
structure
structure
widget
widget
window
window
input
input
range
range
select
select
section
section
sectionhead
sectionhead
command
command
`, async function testAbstract(browser, accDoc) { let getAcc = id => findAccessibleChildByID(accDoc, id); function testAbstractRole(id) { testRole(getAcc(id), ROLE_SECTION); testRole(getAcc(`${id}_mixed`), ROLE_SECTION); } testAbstractRole("composite"); testAbstractRole("landmark"); testAbstractRole("structure"); testAbstractRole("widget"); testAbstractRole("window"); testAbstractRole("input"); testAbstractRole("range"); testAbstractRole("select"); testAbstractRole("section"); testAbstractRole("sectionhead"); testAbstractRole("command"); }, { chrome: true, topLevel: true } ); /** * Test child roles dependent on ancestor role presence */ addAccessibleTask( `
cell
cell
foo
foo
`, async function testAncestorDependent(browser, accDoc) { let getAcc = id => findAccessibleChildByID(accDoc, id); testRole(getAcc("buttontable_row"), ROLE_TEXT_CONTAINER); testRole(getAcc("buttontable_row_mixed"), ROLE_TEXT_CONTAINER); testRole(getAcc("buttontable_cell"), ROLE_TEXT_CONTAINER); testRole(getAcc("buttontable_cell_mixed"), ROLE_TEXT_CONTAINER); testRole(getAcc("implicit_gridcell"), ROLE_GRID_CELL); testRole(getAcc("implicit_gridcell_mixed"), ROLE_GRID_CELL); testRole(getAcc("aria_columnheader"), ROLE_COLUMNHEADER); testRole(getAcc("aria_columnheader_mixed"), ROLE_COLUMNHEADER); testRole(getAcc("aria_gridcell"), ROLE_GRID_CELL); testRole(getAcc("aria_gridcell_mixed"), ROLE_GRID_CELL); testRole(getAcc("aria_rowheader"), ROLE_ROWHEADER); testRole(getAcc("aria_rowheader_mixed"), ROLE_ROWHEADER); testRole(getAcc("aria_listitem"), ROLE_LISTITEM); testRole(getAcc("aria_listitem_mixed"), ROLE_LISTITEM); testRole(getAcc("aria_menuitem"), ROLE_MENUITEM); testRole(getAcc("aria_menuitem_mixed"), ROLE_MENUITEM); testRole(getAcc("aria_menuitemcheckbox"), ROLE_CHECK_MENU_ITEM); testRole(getAcc("aria_menuitemcheckbox_mixed"), ROLE_CHECK_MENU_ITEM); testRole(getAcc("aria_menuitemradio"), ROLE_RADIO_MENU_ITEM); testRole(getAcc("aria_menuitemradio_mixed"), ROLE_RADIO_MENU_ITEM); testRole(getAcc("aria_row"), ROLE_ROW); testRole(getAcc("aria_row_mixed"), ROLE_ROW); testRole(getAcc("aria_tab"), ROLE_PAGETAB); testRole(getAcc("aria_tab_mixed"), ROLE_PAGETAB); testRole(getAcc("aria_treeitem"), ROLE_OUTLINEITEM); testRole(getAcc("aria_treeitem_mixed"), ROLE_OUTLINEITEM); // roles transformed by ARIA state attributes testRole(getAcc("togglebutton"), ROLE_TOGGLE_BUTTON); testRole(getAcc("togglebutton_mixed"), ROLE_TOGGLE_BUTTON); }, { chrome: true, topLevel: true } ); /** * Test misc quirks */ addAccessibleTask( `
worm button
worm button
note
note
scrollbar
scrollbar
A
B
C
A
B
C
`, async function testRoleQuirks(browser, accDoc) { let getAcc = id => findAccessibleChildByID(accDoc, id); // //////////////////////////////////////////////////////////////////////// // ignore unknown roles, take first known testRole(getAcc("unknown_roles"), ROLE_PUSHBUTTON); testRole(getAcc("unknown_roles_mixed"), ROLE_PUSHBUTTON); // //////////////////////////////////////////////////////////////////////// // misc roles testRole(getAcc("note"), ROLE_NOTE); testRole(getAcc("note_mixed"), ROLE_NOTE); testRole(getAcc("scrollbar"), ROLE_SCROLLBAR); testRole(getAcc("scrollbar_mixed"), ROLE_SCROLLBAR); testRole(getAcc("dir"), ROLE_LIST); testRole(getAcc("dir_mixed"), ROLE_LIST); }, { chrome: true, topLevel: true } ); /** * Test equations */ addAccessibleTask( `

Image: x^2 + y^2 + z^2

Image: x^2 + y^2 + z^2

Text: x2 + y2 + z2

Text: x2 + y2 + z2

`, async function testRoleQuirks(browser, accDoc) { let getAcc = id => findAccessibleChildByID(accDoc, id); // Test equation image testRole(getAcc("img_eq"), ROLE_FLAT_EQUATION); testRole(getAcc("img_eq_mixed"), ROLE_FLAT_EQUATION); // Test textual equation testRole(getAcc("txt_eq"), ROLE_FLAT_EQUATION); testRole(getAcc("txt_eq_mixed"), ROLE_FLAT_EQUATION); }, { chrome: true, topLevel: true } ); /** * Test doc role changes */ addAccessibleTask( ``, async function testRoleQuirks(browser, accDoc) { await invokeSetAttribute(browser, "body", "role", "application"); await untilCacheIs( () => accDoc.role, ROLE_APPLICATION, "Doc role is 'application'" ); await invokeSetAttribute(browser, "body", "role", "dialog"); await untilCacheIs(() => accDoc.role, ROLE_DIALOG, "Doc role is 'dialog'"); // Other roles aren't valid on body elements. await invokeSetAttribute(browser, "body", "role", "document"); await untilCacheIs( () => accDoc.role, ROLE_DOCUMENT, "Doc role is 'document'" ); await invokeSetAttribute(browser, "body", "role", "button"); await untilCacheIs( () => accDoc.role, ROLE_DOCUMENT, "Doc role is 'document'" ); // ... but mixed roles should still function like their regular variants await invokeSetAttribute(browser, "body", "role", "ApPLiCaTiOn"); await untilCacheIs( () => accDoc.role, ROLE_APPLICATION, "Doc role is 'application'" ); await invokeSetAttribute(browser, "body", "role", "dIaLoG"); await untilCacheIs(() => accDoc.role, ROLE_DIALOG, "Doc role is 'dialog'"); }, { chrome: true, topLevel: true } ); /** * Test re-parented list item's role gets recomputed. */ addAccessibleTask( `
Bananas
`, async function testListItemRelocation(browser, accDoc) { is( findAccessibleChildByID(accDoc, "aria-listitem").role, ROLE_SECTION, "List item in list should have section role" ); let evt = waitForEvent(EVENT_INNER_REORDER, "aria-list"); await invokeSetAttribute( browser, "aria-list", "aria-owns", "aria-listitem" ); await evt; is( findAccessibleChildByID(accDoc, "aria-listitem").role, ROLE_LISTITEM, "List item in list should have listitem role" ); }, { chrome: true, topLevel: true } );