browser_markup_accessibility_semantics.js (4453B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 // Test that inspector markup view has all expected ARIA properties set and 8 // updated. 9 10 const TOP_CONTAINER_LEVEL = 3; 11 12 add_task(async function () { 13 const { inspector } = await openInspectorForURL(` 14 data:text/html;charset=utf-8, 15 <h1>foo</h1> 16 <span>bar</span> 17 <dl> 18 <dt></dt> 19 </dl>`); 20 const markup = inspector.markup; 21 const doc = markup.doc; 22 const win = doc.defaultView; 23 24 const rootElt = markup.getContainer(markup._rootNode).elt; 25 const bodyContainer = await getContainerForSelector("body", inspector); 26 const spanContainer = await getContainerForSelector("span", inspector); 27 const headerContainer = await getContainerForSelector("h1", inspector); 28 const listContainer = await getContainerForSelector("dl", inspector); 29 30 // Focus on the tree element. 31 rootElt.focus(); 32 33 // Test tree related semantics 34 is( 35 rootElt.getAttribute("role"), 36 "tree", 37 "Root container should have tree semantics" 38 ); 39 is( 40 rootElt.getAttribute("aria-dropeffect"), 41 "none", 42 "By default root container's drop effect should be set to none" 43 ); 44 is( 45 rootElt.getAttribute("aria-activedescendant"), 46 bodyContainer.tagLine.getAttribute("id"), 47 "Default active descendant should be set to body" 48 ); 49 is( 50 parseInt(bodyContainer.tagLine.getAttribute("aria-level"), 10), 51 TOP_CONTAINER_LEVEL - 1, 52 "Body container tagLine should have nested level up to date" 53 ); 54 [spanContainer, headerContainer, listContainer].forEach(container => { 55 const treeitem = container.tagLine; 56 is( 57 treeitem.getAttribute("role"), 58 "treeitem", 59 "Child container tagLine elements should have tree item semantics" 60 ); 61 is( 62 parseInt(treeitem.getAttribute("aria-level"), 10), 63 TOP_CONTAINER_LEVEL, 64 "Child container tagLine should have nested level up to date" 65 ); 66 is( 67 treeitem.getAttribute("aria-grabbed"), 68 "false", 69 "Child container should be draggable but not grabbed by default" 70 ); 71 is( 72 container.children.getAttribute("role"), 73 "group", 74 "Container with children should have its children element have group " + 75 "semantics" 76 ); 77 ok(treeitem.id, "Tree item should have id assigned"); 78 if (container.closeTagLine) { 79 is( 80 container.closeTagLine.getAttribute("role"), 81 "presentation", 82 "Ignore closing tag" 83 ); 84 } 85 if (container.expander) { 86 is( 87 container.expander.getAttribute("role"), 88 "presentation", 89 "Ignore expander" 90 ); 91 } 92 }); 93 94 // Test expanding/expandable semantics 95 ok( 96 !spanContainer.tagLine.hasAttribute("aria-expanded"), 97 "Non expandable tree items should not have aria-expanded attribute" 98 ); 99 ok( 100 !headerContainer.tagLine.hasAttribute("aria-expanded"), 101 "Non expandable tree items should not have aria-expanded attribute" 102 ); 103 is( 104 listContainer.tagLine.getAttribute("aria-expanded"), 105 "false", 106 "Closed tree item should have aria-expanded unset" 107 ); 108 109 info("Selecting and expanding list container"); 110 await selectNode("dl", inspector); 111 EventUtils.synthesizeKey("VK_RIGHT", {}, win); 112 await waitForMultipleChildrenUpdates(inspector); 113 114 is( 115 rootElt.getAttribute("aria-activedescendant"), 116 listContainer.tagLine.getAttribute("id"), 117 "Active descendant should not be set to list container tagLine" 118 ); 119 is( 120 listContainer.tagLine.getAttribute("aria-expanded"), 121 "true", 122 "Open tree item should have aria-expanded set" 123 ); 124 const listItemContainer = await getContainerForSelector("dt", inspector); 125 is( 126 parseInt(listItemContainer.tagLine.getAttribute("aria-level"), 10), 127 TOP_CONTAINER_LEVEL + 1, 128 "Grand child container tagLine should have nested level up to date" 129 ); 130 is( 131 listItemContainer.children.getAttribute("role"), 132 "presentation", 133 "Container with no children should have its children element ignored by " + 134 "accessibility" 135 ); 136 137 info("Collapsing list container"); 138 EventUtils.synthesizeKey("VK_LEFT", {}, win); 139 await waitForMultipleChildrenUpdates(inspector); 140 141 is( 142 listContainer.tagLine.getAttribute("aria-expanded"), 143 "false", 144 "Closed tree item should have aria-expanded unset" 145 ); 146 });