summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_webconsole_object_inspector_getters_shadowed.js
blob: d443225f0fb311f5c0bc9a20e236de614d7a183b (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Check evaluating shadowed getters in the console.
const TEST_URI =
  "data:text/html;charset=utf8,<!DOCTYPE html><h1>Object Inspector on Getters</h1>";

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

  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
    const a = {
      getter: "[A]",
      __proto__: {
        get getter() {
          return "[B]";
        },
        __proto__: {
          get getter() {
            return "[C]";
          },
        },
      },
    };
    const b = {
      value: 1,
      get getter() {
        return `[A-${this.value}]`;
      },
      __proto__: {
        value: 2,
        get getter() {
          return `[B-${this.value}]`;
        },
      },
    };
    content.wrappedJSObject.console.log("oi-test", a, b);
  });

  const node = await waitFor(() => findConsoleAPIMessage(hud, "oi-test"));
  const [a, b] = node.querySelectorAll(".tree");

  await testObject(a, [null, "[B]", "[C]"]);
  await testObject(b, ["[A-1]", "[B-1]"]);
});

async function testObject(oi, values) {
  let node = oi.querySelector(".tree-node");
  for (const value of values) {
    await expand(node);
    if (value != null) {
      const getter = findObjectInspectorNodeChild(node, "getter");
      await invokeGetter(getter);
      ok(
        getter.textContent.includes(`getter: "${value}"`),
        `Getter now has the expected "${value}" content`
      );
    }
    node = findObjectInspectorNodeChild(node, "<prototype>");
  }
}

function expand(node) {
  expandObjectInspectorNode(node);
  return waitFor(() => !!getObjectInspectorChildrenNodes(node).length);
}

function invokeGetter(node) {
  getObjectInspectorInvokeGetterButton(node).click();
  return waitFor(() => !getObjectInspectorInvokeGetterButton(node));
}

function findObjectInspectorNodeChild(node, nodeLabel) {
  return getObjectInspectorChildrenNodes(node).find(child => {
    const label = child.querySelector(".object-label");
    return label && label.textContent === nodeLabel;
  });
}