Bug 1931425 - Limit how often moz-label's #setStyles runs r=reusable-components-revie...
[gecko.git] / devtools / server / tests / chrome / webconsole-helpers.js
blob8be8554e35449842934d6fe634db0d215aa5068d
1 /* exported addTabAndCreateCommands */
2 "use strict";
4 const { require } = ChromeUtils.importESModule(
5 "resource://devtools/shared/loader/Loader.sys.mjs"
6 );
7 const {
8 DevToolsServer,
9 } = require("resource://devtools/server/devtools-server.js");
10 const {
11 CommandsFactory,
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");
18 });
20 if (!DevToolsServer.initialized) {
21 DevToolsServer.init();
22 DevToolsServer.registerAllActors();
23 SimpleTest.registerCleanupFunction(function () {
24 DevToolsServer.destroy();
25 });
28 /**
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();
40 return commands;
43 /**
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);
53 return tab;