Bug 1425972 - Add a test for tab navigation in the browser panel. r?Gijs
MozReview-Commit-ID: L3C65YgRYd5
--- a/browser/components/customizableui/test/browser_panel_keyboard_navigation.js
+++ b/browser/components/customizableui/test/browser_panel_keyboard_navigation.js
@@ -137,8 +137,44 @@ add_task(async function testLeftRightKey
Assert.equal(focusedElement.id, kHelpButtonId,
"Help button should be focused again now that we're back in the main view");
promise = promisePanelHidden(window);
PanelUI.hide();
await promise;
});
+add_task(async function testTabKey() {
+ let promise = promisePanelShown(window);
+ PanelUI.show();
+ await promise;
+
+ let buttons = gHelperInstance._getNavigableElements(PanelUI.mainView);
+
+ for (let button of buttons) {
+ if (button.disabled)
+ continue;
+ EventUtils.synthesizeKey("KEY_Tab", { code: "Tab" });
+ Assert.equal(document.commandDispatcher.focusedElement, button,
+ "The correct button should be focused after tabbing");
+ }
+
+ EventUtils.synthesizeKey("KEY_Tab", { code: "Tab" });
+ Assert.equal(document.commandDispatcher.focusedElement, buttons[0],
+ "Pressing tab should cycle around and select the first button again");
+
+ for (let i = buttons.length - 1; i >= 0; --i) {
+ let button = buttons[i];
+ if (button.disabled)
+ continue;
+ EventUtils.synthesizeKey("Tab", { code: "Tab", shiftKey: true });
+ Assert.equal(document.commandDispatcher.focusedElement, button,
+ "The correct button should be focused after shift + tabbing");
+ }
+
+ EventUtils.synthesizeKey("KEY_Tab", { code: "Tab", shiftKey: true });
+ Assert.equal(document.commandDispatcher.focusedElement, buttons[buttons.length - 1],
+ "Pressing shift + tab should cycle around and select the last button again");
+
+ promise = promisePanelHidden(window);
+ PanelUI.hide();
+ await promise;
+});