зеркало из https://github.com/mozilla/gecko-dev.git
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
This commit is contained in:
Родитель
2bb751479d
Коммит
c1ea0a64c2
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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.");
|
||||
|
|
|
@ -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.");
|
||||
});
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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") {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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]
|
||||
|
|
Загрузка…
Ссылка в новой задаче