Bug 1539213 - Emit `Target.targetCreated` for already-opened tabs. r=ato

When `Target.setDiscoverTargets` is called, one `Target.targetCreated` event
should be sent per already opened tab.

Differential Revision: https://phabricator.services.mozilla.com/D25558

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alexandre Poirot 2019-04-01 14:25:28 +00:00
Родитель 360f8973bc
Коммит 0b2e8e6e9d
2 изменённых файлов: 9 добавлений и 0 удалений

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

@ -32,6 +32,9 @@ class Target extends Domain {
} else {
targets.off("connect", this.onTargetCreated);
}
for (const target of targets) {
this.onTargetCreated("connect", target);
}
}
onTargetCreated(eventName, target) {

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

@ -42,9 +42,15 @@ async function testCDP() {
const {Target} = client;
ok("Target" in client, "Target domain is available");
const targetCreatedForAlreadyOpenedTab = Target.targetCreated();
// Instruct the server to fire Target.targetCreated events
Target.setDiscoverTargets({ discover: true });
// Calling `setDiscoverTargets` will dispatch `targetCreated` event for all
// already opened tabs
await targetCreatedForAlreadyOpenedTab;
// Create a new target so that the test runs against a fresh new tab
const targetCreated = Target.targetCreated();
const {targetId} = await Target.createTarget();