Skip to content

Commit

Permalink
Bug 1811130 - [cdp] Fix Target.setDiscoverTargets emitting targetCrea…
Browse files Browse the repository at this point in the history
…ted events with discover false r=webdriver-reviewers,whimboo

Target.setDiscoverTargets should only emit targetCreated events when ran
with discover as true. Also added tests for discover false.

Differential Revision: https://phabricator.services.mozilla.com/D167210
  • Loading branch information
CanadaHonk committed Apr 13, 2023
1 parent 66adc80 commit 6bfc78e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
8 changes: 4 additions & 4 deletions remote/cdp/domains/parent/Target.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ export class Target extends Domain {
if (discover) {
targetList.on("target-created", this._onTargetCreated);
targetList.on("target-destroyed", this._onTargetDestroyed);

for (const target of targetList) {
this._onTargetCreated("target-created", target);
}
} else {
targetList.off("target-created", this._onTargetCreated);
targetList.off("target-destroyed", this._onTargetDestroyed);
}

for (const target of targetList) {
this._onTargetCreated("target-created", target);
}
}

async createTarget(options = {}) {
Expand Down
39 changes: 39 additions & 0 deletions remote/cdp/test/browser/target/browser_setDiscoverTargets.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,45 @@ add_task(
{ createTab: false }
);

add_task(
async function noTargetsWithDiscoverFalse({ client }) {
const { Target } = client;

await loadURL(PAGE_TEST);

const targets = await getDiscoveredTargets(Target, { discover: false });
is(targets.length, 0, "Got 0 targets with discover false");
},
{ createTab: false }
);

add_task(
async function noEventsWithDiscoverFalse({ client }) {
const { Target } = client;

await loadURL(PAGE_TEST);

const targets = [];
const unsubscribe = Target.targetCreated(target => {
targets.push(target.targetInfo);
});

await Target.setDiscoverTargets({
discover: false,
});

// Cannot use openTab() helper as it relies on the event
await BrowserTestUtils.openNewForegroundTab(gBrowser);

// Wait 1s for the event to possibly dispatch
await timeoutPromise(1000);

unsubscribe();
is(targets.length, 0, "Got 0 target created events with discover false");
},
{ createTab: false }
);

add_task(
async function targetInfoValues({ client }) {
const { Target, target } = client;
Expand Down

0 comments on commit 6bfc78e

Please sign in to comment.