tor-browser

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

test_census-tree-node-05.js (3584B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 /**
      6 * Tests CensusTreeNode with `allocationStack` => `objectClass` breakdown.
      7 */
      8 
      9 function run_test() {
     10  const countBreakdown = { by: "count", count: true, bytes: true };
     11 
     12  const BREAKDOWN = {
     13    by: "allocationStack",
     14    then: {
     15      by: "objectClass",
     16      then: countBreakdown,
     17      other: countBreakdown,
     18    },
     19    noStack: countBreakdown,
     20  };
     21 
     22  let stack;
     23 
     24  (function a() {
     25    (function b() {
     26      (function c() {
     27        stack = saveStack(3);
     28      })();
     29    })();
     30  })();
     31 
     32  const REPORT = new Map([
     33    [
     34      stack,
     35      {
     36        Foo: { bytes: 10, count: 1 },
     37        Bar: { bytes: 20, count: 2 },
     38        Baz: { bytes: 30, count: 3 },
     39        other: { bytes: 40, count: 4 },
     40      },
     41    ],
     42    ["noStack", { bytes: 50, count: 5 }],
     43  ]);
     44 
     45  const EXPECTED = {
     46    name: null,
     47    bytes: 0,
     48    totalBytes: 150,
     49    count: 0,
     50    totalCount: 15,
     51    children: [
     52      {
     53        name: stack.parent.parent,
     54        bytes: 0,
     55        totalBytes: 100,
     56        count: 0,
     57        totalCount: 10,
     58        children: [
     59          {
     60            name: stack.parent,
     61            bytes: 0,
     62            totalBytes: 100,
     63            count: 0,
     64            totalCount: 10,
     65            children: [
     66              {
     67                name: stack,
     68                bytes: 0,
     69                totalBytes: 100,
     70                count: 0,
     71                totalCount: 10,
     72                children: [
     73                  {
     74                    name: "other",
     75                    bytes: 40,
     76                    totalBytes: 40,
     77                    count: 4,
     78                    totalCount: 4,
     79                    children: undefined,
     80                    id: 8,
     81                    parent: 4,
     82                    reportLeafIndex: 5,
     83                  },
     84                  {
     85                    name: "Baz",
     86                    bytes: 30,
     87                    totalBytes: 30,
     88                    count: 3,
     89                    totalCount: 3,
     90                    children: undefined,
     91                    id: 7,
     92                    parent: 4,
     93                    reportLeafIndex: 4,
     94                  },
     95                  {
     96                    name: "Bar",
     97                    bytes: 20,
     98                    totalBytes: 20,
     99                    count: 2,
    100                    totalCount: 2,
    101                    children: undefined,
    102                    id: 6,
    103                    parent: 4,
    104                    reportLeafIndex: 3,
    105                  },
    106                  {
    107                    name: "Foo",
    108                    bytes: 10,
    109                    totalBytes: 10,
    110                    count: 1,
    111                    totalCount: 1,
    112                    children: undefined,
    113                    id: 5,
    114                    parent: 4,
    115                    reportLeafIndex: 2,
    116                  },
    117                ],
    118                id: 4,
    119                parent: 3,
    120                reportLeafIndex: undefined,
    121              },
    122            ],
    123            id: 3,
    124            parent: 2,
    125            reportLeafIndex: undefined,
    126          },
    127        ],
    128        id: 2,
    129        parent: 1,
    130        reportLeafIndex: undefined,
    131      },
    132      {
    133        name: "noStack",
    134        bytes: 50,
    135        totalBytes: 50,
    136        count: 5,
    137        totalCount: 5,
    138        children: undefined,
    139        id: 9,
    140        parent: 1,
    141        reportLeafIndex: 6,
    142      },
    143    ],
    144    id: 1,
    145    parent: undefined,
    146    reportLeafIndex: undefined,
    147  };
    148 
    149  compareCensusViewData(BREAKDOWN, REPORT, EXPECTED);
    150 }