summaryrefslogtreecommitdiffstats
path: root/dom/heapsnapshot/tests/unit/test_HeapAnalyses_getDominatorTree_01.js
blob: cedea5375418e3969f2b5a4a06ec628b88108225 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

// Test the HeapAnalyses{Client,Worker} "getDominatorTree" request.

function run_test() {
  run_next_test();
}

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

add_task(function* () {
  const client = new HeapAnalysesClient();

  const snapshotFilePath = saveNewHeapSnapshot();
  yield client.readHeapSnapshot(snapshotFilePath);
  ok(true, "Should have read the heap snapshot");

  const dominatorTreeId = yield client.computeDominatorTree(snapshotFilePath);
  equal(typeof dominatorTreeId, "number",
        "should get a dominator tree id, and it should be a number");

  const partialTree = yield client.getDominatorTree({
    dominatorTreeId,
    breakdown
  });
  ok(partialTree, "Should get a partial tree");
  equal(typeof partialTree, "object",
        "partialTree should be an object");

  function checkTree(node) {
    equal(typeof node.nodeId, "number", "each node should have an id");

    if (node === partialTree) {
      equal(node.parentId, undefined, "the root has no parent");
    } else {
      equal(typeof node.parentId, "number", "each node should have a parent id");
    }

    equal(typeof node.retainedSize, "number",
          "each node should have a retained size");

    ok(node.children === undefined || Array.isArray(node.children),
       "each node either has a list of children, or undefined meaning no children loaded");
    equal(typeof node.moreChildrenAvailable, "boolean",
          "each node should indicate if there are more children available or not");

    equal(typeof node.shortestPaths, "object",
          "Should have shortest paths");
    equal(typeof node.shortestPaths.nodes, "object",
          "Should have shortest paths' nodes");
    equal(typeof node.shortestPaths.edges, "object",
          "Should have shortest paths' edges");

    if (node.children) {
      node.children.forEach(checkTree);
    }
  }

  checkTree(partialTree);

  client.destroy();
});