/* 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/. */
// GUID to be used as a separator in compound keys. This must match the same // constant in devtools/server/actors/resources/storage/index.js, // devtools/client/storage/ui.js and devtools/client/storage/test/head.js const SEPARATOR_GUID = "{9d414cc5-8319-0a04-0586-c0a6ae01670a}";
// All tests are asynchronous.
waitForExplicitFinish();
// does almost the same thing as addTab, but directly returns an object
async function addTabTarget(url) {
info(`Adding a new tab with URL: ${url}`); const tab = (gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, url));
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
info(`Tab added a URL ${url} loaded`); return createAndAttachTargetForTab(tab);
}
function initDevToolsServer() { try { // Sometimes devtools server does not get destroyed correctly by previous // tests.
DevToolsServer.destroy();
} catch (e) {
info(`DevToolsServer destroy error: ${e}\n${e.stack}`);
}
DevToolsServer.init();
DevToolsServer.registerAllActors();
}
async function initPerfFront() {
initDevToolsServer(); const client = new DevToolsClient(DevToolsServer.connectPipe());
await waitUntilClientConnected(client); const front = await client.mainRoot.getFront("perf"); return { front, client };
}
/** * Wait until a DevToolsClient is connected. * @param {DevToolsClient} client * @return {Promise} Resolves when connected.
*/ function waitUntilClientConnected(client) { return client.once("connected");
}
/** * Wait for eventName on target. * @param {Object} target An observable object that either supports on/off or * addEventListener/removeEventListener * @param {String} eventName * @param {Boolean} useCapture Optional, for addEventListener/removeEventListener * @return A promise that resolves when the event has been handled
*/ function once(target, eventName, useCapture = false) {
info("Waiting for event: '" + eventName + "' on " + target + ".");
returnnew Promise(resolve => { for (const [add, remove] of [
["addEventListener", "removeEventListener"],
["addListener", "removeListener"],
["on", "off"],
]) { if (add in target && remove in target) {
target[add](
eventName, function onEvent(...aArgs) {
info("Got event: '" + eventName + "' on " + target + ".");
target[remove](eventName, onEvent, useCapture);
resolve(...aArgs);
},
useCapture
); break;
}
}
});
}
/** * Forces GC, CC and Shrinking GC to get rid of disconnected docshells and * windows.
*/ function forceCollections() {
Cu.forceGC();
Cu.forceCC();
Cu.forceShrinkingGC();
}
while (gBrowser.tabs.length > 1) {
gBrowser.removeCurrentTab();
}
});
function idleWait(time) { return DevToolsUtils.waitForTime(time);
}
function busyWait(time) { const start = Date.now();
let stack; while (Date.now() - start < time) {
stack = Components.stack; // eslint-disable-line no-unused-vars
}
}
/** * Waits until a predicate returns true. * * @param function predicate * Invoked once in a while until it returns true. * @param number interval [optional] * How often the predicate is invoked, in milliseconds.
*/ function waitUntil(predicate, interval = 10) { if (predicate()) { return Promise.resolve(true);
} returnnew Promise(resolve => {
setTimeout(function () {
waitUntil(predicate).then(() => resolve(true));
}, interval);
});
}
/** * Trigger DOM activity and wait for the corresponding accessibility event. * @param {Object} emitter Devtools event emitter, usually a front. * @param {Sting} name Accessibility event in question. * @param {Function} handler Accessibility event handler function with checks. * @param {Promise} task A promise that resolves when DOM activity is done.
*/
async function emitA11yEvent(emitter, name, handler, task) { const promise = emitter.once(name, handler);
await task();
await promise;
}
/** * Check that accessibilty front is correct and its attributes are also * up-to-date. * @param {Object} front Accessibility front to be tested. * @param {Object} expected A map of a11y front properties to be verified. * @param {Object} expectedFront Expected accessibility front.
*/ function checkA11yFront(front, expected, expectedFront) {
ok(front, "The accessibility front is created");
if (expectedFront) {
is(front, expectedFront, "Matching accessibility front");
}
// Clone the front so we could modify some values for comparison.
front = Object.assign(front); for (const key in expected) { if (key === "checks") { const { CONTRAST } = front[key]; // Contrast values are rounded to two digits after the decimal point. if (CONTRAST && CONTRAST.value) {
CONTRAST.value = parseFloat(CONTRAST.value.toFixed(2));
}
}
if (["actions", "states", "attributes", "checks"].includes(key)) {
SimpleTest.isDeeply(
front[key],
expected[key],
`Accessible Front has correct ${key}`
);
} else {
is(front[key], expected[key], `accessibility front has correct ${key}`);
}
}
}
/** * Wait for accessibility service to shut down. We consider it shut down when * an "a11y-init-or-shutdown" event is received with a value of "0".
*/
async function waitForA11yShutdown(parentAccessibility) {
await parentAccessibility.disable(); if (!Services.appinfo.accessibilityEnabled) { return;
}
/** * Wait for accessibility service to initialize. We consider it initialized when * an "a11y-init-or-shutdown" event is received with a value of "1".
*/
async function waitForA11yInit() { if (Services.appinfo.accessibilityEnabled) { return;
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.30Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.