From c1ea0a64c2b16955220c314504f4cc310386e7d0 Mon Sep 17 00:00:00 2001 From: Alexandre Poirot Date: Tue, 11 Dec 2018 15:58:13 +0000 Subject: [PATCH] Bug 1512220 - Refactor promises tests to use the same test helper than memory actor's tests. r=yulia This isn't thread client test, but here we could share some more code with the memory tests and use Target objects to retrieve the fronts. MozReview-Commit-ID: C9S1VjTLrSF Depends on D13899 Differential Revision: https://phabricator.services.mozilla.com/D13900 --HG-- extra : moz-landing-system : lando --- devtools/server/tests/unit/head_dbg.js | 119 +++++++++++++----- .../test_MemoryActor_saveHeapSnapshot_01.js | 5 +- .../test_MemoryActor_saveHeapSnapshot_02.js | 5 +- .../test_MemoryActor_saveHeapSnapshot_03.js | 5 +- .../tests/unit/test_promises_actor_attach.js | 24 ++-- .../tests/unit/test_promises_actor_exist.js | 34 ----- .../unit/test_promises_actor_list_promises.js | 30 ++--- .../unit/test_promises_actor_onnewpromise.js | 37 ++---- .../test_promises_actor_onpromisesettled.js | 39 +++--- ...st_promises_client_getdependentpromises.js | 28 ++--- .../test_promises_object_creationtimestamp.js | 33 ++--- .../test_promises_object_timetosettle-01.js | 29 ++--- .../test_promises_object_timetosettle-02.js | 34 ++--- devtools/server/tests/unit/xpcshell.ini | 1 - 14 files changed, 177 insertions(+), 246 deletions(-) delete mode 100644 devtools/server/tests/unit/test_promises_actor_exist.js diff --git a/devtools/server/tests/unit/head_dbg.js b/devtools/server/tests/unit/head_dbg.js index 0ad5f71ff57f..8e8d128b6f92 100644 --- a/devtools/server/tests/unit/head_dbg.js +++ b/devtools/server/tests/unit/head_dbg.js @@ -60,40 +60,21 @@ function startupAddonsManager() { internalManager.observe(null, "addons-startup", null); } -/** - * Create a MemoryFront for a fake test tab. - * - * When the test ends, the front should be detached and we should call - * `finishClient(client)`. - */ -async function createTabMemoryFront() { - const client = await startTestDebuggerServer("test_MemoryActor"); - - // MemoryFront requires the HeadSnapshotActor actor to be available - // as a global actor. This isn't registered by startTestDebuggerServer which - // only register the target actors and not the browser ones. - DebuggerServer.registerActors({ browser: true }); +async function createTargetForFakeTab(title) { + const client = await startTestDebuggerServer(title); const { tabs } = await listTabs(client); - const tab = findTab(tabs, "test_MemoryActor"); + const tab = findTab(tabs, title); const options = { form: tab, client, chrome: false, }; const target = await TargetFactory.forRemoteTab(options); - - const memoryFront = await target.getFront("memory"); - await memoryFront.attach(); - - return { client, memoryFront }; + return target; } -/** - * Same as createTabMemoryFront but attaches the MemoryFront to the MemoryActor - * scoped to the full runtime rather than to a tab. - */ -async function createFullRuntimeMemoryFront() { +async function createTargetForMainProcess() { DebuggerServer.init(); DebuggerServer.registerAllActors(); DebuggerServer.allowChromeProcess = true; @@ -108,11 +89,94 @@ async function createFullRuntimeMemoryFront() { chrome: true, }; const target = await TargetFactory.forRemoteTab(options); + return target; +} + +/** + * Create a MemoryFront for a fake test tab. + */ +async function createTabMemoryFront() { + const target = await createTargetForFakeTab("test_memory"); + + // MemoryFront requires the HeadSnapshotActor actor to be available + // as a global actor. This isn't registered by startTestDebuggerServer which + // only register the target actors and not the browser ones. + DebuggerServer.registerActors({ browser: true }); const memoryFront = await target.getFront("memory"); await memoryFront.attach(); - return { client, memoryFront }; + registerCleanupFunction(async () => { + await memoryFront.detach(); + + // On XPCShell, the target isn't for a local tab and so target.destroy + // won't close the client. So do it so here. It will automatically destroy the target. + await target.client.close(); + }); + + return { target, memoryFront }; +} + +/** + * Create a PromisesFront for a fake test tab. + */ +async function createTabPromisesFront() { + const title = "test_promises"; + const target = await createTargetForFakeTab(title); + + // Retrieve the debuggee create by createTargetForFakeTab + const debuggee = DebuggerServer.getTestGlobal(title); + + const promisesFront = await target.getFront("promises"); + + registerCleanupFunction(async () => { + // On XPCShell, the target isn't for a local tab and so target.destroy + // won't close the client. So do it so here. It will automatically destroy the target. + await target.client.close(); + }); + + return { debuggee, client: target.client, promisesFront }; +} + +/** + * Create a PromisesFront for the main process target actor. + */ +async function createMainProcessPromisesFront() { + const target = await createTargetForMainProcess(); + + const promisesFront = await target.getFront("promises"); + + registerCleanupFunction(async () => { + // For XPCShell, the main process target actor is ContentProcessTargetActor + // which doesn't expose any `detach` method. So that the target actor isn't + // destroyed when calling target.destroy. + // Close the client to cleanup everything. + await target.client.close(); + }); + + return { client: target.client, promisesFront }; +} + +/** + * Same as createTabMemoryFront but attaches the MemoryFront to the MemoryActor + * scoped to the full runtime rather than to a tab. + */ +async function createMainProcessMemoryFront() { + const target = await createTargetForMainProcess(); + + const memoryFront = await target.getFront("memory"); + await memoryFront.attach(); + + registerCleanupFunction(async () => { + await memoryFront.detach(); + // For XPCShell, the main process target actor is ContentProcessTargetActor + // which doesn't expose any `detach` method. So that the target actor isn't + // destroyed when calling target.destroy. + // Close the client to cleanup everything. + await target.client.close(); + }); + + return { client: target.client, memoryFront }; } function createTestGlobal(name) { @@ -403,11 +467,6 @@ async function finishClient(client) { do_test_finished(); } -function getParentProcessActors(client, server = DebuggerServer) { - server.allowChromeProcess = true; - return client.mainRoot.getMainProcess().then(response => response.targetForm); -} - /** * Takes a relative file path and returns the absolute file url for it. */ diff --git a/devtools/server/tests/unit/test_MemoryActor_saveHeapSnapshot_01.js b/devtools/server/tests/unit/test_MemoryActor_saveHeapSnapshot_01.js index 6d1be678c57f..d3d4bbb4d5f9 100644 --- a/devtools/server/tests/unit/test_MemoryActor_saveHeapSnapshot_01.js +++ b/devtools/server/tests/unit/test_MemoryActor_saveHeapSnapshot_01.js @@ -9,7 +9,7 @@ const { OS } = require("resource://gre/modules/osfile.jsm"); add_task(async () => { - const { client, memoryFront } = await createTabMemoryFront(); + const { memoryFront } = await createTabMemoryFront(); const snapshotFilePath = await memoryFront.saveHeapSnapshot(); ok(!!(await OS.File.stat(snapshotFilePath)), @@ -17,7 +17,4 @@ add_task(async () => { const snapshot = ChromeUtils.readHeapSnapshot(snapshotFilePath); ok(snapshot instanceof HeapSnapshot, "And we should be able to read a HeapSnapshot instance from the file"); - - await memoryFront.detach(); - await finishClient(client); }); diff --git a/devtools/server/tests/unit/test_MemoryActor_saveHeapSnapshot_02.js b/devtools/server/tests/unit/test_MemoryActor_saveHeapSnapshot_02.js index ad3d7ac75888..f6fab52aabce 100644 --- a/devtools/server/tests/unit/test_MemoryActor_saveHeapSnapshot_02.js +++ b/devtools/server/tests/unit/test_MemoryActor_saveHeapSnapshot_02.js @@ -9,7 +9,7 @@ const { OS } = require("resource://gre/modules/osfile.jsm"); add_task(async () => { - const { client, memoryFront } = await createTabMemoryFront(); + const { memoryFront } = await createTabMemoryFront(); const snapshotFilePath = await memoryFront.saveHeapSnapshot({ forceCopy: true, @@ -19,7 +19,4 @@ add_task(async () => { const snapshot = ChromeUtils.readHeapSnapshot(snapshotFilePath); ok(snapshot instanceof HeapSnapshot, "And we should be able to read a HeapSnapshot instance from the file"); - - await memoryFront.detach(); - await finishClient(client); }); diff --git a/devtools/server/tests/unit/test_MemoryActor_saveHeapSnapshot_03.js b/devtools/server/tests/unit/test_MemoryActor_saveHeapSnapshot_03.js index 4da343d8918f..a3ba0a189049 100644 --- a/devtools/server/tests/unit/test_MemoryActor_saveHeapSnapshot_03.js +++ b/devtools/server/tests/unit/test_MemoryActor_saveHeapSnapshot_03.js @@ -9,7 +9,7 @@ const { OS } = require("resource://gre/modules/osfile.jsm"); add_task(async () => { - const { client, memoryFront } = await createFullRuntimeMemoryFront(); + const { memoryFront } = await createMainProcessMemoryFront(); const snapshotFilePath = await memoryFront.saveHeapSnapshot(); ok(!!(await OS.File.stat(snapshotFilePath)), @@ -17,7 +17,4 @@ add_task(async () => { const snapshot = ChromeUtils.readHeapSnapshot(snapshotFilePath); ok(snapshot instanceof HeapSnapshot, "And we should be able to read a HeapSnapshot instance from the file"); - - await memoryFront.detach(); - await finishClient(client); }); diff --git a/devtools/server/tests/unit/test_promises_actor_attach.js b/devtools/server/tests/unit/test_promises_actor_attach.js index ee19f76859b3..a8bfe8298721 100644 --- a/devtools/server/tests/unit/test_promises_actor_attach.js +++ b/devtools/server/tests/unit/test_promises_actor_attach.js @@ -8,27 +8,17 @@ * states. */ -const { PromisesFront } = require("devtools/shared/fronts/promises"); - add_task(async function() { - const client = await startTestDebuggerServer("promises-actor-test"); - const parentProcessActors = await getParentProcessActors(client); - - // We have to attach the chrome target actor before playing with the PromiseActor - await testAttach(client, parentProcessActors); - - const response = await listTabs(client); - const targetTab = findTab(response.tabs, "promises-actor-test"); - ok(targetTab, "Found our target tab."); - - await testAttach(client, targetTab); - - await close(client); + const { promisesFront } = await createMainProcessPromisesFront(); + await testAttach(promisesFront); }); -async function testAttach(client, parent) { - const promises = new PromisesFront(client, parent); +add_task(async function() { + const { promisesFront } = await createTabPromisesFront(); + await testAttach(promisesFront); +}); +async function testAttach(promises) { try { await promises.detach(); ok(false, "Should not be able to detach when in a detached state."); diff --git a/devtools/server/tests/unit/test_promises_actor_exist.js b/devtools/server/tests/unit/test_promises_actor_exist.js deleted file mode 100644 index ce06910dfc85..000000000000 --- a/devtools/server/tests/unit/test_promises_actor_exist.js +++ /dev/null @@ -1,34 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ -/* eslint-disable no-shadow */ - -"use strict"; - -/** - * Test that the PromisesActor exists in the BrowsingContextTargetActors and - * ParentProcessTargetActors. - */ - -add_task(async function() { - const client = await startTestDebuggerServer("promises-actor-test"); - - const response = await listTabs(client); - const targetTab = findTab(response.tabs, "promises-actor-test"); - Assert.ok(targetTab, "Found our target tab."); - - // Attach to the BrowsingContextTargetActor and check the response - await new Promise(resolve => { - client.request({ to: targetTab.actor, type: "attach" }, response => { - Assert.ok(!("error" in response), "Expect no error in response."); - Assert.equal(response.from, targetTab.actor, - "Expect the target BrowsingContextTargetActor in response form field."); - Assert.equal(response.type, "tabAttached", - "Expect tabAttached in the response type."); - resolve(); - }); - }); - - const parentProcessActors = await getParentProcessActors(client); - Assert.ok(typeof parentProcessActors.promisesActor === "string", - "Should have a chrome context PromisesActor."); -}); diff --git a/devtools/server/tests/unit/test_promises_actor_list_promises.js b/devtools/server/tests/unit/test_promises_actor_list_promises.js index e69667113479..93ecd4a907b6 100644 --- a/devtools/server/tests/unit/test_promises_actor_list_promises.js +++ b/devtools/server/tests/unit/test_promises_actor_list_promises.js @@ -8,33 +8,25 @@ "use strict"; -const { PromisesFront } = require("devtools/shared/fronts/promises"); const SECRET = "MyLittleSecret"; add_task(async function() { - const client = await startTestDebuggerServer("promises-actor-test"); - const parentProcessActors = await getParentProcessActors(client); - - // We have to attach the chrome target actor before playing with the PromiseActor - await testListPromises(client, parentProcessActors, v => - new Promise(resolve => resolve(v))); - - const response = await listTabs(client); - const targetTab = findTab(response.tabs, "promises-actor-test"); - ok(targetTab, "Found our target tab."); - - await testListPromises(client, targetTab, v => { - const debuggee = DebuggerServer.getTestGlobal("promises-actor-test"); - return debuggee.Promise.resolve(v); + const { promisesFront } = await createMainProcessPromisesFront(); + await testListPromises(promisesFront, v => { + return new Promise(resolve => resolve(v)); }); - - await close(client); }); -async function testListPromises(client, form, makePromise) { +add_task(async function() { + const { debuggee, promisesFront } = await createTabPromisesFront(); + await testListPromises(promisesFront, v => { + return debuggee.Promise.resolve(v); + }); +}); + +async function testListPromises(front, makePromise) { const resolution = SECRET + Math.random(); const promise = makePromise(resolution); - const front = new PromisesFront(client, form); await front.attach(); diff --git a/devtools/server/tests/unit/test_promises_actor_onnewpromise.js b/devtools/server/tests/unit/test_promises_actor_onnewpromise.js index c6178bd528f2..c46199cb44e2 100644 --- a/devtools/server/tests/unit/test_promises_actor_onnewpromise.js +++ b/devtools/server/tests/unit/test_promises_actor_onnewpromise.js @@ -8,34 +8,23 @@ "use strict"; -const { PromisesFront } = require("devtools/shared/fronts/promises"); - -var EventEmitter = require("devtools/shared/event-emitter"); - add_task(async function() { - const client = await startTestDebuggerServer("promises-actor-test"); - const parentProcessActors = await getParentProcessActors(client); - + const { promisesFront } = await createMainProcessPromisesFront(); ok(Promise.toString().includes("native code"), "Expect native DOM Promise"); - - // We have to attach the chrome target actor before playing with the PromiseActor - await testNewPromisesEvent(client, parentProcessActors, - v => new Promise(resolve => resolve(v))); - - const response = await listTabs(client); - const targetTab = findTab(response.tabs, "promises-actor-test"); - ok(targetTab, "Found our target tab."); - - await testNewPromisesEvent(client, targetTab, v => { - const debuggee = DebuggerServer.getTestGlobal("promises-actor-test"); - return debuggee.Promise.resolve(v); + await testNewPromisesEvent(promisesFront, v => { + return new Promise(resolve => resolve(v)); }); - - await close(client); }); -async function testNewPromisesEvent(client, form, makePromise) { - const front = new PromisesFront(client, form); +add_task(async function() { + const { debuggee, promisesFront } = await createTabPromisesFront(); + + await testNewPromisesEvent(promisesFront, v => { + return debuggee.Promise.resolve(v); + }); +}); + +async function testNewPromisesEvent(front, makePromise) { const resolution = "MyLittleSecret" + Math.random(); let found = false; @@ -43,7 +32,7 @@ async function testNewPromisesEvent(client, form, makePromise) { await front.listPromises(); const onNewPromise = new Promise(resolve => { - EventEmitter.on(front, "new-promises", promises => { + front.on("new-promises", promises => { for (const p of promises) { equal(p.type, "object", "Expect type to be Object"); equal(p.class, "Promise", "Expect class to be Promise"); diff --git a/devtools/server/tests/unit/test_promises_actor_onpromisesettled.js b/devtools/server/tests/unit/test_promises_actor_onpromisesettled.js index de43ebd6f4cf..abd5938e4585 100644 --- a/devtools/server/tests/unit/test_promises_actor_onpromisesettled.js +++ b/devtools/server/tests/unit/test_promises_actor_onpromisesettled.js @@ -10,39 +10,28 @@ ChromeUtils.import("resource://testing-common/PromiseTestUtils.jsm", this); -const { PromisesFront } = require("devtools/shared/fronts/promises"); - -var EventEmitter = require("devtools/shared/event-emitter"); - add_task(async function() { - const client = await startTestDebuggerServer("promises-actor-test"); - const parentProcessActors = await getParentProcessActors(client); + const { promisesFront } = await createMainProcessPromisesFront(); ok(Promise.toString().includes("native code"), "Expect native DOM Promise"); - // We have to attach the chrome target actor before playing with the PromiseActor - await testPromisesSettled(client, parentProcessActors, + await testPromisesSettled(promisesFront, v => new Promise(resolve => resolve(v)), v => new Promise((resolve, reject) => reject(v))); - - const response = await listTabs(client); - const targetTab = findTab(response.tabs, "promises-actor-test"); - ok(targetTab, "Found our target tab."); - - await testPromisesSettled(client, targetTab, v => { - const debuggee = DebuggerServer.getTestGlobal("promises-actor-test"); - return debuggee.Promise.resolve(v); - }, v => { - const debuggee = DebuggerServer.getTestGlobal("promises-actor-test"); - return debuggee.Promise.reject(v); - }); - - await close(client); }); -async function testPromisesSettled(client, form, makeResolvePromise, +add_task(async function() { + const { debuggee, promisesFront } = await createTabPromisesFront(); + + await testPromisesSettled(promisesFront, v => { + return debuggee.Promise.resolve(v); + }, v => { + return debuggee.Promise.reject(v); + }); +}); + +async function testPromisesSettled(front, makeResolvePromise, makeRejectPromise) { - const front = new PromisesFront(client, form); const resolution = "MyLittleSecret" + Math.random(); await front.attach(); @@ -67,7 +56,7 @@ async function testPromisesSettled(client, form, makeResolvePromise, function oncePromiseSettled(front, resolution, resolveValue, rejectValue) { return new Promise(resolve => { - EventEmitter.on(front, "promises-settled", promises => { + front.on("promises-settled", promises => { for (const p of promises) { equal(p.type, "object", "Expect type to be Object"); equal(p.class, "Promise", "Expect class to be Promise"); diff --git a/devtools/server/tests/unit/test_promises_client_getdependentpromises.js b/devtools/server/tests/unit/test_promises_client_getdependentpromises.js index 0a5587c7a9c4..11979483ae54 100644 --- a/devtools/server/tests/unit/test_promises_client_getdependentpromises.js +++ b/devtools/server/tests/unit/test_promises_client_getdependentpromises.js @@ -7,17 +7,12 @@ "use strict"; -const { PromisesFront } = require("devtools/shared/fronts/promises"); - -var EventEmitter = require("devtools/shared/event-emitter"); - add_task(async function() { - const client = await startTestDebuggerServer("test-promises-dependentpromises"); - const parentProcessActors = await getParentProcessActors(client); + const { client, promisesFront } = await createMainProcessPromisesFront(); ok(Promise.toString().includes("native code"), "Expect native DOM Promise."); - await testGetDependentPromises(client, parentProcessActors, () => { + await testGetDependentPromises(client, promisesFront, () => { const p = new Promise(() => {}); p.name = "p"; const q = p.then(); @@ -27,15 +22,12 @@ add_task(async function() { return p; }); +}); - const response = await listTabs(client); - const targetTab = findTab(response.tabs, "test-promises-dependentpromises"); - ok(targetTab, "Found our target tab."); - - await testGetDependentPromises(client, targetTab, () => { - const debuggee = - DebuggerServer.getTestGlobal("test-promises-dependentpromises"); +add_task(async function() { + const { debuggee, client, promisesFront } = await createTabPromisesFront(); + await testGetDependentPromises(client, promisesFront, () => { const p = new debuggee.Promise(() => {}); p.name = "p"; const q = p.then(); @@ -45,19 +37,15 @@ add_task(async function() { return p; }); - - await close(client); }); -async function testGetDependentPromises(client, form, makePromises) { - const front = new PromisesFront(client, form); - +async function testGetDependentPromises(client, front, makePromises) { await front.attach(); await front.listPromises(); // Get the grip for promise p const onNewPromise = new Promise(resolve => { - EventEmitter.on(front, "new-promises", promises => { + front.on("new-promises", promises => { for (const p of promises) { if (p.preview.ownProperties.name && p.preview.ownProperties.name.value === "p") { diff --git a/devtools/server/tests/unit/test_promises_object_creationtimestamp.js b/devtools/server/tests/unit/test_promises_object_creationtimestamp.js index a1b258bc9c7d..618fc8b50f9c 100644 --- a/devtools/server/tests/unit/test_promises_object_creationtimestamp.js +++ b/devtools/server/tests/unit/test_promises_object_creationtimestamp.js @@ -7,10 +7,6 @@ "use strict"; -const { PromisesFront } = require("devtools/shared/fronts/promises"); - -var EventEmitter = require("devtools/shared/event-emitter"); - ChromeUtils.defineModuleGetter(this, "Preferences", "resource://gre/modules/Preferences.jsm"); @@ -22,37 +18,32 @@ add_task(async function() { Preferences.set("privacy.reduceTimerPrecision", timerPrecision); }); - const client = await startTestDebuggerServer("promises-object-test"); - const parentProcessActors = await getParentProcessActors(client); + const { promisesFront } = await createMainProcessPromisesFront(); ok(Promise.toString().includes("native code"), "Expect native DOM Promise."); // We have to attach the chrome target actor before playing with the PromiseActor - await testPromiseCreationTimestamp(client, parentProcessActors, v => { + await testPromiseCreationTimestamp(promisesFront, v => { return new Promise(resolve => resolve(v)); }); - - const response = await listTabs(client); - const targetTab = findTab(response.tabs, "promises-object-test"); - ok(targetTab, "Found our target tab."); - - await testPromiseCreationTimestamp(client, targetTab, v => { - const debuggee = DebuggerServer.getTestGlobal("promises-object-test"); - return debuggee.Promise.resolve(v); - }); - - await close(client); }); -async function testPromiseCreationTimestamp(client, form, makePromise) { - const front = new PromisesFront(client, form); +add_task(async function() { + const { debuggee, promisesFront } = await createTabPromisesFront(); + + await testPromiseCreationTimestamp(promisesFront, v => { + return debuggee.Promise.resolve(v); + }); +}); + +async function testPromiseCreationTimestamp(front, makePromise) { const resolution = "MyLittleSecret" + Math.random(); await front.attach(); await front.listPromises(); const onNewPromise = new Promise(resolve => { - EventEmitter.on(front, "new-promises", promises => { + front.on("new-promises", promises => { for (const p of promises) { if (p.promiseState.state === "fulfilled" && p.promiseState.value === resolution) { diff --git a/devtools/server/tests/unit/test_promises_object_timetosettle-01.js b/devtools/server/tests/unit/test_promises_object_timetosettle-01.js index 7c164f96fb12..355f21fe0f51 100644 --- a/devtools/server/tests/unit/test_promises_object_timetosettle-01.js +++ b/devtools/server/tests/unit/test_promises_object_timetosettle-01.js @@ -8,18 +8,12 @@ "use strict"; -const { PromisesFront } = require("devtools/shared/fronts/promises"); - -var EventEmitter = require("devtools/shared/event-emitter"); - add_task(async function() { - const client = await startTestDebuggerServer("test-promises-timetosettle"); - const parentProcessActors = await getParentProcessActors(client); + const { promisesFront } = await createMainProcessPromisesFront(); ok(Promise.toString().includes("native code"), "Expect native DOM Promise."); - // We have to attach the chrome target actor before playing with the PromiseActor - await testGetTimeToSettle(client, parentProcessActors, () => { + await testGetTimeToSettle(promisesFront, () => { const p = new Promise(() => {}); p.name = "p"; const q = p.then(); @@ -27,15 +21,12 @@ add_task(async function() { return p; }); +}); - const response = await listTabs(client); - const targetTab = findTab(response.tabs, "test-promises-timetosettle"); - ok(targetTab, "Found our target tab."); - - await testGetTimeToSettle(client, targetTab, () => { - const debuggee = - DebuggerServer.getTestGlobal("test-promises-timetosettle"); +add_task(async function() { + const { debuggee, promisesFront } = await createTabPromisesFront(); + await testGetTimeToSettle(promisesFront, () => { const p = new debuggee.Promise(() => {}); p.name = "p"; const q = p.then(); @@ -43,18 +34,14 @@ add_task(async function() { return p; }); - - await close(client); }); -async function testGetTimeToSettle(client, form, makePromises) { - const front = new PromisesFront(client, form); - +async function testGetTimeToSettle(front, makePromises) { await front.attach(); await front.listPromises(); const onNewPromise = new Promise(resolve => { - EventEmitter.on(front, "new-promises", promises => { + front.on("new-promises", promises => { for (const p of promises) { if (p.promiseState.state === "pending") { ok(!p.promiseState.timeToSettle, diff --git a/devtools/server/tests/unit/test_promises_object_timetosettle-02.js b/devtools/server/tests/unit/test_promises_object_timetosettle-02.js index 6cdd821883b8..7af139aaddc0 100644 --- a/devtools/server/tests/unit/test_promises_object_timetosettle-02.js +++ b/devtools/server/tests/unit/test_promises_object_timetosettle-02.js @@ -8,36 +8,26 @@ "use strict"; -const { PromisesFront } = require("devtools/shared/fronts/promises"); const { setTimeout } = ChromeUtils.import("resource://gre/modules/Timer.jsm", {}); -var EventEmitter = require("devtools/shared/event-emitter"); - add_task(async function() { - const client = await startTestDebuggerServer("test-promises-timetosettle"); - const parentProcessActors = await getParentProcessActors(client); + const { promisesFront } = await createMainProcessPromisesFront(); ok(Promise.toString().includes("native code"), "Expect native DOM Promise."); - // We have to attach the chrome target actor before playing with the PromiseActor - await testGetTimeToSettle(client, parentProcessActors, + await testGetTimeToSettle(promisesFront, v => new Promise(resolve => setTimeout(() => resolve(v), 100))); - - const response = await listTabs(client); - const targetTab = findTab(response.tabs, "test-promises-timetosettle"); - ok(targetTab, "Found our target tab."); - - await testGetTimeToSettle(client, targetTab, v => { - const debuggee = - DebuggerServer.getTestGlobal("test-promises-timetosettle"); - return new debuggee.Promise(resolve => setTimeout(() => resolve(v), 100)); - }); - - await close(client); }); -async function testGetTimeToSettle(client, form, makePromise) { - const front = new PromisesFront(client, form); +add_task(async function() { + const { debuggee, promisesFront } = await createTabPromisesFront(); + + await testGetTimeToSettle(promisesFront, v => { + return new debuggee.Promise(resolve => setTimeout(() => resolve(v), 100)); + }); +}); + +async function testGetTimeToSettle(front, makePromise) { const resolution = "MyLittleSecret" + Math.random(); let found = false; @@ -45,7 +35,7 @@ async function testGetTimeToSettle(client, form, makePromise) { await front.listPromises(); const onNewPromise = new Promise(resolve => { - EventEmitter.on(front, "promises-settled", promises => { + front.on("promises-settled", promises => { for (const p of promises) { if (p.promiseState.state === "fulfilled" && p.promiseState.value === resolution) { diff --git a/devtools/server/tests/unit/xpcshell.ini b/devtools/server/tests/unit/xpcshell.ini index 93e5570c1680..1b1dff933aac 100644 --- a/devtools/server/tests/unit/xpcshell.ini +++ b/devtools/server/tests/unit/xpcshell.ini @@ -91,7 +91,6 @@ support-files = [test_eval-05.js] [test_format_command.js] [test_promises_actor_attach.js] -[test_promises_actor_exist.js] [test_promises_actor_list_promises.js] skip-if = coverage # bug 1336670 [test_promises_actor_onnewpromise.js]