tor-browser

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

test_getCensusIndividuals_01.js (1684B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 // Test basic functionality of `CensusUtils.getCensusIndividuals`.
      6 
      7 function run_test() {
      8  const stack1 = saveStack(1);
      9  const stack2 = saveStack(1);
     10  const stack3 = saveStack(1);
     11 
     12  const COUNT = { by: "count", count: true, bytes: true };
     13  const INTERNAL_TYPE = { by: "internalType", then: COUNT };
     14 
     15  const BREAKDOWN = {
     16    by: "allocationStack",
     17    then: INTERNAL_TYPE,
     18    noStack: INTERNAL_TYPE,
     19  };
     20 
     21  const MOCK_SNAPSHOT = {
     22    takeCensus: ({ breakdown }) => {
     23      assertStructurallyEquivalent(
     24        breakdown,
     25        CensusUtils.countToBucketBreakdown(BREAKDOWN)
     26      );
     27 
     28      //                                DFS Index
     29      // prettier-ignore
     30      return new Map([               // 0
     31        [stack1, {                   // 1
     32          JSObject: [101, 102, 103], // 2
     33          JSString: [111, 112, 113], // 3
     34        }],
     35        [stack2, {                   // 4
     36          JSObject: [201, 202, 203], // 5
     37          JSString: [211, 212, 213], // 6
     38        }],
     39        [stack3, {                   // 7
     40          JSObject: [301, 302, 303], // 8
     41          JSString: [311, 312, 313], // 9
     42        }],
     43        ["noStack", {                // 10
     44          JSObject: [401, 402, 403], // 11
     45          JSString: [411, 412, 413], // 12
     46        }],
     47      ]);
     48    },
     49  };
     50 
     51  const INDICES = new Set([3, 5, 9]);
     52 
     53  const EXPECTED = new Set([111, 112, 113, 201, 202, 203, 311, 312, 313]);
     54 
     55  const actual = new Set(
     56    CensusUtils.getCensusIndividuals(INDICES, BREAKDOWN, MOCK_SNAPSHOT)
     57  );
     58 
     59  assertStructurallyEquivalent(EXPECTED, actual);
     60 }