summaryrefslogtreecommitdiffstats
path: root/devtools/shared/heapsnapshot/tests/xpcshell/test_DominatorTreeNode_partialTraversal_01.js
blob: 6da0587f57cd87aa3c9f6162f9e1a811b0d1158a (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";

// Test that we correctly set `moreChildrenAvailable` when doing a partial
// traversal of a dominator tree to create the initial incrementally loaded
// `DominatorTreeNode` tree.

// `tree` maps parent to children:
//
// 100
//   |- 200
//   |    |- 500
//   |    |- 600
//   |    `- 700
//   |- 300
//   |    |- 800
//   |    |- 900
//   `- 400
//        |- 1000
//        |- 1100
//        `- 1200
const tree = new Map([
  [100, [200, 300, 400]],
  [200, [500, 600, 700]],
  [300, [800, 900]],
  [400, [1000, 1100, 1200]],
]);

const mockDominatorTree = {
  root: 100,
  getRetainedSize: _ => 10,
  getImmediatelyDominated: id => (tree.get(id) || []).slice(),
};

const mockSnapshot = {
  describeNode: _ => ({
    objects: { count: 0, bytes: 0 },
    strings: { count: 0, bytes: 0 },
    scripts: { count: 0, bytes: 0 },
    other: { SomeType: { count: 1, bytes: 10 } },
    domNode: { count: 0, bytes: 0 },
  }),
};

const breakdown = {
  by: "coarseType",
  objects: { by: "count", count: true, bytes: true },
  strings: { by: "count", count: true, bytes: true },
  scripts: { by: "count", count: true, bytes: true },
  other: {
    by: "internalType",
    then: { by: "count", count: true, bytes: true },
  },
  domNode: { by: "count", count: true, bytes: true },
};

const expected = {
  nodeId: 100,
  label: ["other", "SomeType"],
  shallowSize: 10,
  retainedSize: 10,
  shortestPaths: undefined,
  children: [
    {
      nodeId: 200,
      label: ["other", "SomeType"],
      shallowSize: 10,
      retainedSize: 10,
      parentId: 100,
      shortestPaths: undefined,
      children: [
        {
          nodeId: 500,
          label: ["other", "SomeType"],
          shallowSize: 10,
          retainedSize: 10,
          parentId: 200,
          moreChildrenAvailable: false,
          shortestPaths: undefined,
          children: undefined,
        },
        {
          nodeId: 600,
          label: ["other", "SomeType"],
          shallowSize: 10,
          retainedSize: 10,
          parentId: 200,
          moreChildrenAvailable: false,
          shortestPaths: undefined,
          children: undefined,
        },
      ],
      moreChildrenAvailable: true,
    },
    {
      nodeId: 300,
      label: ["other", "SomeType"],
      shallowSize: 10,
      retainedSize: 10,
      parentId: 100,
      shortestPaths: undefined,
      children: [
        {
          nodeId: 800,
          label: ["other", "SomeType"],
          shallowSize: 10,
          retainedSize: 10,
          parentId: 300,
          moreChildrenAvailable: false,
          shortestPaths: undefined,
          children: undefined,
        },
        {
          nodeId: 900,
          label: ["other", "SomeType"],
          shallowSize: 10,
          retainedSize: 10,
          parentId: 300,
          moreChildrenAvailable: false,
          shortestPaths: undefined,
          children: undefined,
        },
      ],
      moreChildrenAvailable: false,
    },
  ],
  moreChildrenAvailable: true,
  parentId: undefined,
};

function run_test() {
  // Traverse the whole depth of the test tree, but one short of the number of
  // siblings. This will exercise the moreChildrenAvailable handling for
  // siblings.
  const actual = DominatorTreeNode.partialTraversal(
    mockDominatorTree,
    mockSnapshot,
    breakdown,
    // maxDepth
    4,
    // siblings
    2
  );

  dumpn("Expected = " + JSON.stringify(expected, null, 2));
  dumpn("Actual = " + JSON.stringify(actual, null, 2));

  assertStructurallyEquivalent(expected, actual);
}