Backed out changeset 9dfd5e6601a1 (bug 1505304) as requested by nchevobbe

This commit is contained in:
Narcis Beleuzu 2021-11-23 14:56:24 +02:00
Родитель 16be926c53
Коммит 81698c54eb
36 изменённых файлов: 278 добавлений и 429 удалений

Просмотреть файл

@ -411,12 +411,12 @@ class AccessibilityProxy {
}
async initialize() {
await this.commands.targetCommand.watchTargets({
types: [this.commands.targetCommand.TYPES.FRAME],
onAvailable: this.onTargetAvailable,
onSelected: this.onTargetSelected,
onDestroyed: this.onTargetDestroyed,
});
await this.commands.targetCommand.watchTargets(
[this.commands.targetCommand.TYPES.FRAME],
this.onTargetAvailable,
this.onTargetDestroyed,
this.onTargetSelected
);
await this.commands.resourceCommand.watchResources(
[this.commands.resourceCommand.TYPES.DOCUMENT_EVENT],
{
@ -429,12 +429,12 @@ class AccessibilityProxy {
}
destroy() {
this.commands.targetCommand.unwatchTargets({
types: [this.commands.targetCommand.TYPES.FRAME],
onAvailable: this.onTargetAvailable,
onSelected: this.onTargetSelected,
onDestroyed: this.onTargetDestroyed,
});
this.commands.targetCommand.unwatchTargets(
[this.commands.targetCommand.TYPES.FRAME],
this.onTargetAvailable,
this.onTargetDestroyed,
this.onTargetSelected
);
this.commands.resourceCommand.unwatchResources(
[this.commands.resourceCommand.TYPES.DOCUMENT_EVENT],
{ onAvailable: this.onResourceAvailable }

Просмотреть файл

@ -66,11 +66,11 @@ export async function onConnect(_commands, _resourceCommand, _actions, store) {
targetFront.isWebExtension
);
await targetCommand.watchTargets({
types: targetCommand.ALL_TYPES,
onAvailable: onTargetAvailable,
onDestroyed: onTargetDestroyed,
});
await targetCommand.watchTargets(
targetCommand.ALL_TYPES,
onTargetAvailable,
onTargetDestroyed
);
// Use independant listeners for SOURCE and THREAD_STATE in order to ease
// doing batching and notify about a set of SOURCE's in one redux action.
@ -92,11 +92,11 @@ export async function onConnect(_commands, _resourceCommand, _actions, store) {
}
export function onDisconnect() {
targetCommand.unwatchTargets({
types: targetCommand.ALL_TYPES,
onAvailable: onTargetAvailable,
onDestroyed: onTargetDestroyed,
});
targetCommand.unwatchTargets(
targetCommand.ALL_TYPES,
onTargetAvailable,
onTargetDestroyed
);
resourceCommand.unwatchResources([resourceCommand.TYPES.SOURCE], {
onAvailable: onSourceAvailable,
});

Просмотреть файл

@ -64,11 +64,12 @@ DomPanel.prototype = {
// onTargetAvailable is mandatory when calling watchTargets
this._onTargetAvailable = () => {};
this._onTargetSelected = this._onTargetSelected.bind(this);
await this._commands.targetCommand.watchTargets({
types: [this._commands.targetCommand.TYPES.FRAME],
onAvailable: this._onTargetAvailable,
onSelected: this._onTargetSelected,
});
await this._commands.targetCommand.watchTargets(
[this._commands.targetCommand.TYPES.FRAME],
this._onTargetAvailable,
null,
this._onTargetSelected
);
this.onResourceAvailable = this.onResourceAvailable.bind(this);
await this._commands.resourceCommand.watchResources(
@ -101,11 +102,12 @@ DomPanel.prototype = {
}
this._destroyed = true;
this._commands.targetCommand.unwatchTargets({
types: [this._commands.targetCommand.TYPES.FRAME],
onAvailable: this._onTargetAvailable,
onSelected: this._onTargetSelected,
});
this._commands.targetCommand.unwatchTargets(
[this._commands.targetCommand.TYPES.FRAME],
this._onTargetAvailable,
null,
this._onTargetSelected
);
this._commands.resourceCommand.unwatchResources(
[this._commands.resourceCommand.TYPES.DOCUMENT_EVENT],
{ onAvailable: this.onResourceAvailable }

Просмотреть файл

@ -900,12 +900,12 @@ Toolbox.prototype = {
// and we are registering the first target listener, which means
// Toolbox._onTargetAvailable will be called first, before any other
// onTargetAvailable listener that might be registered on targetCommand.
await this.commands.targetCommand.watchTargets({
types: this.commands.targetCommand.ALL_TYPES,
onAvailable: this._onTargetAvailable,
onSelected: this._onTargetSelected,
onDestroyed: this._onTargetDestroyed,
});
await this.commands.targetCommand.watchTargets(
this.commands.targetCommand.ALL_TYPES,
this._onTargetAvailable,
this._onTargetDestroyed,
this._onTargetSelected
);
const onResourcesWatched = this.resourceCommand.watchResources(
[
@ -3964,12 +3964,12 @@ Toolbox.prototype = {
// Reset preferences set by the toolbox
outstanding.push(this.resetPreference());
this.commands.targetCommand.unwatchTargets({
types: this.commands.targetCommand.ALL_TYPES,
onAvailable: this._onTargetAvailable,
onSelected: this._onTargetSelected,
onDestroyed: this._onTargetDestroyed,
});
this.commands.targetCommand.unwatchTargets(
this.commands.targetCommand.ALL_TYPES,
this._onTargetAvailable,
this._onTargetDestroyed,
this._onTargetSelected
);
this.resourceCommand.unwatchResources(
[
this.resourceCommand.TYPES.CONSOLE_MESSAGE,

Просмотреть файл

@ -147,10 +147,10 @@ class AnimationInspector {
}
async initListeners() {
await this.inspector.commands.targetCommand.watchTargets({
types: [this.inspector.commands.targetCommand.TYPES.FRAME],
onAvailable: this.onTargetAvailable,
});
await this.inspector.commands.targetCommand.watchTargets(
[this.inspector.commands.targetCommand.TYPES.FRAME],
this.onTargetAvailable
);
this.inspector.on("new-root", this.onNavigate);
this.inspector.selection.on("new-node-front", this.update);

Просмотреть файл

@ -206,12 +206,12 @@ Inspector.prototype = {
// iframe if it had already been initialized.
this.setupSplitter();
await this.commands.targetCommand.watchTargets({
types: [this.commands.targetCommand.TYPES.FRAME],
onAvailable: this._onTargetAvailable,
onSelected: this._onTargetSelected,
onDestroyed: this._onTargetDestroyed,
});
await this.commands.targetCommand.watchTargets(
[this.commands.targetCommand.TYPES.FRAME],
this._onTargetAvailable,
this._onTargetDestroyed,
this._onTargetSelected
);
await this.toolbox.resourceCommand.watchResources(
[
@ -1730,12 +1730,12 @@ Inspector.prototype = {
this.searchboxShortcuts.destroy();
this.searchboxShortcuts = null;
this.commands.targetCommand.unwatchTargets({
types: [this.commands.targetCommand.TYPES.FRAME],
onAvailable: this._onTargetAvailable,
onSelected: this._onTargetSelected,
onDestroyed: this._onTargetDestroyed,
});
this.commands.targetCommand.unwatchTargets(
[this.commands.targetCommand.TYPES.FRAME],
this._onTargetAvailable,
this._onTargetDestroyed,
this._onTargetSelected
);
const { resourceCommand } = this.toolbox;
resourceCommand.unwatchResources(
[

Просмотреть файл

@ -155,10 +155,10 @@ class NodePicker extends EventEmitter {
this.emit("picker-starting");
this.targetCommand.watchTargets({
types: this.targetCommand.ALL_TYPES,
onAvailable: this._onTargetAvailable,
});
this.targetCommand.watchTargets(
this.targetCommand.ALL_TYPES,
this._onTargetAvailable
);
this.emit("picker-started");
}
@ -181,10 +181,10 @@ class NodePicker extends EventEmitter {
this.isPicking = false;
this.doFocus = false;
this.targetCommand.unwatchTargets({
types: this.targetCommand.ALL_TYPES,
onAvailable: this._onTargetAvailable,
});
this.targetCommand.unwatchTargets(
this.targetCommand.ALL_TYPES,
this._onTargetAvailable
);
for (const inspectorFront of this._currentInspectorFronts) {
await this._onInspectorFrontDestroyed(inspectorFront, {

Просмотреть файл

@ -32,11 +32,11 @@ class WalkerEventListener {
* Clean up function.
*/
destroy() {
this._inspector.commands.targetCommand.unwatchTargets({
types: [this._inspector.commands.targetCommand.TYPES.FRAME],
onAvailable: this._onTargetAvailable,
onDestroyed: this._onTargetDestroyed,
});
this._inspector.commands.targetCommand.unwatchTargets(
[this._inspector.commands.targetCommand.TYPES.FRAME],
this._onTargetAvailable,
this._onTargetDestroyed
);
const targets = this._inspector.commands.targetCommand.getAllTargets([
this._inspector.commands.targetCommand.TYPES.FRAME,
@ -52,11 +52,11 @@ class WalkerEventListener {
}
_init() {
this._inspector.commands.targetCommand.watchTargets({
types: [this._inspector.commands.targetCommand.TYPES.FRAME],
onAvailable: this._onTargetAvailable,
onDestroyed: this._onTargetDestroyed,
});
this._inspector.commands.targetCommand.watchTargets(
[this._inspector.commands.targetCommand.TYPES.FRAME],
this._onTargetAvailable,
this._onTargetDestroyed
);
}
async _onTargetAvailable({ targetFront }) {

Просмотреть файл

@ -34,10 +34,10 @@ MemoryPanel.prototype = {
await this.initializer.initialize(this._commands);
await this._commands.targetCommand.watchTargets({
types: [this._commands.targetCommand.TYPES.FRAME],
onAvailable: this._onTargetAvailable,
});
await this._commands.targetCommand.watchTargets(
[this._commands.targetCommand.TYPES.FRAME],
this._onTargetAvailable
);
return this;
},
@ -59,10 +59,10 @@ MemoryPanel.prototype = {
}
this._destroyed = true;
this._commands.targetCommand.unwatchTargets({
types: [this._commands.targetCommand.TYPES.FRAME],
onAvailable: this._onTargetAvailable,
});
this._commands.targetCommand.unwatchTargets(
[this._commands.targetCommand.TYPES.FRAME],
this._onTargetAvailable
);
this.initializer.destroy();

Просмотреть файл

@ -93,10 +93,10 @@ class Connector {
owner: this.owner,
});
await this.commands.targetCommand.watchTargets({
types: [this.commands.targetCommand.TYPES.FRAME],
onAvailable: this.onTargetAvailable,
});
await this.commands.targetCommand.watchTargets(
[this.commands.targetCommand.TYPES.FRAME],
this.onTargetAvailable
);
const { TYPES } = this.toolbox.resourceCommand;
const targetResources = [
@ -141,10 +141,10 @@ class Connector {
this._destroyed = true;
this.commands.targetCommand.unwatchTargets({
types: [this.commands.targetCommand.TYPES.FRAME],
onAvailable: this.onTargetAvailable,
});
this.commands.targetCommand.unwatchTargets(
[this.commands.targetCommand.TYPES.FRAME],
this.onTargetAvailable
);
const { TYPES } = this.toolbox.resourceCommand;
this.toolbox.resourceCommand.unwatchResources(

Просмотреть файл

@ -50,10 +50,10 @@ PerformancePanel.prototype = {
// the `watchTargets` function.
// So this `await` waits for initialization with current target, happening
// in `_onTargetAvailable`.
await this.commands.targetCommand.watchTargets({
types: [this.commands.targetCommand.TYPES.FRAME],
onAvailable: this._onTargetAvailable,
});
await this.commands.targetCommand.watchTargets(
[this.commands.targetCommand.TYPES.FRAME],
this._onTargetAvailable
);
// Fire this once incase we have an in-progress recording (console profile)
// that caused this start up, and no state change yet, so we can highlight the
@ -88,10 +88,10 @@ PerformancePanel.prototype = {
this._checkRecordingStatus
);
this.commands.targetCommand.unwatchTargets({
types: [this.commands.targetCommand.TYPES.FRAME],
onAvailable: this._onTargetAvailable,
});
this.commands.targetCommand.unwatchTargets(
[this.commands.targetCommand.TYPES.FRAME],
this._onTargetAvailable
);
await PerformanceController.destroy();
await PerformanceView.destroy();
PerformanceController.disableFrontEventListeners();

Просмотреть файл

@ -320,10 +320,10 @@ class ResponsiveUI {
// any resource & target anymore, the JSWindowActors will be unregistered
// which will trigger an early destruction of the RDM target, before we
// could finalize the cleanup.
this.commands.targetCommand.unwatchTargets({
types: [this.commands.targetCommand.TYPES.FRAME],
onAvailable: this.onTargetAvailable,
});
this.commands.targetCommand.unwatchTargets(
[this.commands.targetCommand.TYPES.FRAME],
this.onTargetAvailable
);
this.resourceCommand.unwatchResources(
[this.resourceCommand.TYPES.NETWORK_EVENT],
@ -367,10 +367,10 @@ class ResponsiveUI {
await this.commands.targetCommand.startListening();
await this.commands.targetCommand.watchTargets({
types: [this.commands.targetCommand.TYPES.FRAME],
onAvailable: this.onTargetAvailable,
});
await this.commands.targetCommand.watchTargets(
[this.commands.targetCommand.TYPES.FRAME],
this.onTargetAvailable
);
// To support network throttling the resource command
// needs to be watching for network resources.

Просмотреть файл

@ -267,7 +267,7 @@ class StorageUI {
}
async init() {
// This is a distionary of arrays, keyed by storage key
// This is a distionarry of arrays, keyed by storage key
// - Keys are storage keys, available on each storage resource, via ${resource.resourceKey}
// and are typically "Cache", "cookies", "indexedDB", "localStorage", ...
// - Values are arrays of storage fronts. This isn't the deprecated global storage front (target.getFront(storage), only used by legacy listener),
@ -276,11 +276,11 @@ class StorageUI {
this._onTargetAvailable = this._onTargetAvailable.bind(this);
this._onTargetDestroyed = this._onTargetDestroyed.bind(this);
await this._commands.targetCommand.watchTargets({
types: [this._commands.targetCommand.TYPES.FRAME],
onAvailable: this._onTargetAvailable,
onDestroyed: this._onTargetDestroyed,
});
await this._commands.targetCommand.watchTargets(
[this._commands.targetCommand.TYPES.FRAME],
this._onTargetAvailable,
this._onTargetDestroyed
);
this._onResourceListAvailable = this._onResourceListAvailable.bind(this);

Просмотреть файл

@ -71,17 +71,14 @@ add_task(async function() {
: new Promise(resolve => {
const onAvailable = ({ targetFront }) => {
if (targetFront.url.includes("view-source:")) {
targetCommand.unwatchTargets({
types: [targetCommand.TYPES.FRAME],
onAvailable,
});
targetCommand.unwatchTargets(
[targetCommand.TYPES.FRAME],
onAvailable
);
resolve();
}
};
targetCommand.watchTargets({
types: [targetCommand.TYPES.FRAME],
onAvailable,
});
targetCommand.watchTargets([targetCommand.TYPES.FRAME], onAvailable);
});
const onTabOpen = BrowserTestUtils.waitForNewTab(

Просмотреть файл

@ -187,16 +187,10 @@ function waitForSourceMapWorker(hud) {
!seenWorkerTargets.has(targetFront)
) {
seenWorkerTargets.add(targetFront);
targetCommand.unwatchTargets({
types: [targetCommand.TYPES.WORKER],
onAvailable,
});
targetCommand.unwatchTargets([targetCommand.TYPES.WORKER], onAvailable);
resolve();
}
};
targetCommand.watchTargets({
types: [targetCommand.TYPES.WORKER],
onAvailable,
});
targetCommand.watchTargets([targetCommand.TYPES.WORKER], onAvailable);
});
}

Просмотреть файл

@ -208,11 +208,11 @@ class WebConsoleUI {
}
// Stop listening for targets
this.hud.commands.targetCommand.unwatchTargets({
types: this.hud.commands.targetCommand.ALL_TYPES,
onAvailable: this._onTargetAvailable,
onDestroyed: this._onTargetDestroy,
});
this.hud.commands.targetCommand.unwatchTargets(
this.hud.commands.targetCommand.ALL_TYPES,
this._onTargetAvailable,
this._onTargetDestroy
);
const resourceCommand = this.hud.resourceCommand;
resourceCommand.unwatchResources(
@ -344,11 +344,11 @@ class WebConsoleUI {
// - workers, for similar reason. When we open a toolbox
// for just a worker, the top level target is a worker target.
// - processes, as we want to spawn additional proxies for them.
await commands.targetCommand.watchTargets({
types: this.hud.commands.targetCommand.ALL_TYPES,
onAvailable: this._onTargetAvailable,
onDestroyed: this._onTargetDestroy,
});
await commands.targetCommand.watchTargets(
commands.targetCommand.ALL_TYPES,
this._onTargetAvailable,
this._onTargetDestroy
);
const resourceCommand = commands.resourceCommand;
await resourceCommand.watchResources(

Просмотреть файл

@ -325,11 +325,11 @@ class ResourceCommand {
// If this is the very first listener registered, of all kind of resource types:
// * we want to start observing targets via TargetCommand
// * _onTargetAvailable will be called for each already existing targets and the next one to come
this._watchTargetsPromise = this.targetCommand.watchTargets({
types: this.targetCommand.ALL_TYPES,
onAvailable: this._onTargetAvailable,
onDestroyed: this._onTargetDestroyed,
});
this._watchTargetsPromise = this.targetCommand.watchTargets(
this.targetCommand.ALL_TYPES,
this._onTargetAvailable,
this._onTargetDestroyed
);
}
return this._watchTargetsPromise;
}
@ -345,11 +345,11 @@ class ResourceCommand {
this._offTargetFrontListeners.clear();
this._watchTargetsPromise = null;
this.targetCommand.unwatchTargets({
types: this.targetCommand.ALL_TYPES,
onAvailable: this._onTargetAvailable,
onDestroyed: this._onTargetDestroyed,
});
this.targetCommand.unwatchTargets(
this.targetCommand.ALL_TYPES,
this._onTargetAvailable,
this._onTargetDestroyed
);
}
/**

Просмотреть файл

@ -31,10 +31,7 @@ add_task(async function() {
resolve();
}
};
targetCommand.watchTargets({
types: [targetCommand.TYPES.WORKER],
onAvailable,
});
targetCommand.watchTargets([targetCommand.TYPES.WORKER], onAvailable);
});
// The worker logs a message right when it starts, containing its location, so we can

Просмотреть файл

@ -25,11 +25,10 @@ add_task(async function() {
await targetCommand.startListening();
const targets = [];
await targetCommand.watchTargets({
types: targetCommand.ALL_TYPES,
onAvailable: async function({ targetFront }) {
targets.push(targetFront);
},
await targetCommand.watchTargets(targetCommand.ALL_TYPES, async function({
targetFront,
}) {
targets.push(targetFront);
});
is(targets.length, 3, "Got expected number of targets");

Просмотреть файл

@ -114,10 +114,10 @@ add_task(async function() {
const otherTargetCommand = otherCommands.targetCommand;
await otherTargetCommand.startListening();
// wait for the target to be fully attached to avoid pending connection to the server
await otherTargetCommand.watchTargets({
types: [otherTargetCommand.TYPES.FRAME],
onAvailable: () => {},
});
await otherTargetCommand.watchTargets(
[otherTargetCommand.TYPES.FRAME],
() => {}
);
// Let's update the configuration with this commands instance to make sure we hit the TargetConfigurationActor
await otherTargetConfigurationCommand.updateConfiguration({

Просмотреть файл

@ -74,10 +74,10 @@ add_task(async function() {
await otherTargetCommand.startListening();
// Watch targets so we wait for server communication to settle (e.g. attach calls), as
// this could cause intermittent failures.
await otherTargetCommand.watchTargets({
types: [otherTargetCommand.TYPES.FRAME],
onAvailable: () => {},
});
await otherTargetCommand.watchTargets(
[otherTargetCommand.TYPES.FRAME],
() => {}
);
// Let's update the configuration with this commands instance to make sure we hit the TargetConfigurationActor
await otherTargetConfigurationCommand.updateConfiguration({

Просмотреть файл

@ -142,11 +142,11 @@ class LegacyWorkersWatcher {
this.target = this.targetCommand.targetFront;
if (this.target.isParentProcess) {
await this.targetCommand.watchTargets({
types: [this.targetCommand.TYPES.PROCESS],
onAvailable: this._onProcessAvailable,
onDestroyed: this._onProcessDestroyed,
});
await this.targetCommand.watchTargets(
[this.targetCommand.TYPES.PROCESS],
this._onProcessAvailable,
this._onProcessDestroyed
);
// The ParentProcessTarget front is considered to be a FRAME instead of a PROCESS.
// So process it manually here.
@ -199,11 +199,11 @@ class LegacyWorkersWatcher {
unlisten({ isTargetSwitching } = {}) {
// Stop listening for new process targets.
if (this.target.isParentProcess) {
this.targetCommand.unwatchTargets({
types: [this.targetCommand.TYPES.PROCESS],
onAvailable: this._onProcessAvailable,
onDestroyed: this._onProcessDestroyed,
});
this.targetCommand.unwatchTargets(
[this.targetCommand.TYPES.PROCESS],
this._onProcessAvailable,
this._onProcessDestroyed
);
} else if (this._isServiceWorkerWatcher) {
this._legacyProcessesWatcher.unlisten();
}

Просмотреть файл

@ -632,45 +632,26 @@ class TargetCommand extends EventEmitter {
/**
* Listen for the creation and/or destruction of target fronts matching one of the provided types.
*
* @param {Object} options
* @param {Array<String>} options.types
* @param {Array<String>} types
* The type of target to listen for. Constant of TargetCommand.TYPES.
* @param {Function} options.onAvailable
* Mandatory callback fired when a target has been just created or was already available.
* @param {Function} onAvailable
* Callback fired when a target has been just created or was already available.
* The function is called with a single object argument containing the following properties:
* - {TargetFront} targetFront: The target Front
* - {Boolean} isTargetSwitching: Is this target relates to a navigation and
* this replaced a previously available target, this flag will be true
* @param {Function} options.onDestroyed
* Optional callback fired in case of target front destruction.
* @param {Function} onDestroy
* Callback fired in case of target front destruction.
* The function is called with the same arguments than onAvailable.
* @param {Function} options.onSelected
* Optional callback fired when a given target is selected from the iframe picker
* @param {Function} onSelect.
* Callback fired when a given target is selected from the iframe picker
* The function is called with a single object argument containing the following properties:
* - {TargetFront} targetFront: The target Front
*/
async watchTargets(options = {}) {
const availableOptions = [
"types",
"onAvailable",
"onDestroyed",
"onSelected",
];
const unsupportedKeys = Object.keys(options).filter(
key => !availableOptions.includes(key)
);
if (unsupportedKeys.length > 0) {
throw new Error(
`TargetCommand.watchTargets does not expect the following options: ${unsupportedKeys.join(
", "
)}`
);
}
const { types, onAvailable, onDestroyed, onSelected } = options;
async watchTargets(types, onAvailable, onDestroy, onSelect) {
if (typeof onAvailable != "function") {
throw new Error(
"TargetCommand.watchTargets expects a function for the onAvailable option"
"TargetCommand.watchTargets expects a function as second argument"
);
}
@ -734,11 +715,11 @@ class TargetCommand extends EventEmitter {
for (const type of types) {
this._createListeners.on(type, onAvailable);
if (onDestroyed) {
this._destroyListeners.on(type, onDestroyed);
if (onDestroy) {
this._destroyListeners.on(type, onDestroy);
}
if (onSelected) {
this._selectListeners.on(type, onSelected);
if (onSelect) {
this._selectListeners.on(type, onSelect);
}
}
@ -750,28 +731,10 @@ class TargetCommand extends EventEmitter {
* Stop listening for the creation and/or destruction of a given type of target fronts.
* See `watchTargets()` for documentation of the arguments.
*/
unwatchTargets(options = {}) {
const availableOptions = [
"types",
"onAvailable",
"onDestroyed",
"onSelected",
];
const unsupportedKeys = Object.keys(options).filter(
key => !availableOptions.includes(key)
);
if (unsupportedKeys.length > 0) {
throw new Error(
`TargetCommand.unwatchTargets does not expect the following options: ${unsupportedKeys.join(
", "
)}`
);
}
const { types, onAvailable, onDestroyed, onSelected } = options;
unwatchTargets(types, onAvailable, onDestroy, onSelect) {
if (typeof onAvailable != "function") {
throw new Error(
"TargetCommand.unwatchTargets expects a function for the onAvailable option"
"TargetCommand.unwatchTargets expects a function as second argument"
);
}
@ -783,11 +746,11 @@ class TargetCommand extends EventEmitter {
}
this._createListeners.off(type, onAvailable);
if (onDestroyed) {
this._destroyListeners.off(type, onDestroyed);
if (onDestroy) {
this._destroyListeners.off(type, onDestroy);
}
if (onSelected) {
this._selectListeners.off(type, onSelected);
if (onSelect) {
this._selectListeners.off(type, onSelect);
}
}
this._pendingWatchTargetInitialization.delete(onAvailable);

Просмотреть файл

@ -72,11 +72,7 @@ async function testTopLevelNavigations(bfcacheInParent) {
destroyedTargets.push(targetFront);
};
await targetCommand.watchTargets({
types: [TYPES.FRAME],
onAvailable,
onDestroyed,
});
await targetCommand.watchTargets([TYPES.FRAME], onAvailable, onDestroyed);
is(targets.length, 1, "retrieved only the top level target");
is(targets[0], targetCommand.targetFront, "the target is the top level one");
is(
@ -278,7 +274,7 @@ async function testTopLevelNavigations(bfcacheInParent) {
await waitForAllTargetsToBeAttached(targetCommand);
targetCommand.unwatchTargets({ types: [TYPES.FRAME], onAvailable });
targetCommand.unwatchTargets([TYPES.FRAME], onAvailable);
BrowserTestUtils.removeTab(tab);
@ -323,11 +319,7 @@ async function testTopLevelNavigationsOnDocumentWithIframe(bfcacheInParent) {
destroyedTargets.push(targetFront);
};
await targetCommand.watchTargets({
types: [TYPES.FRAME],
onAvailable,
onDestroyed,
});
await targetCommand.watchTargets([TYPES.FRAME], onAvailable, onDestroyed);
if (isEveryFrameTargetEnabled()) {
is(
@ -458,11 +450,7 @@ async function testTopLevelNavigationsOnDocumentWithIframe(bfcacheInParent) {
await waitForAllTargetsToBeAttached(targetCommand);
targetCommand.unwatchTargets({
types: [TYPES.FRAME],
onAvailable,
onDestroyed,
});
targetCommand.unwatchTargets([TYPES.FRAME], onAvailable);
BrowserTestUtils.removeTab(tab);
@ -491,7 +479,7 @@ async function testIframeNavigations() {
);
targets.push(targetFront);
};
await targetCommand.watchTargets({ types: [TYPES.FRAME], onAvailable });
await targetCommand.watchTargets([TYPES.FRAME], onAvailable);
// When fission/EFT is off, there isn't much to test for iframes as they are debugged
// when the unique top level target
@ -555,7 +543,7 @@ async function testIframeNavigations() {
is(targets[4].url, secondPageUrl, "the 4th target is for the second url");
ok(targets[3].isDestroyed(), "the third target is destroyed");
targetCommand.unwatchTargets({ types: [TYPES.FRAME], onAvailable });
targetCommand.unwatchTargets([TYPES.FRAME], onAvailable);
await waitForAllTargetsToBeAttached(targetCommand);

Просмотреть файл

@ -124,10 +124,10 @@ add_task(async function() {
);
targets.push(targetFront);
};
await targetCommand.watchTargets({
types: [TYPES.WORKER, TYPES.SHARED_WORKER, TYPES.SERVICE_WORKER],
onAvailable,
});
await targetCommand.watchTargets(
[TYPES.WORKER, TYPES.SHARED_WORKER, TYPES.SERVICE_WORKER],
onAvailable
);
is(
targets.length,
workers.length + sharedWorkers.length + serviceWorkers.length,
@ -147,10 +147,10 @@ add_task(async function() {
);
}
targetCommand.unwatchTargets({
types: [TYPES.WORKER, TYPES.SHARED_WORKER, TYPES.SERVICE_WORKER],
onAvailable,
});
targetCommand.unwatchTargets(
[TYPES.WORKER, TYPES.SHARED_WORKER, TYPES.SERVICE_WORKER],
onAvailable
);
// Create a new worker and see if the worker target is reported
const onWorkerCreated = new Promise(resolve => {
@ -158,16 +158,10 @@ add_task(async function() {
if (targets.includes(targetFront)) {
return;
}
targetCommand.unwatchTargets({
types: [TYPES.WORKER],
onAvailable: onAvailable2,
});
targetCommand.unwatchTargets([TYPES.WORKER], onAvailable2);
resolve(targetFront);
};
targetCommand.watchTargets({
types: [TYPES.WORKER],
onAvailable: onAvailable2,
});
targetCommand.watchTargets([TYPES.WORKER], onAvailable2);
});
// eslint-disable-next-line no-unused-vars
const worker2 = new Worker(CHROME_WORKER_URL + "#second");
@ -197,19 +191,11 @@ add_task(async function() {
const onWorkerDestroyed = new Promise(resolve => {
const emptyFn = () => {};
const onDestroyed = ({ targetFront }) => {
targetCommand.unwatchTargets({
types: [TYPES.WORKER],
onAvailable: emptyFn,
onDestroyed,
});
targetCommand.unwatchTargets([TYPES.WORKER], emptyFn, onDestroyed);
resolve(targetFront);
};
targetCommand.watchTargets({
types: [TYPES.WORKER],
onAvailable: emptyFn,
onDestroyed,
});
targetCommand.watchTargets([TYPES.WORKER], emptyFn, onDestroyed);
});
worker2.terminate();
const workerTargetFront = await onWorkerDestroyed;

Просмотреть файл

@ -243,7 +243,7 @@ async function testBrowserFrames() {
);
targets.push(targetFront);
};
await targetCommand.watchTargets({ types: [TYPES.FRAME], onAvailable });
await targetCommand.watchTargets([TYPES.FRAME], onAvailable);
is(
targets.length,
frames.length,
@ -358,7 +358,7 @@ async function testBrowserFrames() {
);
chromeWindow.close();
targetCommand.unwatchTargets({ types: [TYPES.FRAME], onAvailable });
targetCommand.unwatchTargets([TYPES.FRAME], onAvailable);
targetCommand.destroy();
await waitForAllTargetsToBeAttached(targetCommand);
@ -414,11 +414,7 @@ async function testTabFrames(mainRoot) {
);
destroyedTargets.push({ targetFront, isTargetSwitching });
};
await targetCommand.watchTargets({
types: [TYPES.FRAME],
onAvailable,
onDestroyed,
});
await targetCommand.watchTargets([TYPES.FRAME], onAvailable, onDestroyed);
is(
targets.length,
frames.length,
@ -585,7 +581,7 @@ async function testTabFrames(mainRoot) {
await onNewTargetProcessed;
targetCommand.unwatchTargets({ types: [TYPES.FRAME], onAvailable });
targetCommand.unwatchTargets([TYPES.FRAME], onAvailable);
targetCommand.destroy();

Просмотреть файл

@ -36,11 +36,7 @@ add_task(async function() {
const onDestroyed = ({ targetFront }) => {
destroyedTargets.push(targetFront);
};
await targetCommand.watchTargets({
types: [TYPES.FRAME],
onAvailable,
onDestroyed,
});
await targetCommand.watchTargets([TYPES.FRAME], onAvailable, onDestroyed);
await waitFor(() => targets.length === 3);
ok(
@ -96,11 +92,7 @@ add_task(async function() {
}
}
targetCommand.unwatchTargets({
types: [TYPES.FRAME],
onAvailable,
onDestroyed,
});
targetCommand.unwatchTargets([TYPES.FRAME], onAvailable, onDestroyed);
targetCommand.destroy();
BrowserTestUtils.removeTab(tab);
await commands.destroy();

Просмотреть файл

@ -18,57 +18,56 @@ add_task(async function() {
const onAvailable = function() {};
await Assert.rejects(
targetCommand.watchTargets({ types: [null], onAvailable }),
targetCommand.watchTargets([null], onAvailable),
/TargetCommand.watchTargets invoked with an unknown type/,
"watchTargets should throw for null type"
);
await Assert.rejects(
targetCommand.watchTargets({ types: [undefined], onAvailable }),
targetCommand.watchTargets([undefined], onAvailable),
/TargetCommand.watchTargets invoked with an unknown type/,
"watchTargets should throw for undefined type"
);
await Assert.rejects(
targetCommand.watchTargets({ types: ["NOT_A_TARGET"], onAvailable }),
targetCommand.watchTargets(["NOT_A_TARGET"], onAvailable),
/TargetCommand.watchTargets invoked with an unknown type/,
"watchTargets should throw for unknown type"
);
await Assert.rejects(
targetCommand.watchTargets({
types: [targetCommand.TYPES.FRAME, "NOT_A_TARGET"],
onAvailable,
}),
targetCommand.watchTargets(
[targetCommand.TYPES.FRAME, "NOT_A_TARGET"],
onAvailable
),
/TargetCommand.watchTargets invoked with an unknown type/,
"watchTargets should throw for unknown type mixed with a correct type"
);
Assert.throws(
() => targetCommand.unwatchTargets({ types: [null], onAvailable }),
() => targetCommand.unwatchTargets([null], onAvailable),
/TargetCommand.unwatchTargets invoked with an unknown type/,
"unwatchTargets should throw for null type"
);
Assert.throws(
() => targetCommand.unwatchTargets({ types: [undefined], onAvailable }),
() => targetCommand.unwatchTargets([undefined], onAvailable),
/TargetCommand.unwatchTargets invoked with an unknown type/,
"unwatchTargets should throw for undefined type"
);
Assert.throws(
() =>
targetCommand.unwatchTargets({ types: ["NOT_A_TARGET"], onAvailable }),
() => targetCommand.unwatchTargets(["NOT_A_TARGET"], onAvailable),
/TargetCommand.unwatchTargets invoked with an unknown type/,
"unwatchTargets should throw for unknown type"
);
Assert.throws(
() =>
targetCommand.unwatchTargets({
types: [targetCommand.TYPES.CONSOLE_MESSAGE, "NOT_A_TARGET"],
onAvailable,
}),
targetCommand.unwatchTargets(
[targetCommand.TYPES.CONSOLE_MESSAGE, "NOT_A_TARGET"],
onAvailable
),
/TargetCommand.unwatchTargets invoked with an unknown type/,
"unwatchTargets should throw for unknown type mixed with a correct type"
);

Просмотреть файл

@ -51,15 +51,9 @@ async function testPreffedOffMainProcess() {
const onProcessAvailable = ({ targetFront }) => {
processTargets.push(targetFront);
};
await targetCommand.watchTargets({
types: [TYPES.PROCESS],
onAvailable: onProcessAvailable,
});
await targetCommand.watchTargets([TYPES.PROCESS], onProcessAvailable);
is(processTargets.length, 0, "We get no process when preffed-off");
targetCommand.unwatchTargets({
types: [TYPES.PROCESS],
onAvailable: onProcessAvailable,
});
targetCommand.unwatchTargets([TYPES.PROCESS], onProcessAvailable);
const frameTargets = [];
const onFrameAvailable = ({ targetFront }) => {
@ -74,10 +68,7 @@ async function testPreffedOffMainProcess() {
);
frameTargets.push(targetFront);
};
await targetCommand.watchTargets({
types: [TYPES.FRAME],
onAvailable: onFrameAvailable,
});
await targetCommand.watchTargets([TYPES.FRAME], onFrameAvailable);
is(
frameTargets.length,
1,
@ -88,10 +79,7 @@ async function testPreffedOffMainProcess() {
mainProcess,
"The target is the top level one via watchTargets"
);
targetCommand.unwatchTargets({
types: [TYPES.FRAME],
onAvailable: onFrameAvailable,
});
targetCommand.unwatchTargets([TYPES.FRAME], onFrameAvailable);
targetCommand.destroy();

Просмотреть файл

@ -47,11 +47,11 @@ add_task(async function() {
const onDestroyed = ({ targetFront }) => {
destroyed.push(targetFront);
};
await targetCommand.watchTargets({
types: [targetCommand.TYPES.PROCESS],
await targetCommand.watchTargets(
[targetCommand.TYPES.PROCESS],
onAvailable,
onDestroyed,
});
onDestroyed
);
ok(created.length > 1, "We get many content process targets");
targetCommand.stopListening();
@ -126,7 +126,7 @@ async function testProcesses(targetCommand, target) {
if (!targets.has(targetFront)) {
ok(
false,
"A target is declared destroyed via onDestroy without being notified via onAvailable"
"A target is declared destroyed via onDestroyed without being notified via onAvailable"
);
}
is(
@ -140,11 +140,7 @@ async function testProcesses(targetCommand, target) {
);
targets.delete(targetFront);
};
await targetCommand.watchTargets({
types: [TYPES.PROCESS],
onAvailable,
onDestroyed,
});
await targetCommand.watchTargets([TYPES.PROCESS], onAvailable, onDestroyed);
is(
targets.size,
originalProcessesCount,
@ -164,16 +160,10 @@ async function testProcesses(targetCommand, target) {
if (previousTargets.has(targetFront)) {
return;
}
targetCommand.unwatchTargets({
types: [TYPES.PROCESS],
onAvailable: onAvailable2,
});
targetCommand.unwatchTargets([TYPES.PROCESS], onAvailable2);
resolve(targetFront);
};
targetCommand.watchTargets({
types: [TYPES.PROCESS],
onAvailable: onAvailable2,
});
targetCommand.watchTargets([TYPES.PROCESS], onAvailable2);
});
const tab1 = await BrowserTestUtils.openNewForegroundTab({
gBrowser,
@ -187,22 +177,14 @@ async function testProcesses(targetCommand, target) {
const processCountAfterTabOpen = targets.size;
// Assert that onDestroy is called for destroyed processes
// Assert that onDestroyed is called for destroyed processes
const onProcessDestroyed = new Promise(resolve => {
const onAvailable3 = () => {};
const onDestroyed3 = ({ targetFront }) => {
resolve(targetFront);
targetCommand.unwatchTargets({
types: [TYPES.PROCESS],
onAvailable: onAvailable3,
onDestroyed: onDestroyed3,
});
targetCommand.unwatchTargets([TYPES.PROCESS], onAvailable3, onDestroyed3);
};
targetCommand.watchTargets({
types: [TYPES.PROCESS],
onAvailable: onAvailable3,
onDestroyed: onDestroyed3,
});
targetCommand.watchTargets([TYPES.PROCESS], onAvailable3, onDestroyed3);
});
BrowserTestUtils.removeTab(tab1);
@ -223,11 +205,7 @@ async function testProcesses(targetCommand, target) {
"The destroyed target is the one that has been reported as created"
);
targetCommand.unwatchTargets({
types: [TYPES.PROCESS],
onAvailable,
onDestroyed,
});
targetCommand.unwatchTargets([TYPES.PROCESS], onAvailable, onDestroyed);
// Ensure that getAllTargets still works after the call to unwatchTargets
const processes3 = await targetCommand.getAllTargets([TYPES.PROCESS]);

Просмотреть файл

@ -48,11 +48,11 @@ add_task(async function() {
const onDestroyed = ({ targetFront }) =>
targets.splice(targets.indexOf(targetFront), 1);
await targetCommand.watchTargets({
types: [TYPES.SERVICE_WORKER],
await targetCommand.watchTargets(
[TYPES.SERVICE_WORKER],
onAvailable,
onDestroyed,
});
onDestroyed
);
// We expect onAvailable to have been called one time, for the only service
// worker target available in the test page.

Просмотреть файл

@ -337,11 +337,11 @@ async function watchServiceWorkerTargets({
hooks.targets.splice(hooks.targets.indexOf(targetFront), 1);
};
await targetCommand.watchTargets({
types: [targetCommand.TYPES.SERVICE_WORKER],
await targetCommand.watchTargets(
[targetCommand.TYPES.SERVICE_WORKER],
onAvailable,
onDestroyed,
});
onDestroyed
);
return { hooks, commands, targetCommand };
}

Просмотреть файл

@ -84,11 +84,11 @@ add_task(async function testSwitchToTarget() {
}
destroyedTargets.push(targetFront);
};
await targetCommand.watchTargets({
types: [TYPES.FRAME],
onAvailable: onFrameAvailable,
onDestroyed: onFrameDestroyed,
});
await targetCommand.watchTargets(
[TYPES.FRAME],
onFrameAvailable,
onFrameDestroyed
);
// Save the original list of targets
const createdTargets = [...frameTargets];

Просмотреть файл

@ -73,7 +73,7 @@ add_task(async function() {
targets.push(targetFront);
info(`Handled ${targets.length} targets\n`);
};
const onDestroyed = async ({ targetFront }) => {
const onDestroy = async ({ targetFront }) => {
is(
targetFront.targetType,
TYPES.WORKER,
@ -83,11 +83,11 @@ add_task(async function() {
destroyedTargets.push(targetFront);
};
await targetCommand.watchTargets({
types: [TYPES.WORKER, TYPES.SHARED_WORKER],
await targetCommand.watchTargets(
[TYPES.WORKER, TYPES.SHARED_WORKER],
onAvailable,
onDestroyed,
});
onDestroy
);
// XXX: This should be modified in Bug 1607778, where we plan to add support for shared workers.
info("Check that watched targets return the same fronts as getAllTargets");
@ -304,11 +304,11 @@ add_task(async function() {
"second spawned remote iframe worker target was destroyed"
);
targetCommand.unwatchTargets({
types: [TYPES.WORKER, TYPES.SHARED_WORKER],
targetCommand.unwatchTargets(
[TYPES.WORKER, TYPES.SHARED_WORKER],
onAvailable,
onDestroyed,
});
onDestroy
);
targetCommand.destroy();
info("Unregister service workers so they don't appear in other tests.");

Просмотреть файл

@ -57,7 +57,7 @@ add_task(async function() {
targets.push(targetFront);
info(`Handled ${targets.length} new targets`);
};
const onDestroyed = async ({ targetFront }) => {
const onDestroy = async ({ targetFront }) => {
is(
targetFront.targetType,
TYPES.WORKER,
@ -67,11 +67,11 @@ add_task(async function() {
destroyedTargets.push(targetFront);
};
await targetCommand.watchTargets({
types: [TYPES.WORKER, TYPES.SHARED_WORKER],
await targetCommand.watchTargets(
[TYPES.WORKER, TYPES.SHARED_WORKER],
onAvailable,
onDestroyed,
});
onDestroy
);
is(targets.length, 2, "watchTargets retrieved 2 workers…");
const mainPageWorkerTarget = targets.find(

Просмотреть файл

@ -74,11 +74,7 @@ async function testWatchTargets() {
);
targets.delete(targetFront);
};
await targetCommand.watchTargets({
types: [TYPES.PROCESS],
onAvailable,
onDestroyed,
});
await targetCommand.watchTargets([TYPES.PROCESS], onAvailable, onDestroyed);
is(
targets.size,
originalProcessesCount,
@ -105,16 +101,10 @@ async function testWatchTargets() {
if (previousTargets.has(targetFront)) {
return;
}
targetCommand.unwatchTargets({
types: [TYPES.PROCESS],
onAvailable: onAvailable2,
});
targetCommand.unwatchTargets([TYPES.PROCESS], onAvailable2);
resolve(targetFront);
};
targetCommand.watchTargets({
types: [TYPES.PROCESS],
onAvailable: onAvailable2,
});
targetCommand.watchTargets([TYPES.PROCESS], onAvailable2);
});
const tab1 = await BrowserTestUtils.openNewForegroundTab({
gBrowser,
@ -134,17 +124,9 @@ async function testWatchTargets() {
const onAvailable3 = () => {};
const onDestroyed3 = ({ targetFront }) => {
resolve(targetFront);
targetCommand.unwatchTargets({
types: [TYPES.PROCESS],
onAvailable: onAvailable3,
onDestroyed: onDestroyed3,
});
targetCommand.unwatchTargets([TYPES.PROCESS], onAvailable3, onDestroyed3);
};
targetCommand.watchTargets({
types: [TYPES.PROCESS],
onAvailable: onAvailable3,
onDestroyed: onDestroyed3,
});
targetCommand.watchTargets([TYPES.PROCESS], onAvailable3, onDestroyed3);
});
BrowserTestUtils.removeTab(tab1);
@ -165,11 +147,7 @@ async function testWatchTargets() {
"The destroyed target is the one that has been reported as created"
);
targetCommand.unwatchTargets({
types: [TYPES.PROCESS],
onAvailable,
onDestroyed,
});
targetCommand.unwatchTargets([TYPES.PROCESS], onAvailable, onDestroyed);
targetCommand.destroy();
@ -212,23 +190,15 @@ async function testContentProcessTarget() {
targets.add(targetFront);
};
const onDestroyed = _ => {
ok(false, "onDestroy should never be called in this test");
ok(false, "onDestroyed should never be called in this test");
};
await targetCommand.watchTargets({
types: [TYPES.PROCESS],
onAvailable,
onDestroyed,
});
await targetCommand.watchTargets([TYPES.PROCESS], onAvailable, onDestroyed);
// This may fail if the top level target is reported by LegacyImplementation
// to TargetCommand and registers a duplicated entry
is(targets.size, 1, "We were only notified about the top level target");
targetCommand.unwatchTargets({
types: [TYPES.PROCESS],
onAvailable,
onDestroyed,
});
targetCommand.unwatchTargets([TYPES.PROCESS], onAvailable, onDestroyed);
targetCommand.destroy();
await commands.destroy();
@ -260,7 +230,7 @@ async function testThrowingInOnAvailable() {
}
targets.add(targetFront);
};
await targetCommand.watchTargets({ types: [TYPES.PROCESS], onAvailable });
await targetCommand.watchTargets([TYPES.PROCESS], onAvailable);
is(
targets.size,
originalProcessesCount - 1,