// XXX move some API into devtools/shared/test/shared-head.js
/** * Add a new test tab in the browser and load the given url. * @param {String} url * The url to be loaded in the new tab. * * @param {Object} [optional] * An object with the following optional properties: * - appReadyState: The readyState of the JSON Viewer app that you want to * wait for. Its value can be one of: * - "uninitialized": The converter has started the request. * If JavaScript is disabled, there will be no more readyState changes. * - "loading": RequireJS started loading the scripts for the JSON Viewer. * If the load timeouts, there will be no more readyState changes. * - "interactive": The JSON Viewer app loaded, but possibly not all the JSON * data has been received. * - "complete" (default): The app is fully loaded with all the JSON. * - docReadyState: The standard readyState of the document that you want to * wait for. Its value can be one of: * - "loading": The JSON data has not been completely loaded (but the app might). * - "interactive": All the JSON data has been received. * - "complete" (default): Since there aren't sub-resources like images, * behaves as "interactive". Note the app might not be loaded yet.
*/
async function addJsonViewTab(
url,
{ appReadyState = "complete", docReadyState = "complete" } = {}
) {
info("Adding a new JSON tab with URL: '" + url + "'"); const tabAdded = BrowserTestUtils.waitForNewTab(gBrowser, url); const tabLoaded = addTab(url);
// The `tabAdded` promise resolves when the JSON Viewer starts loading. // This is usually what we want, however, it never resolves for unrecognized // content types that trigger a download. // On the other hand, `tabLoaded` always resolves, but not until the document // is fully loaded, which is too late if `docReadyState !== "complete"`. // Therefore, we race both promises. const tab = await Promise.race([tabAdded, tabLoaded]); const browser = tab.linkedBrowser;
const data = { rootDir, appReadyState, docReadyState };
await Promise.race([
error, // eslint-disable-next-line no-shadow
ContentTask.spawn(browser, data, async function (data) { // Check if there is a JSONView object. const { JSONView } = content.wrappedJSObject; if (!JSONView) { thrownew Error("The JSON Viewer did not load.");
}
function focusElement(selector) {
info("Focus element: '" + selector + "'");
return SpecialPowers.spawn(
gBrowser.selectedBrowser,
[selector],
selectorChild => { const element = content.document.querySelector(selectorChild); if (element) {
element.focus();
}
}
);
}
/** * Send the string aStr to the focused element. * * For now this method only works for ASCII characters and emulates the shift * key state on US keyboard layout.
*/ function sendString(str, selector) {
info("Send string: '" + str + "'");
return SpecialPowers.spawn(
gBrowser.selectedBrowser,
[selector, str],
(selectorChild, strChild) => { if (selectorChild) { const element = content.document.querySelector(selectorChild); if (element) {
element.focus();
}
}
EventUtils.sendString(strChild, content);
}
);
}
function waitForTime(delay) { returnnew Promise(resolve => setTimeout(resolve, delay));
}
// Check if the filter is already set. if (firstRow.classList.contains("hidden")) {
resolve(); return;
}
// Wait till the first row has 'hidden' class set. const observer = new content.MutationObserver(function (mutations) { for (let i = 0; i < mutations.length; i++) { const mutation = mutations[i]; if (mutation.attributeName == "class") { if (firstRow.classList.contains("hidden")) {
observer.disconnect();
resolve(); break;
}
}
}
});
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.