tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_DominatorTreeNode_partialTraversal_01.js (3671B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 // Test that we correctly set `moreChildrenAvailable` when doing a partial
      6 // traversal of a dominator tree to create the initial incrementally loaded
      7 // `DominatorTreeNode` tree.
      8 
      9 // `tree` maps parent to children:
     10 //
     11 // 100
     12 //   |- 200
     13 //   |    |- 500
     14 //   |    |- 600
     15 //   |    `- 700
     16 //   |- 300
     17 //   |    |- 800
     18 //   |    |- 900
     19 //   `- 400
     20 //        |- 1000
     21 //        |- 1100
     22 //        `- 1200
     23 const tree = new Map([
     24  [100, [200, 300, 400]],
     25  [200, [500, 600, 700]],
     26  [300, [800, 900]],
     27  [400, [1000, 1100, 1200]],
     28 ]);
     29 
     30 const mockDominatorTree = {
     31  root: 100,
     32  getRetainedSize: _ => 10,
     33  getImmediatelyDominated: id => (tree.get(id) || []).slice(),
     34 };
     35 
     36 const mockSnapshot = {
     37  describeNode: _ => ({
     38    objects: { count: 0, bytes: 0 },
     39    strings: { count: 0, bytes: 0 },
     40    scripts: { count: 0, bytes: 0 },
     41    other: { SomeType: { count: 1, bytes: 10 } },
     42    domNode: { count: 0, bytes: 0 },
     43  }),
     44 };
     45 
     46 const breakdown = {
     47  by: "coarseType",
     48  objects: { by: "count", count: true, bytes: true },
     49  strings: { by: "count", count: true, bytes: true },
     50  scripts: { by: "count", count: true, bytes: true },
     51  other: {
     52    by: "internalType",
     53    then: { by: "count", count: true, bytes: true },
     54  },
     55  domNode: { by: "count", count: true, bytes: true },
     56 };
     57 
     58 const expected = {
     59  nodeId: 100,
     60  label: ["other", "SomeType"],
     61  shallowSize: 10,
     62  retainedSize: 10,
     63  shortestPaths: undefined,
     64  children: [
     65    {
     66      nodeId: 200,
     67      label: ["other", "SomeType"],
     68      shallowSize: 10,
     69      retainedSize: 10,
     70      parentId: 100,
     71      shortestPaths: undefined,
     72      children: [
     73        {
     74          nodeId: 500,
     75          label: ["other", "SomeType"],
     76          shallowSize: 10,
     77          retainedSize: 10,
     78          parentId: 200,
     79          moreChildrenAvailable: false,
     80          shortestPaths: undefined,
     81          children: undefined,
     82        },
     83        {
     84          nodeId: 600,
     85          label: ["other", "SomeType"],
     86          shallowSize: 10,
     87          retainedSize: 10,
     88          parentId: 200,
     89          moreChildrenAvailable: false,
     90          shortestPaths: undefined,
     91          children: undefined,
     92        },
     93      ],
     94      moreChildrenAvailable: true,
     95    },
     96    {
     97      nodeId: 300,
     98      label: ["other", "SomeType"],
     99      shallowSize: 10,
    100      retainedSize: 10,
    101      parentId: 100,
    102      shortestPaths: undefined,
    103      children: [
    104        {
    105          nodeId: 800,
    106          label: ["other", "SomeType"],
    107          shallowSize: 10,
    108          retainedSize: 10,
    109          parentId: 300,
    110          moreChildrenAvailable: false,
    111          shortestPaths: undefined,
    112          children: undefined,
    113        },
    114        {
    115          nodeId: 900,
    116          label: ["other", "SomeType"],
    117          shallowSize: 10,
    118          retainedSize: 10,
    119          parentId: 300,
    120          moreChildrenAvailable: false,
    121          shortestPaths: undefined,
    122          children: undefined,
    123        },
    124      ],
    125      moreChildrenAvailable: false,
    126    },
    127  ],
    128  moreChildrenAvailable: true,
    129  parentId: undefined,
    130 };
    131 
    132 function run_test() {
    133  // Traverse the whole depth of the test tree, but one short of the number of
    134  // siblings. This will exercise the moreChildrenAvailable handling for
    135  // siblings.
    136  const actual = DominatorTreeNode.partialTraversal(
    137    mockDominatorTree,
    138    mockSnapshot,
    139    breakdown,
    140    // maxDepth
    141    4,
    142    // siblings
    143    2
    144  );
    145 
    146  dumpn("Expected = " + JSON.stringify(expected, null, 2));
    147  dumpn("Actual = " + JSON.stringify(actual, null, 2));
    148 
    149  assertStructurallyEquivalent(expected, actual);
    150 }