Bug 1686238: Only attempt to traverse containers menu if containers are enabled and defined r=yzen

Differential Revision: https://phabricator.services.mozilla.com/D102799
This commit is contained in:
Morgan Reschenberg 2021-01-22 21:02:50 +00:00
Родитель cdbe04ecfa
Коммит 7dc8c1a190
1 изменённых файлов: 54 добавлений и 52 удалений

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

@ -199,12 +199,14 @@ add_task(async () => {
Assert.ok(Services.search.isInitialized); Assert.ok(Services.search.isInitialized);
} }
const hasContainers =
Services.prefs.getBoolPref("privacy.userContext.enabled") &&
ContextualIdentityService.getPublicIdentities().length;
// synthesize a right click on the link to open the link context menu // synthesize a right click on the link to open the link context menu
let menu = document.getElementById("contentAreaContextMenu"); let menu = document.getElementById("contentAreaContextMenu");
await BrowserTestUtils.synthesizeMouse( await BrowserTestUtils.synthesizeMouseAtCenter(
"#exampleLink", "#exampleLink",
2,
2,
{ type: "contextmenu" }, { type: "contextmenu" },
browser browser
); );
@ -212,16 +214,19 @@ add_task(async () => {
menu = await getMacAccessible(menu); menu = await getMacAccessible(menu);
let menuChildren = menu.getAttributeValue("AXChildren"); let menuChildren = menu.getAttributeValue("AXChildren");
// menu contains 12 items and 3 splitters for 15 items total // menu contains 14 items when containers disabled, 15 items otherwise
const expectedChildCount = hasContainers ? 15 : 14;
is( is(
menuChildren.length, menuChildren.length,
15, expectedChildCount,
"Context menu on link contains fifteen items" "Context menu on link contains 14 or 15 items depending on release"
); );
// items at indicies 4, 10, and 12 are the splitters when containers exist
// everything else should be a menu item, otherwise indicies of splitters are
// 3, 9, and 11
const splitterIndicies = hasContainers ? [4, 10, 12] : [3, 9, 11];
for (let i = 0; i < menuChildren.length; i++) { for (let i = 0; i < menuChildren.length; i++) {
// items at indicies 4, 10, and 12 are the splitters, everything else should be a menu item if (splitterIndicies.includes(i)) {
if (i == 4 || i == 10 || i == 12) {
is( is(
menuChildren[i].getAttributeValue("AXRole"), menuChildren[i].getAttributeValue("AXRole"),
"AXSplitter", "AXSplitter",
@ -236,53 +241,50 @@ add_task(async () => {
} }
} }
// submenus are at indicies 1 and 10 // check the containers sub menu in depth if it exists
// first check they have no children when hidden if (hasContainers) {
is( is(
menuChildren[1].getAttributeValue("AXVisibleChildren"), menuChildren[1].getAttributeValue("AXVisibleChildren"),
null, null,
"Submenu 1 has no visible chldren when hidden" "Submenu 1 has no visible chldren when hidden"
); );
is(
menuChildren[11].getAttributeValue("AXVisibleChildren"),
null,
"Submenu 2 has no visible chldren when hidden"
);
// focus the first submenu // focus the first submenu
EventUtils.synthesizeKey("KEY_ArrowDown"); EventUtils.synthesizeKey("KEY_ArrowDown");
EventUtils.synthesizeKey("KEY_ArrowDown"); EventUtils.synthesizeKey("KEY_ArrowDown");
EventUtils.synthesizeKey("KEY_ArrowRight"); EventUtils.synthesizeKey("KEY_ArrowRight");
await waitForMacEvent("AXMenuOpened"); await waitForMacEvent("AXMenuOpened");
// after the submenu is opened, refetch it // after the submenu is opened, refetch it
menu = document.getElementById("contentAreaContextMenu"); menu = document.getElementById("contentAreaContextMenu");
menu = await getMacAccessible(menu); menu = await getMacAccessible(menu);
menuChildren = menu.getAttributeValue("AXChildren"); menuChildren = menu.getAttributeValue("AXChildren");
// verify submenu-menuitem's attributes // verify submenu-menuitem's attributes
is( is(
menuChildren[1].getAttributeValue("AXChildren").length, menuChildren[1].getAttributeValue("AXChildren").length,
1, 1,
"Submenu 1 has one child when open" "Submenu 1 has one child when open"
); );
const subMenu = menuChildren[1].getAttributeValue("AXChildren")[0]; const subMenu = menuChildren[1].getAttributeValue("AXChildren")[0];
is( is(
subMenu.getAttributeValue("AXRole"), subMenu.getAttributeValue("AXRole"),
"AXMenu", "AXMenu",
"submenu has role of menu" "submenu has role of menu"
); );
const subMenuChildren = subMenu.getAttributeValue("AXChildren"); const subMenuChildren = subMenu.getAttributeValue("AXChildren");
is(subMenuChildren.length, 4, "sub menu has 4 children"); is(subMenuChildren.length, 4, "sub menu has 4 children");
is( is(
subMenu.getAttributeValue("AXVisibleChildren").length, subMenu.getAttributeValue("AXVisibleChildren").length,
4, 4,
"submenu has 4 visible children" "submenu has 4 visible children"
); );
// close context menu
EventUtils.synthesizeKey("KEY_Escape");
await waitForMacEvent("AXMenuClosed");
}
// close context menu
EventUtils.synthesizeKey("KEY_Escape");
await waitForMacEvent("AXMenuClosed");
EventUtils.synthesizeKey("KEY_Escape"); EventUtils.synthesizeKey("KEY_Escape");
await waitForMacEvent("AXMenuClosed"); await waitForMacEvent("AXMenuClosed");
} }