/* Any copyright is dedicated to the Public Domain. * http://creativecommons.org/publicdomain/zero/1.0/ */ // shared-head.js handles imports, constants, and utility functions Services.scriptloader.loadSubScript( "chrome://mochitests/content/browser/devtools/client/shared/test/shared-head.js", this ); Services.scriptloader.loadSubScript( "chrome://mochitests/content/browser/devtools/client/inspector/test/shared-head.js", this ); const EventEmitter = require("resource://devtools/shared/event-emitter.js"); /** * Retrieve all tool ids compatible with a target created for the provided tab. * * @param {XULTab} tab * The tab for which we want to get the list of supported toolIds * @return {Array} array of tool ids */ async function getSupportedToolIds(tab) { info("Getting the entire list of tools supported in this tab"); let shouldDestroyToolbox = false; // Get the toolbox for this tab, or create one if needed. let toolbox = await gDevTools.getToolboxForTab(tab); if (!toolbox) { toolbox = await gDevTools.showToolboxForTab(tab); shouldDestroyToolbox = true; } const toolIds = gDevTools .getToolDefinitionArray() .filter(def => def.isToolSupported(toolbox)) .map(def => def.id); if (shouldDestroyToolbox) { // Only close the toolbox if it was explicitly created here. await toolbox.destroy(); } return toolIds; } function toggleAllTools(state) { for (const [, tool] of gDevTools._tools) { if (!tool.visibilityswitch) { continue; } if (state) { Services.prefs.setBoolPref(tool.visibilityswitch, true); } else { Services.prefs.clearUserPref(tool.visibilityswitch); } } } async function getParentProcessActors(callback) { const commands = await CommandsFactory.forMainProcess(); const mainProcessTargetFront = await commands.descriptorFront.getTarget(); callback(commands.client, mainProcessTargetFront); } function getSourceActor(aSources, aURL) { const item = aSources.getItemForAttachment(a => a.source.url === aURL); return item && item.value; } /** * Synthesize a keypress from a element, taking into account * any modifiers. * @param {Element} el the element to synthesize */ function synthesizeKeyElement(el) { const key = el.getAttribute("key") || el.getAttribute("keycode"); const mod = {}; el.getAttribute("modifiers") .split(" ") .forEach(m => (mod[m + "Key"] = true)); info(`Synthesizing: key=${key}, mod=${JSON.stringify(mod)}`); EventUtils.synthesizeKey(key, mod, el.ownerDocument.defaultView); } /* Check the toolbox host type and prefs to make sure they match the * expected values * @param {Toolbox} * @param {HostType} hostType * One of {SIDE, BOTTOM, WINDOW} from Toolbox.HostType * @param {HostType} Optional previousHostType * The host that will be switched to when calling switchToPreviousHost */ function checkHostType(toolbox, hostType, previousHostType) { is(toolbox.hostType, hostType, "host type is " + hostType); const pref = Services.prefs.getCharPref("devtools.toolbox.host"); is(pref, hostType, "host pref is " + hostType); if (previousHostType) { is( Services.prefs.getCharPref("devtools.toolbox.previousHost"), previousHostType, "The previous host is correct" ); } } /** * Create a new