browser_aboutdebugging_process_main.js (2864B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /* import-globals-from helper-collapsibilities.js */ 7 Services.scriptloader.loadSubScript( 8 CHROME_URL_ROOT + "helper-collapsibilities.js", 9 this 10 ); 11 12 const MULTIPROCESS_TOOLBOX_NAME = "Multiprocess Toolbox"; 13 const MULTIPROCESS_TOOLBOX_DESCRIPTION = 14 "Main Process and Content Processes for the target browser"; 15 16 const RUNTIME_ID = "test-runtime-id"; 17 const RUNTIME_DEVICE_NAME = "test device name"; 18 const RUNTIME_APP_NAME = "TestApp"; 19 20 // Test for main process. 21 add_task(async function () { 22 await pushPref("devtools.aboutdebugging.process-debugging", true); 23 const mocks = new Mocks(); 24 25 const { document, tab, window } = await openAboutDebugging(); 26 27 const usbRuntime = mocks.createUSBRuntime(RUNTIME_ID, { 28 deviceName: RUNTIME_DEVICE_NAME, 29 name: RUNTIME_APP_NAME, 30 }); 31 32 // Note: about:debugging assumes that the main process has the id 0 and will 33 // rely on it to create the about:devtools-toolbox URL. 34 // Only check that about:debugging doesn't create a target unnecessarily. 35 usbRuntime.getMainProcess = () => { 36 return { 37 getTarget: () => { 38 ok(false, "about:debugging should not create the main process target"); 39 }, 40 }; 41 }; 42 mocks.emitUSBUpdate(); 43 44 info("Select USB runtime"); 45 await connectToRuntime(RUNTIME_DEVICE_NAME, document); 46 await waitForRuntimePage(RUNTIME_APP_NAME, document); 47 48 info("Check debug target item of the main process"); 49 await waitUntil(() => 50 findDebugTargetByText(MULTIPROCESS_TOOLBOX_NAME, document) 51 ); 52 const mainProcessItem = findDebugTargetByText( 53 MULTIPROCESS_TOOLBOX_NAME, 54 document 55 ); 56 ok(mainProcessItem, "Debug target item of the main process should display"); 57 ok( 58 mainProcessItem.textContent.includes(MULTIPROCESS_TOOLBOX_DESCRIPTION), 59 "Debug target item of the main process should contains the description" 60 ); 61 62 info("Inspect main process"); 63 const { devtoolsTab, devtoolsWindow } = await openAboutDevtoolsToolbox( 64 document, 65 tab, 66 window, 67 MULTIPROCESS_TOOLBOX_NAME, 68 false 69 ); 70 71 const url = new window.URL(devtoolsWindow.location.href); 72 const type = url.searchParams.get("type"); 73 is(type, "process", "Correct type argument"); 74 const remoteID = url.searchParams.get("remoteId"); 75 is(remoteID, `${RUNTIME_ID}-usb`, "Correct remote runtime id"); 76 77 info("Remove USB runtime"); 78 mocks.removeUSBRuntime(RUNTIME_ID); 79 mocks.emitUSBUpdate(); 80 await waitUntilUsbDeviceIsUnplugged(RUNTIME_DEVICE_NAME, document); 81 82 // Note that we can't use `closeAboutDevtoolsToolbox` because the toolbox init 83 // is expected to fail, and we are redirected to the error page. 84 await removeTab(devtoolsTab); 85 await waitUntil(() => !findDebugTargetByText("Toolbox - ", document)); 86 await removeTab(tab); 87 });