browser_chromeutils_getalldomprocesses.js (2380B)
1 add_task(async function testParentProcess() { 2 const [parentProcess] = ChromeUtils.getAllDOMProcesses(); 3 // browser.xhtml is in the parent process, so its domProcess is the parent process one 4 is( 5 parentProcess, 6 window.browsingContext.currentWindowGlobal.domProcess, 7 "The first element is the parent process" 8 ); 9 is( 10 parentProcess.osPid, 11 Services.appinfo.processID, 12 "We got the right OS Pid" 13 ); 14 is(parentProcess.childID, 0, "Parent process has childID set to 0"); 15 }); 16 17 add_task(async function testContentProcesses() { 18 info("Open a tab in a content process"); 19 BrowserTestUtils.startLoadingURIString( 20 gBrowser.selectedBrowser, 21 "about:blank" 22 ); 23 await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, { 24 wantLoad: "about:blank", 25 }); 26 27 info("Sanity checks against all returned elements of getAllDOMProcesses"); 28 const processes = ChromeUtils.getAllDOMProcesses(); 29 const allPids = [], 30 allChildIDs = []; 31 for (const process of processes) { 32 ok( 33 process instanceof Ci.nsIDOMProcessParent, 34 `Each element of the array is a nsIDOMProcessParent (${process})` 35 ); 36 Assert.greater(process.osPid, 0, `OS Pid looks correct ${process.osPid}`); 37 if (process == processes[0]) { 38 is( 39 process.childID, 40 0, 41 `Child ID is 0 for the parent process, which is the first element of the returned array` 42 ); 43 is( 44 process.remoteType, 45 null, 46 "The main process's remote type should be NOT_REMOTE" 47 ); 48 } else { 49 Assert.greater( 50 process.childID, 51 0, 52 `Child ID looks also correct ${process.childID}` 53 ); 54 ok(process.remoteType, "Should have a remote type"); 55 } 56 57 ok( 58 !allPids.includes(process.osPid), 59 "We only get one nsIDOMProcessParent per OS process == each osPid is different" 60 ); 61 allPids.push(process.osPid); 62 ok(!allChildIDs.includes(process.childID), "Each childID is different"); 63 allChildIDs.push(process.childID); 64 } 65 66 info("Search for the nsIDOMProcessParent for the opened tab"); 67 const { currentWindowGlobal } = gBrowser.selectedBrowser.browsingContext; 68 const tabProcess = currentWindowGlobal.domProcess; 69 ok(processes.includes(tabProcess), "Found the tab process in the list"); 70 is(tabProcess.osPid, currentWindowGlobal.osPid, "We got the right OS Pid"); 71 });