Bug 1811137 - [devtools] Use shared-head's addTab in devtools/server browser mochitests r=ochameau

Quick follow up to Bug 1810579. We can completely get rid of the helper and use our existing shared helper.

Differential Revision: https://phabricator.services.mozilla.com/D167208
This commit is contained in:
Julian Descottes 2023-01-19 12:39:21 +00:00
Родитель 09093658ff
Коммит 36f326762e
11 изменённых файлов: 47 добавлений и 64 удалений

Просмотреть файл

@ -9,9 +9,9 @@ const TEST_URL =
"data:text/html;charset=utf-8,CanvasFrameAnonymousContentHelper test";
add_task(async function() {
const browser = await addTab(TEST_URL);
const tab = await addTab(TEST_URL);
await SpecialPowers.spawn(browser, [], async function() {
await SpecialPowers.spawn(tab.linkedBrowser, [], async function() {
const { require } = ChromeUtils.importESModule(
"resource://devtools/shared/loader/Loader.sys.mjs"
);

Просмотреть файл

@ -7,11 +7,11 @@
// XUL windows.
add_task(async function() {
const browser = await addTab(
const tab = await addTab(
"chrome://mochitests/content/browser/devtools/server/tests/browser/test-window.xhtml"
);
await SpecialPowers.spawn(browser, [], async function() {
await SpecialPowers.spawn(tab.linkedBrowser, [], async function() {
const { require } = ChromeUtils.importESModule(
"resource://devtools/shared/loader/Loader.sys.mjs"
);

Просмотреть файл

@ -9,8 +9,8 @@ const TEST_URL =
"data:text/html;charset=utf-8,CanvasFrameAnonymousContentHelper test";
add_task(async function() {
const browser = await addTab(TEST_URL);
await SpecialPowers.spawn(browser, [], async function() {
const tab = await addTab(TEST_URL);
await SpecialPowers.spawn(tab.linkedBrowser, [], async function() {
const { require } = ChromeUtils.importESModule(
"resource://devtools/shared/loader/Loader.sys.mjs"
);

Просмотреть файл

@ -12,8 +12,10 @@ const TEST_URL_2 =
"data:text/html;charset=utf-8,CanvasFrameAnonymousContentHelper test 2";
add_task(async function() {
const browser = await addTab(TEST_URL_1);
await SpecialPowers.spawn(browser, [TEST_URL_2], async function(url2) {
const tab = await addTab(TEST_URL_1);
await SpecialPowers.spawn(tab.linkedBrowser, [TEST_URL_2], async function(
url2
) {
const { require } = ChromeUtils.importESModule(
"resource://devtools/shared/loader/Loader.sys.mjs"
);

Просмотреть файл

@ -10,8 +10,8 @@ const TEST_URL =
"data:text/html;charset=utf-8,CanvasFrameAnonymousContentHelper test";
add_task(async function() {
const browser = await addTab(TEST_URL);
await SpecialPowers.spawn(browser, [], async function() {
const tab = await addTab(TEST_URL);
await SpecialPowers.spawn(tab.linkedBrowser, [], async function() {
const { require } = ChromeUtils.importESModule(
"resource://devtools/shared/loader/Loader.sys.mjs"
);

Просмотреть файл

@ -10,8 +10,8 @@ const TEST_URL =
"data:text/html;charset=utf-8,CanvasFrameAnonymousContentHelper test";
add_task(async function() {
const browser = await addTab(TEST_URL);
await SpecialPowers.spawn(browser, [], async function() {
const tab = await addTab(TEST_URL);
await SpecialPowers.spawn(tab.linkedBrowser, [], async function() {
const { require } = ChromeUtils.importESModule(
"resource://devtools/shared/loader/Loader.sys.mjs"
);

Просмотреть файл

@ -17,15 +17,14 @@ add_task(async function() {
});
async function testDevToolsServerInitialized() {
const browser = await addTab("data:text/html;charset=utf-8,foo");
const tab = gBrowser.getTabForBrowser(browser);
const tab = await addTab("data:text/html;charset=utf-8,foo");
ok(
!DevToolsServer.initialized,
"By default, the DevToolsServer isn't initialized in parent process"
);
await assertServerInitialized(
browser,
tab,
false,
"By default, the DevToolsServer isn't initialized not in content process"
);
@ -37,7 +36,7 @@ async function testDevToolsServerInitialized() {
"Creating the commands will initialize the DevToolsServer in parent process"
);
await assertServerInitialized(
browser,
tab,
false,
"Creating the commands isn't enough to initialize the DevToolsServer in content process"
);
@ -45,7 +44,7 @@ async function testDevToolsServerInitialized() {
await commands.targetCommand.startListening();
await assertServerInitialized(
browser,
tab,
true,
"Initializing the TargetCommand will initialize the DevToolsServer in content process"
);
@ -58,7 +57,7 @@ async function testDevToolsServerInitialized() {
"Destroying the commands destroys the DevToolsServer in the parent process"
);
await assertServerInitialized(
browser,
tab,
false,
"But destroying the commands ends up destroying the DevToolsServer in the content process"
);
@ -68,11 +67,10 @@ async function testDevToolsServerInitialized() {
}
async function testDevToolsServerKeepAlive() {
const browser = await addTab("data:text/html;charset=utf-8,foo");
const tab = gBrowser.getTabForBrowser(browser);
const tab = await addTab("data:text/html;charset=utf-8,foo");
await assertServerInitialized(
browser,
tab,
false,
"Server not started in content process"
);
@ -80,21 +78,17 @@ async function testDevToolsServerKeepAlive() {
const commands = await CommandsFactory.forTab(tab);
await commands.targetCommand.startListening();
await assertServerInitialized(
browser,
true,
"Server started in content process"
);
await assertServerInitialized(tab, true, "Server started in content process");
info("Set DevToolsServer.keepAlive to true in the content process");
DevToolsServer.keepAlive = true;
await setContentServerKeepAlive(browser, true);
await setContentServerKeepAlive(tab, true);
info("Destroy the commands, the content server should be kept alive");
await commands.destroy();
await assertServerInitialized(
browser,
tab,
true,
"Server still running in content process"
);
@ -106,7 +100,7 @@ async function testDevToolsServerKeepAlive() {
info("Set DevToolsServer.keepAlive back to false");
DevToolsServer.keepAlive = false;
await setContentServerKeepAlive(browser, false);
await setContentServerKeepAlive(tab, false);
info("Create and destroy a commands again");
const newCommands = await CommandsFactory.forTab(tab);
@ -115,7 +109,7 @@ async function testDevToolsServerKeepAlive() {
await newCommands.destroy();
await assertServerInitialized(
browser,
tab,
false,
"Server stopped in content process"
);
@ -129,21 +123,27 @@ async function testDevToolsServerKeepAlive() {
DevToolsServer.destroy();
}
async function assertServerInitialized(browser, expected, message) {
const isInitialized = await SpecialPowers.spawn(browser, [], function() {
const { require } = ChromeUtils.importESModule(
"resource://devtools/shared/loader/Loader.sys.mjs"
);
const {
DevToolsServer,
} = require("resource://devtools/server/devtools-server.js");
return DevToolsServer.initialized;
});
async function assertServerInitialized(tab, expected, message) {
const isInitialized = await SpecialPowers.spawn(
tab.linkedBrowser,
[],
function() {
const { require } = ChromeUtils.importESModule(
"resource://devtools/shared/loader/Loader.sys.mjs"
);
const {
DevToolsServer,
} = require("resource://devtools/server/devtools-server.js");
return DevToolsServer.initialized;
}
);
is(isInitialized, expected, message);
}
async function setContentServerKeepAlive(browser, keepAlive, message) {
await SpecialPowers.spawn(browser, [keepAlive], function(_keepAlive) {
async function setContentServerKeepAlive(tab, keepAlive, message) {
await SpecialPowers.spawn(tab.linkedBrowser, [keepAlive], function(
_keepAlive
) {
const { require } = ChromeUtils.importESModule(
"resource://devtools/shared/loader/Loader.sys.mjs"
);

Просмотреть файл

@ -15,7 +15,7 @@ add_task(async function() {
// And get rid of this code from the old storage actor.
await pushPref("devtools.target-switching.server.enabled", false);
const browser = await addTab("data:text/html;charset=utf-8,foo");
const tab = await addTab("data:text/html;charset=utf-8,foo");
info("Register target-scoped actor in the content process");
await registerActorInContentProcess(ACTOR_URL, {
@ -24,7 +24,6 @@ add_task(async function() {
type: { target: true },
});
const tab = gBrowser.getTabForBrowser(browser);
const target = await createAndAttachTargetForTab(tab);
const { client } = target;
const form = target.targetForm;

Просмотреть файл

@ -11,8 +11,7 @@ const TEST_URI = `data:text/html;charset=utf-8,<style>${encodeURIComponent(
)}</style>`;
add_task(async function() {
const browser = await addTab(TEST_URI);
const tab = gBrowser.getTabForBrowser(browser);
const tab = await addTab(TEST_URI);
const commands = await CommandsFactory.forTab(tab);
await commands.targetCommand.startListening();

Просмотреть файл

@ -36,23 +36,6 @@ const SEPARATOR_GUID = "{9d414cc5-8319-0a04-0586-c0a6ae01670a}";
// All tests are asynchronous.
waitForExplicitFinish();
/**
* Add a new test tab in the browser and load the given url.
* @param {String} url The url to be loaded in the new tab
* @return a promise that resolves to the new browser that the document
* is loaded in. Note that we cannot return the document
* directly, as we aren't able to access that in the parent.
*/
var addTab = async function(url) {
info(`Adding a new tab with URL: ${url}`);
const tab = (gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, url));
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
info(`Tab added a URL ${url} loaded`);
return tab.linkedBrowser;
};
// does almost the same thing as addTab, but directly returns an object
async function addTabTarget(url) {
info(`Adding a new tab with URL: ${url}`);

Просмотреть файл

@ -24,7 +24,7 @@ async function openTabAndSetupStorage(url) {
set: [[LEGACY_ACTORS_PREF, true]],
});
const content = await addTab(url);
await addTab(url);
// Setup the async storages in main window and for all its iframes
const browsingContexts = gBrowser.selectedBrowser.browsingContext.getAllBrowsingContextsInSubtree();