Created
October 23, 2019 15:30
-
-
Save juliandescottes/fbb1473fa3d037e86c165f166f49caff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Any copyright is dedicated to the Public Domain. | |
http://creativecommons.org/publicdomain/zero/1.0/ */ | |
"use strict"; | |
// Test the TargetList API | |
const { DebuggerClient } = require("devtools/shared/client/debugger-client"); | |
const { DebuggerServer } = require("devtools/server/debugger-server"); | |
const { TargetList } = require("devtools/shared/resources/target-list"); | |
add_task(async function() { | |
// Enabled fission's pref as the TargetList is almost disabled without it | |
await pushPref("devtools.browsertoolbox.fission", true); | |
// Disable the preloaded process as it gets created lazily and may interfere | |
// with process count assertions | |
await pushPref("dom.ipc.processPrelaunch.enabled", false); | |
// This preference helps destroying the content process when we close the tab | |
await pushPref("dom.ipc.keepProcessesAlive.web", 1); | |
// Instantiate a minimal server | |
DebuggerServer.init(); | |
DebuggerServer.allowChromeProcess = true; | |
if (!DebuggerServer.createRootActor) { | |
DebuggerServer.registerAllActors(); | |
} | |
const transport = DebuggerServer.connectPipe(); | |
const client = new DebuggerClient(transport); | |
await client.connect(); | |
const mainRoot = client.mainRoot; | |
const { processes } = await mainRoot.listProcesses(); | |
const contentProcessTargetFront = await processes[1].getTarget(); | |
const targetList = new TargetList(mainRoot, contentProcessTargetFront); | |
await testProcesses(targetList); | |
await client.close(); | |
}); | |
async function testProcesses(targetList) { | |
info("Test TargetList againts processes"); | |
// Note that ppmm also includes the parent process, which is considered as a frame rather than a process | |
const originalProcessesCount = Services.ppmm.childCount - 1; | |
// Assert that watchTargets will call the create callback for all existing frames | |
const targets = new Set(); | |
const onAvailable = target => { | |
if (targets.has(target)) { | |
// XXX: this will fail because onAvailable is called twice for the top target | |
ok(false, "The same target is notified multiple times via onAvailable"); | |
} | |
targets.add(target); | |
}; | |
const onDestroyed = target => { | |
if (!targets.has(target)) { | |
ok( | |
false, | |
"A target is declared destroyed via onDestroyed without being notified via onAvailable" | |
); | |
} | |
targets.delete(target); | |
}; | |
await targetList.watchTargets("process", onAvailable, onDestroyed); | |
// XXX: Wait for all targets to be connected, should we add a helper on | |
// targetList to do that? | |
await new Promise(r => setTimeout(r, 1000)); | |
// XXX: This will fail because the MainProcessDescriptor will be considered as | |
// a valid process descriptor by the Legacy implementation. | |
is( | |
targets.size, | |
originalProcessesCount, | |
"retrieved the same number of processes via watchTargets" | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment