Bug 1512220 - Convert debugger server test helper to async functions. r=yulia

This cleanup will help next refactorings.
Note that attachTestThread and attachTestTabAndResume are still using the callback style
as it is still being used by tests that aren't using threadClientTest helper.

MozReview-Commit-ID: 6FvoDtzEBmL

Depends on D13901

Differential Revision: https://phabricator.services.mozilla.com/D13902

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alexandre Poirot 2018-12-11 12:14:59 +00:00
Родитель 6448b30e9c
Коммит 3937fdfc00
1 изменённых файлов: 34 добавлений и 43 удалений

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

@ -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