/* 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/. */ /* eslint no-unused-vars: [2, {"vars": "local", "args": "none"}] */
"use strict";
// shared-head.js handles imports, constants, and utility functions
Services.scriptloader.loadSubScript( "chrome://mochitests/content/browser/devtools/client/shared/test/shared-head.js", this
);
/** * Polls a given function waiting for the given value. * * @param object options * Options object with the following properties: * - validator * A validator function that should return the expected value. This is * called every few milliseconds to check if the result is the expected * one. When the returned result is the expected one, then the |success| * function is called and polling stops. If |validator| never returns * the expected value, then polling timeouts after several tries and * a failure is recorded - the given |failure| function is invoked. * - success * A function called when the validator function returns the expected * value. * - failure * A function called if the validator function timeouts - fails to return * the expected value in the given time. * - name * Name of test. This is used to generate the success and failure * messages. * - timeout * Timeout for validator function, in milliseconds. Default is 5000 ms. * - value * The expected value. If this option is omitted then the |validator| * function must return a trueish value. * Each of the provided callback functions will receive two arguments: * the |options| object and the last value returned by |validator|.
*/ function waitForValue(options) { const start = Date.now(); const timeout = options.timeout || 5000;
let lastValue;
function wait(validatorFn, successFn, failureFn) { if (Date.now() - start > timeout) { // Log the failure.
ok(false, "Timed out while waiting for: " + options.name); const expected = "value" in options ? "'" + options.value + "'" : "a trueish value";
info("timeout info :: got '" + lastValue + "', expected " + expected);
failureFn(options, lastValue); return;
}
/** * Open and close the toolbox in the current browser tab, several times, waiting * some amount of time in between. * @param {Number} nbOfTimes * @param {Number} usageTime in milliseconds * @param {String} toolId
*/
async function openAndCloseToolbox(nbOfTimes, usageTime, toolId) { for (let i = 0; i < nbOfTimes; i++) {
info("Opening toolbox " + (i + 1));
/** * 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);
});
}
/** * Show the presets list sidebar in the cssfilter widget popup * @param {CSSFilterWidget} widget * @return {Promise}
*/ function showFilterPopupPresets(widget) { const onRender = widget.once("render");
widget._togglePresets(); return onRender;
}
/** * Show presets list and create a sample preset with the name and value provided * @param {CSSFilterWidget} widget * @param {string} name * @param {string} value * @return {Promise}
*/ const showFilterPopupPresetsAndCreatePreset = async function (
widget,
name,
value
) {
await showFilterPopupPresets(widget);
let onRender = widget.once("render");
widget.setCssValue(value);
await onRender;
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.