Files
Alexandre Poirot 3af4a6d2ad Bug 1622857 - [devtools] Use MOZ_LOG to trace RDP packets in tests. r=devtools-reviewers,nchevobbe
Also remove disabled/commented logging.
You may use "--env MOZ_LOG=devtools_rdp:3" to trace RDP packets on try runs.
Some tests are still toggling the old preference as they may want to
trace other usages of dumpn/dumpv.

Differential Revision: https://phabricator.services.mozilla.com/D299055
2026-05-18 09:12:29 +00:00

55 lines
1.6 KiB
JavaScript

/* exported addTabAndCreateCommands */
"use strict";
const { require } = ChromeUtils.importESModule(
"resource://devtools/shared/loader/Loader.sys.mjs"
);
const {
DevToolsServer,
} = require("resource://devtools/server/devtools-server.js");
const {
CommandsFactory,
} = require("resource://devtools/shared/commands/commands-factory.js");
// Always log packets when running tests.
Services.prefs.setIntPref("logging.devtools_rdp", 5);
SimpleTest.registerCleanupFunction(function () {
Services.prefs.clearUserPref("logging.devtools_rdp");
});
if (!DevToolsServer.initialized) {
DevToolsServer.init();
DevToolsServer.registerAllActors();
SimpleTest.registerCleanupFunction(function () {
DevToolsServer.destroy();
});
}
/**
* Open a tab, load the url, find the tab with the devtools server,
* and attach the console to it.
*
* @param {string} url : url to navigate to
* @return {Promise} Promise resolving when commands are initialized
* The Promise resolves with the commands.
*/
async function addTabAndCreateCommands(url) {
const tab = await addTab(url);
const commands = await CommandsFactory.forTab(tab);
await commands.targetCommand.startListening();
return commands;
}
/**
* Naive implementaion of addTab working from a mochitest-chrome test.
*/
async function addTab(url) {
const { gBrowser } = Services.wm.getMostRecentBrowserWindow();
const { BrowserTestUtils } = ChromeUtils.importESModule(
"resource://testing-common/BrowserTestUtils.sys.mjs"
);
const tab = (gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, url));
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
return tab;
}