tor-browser

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

test_census_diff_06.js (3012B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 // Test diffing census reports of a "complex" and "realistic" breakdown.
      6 
      7 const BREAKDOWN = {
      8  by: "coarseType",
      9  objects: {
     10    by: "allocationStack",
     11    then: {
     12      by: "objectClass",
     13      then: { by: "count", count: false, bytes: true },
     14      other: { by: "count", count: false, bytes: true },
     15    },
     16    noStack: {
     17      by: "objectClass",
     18      then: { by: "count", count: false, bytes: true },
     19      other: { by: "count", count: false, bytes: true },
     20    },
     21  },
     22  strings: {
     23    by: "internalType",
     24    then: { by: "count", count: false, bytes: true },
     25  },
     26  scripts: {
     27    by: "internalType",
     28    then: { by: "count", count: false, bytes: true },
     29  },
     30  other: {
     31    by: "internalType",
     32    then: { by: "count", count: false, bytes: true },
     33  },
     34  domNode: {
     35    by: "internalType",
     36    then: { by: "count", count: false, bytes: true },
     37  },
     38 };
     39 
     40 const stack1 = saveStack();
     41 const stack2 = saveStack();
     42 const stack3 = saveStack();
     43 
     44 const REPORT1 = {
     45  objects: new Map([
     46    [
     47      stack1,
     48      { Function: { bytes: 1 }, Object: { bytes: 2 }, other: { bytes: 0 } },
     49    ],
     50    [stack2, { Array: { bytes: 3 }, Date: { bytes: 4 }, other: { bytes: 0 } }],
     51    ["noStack", { Object: { bytes: 3 } }],
     52  ]),
     53  strings: {
     54    JSAtom: { bytes: 10 },
     55    JSLinearString: { bytes: 5 },
     56  },
     57  scripts: {
     58    JSScript: { bytes: 1 },
     59    "js::jit::JitCode": { bytes: 2 },
     60  },
     61  other: {
     62    "mozilla::dom::Thing": { bytes: 1 },
     63  },
     64  domNode: {},
     65 };
     66 
     67 const REPORT2 = {
     68  objects: new Map([
     69    [stack2, { Array: { bytes: 1 }, Date: { bytes: 2 }, other: { bytes: 3 } }],
     70    [
     71      stack3,
     72      { Function: { bytes: 1 }, Object: { bytes: 2 }, other: { bytes: 0 } },
     73    ],
     74    ["noStack", { Object: { bytes: 3 } }],
     75  ]),
     76  strings: {
     77    JSAtom: { bytes: 5 },
     78    JSLinearString: { bytes: 10 },
     79  },
     80  scripts: {
     81    JSScript: { bytes: 2 },
     82    "js::LazyScript": { bytes: 42 },
     83    "js::jit::JitCode": { bytes: 1 },
     84  },
     85  other: {
     86    "mozilla::dom::OtherThing": { bytes: 1 },
     87  },
     88  domNode: {},
     89 };
     90 
     91 const EXPECTED = {
     92  objects: new Map([
     93    [
     94      stack1,
     95      { Function: { bytes: -1 }, Object: { bytes: -2 }, other: { bytes: 0 } },
     96    ],
     97    [
     98      stack2,
     99      { Array: { bytes: -2 }, Date: { bytes: -2 }, other: { bytes: 3 } },
    100    ],
    101    [
    102      stack3,
    103      { Function: { bytes: 1 }, Object: { bytes: 2 }, other: { bytes: 0 } },
    104    ],
    105    ["noStack", { Object: { bytes: 0 } }],
    106  ]),
    107  scripts: {
    108    JSScript: {
    109      bytes: 1,
    110    },
    111    "js::jit::JitCode": {
    112      bytes: -1,
    113    },
    114    "js::LazyScript": {
    115      bytes: 42,
    116    },
    117  },
    118  strings: {
    119    JSAtom: {
    120      bytes: -5,
    121    },
    122    JSLinearString: {
    123      bytes: 5,
    124    },
    125  },
    126  other: {
    127    "mozilla::dom::Thing": {
    128      bytes: -1,
    129    },
    130    "mozilla::dom::OtherThing": {
    131      bytes: 1,
    132    },
    133  },
    134  domNode: {},
    135 };
    136 
    137 function run_test() {
    138  assertDiff(BREAKDOWN, REPORT1, REPORT2, EXPECTED);
    139 }