/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const gClickEvents = ["mousedown", "mouseup", "click"];
const gActionDescrMap = {
jump: "Jump",
press: "Press",
check: "Check",
uncheck: "Uncheck",
select: "Select",
open: "Open",
close: "Close",
switch: "Switch",
click: "Click",
collapse: "Collapse",
expand: "Expand",
activate: "Activate",
cycle: "Cycle",
"click ancestor": "Click ancestor",
};
async function testActions(browser, docAcc, id, expectedActions, domEvents) {
const acc = findAccessibleChildByID(docAcc, id);
is(acc.actionCount, expectedActions.length, "Correct action count");
let actionNames = [];
let actionDescriptions = [];
for (let i = 0; i < acc.actionCount; i++) {
actionNames.push(acc.getActionName(i));
actionDescriptions.push(acc.getActionDescription(i));
}
is(actionNames.join(","), expectedActions.join(","), "Correct action names");
is(
actionDescriptions.join(","),
expectedActions.map(a => gActionDescrMap[a]).join(","),
"Correct action descriptions"
);
if (!domEvents) {
return;
}
// We need to set up the listener, and wait for the promise in two separate
// content tasks.
await invokeContentTask(browser, [id, domEvents], (_id, _domEvents) => {
let promises = _domEvents.map(
evtName =>
new Promise(resolve => {
const listener = e => {
if (e.target.id == _id) {
content.removeEventListener(evtName, listener);
content.evtPromise = null;
resolve(42);
}
};
content.addEventListener(evtName, listener);
})
);
content.evtPromise = Promise.all(promises);
});
acc.doAction(0);
let eventFired = await invokeContentTask(browser, [], async () => {
await content.evtPromise;
return true;
});
ok(eventFired, `DOM events fired '${domEvents}'`);
}
addAccessibleTask(
`