summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_webconsole_object_inspector_nested_proxy.js
blob: ee3f1501e90df477f562c1f395a4cc4ec4af27a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Check evaluating and expanding getters in the console.
const TEST_URI =
  "data:text/html;charset=utf8,<!DOCTYPE html>" +
  "<h1>Object Inspector on deeply nested proxies</h1>";

add_task(async function () {
  const hud = await openNewTabAndConsole(TEST_URI);

  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
    let proxy = new Proxy({}, {});
    for (let i = 0; i < 1e5; ++i) {
      proxy = new Proxy(proxy, proxy);
    }
    content.wrappedJSObject.console.log("oi-test", proxy);
  });

  const node = await waitFor(() => findConsoleAPIMessage(hud, "oi-test"));
  const oi = node.querySelector(".tree");
  const [proxyNode] = getObjectInspectorNodes(oi);

  expandObjectInspectorNode(proxyNode);
  await waitFor(() => getObjectInspectorNodes(oi).length > 1);
  checkChildren(proxyNode, [`<target>`, `<handler>`]);

  const targetNode = findObjectInspectorNode(oi, "<target>");
  expandObjectInspectorNode(targetNode);
  await waitFor(() => !!getObjectInspectorChildrenNodes(targetNode).length);
  checkChildren(targetNode, [`<target>`, `<handler>`]);

  const handlerNode = findObjectInspectorNode(oi, "<handler>");
  expandObjectInspectorNode(handlerNode);
  await waitFor(() => !!getObjectInspectorChildrenNodes(handlerNode).length);
  checkChildren(handlerNode, [`<target>`, `<handler>`]);
});

function checkChildren(node, expectedChildren) {
  const children = getObjectInspectorChildrenNodes(node);
  is(
    children.length,
    expectedChildren.length,
    "There is the expected number of children"
  );
  children.forEach((child, index) => {
    ok(
      child.textContent.includes(expectedChildren[index]),
      `Expected "${expectedChildren[index]}" child`
    );
  });
}