Skip to content

Commit

Permalink
Bug 1483828 - [Part 3] Update the expected focusing behavior for some…
Browse files Browse the repository at this point in the history
… devtools tests r=smaug,devtools-reviewers,nchevobbe

Differential Revision: https://phabricator.services.mozilla.com/D202505
  • Loading branch information
sefeng211 committed Mar 4, 2024
1 parent e514703 commit 58b193c
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,27 @@
el.focus();
}

function getExpectedActiveElementForFinalShiftTab() {
if (!SpecialPowers.getBoolPref("dom.disable_tab_focus_to_root_element")) {
return listEl.ownerDocument.documentElement;
}

// When tab focus mode is applied, the "Run Chrome Tests" button is not
// focusable, so this Shift+Tab moves the focus to a Chrome UI element
// instead of the "Run Chrome Tests" button, which makes the focus to
// move to a browsing context that has a different top level browsing context
// than the current browsing context. Since top level browsing contexts are
// different, the activeElement in the old document is not cleared. Also
// this is only the case when e10s is enabled.
if (SpecialPowers.getBoolPref("accessibility.tabfocus_applies_to_xul") &&
SpecialPowers.Services.appinfo.browserTabsRemoteAutostart) {
return listEl;
}

// <body>
return defaultFocus;
}

const tests = [{
name: "Test default List state. Keyboard focus is set to document body by default.",
state: { current: null, active: null },
Expand Down Expand Up @@ -246,10 +267,7 @@
synthesizeKey("KEY_Tab", { shiftKey: true });
},
state: { current: 0, active: null },
activeElement:
!SpecialPowers.getBoolPref("dom.disable_tab_focus_to_root_element.enabled")
? listEl.ownerDocument.documentElement
: defaultFocus,
activeElement: getExpectedActiveElementForFinalShiftTab(),
}];

for (const test of tests) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@
el.focus();
}

function getExpectedActiveElementForFinalShiftTab() {
if (!SpecialPowers.getBoolPref("dom.disable_tab_focus_to_root_element")) {
return treeViewEl.ownerDocument.documentElement;
}

// When tab focus mode is applied, the "Run Chrome Tests" button is not
// focusable, so this Shift+Tab moves the focus to a Chrome UI element
// instead of the "Run Chrome Tests" button, which makes the focus to
// move to a browsing context that has a different top level browsing context
// than the current browsing context. Since top level browsing contexts are
// different, the activeElement in the old document is not cleared. Also
// this is only the case when e10s is enabled.
if (SpecialPowers.getBoolPref("accessibility.tabfocus_applies_to_xul") &&
SpecialPowers.Services.appinfo.browserTabsRemoteAutostart) {
return treeViewEl;
}

return treeViewEl.ownerDocument.body;
}

const tests = [{
name: "Test default TreeView state. Keyboard focus is set to document " +
"body by default.",
Expand Down Expand Up @@ -255,8 +275,9 @@
synthesizeKey("KEY_Tab", { shiftKey: true });
},
state: { selected: "/B", active: null },
activeElement: treeViewEl.ownerDocument.documentElement,
}];
activeElement: getExpectedActiveElementForFinalShiftTab(),
}
];

for (const test of tests) {
const { action, event, state, name } = test;
Expand Down
22 changes: 21 additions & 1 deletion devtools/client/shared/components/test/chrome/test_tree_14.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,26 @@
},
};

function getExpectedActiveElementForFinalShiftTab() {
if (!SpecialPowers.getBoolPref("dom.disable_tab_focus_to_root_element")) {
return document.documentElement;
}

// When tab focus mode is applied, the "Run Chrome Tests" button is not
// focusable, so this Shift+Tab moves the focus to a Chrome UI element
// instead of the "Run Chrome Tests" button, which makes the focus to
// move to a browsing context that has a different top level browsing context
// than the current browsing context. Since top level browsing contexts are
// different, the activeElement in the old document is not cleared. Also
// this is only the case when e10s is enabled.
if (SpecialPowers.getBoolPref("accessibility.tabfocus_applies_to_xul") &&
SpecialPowers.Services.appinfo.browserTabsRemoteAutostart) {
return "tree";
}

return document.body;
}

const tests = [{
name: "Test default Tree props. Keyboard focus is set to document body by default.",
props: { focused: undefined, active: undefined },
Expand Down Expand Up @@ -204,7 +224,7 @@
synthesizeKey("KEY_Tab", { shiftKey: true });
},
props: { focused: "A", active: null },
activeElement: document.documentElement,
activeElement: getExpectedActiveElementForFinalShiftTab(),
}];

for (const test of tests) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ add_task(async function () {
const { doc } = await createHost();

const input = doc.createElement("input");
doc.body.append(input, doc.createElement("input"));
const prevInput = doc.createElement("input");
doc.body.append(prevInput, input, doc.createElement("input"));

const onSelectCalled = [];
const onClickCalled = [];
Expand Down Expand Up @@ -189,7 +190,9 @@ add_task(async function () {
);
EventUtils.synthesizeKey("KEY_Tab", { shiftKey: true });
is(onClickCalled.length, 3, "onClick wasn't called");

is(hasFocus(input), false, "input does not have the focus anymore");
is(hasFocus(prevInput), true, "Shift+Tab moves the focus to prevInput");

const onPopupClose = popup.once("popup-closed");
popup.hidePopup();
Expand Down

0 comments on commit 58b193c

Please sign in to comment.