forked from mirrors/gecko-dev
***
Bug 1514594: Part 3a - Change ChromeUtils.import to return an exports object; not pollute global. r=mccr8
This changes the behavior of ChromeUtils.import() to return an exports object,
rather than a module global, in all cases except when `null` is passed as a
second argument, and changes the default behavior not to pollute the global
scope with the module's exports. Thus, the following code written for the old
model:
ChromeUtils.import("resource://gre/modules/Services.jsm");
is approximately the same as the following, in the new model:
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
Since the two behaviors are mutually incompatible, this patch will land with a
scripted rewrite to update all existing callers to use the new model rather
than the old.
***
Bug 1514594: Part 3b - Mass rewrite all JS code to use the new ChromeUtils.import API. rs=Gijs
This was done using the followng script:
https://bitbucket.org/kmaglione/m-c-rewrites/src/tip/processors/cu-import-exports.jsm
***
Bug 1514594: Part 3c - Update ESLint plugin for ChromeUtils.import API changes. r=Standard8
Differential Revision: https://phabricator.services.mozilla.com/D16747
***
Bug 1514594: Part 3d - Remove/fix hundreds of duplicate imports from sync tests. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16748
***
Bug 1514594: Part 3e - Remove no-op ChromeUtils.import() calls. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16749
***
Bug 1514594: Part 3f.1 - Cleanup various test corner cases after mass rewrite. r=Gijs
***
Bug 1514594: Part 3f.2 - Cleanup various non-test corner cases after mass rewrite. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16750
--HG--
extra : rebase_source : 359574ee3064c90f33bf36c2ebe3159a24cc8895
extra : histedit_source : b93c8f42808b1599f9122d7842d2c0b3e656a594%2C64a3a4e3359dc889e2ab2b49461bab9e27fc10a7
243 lines
8.5 KiB
JavaScript
243 lines
8.5 KiB
JavaScript
"use strict";
|
|
|
|
/**
|
|
* Test keyboard navigation in the app menu panel.
|
|
*/
|
|
|
|
const {PanelView} = ChromeUtils.import("resource:///modules/PanelMultiView.jsm", null);
|
|
const kHelpButtonId = "appMenu-help-button";
|
|
|
|
function getEnabledNavigableElementsForView(panelView) {
|
|
return Array.from(panelView.querySelectorAll(
|
|
"button,toolbarbutton,menulist,.text-link"
|
|
)).filter(element => {
|
|
let bounds = element.getBoundingClientRect();
|
|
return !element.disabled && (bounds.width > 0 && bounds.height > 0);
|
|
});
|
|
}
|
|
|
|
add_task(async function testUpDownKeys() {
|
|
await gCUITestUtils.openMainMenu();
|
|
|
|
let buttons = getEnabledNavigableElementsForView(PanelUI.mainView);
|
|
|
|
for (let button of buttons) {
|
|
if (button.disabled)
|
|
continue;
|
|
EventUtils.synthesizeKey("KEY_ArrowDown");
|
|
Assert.equal(document.commandDispatcher.focusedElement, button,
|
|
"The correct button should be focused after navigating downward");
|
|
}
|
|
|
|
EventUtils.synthesizeKey("KEY_ArrowDown");
|
|
Assert.equal(document.commandDispatcher.focusedElement, buttons[0],
|
|
"Pressing upwards 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("KEY_ArrowUp");
|
|
Assert.equal(document.commandDispatcher.focusedElement, button,
|
|
"The first button should be focused after navigating upward");
|
|
}
|
|
|
|
await gCUITestUtils.hideMainMenu();
|
|
});
|
|
|
|
add_task(async function testHomeEndKeys() {
|
|
await gCUITestUtils.openMainMenu();
|
|
|
|
let buttons = getEnabledNavigableElementsForView(PanelUI.mainView);
|
|
let enabledButtons = buttons.filter(btn => !btn.disabled);
|
|
let firstButton = enabledButtons[0];
|
|
let lastButton = enabledButtons.pop();
|
|
|
|
Assert.ok(firstButton != lastButton, "There is more than one button");
|
|
|
|
EventUtils.synthesizeKey("KEY_End");
|
|
Assert.equal(document.commandDispatcher.focusedElement, lastButton,
|
|
"The last button should be focused after pressing End");
|
|
|
|
EventUtils.synthesizeKey("KEY_Home");
|
|
Assert.equal(document.commandDispatcher.focusedElement, firstButton,
|
|
"The first button should be focused after pressing Home");
|
|
|
|
await gCUITestUtils.hideMainMenu();
|
|
});
|
|
|
|
add_task(async function testEnterKeyBehaviors() {
|
|
await gCUITestUtils.openMainMenu();
|
|
|
|
let buttons = getEnabledNavigableElementsForView(PanelUI.mainView);
|
|
|
|
// Navigate to the 'Help' button, which points to a subview.
|
|
EventUtils.synthesizeKey("KEY_ArrowUp");
|
|
let focusedElement = document.commandDispatcher.focusedElement;
|
|
Assert.equal(focusedElement, buttons[buttons.length - 1],
|
|
"The last button should be focused after navigating upward");
|
|
|
|
let promise = BrowserTestUtils.waitForEvent(PanelUI.helpView, "ViewShown");
|
|
// Make sure the Help button is in focus.
|
|
while (!focusedElement || !focusedElement.id || focusedElement.id != kHelpButtonId) {
|
|
EventUtils.synthesizeKey("KEY_ArrowUp");
|
|
focusedElement = document.commandDispatcher.focusedElement;
|
|
}
|
|
EventUtils.synthesizeKey("KEY_Enter");
|
|
await promise;
|
|
|
|
let helpButtons = getEnabledNavigableElementsForView(PanelUI.helpView);
|
|
Assert.ok(helpButtons[0].classList.contains("subviewbutton-back"),
|
|
"First button in help view should be a back button");
|
|
|
|
// For posterity, check navigating the subview using up/ down arrow keys as well.
|
|
for (let i = helpButtons.length - 1; i >= 0; --i) {
|
|
let button = helpButtons[i];
|
|
if (button.disabled)
|
|
continue;
|
|
EventUtils.synthesizeKey("KEY_ArrowUp");
|
|
focusedElement = document.commandDispatcher.focusedElement;
|
|
Assert.equal(focusedElement, button, "The first button should be focused after navigating upward");
|
|
}
|
|
|
|
// Make sure the back button is in focus again.
|
|
while (focusedElement != helpButtons[0]) {
|
|
EventUtils.synthesizeKey("KEY_ArrowDown");
|
|
focusedElement = document.commandDispatcher.focusedElement;
|
|
}
|
|
|
|
// The first button is the back button. Hittin Enter should navigate us back.
|
|
promise = BrowserTestUtils.waitForEvent(PanelUI.mainView, "ViewShown");
|
|
EventUtils.synthesizeKey("KEY_Enter");
|
|
await promise;
|
|
|
|
// Let's test a 'normal' command button.
|
|
focusedElement = document.commandDispatcher.focusedElement;
|
|
const kFindButtonId = "appMenu-find-button";
|
|
while (!focusedElement || !focusedElement.id || focusedElement.id != kFindButtonId) {
|
|
EventUtils.synthesizeKey("KEY_ArrowUp");
|
|
focusedElement = document.commandDispatcher.focusedElement;
|
|
}
|
|
let findBarPromise = gBrowser.isFindBarInitialized() ?
|
|
null : BrowserTestUtils.waitForEvent(gBrowser.selectedTab, "TabFindInitialized");
|
|
Assert.equal(focusedElement.id, kFindButtonId, "Find button should be selected");
|
|
|
|
await gCUITestUtils.hidePanelMultiView(PanelUI.panel,
|
|
() => EventUtils.synthesizeKey("KEY_Enter"));
|
|
|
|
await findBarPromise;
|
|
Assert.ok(!gFindBar.hidden, "Findbar should have opened");
|
|
gFindBar.close();
|
|
});
|
|
|
|
add_task(async function testLeftRightKeys() {
|
|
await gCUITestUtils.openMainMenu();
|
|
|
|
// Navigate to the 'Help' button, which points to a subview.
|
|
let focusedElement = document.commandDispatcher.focusedElement;
|
|
while (!focusedElement || !focusedElement.id || focusedElement.id != kHelpButtonId) {
|
|
EventUtils.synthesizeKey("KEY_ArrowUp");
|
|
focusedElement = document.commandDispatcher.focusedElement;
|
|
}
|
|
Assert.equal(focusedElement.id, kHelpButtonId, "The last button should be focused after navigating upward");
|
|
|
|
// Hitting ArrowRight on a button that points to a subview should navigate us
|
|
// there.
|
|
let promise = BrowserTestUtils.waitForEvent(PanelUI.helpView, "ViewShown");
|
|
EventUtils.synthesizeKey("KEY_ArrowRight");
|
|
await promise;
|
|
|
|
// Hitting ArrowLeft should navigate us back.
|
|
promise = BrowserTestUtils.waitForEvent(PanelUI.mainView, "ViewShown");
|
|
EventUtils.synthesizeKey("KEY_ArrowLeft");
|
|
await promise;
|
|
|
|
focusedElement = document.commandDispatcher.focusedElement;
|
|
Assert.equal(focusedElement.id, kHelpButtonId,
|
|
"Help button should be focused again now that we're back in the main view");
|
|
|
|
await gCUITestUtils.hideMainMenu();
|
|
});
|
|
|
|
add_task(async function testTabKey() {
|
|
await gCUITestUtils.openMainMenu();
|
|
|
|
let buttons = getEnabledNavigableElementsForView(PanelUI.mainView);
|
|
|
|
for (let button of buttons) {
|
|
if (button.disabled)
|
|
continue;
|
|
EventUtils.synthesizeKey("KEY_Tab");
|
|
Assert.equal(document.commandDispatcher.focusedElement, button,
|
|
"The correct button should be focused after tabbing");
|
|
}
|
|
|
|
EventUtils.synthesizeKey("KEY_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("KEY_Tab", {shiftKey: true});
|
|
Assert.equal(document.commandDispatcher.focusedElement, button,
|
|
"The correct button should be focused after shift + tabbing");
|
|
}
|
|
|
|
EventUtils.synthesizeKey("KEY_Tab", {shiftKey: true});
|
|
Assert.equal(document.commandDispatcher.focusedElement, buttons[buttons.length - 1],
|
|
"Pressing shift + tab should cycle around and select the last button again");
|
|
|
|
await gCUITestUtils.hideMainMenu();
|
|
});
|
|
|
|
add_task(async function testInterleavedTabAndArrowKeys() {
|
|
await gCUITestUtils.openMainMenu();
|
|
|
|
let buttons = getEnabledNavigableElementsForView(PanelUI.mainView);
|
|
let tab = false;
|
|
|
|
for (let button of buttons) {
|
|
if (button.disabled)
|
|
continue;
|
|
if (tab) {
|
|
EventUtils.synthesizeKey("KEY_Tab");
|
|
} else {
|
|
EventUtils.synthesizeKey("KEY_ArrowDown");
|
|
}
|
|
tab = !tab;
|
|
}
|
|
|
|
Assert.equal(document.commandDispatcher.focusedElement, buttons[buttons.length - 1],
|
|
"The last button should be focused after a mix of Tab and ArrowDown");
|
|
|
|
await gCUITestUtils.hideMainMenu();
|
|
});
|
|
|
|
add_task(async function testSpaceDownAfterTabNavigation() {
|
|
await gCUITestUtils.openMainMenu();
|
|
|
|
let buttons = getEnabledNavigableElementsForView(PanelUI.mainView);
|
|
let button;
|
|
|
|
for (button of buttons) {
|
|
if (button.disabled)
|
|
continue;
|
|
EventUtils.synthesizeKey("KEY_Tab");
|
|
if (button.id == kHelpButtonId) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
Assert.equal(document.commandDispatcher.focusedElement, button,
|
|
"Help button should be focused after tabbing to it.");
|
|
|
|
// Pressing down space on a button that points to a subview should navigate us
|
|
// there, before keyup.
|
|
let promise = BrowserTestUtils.waitForEvent(PanelUI.helpView, "ViewShown");
|
|
EventUtils.synthesizeKey(" ", {type: "keydown"});
|
|
await promise;
|
|
|
|
await gCUITestUtils.hideMainMenu();
|
|
});
|