Bug 1696471 - [devtools] Notify about content process target destruction via watcher's target-destroyed-form. r=nchevobbe,jdescottes

We are currently receiving tabDetached for content process targets
when we destroy them via:
  Services.ppmm.broadcastAsyncMessage("debug:destroy-process-script")
done from process-helper and we stop watching for process targets.
Tests now depends on this behavior.

So I'm trying to replicate this behavior in order to later get rid of tabDetached
in favor of target-destroyed-form.

Differential Revision: https://phabricator.services.mozilla.com/D107248
This commit is contained in:
Alexandre Poirot 2021-03-09 12:30:53 +00:00
Родитель f532cf4964
Коммит c43fe05565
2 изменённых файлов: 52 добавлений и 1 удалений

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

@ -105,7 +105,13 @@ function closeWatcherTransports(watcher) {
const matchingTargetActorDescriptions = targetActorDescriptions.filter( const matchingTargetActorDescriptions = targetActorDescriptions.filter(
item => item.watcher === watcher item => item.watcher === watcher
); );
for (const { prefix, childTransport } of matchingTargetActorDescriptions) { for (const {
prefix,
childTransport,
actor,
} of matchingTargetActorDescriptions) {
watcher.notifyTargetDestroyed(actor);
childTransport.close(); childTransport.close();
watcher.conn.cancelForwarding(prefix); watcher.conn.cancelForwarding(prefix);
} }

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

@ -38,6 +38,51 @@ add_task(async function() {
await client.close(); await client.close();
}); });
add_task(async function() {
const client = await createLocalClient();
const targetDescriptor = await client.mainRoot.getMainProcess();
const targetList = new TargetList(targetDescriptor);
await targetList.startListening();
const created = [];
const destroyed = [];
const onAvailable = ({ targetFront }) => {
created.push(targetFront);
};
const onDestroyed = ({ targetFront }) => {
destroyed.push(targetFront);
};
await targetList.watchTargets(
[TargetList.TYPES.PROCESS],
onAvailable,
onDestroyed
);
ok(created.length > 1, "We get many content process targets");
targetList.stopListening();
await waitFor(
() => created.length == destroyed.length,
"Wait for the destruction of all content process targets when calling stopListening"
);
is(
created.length,
destroyed.length,
"Got notification of destruction for all previously reported targets"
);
targetList.destroy();
// Wait for all the targets to be fully attached so we don't have pending requests.
await Promise.all(
targetList
.getAllTargets(targetList.ALL_TYPES)
.map(t => t.attachAndInitThread(targetList))
);
await client.close();
});
async function testProcesses(targetList, target) { async function testProcesses(targetList, target) {
info("Test TargetList against processes"); info("Test TargetList against processes");