1 /* exported addTabAndCreateCommands */
4 const { require
} = ChromeUtils
.importESModule(
5 "resource://devtools/shared/loader/Loader.sys.mjs"
9 } = require("resource://devtools/server/devtools-server.js");
12 } = require("resource://devtools/shared/commands/commands-factory.js");
14 // Always log packets when running tests.
15 Services
.prefs
.setBoolPref("devtools.debugger.log", true);
16 SimpleTest
.registerCleanupFunction(function () {
17 Services
.prefs
.clearUserPref("devtools.debugger.log");
20 if (!DevToolsServer
.initialized
) {
21 DevToolsServer
.init();
22 DevToolsServer
.registerAllActors();
23 SimpleTest
.registerCleanupFunction(function () {
24 DevToolsServer
.destroy();
29 * Open a tab, load the url, find the tab with the devtools server,
30 * and attach the console to it.
32 * @param {string} url : url to navigate to
33 * @return {Promise} Promise resolving when commands are initialized
34 * The Promise resolves with the commands.
36 async
function addTabAndCreateCommands(url
) {
37 const tab
= await
addTab(url
);
38 const commands
= await CommandsFactory
.forTab(tab
);
39 await commands
.targetCommand
.startListening();
44 * Naive implementaion of addTab working from a mochitest-chrome test.
46 async
function addTab(url
) {
47 const { gBrowser
} = Services
.wm
.getMostRecentWindow("navigator:browser");
48 const { BrowserTestUtils
} = ChromeUtils
.importESModule(
49 "resource://testing-common/BrowserTestUtils.sys.mjs"
51 const tab
= (gBrowser
.selectedTab
= BrowserTestUtils
.addTab(gBrowser
, url
));
52 await BrowserTestUtils
.browserLoaded(tab
.linkedBrowser
);