/* Any copyright is dedicated to the Public Domain. * http://creativecommons.org/publicdomain/zero/1.0/ */ "use strict"; // Check evaluating and expanding promises in the console. const TEST_URI = "data:text/html;charset=utf8," + "

Object Inspector on deeply nested promises

"; add_task(async function testExpandNestedPromise() { const hud = await openNewTabAndConsole(TEST_URI); await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () { let nestedPromise = Promise.resolve({}); for (let i = 5; i > 0; --i) { nestedPromise[i] = i; Object.setPrototypeOf(nestedPromise, null); nestedPromise = Promise.resolve(nestedPromise); } nestedPromise[0] = 0; content.wrappedJSObject.console.log("oi-test", nestedPromise); }); const node = await waitFor(() => findConsoleAPIMessage(hud, "oi-test")); const oi = node.querySelector(".tree"); const [promiseNode] = getObjectInspectorNodes(oi); expandObjectInspectorNode(promiseNode); await waitFor(() => getObjectInspectorNodes(oi).length > 1); checkChildren(promiseNode, [`0`, ``, ``, ``]); const valueNode = findObjectInspectorNode(oi, ""); expandObjectInspectorNode(valueNode); await waitFor(() => !!getObjectInspectorChildrenNodes(valueNode).length); checkChildren(valueNode, [`1`, ``, ``]); }); add_task(async function testExpandCyclicPromise() { const hud = await openNewTabAndConsole(TEST_URI); await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () { let resolve; const cyclicPromise = new Promise(r => { resolve = r; }); Object.setPrototypeOf(cyclicPromise, null); cyclicPromise.foo = "foo"; const otherPromise = Promise.reject(cyclicPromise); otherPromise.catch(() => {}); Object.setPrototypeOf(otherPromise, null); otherPromise.bar = "bar"; resolve(otherPromise); content.wrappedJSObject.console.log("oi-test", cyclicPromise); }); const node = await waitFor(() => findConsoleAPIMessage(hud, "oi-test")); const oi = node.querySelector(".tree"); const [promiseNode] = getObjectInspectorNodes(oi); expandObjectInspectorNode(promiseNode); await waitFor(() => getObjectInspectorNodes(oi).length > 1); checkChildren(promiseNode, [`foo`, ``, ``]); const valueNode = findObjectInspectorNode(oi, ""); expandObjectInspectorNode(valueNode); await waitFor(() => !!getObjectInspectorChildrenNodes(valueNode).length); checkChildren(valueNode, [`bar`, ``, ``]); const reasonNode = findObjectInspectorNode(oi, ""); expandObjectInspectorNode(reasonNode); await waitFor(() => !!getObjectInspectorChildrenNodes(reasonNode).length); checkChildren(reasonNode, [`foo`, ``, ``]); }); function checkChildren(node, expectedChildren) { const children = getObjectInspectorChildrenNodes(node); is( children.length, expectedChildren.length, "There is the expected number of children" ); children.forEach((child, index) => { is( child.querySelector(".object-label").textContent, expectedChildren[index], `Found correct child at index ${index}` ); }); }