diff --git a/devtools/server/tests/unit/head_dbg.js b/devtools/server/tests/unit/head_dbg.js index c7b1da87e5b9..dfac8b0a4f2a 100644 --- a/devtools/server/tests/unit/head_dbg.js +++ b/devtools/server/tests/unit/head_dbg.js @@ -375,64 +375,55 @@ function addTestGlobal(name, server = DebuggerServer) { // List the DebuggerClient |client|'s tabs, look for one whose title is // |title|, and apply |callback| to the packet's entry for that tab. -function getTestTab(client, title, callback) { - client.listTabs().then(function(response) { - for (const tab of response.tabs) { - if (tab.title === title) { - callback(tab); - return; - } +async function getTestTab(client, title) { + const { tabs } = await client.mainRoot.listTabs(); + for (const tab of tabs) { + if (tab.title === title) { + return tab; } - callback(null); - }); + } + return null; } -// Attach to |client|'s tab whose title is |title|; pass |callback| the -// response packet and a TargetFront instance referring to that tab. -function attachTestTab(client, title, callback) { - getTestTab(client, title, function(tab) { - client.attachTarget(tab).then(([response, targetFront]) => { - Assert.equal(response.type, "tabAttached"); - Assert.ok(typeof response.threadActor === "string"); - callback(response, targetFront); - }); - }); +// Attach to |client|'s tab whose title is |title|; and return the targetFront instance +// referring to that tab. +async function attachTestTab(client, title) { + const tab = await getTestTab(client, title); + const [, targetFront] = await client.attachTarget(tab); + const response = await targetFront.attach(); + Assert.equal(response.type, "tabAttached"); + Assert.ok(typeof response.threadActor === "string"); + return targetFront; } // Attach to |client|'s tab whose title is |title|, and then attach to // that tab's thread. Pass |callback| the thread attach response packet, a // TargetFront referring to the tab, and a ThreadClient referring to the // thread. -function attachTestThread(client, title, callback) { - attachTestTab(client, title, function(tabResponse, targetFront) { - function onAttach([response, threadClient]) { - Assert.equal(threadClient.state, "paused", "Thread client is paused"); - Assert.equal(response.type, "paused"); - Assert.ok("why" in response); - Assert.equal(response.why.type, "attached"); - callback(response, targetFront, threadClient, tabResponse); - } - targetFront.attachThread({ - useSourceMaps: true, - autoBlackBox: true, - }).then(onAttach); +async function attachTestThread(client, title, callback = () => {}) { + const targetFront = await attachTestTab(client, title); + const [response, threadClient] = await targetFront.attachThread({ + useSourceMaps: true, + autoBlackBox: true, }); + Assert.equal(threadClient.state, "paused", "Thread client is paused"); + Assert.equal(response.type, "paused"); + Assert.ok("why" in response); + Assert.equal(response.why.type, "attached"); + callback(response, targetFront, threadClient); + return { targetFront, threadClient }; } // Attach to |client|'s tab whose title is |title|, attach to the tab's // thread, and then resume it. Pass |callback| the thread's response to // the 'resume' packet, a TargetFront for the tab, and a ThreadClient for the // thread. -function attachTestTabAndResume(client, title, callback = () => {}) { - return new Promise((resolve) => { - attachTestThread(client, title, function(response, targetFront, threadClient) { - threadClient.resume(function(response) { - Assert.equal(response.type, "resumed"); - callback(response, targetFront, threadClient); - resolve([response, targetFront, threadClient]); - }); - }); - }); +async function attachTestTabAndResume(client, title, callback = () => {}) { + const { targetFront, threadClient } = await attachTestThread(client, title); + const response = await threadClient.resume(); + Assert.equal(response.type, "resumed"); + callback(response, targetFront, threadClient); + return { targetFront, threadClient }; } /** @@ -940,7 +931,7 @@ function threadClientTest(test, options = {}) { // Attach to the fake tab target and retrieve the ThreadClient instance. // Automatically resume as the thread is paused by default after attach. - const [, targetFront, threadClient] = + const { targetFront, threadClient } = await attachTestTabAndResume(client, scriptName); // Run the test function