tor-browser

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

test_HeapSnapshot_takeCensus_12.js (1636B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 // Test that when we take a census and get a bucket list of ids that matched the
      6 // given category, that the returned ids are all in the snapshot and their
      7 // reported category.
      8 
      9 function run_test() {
     10  const g = newGlobal();
     11  const dbg = new Debugger(g);
     12 
     13  const path = saveNewHeapSnapshot({ debugger: dbg });
     14  const snapshot = readHeapSnapshot(path);
     15 
     16  const bucket = { by: "bucket" };
     17  const count = { by: "count", count: true, bytes: false };
     18  const objectClassCount = { by: "objectClass", then: count, other: count };
     19 
     20  const byClassName = snapshot.takeCensus({
     21    breakdown: {
     22      by: "objectClass",
     23      then: bucket,
     24      other: bucket,
     25    },
     26  });
     27 
     28  const byClassNameCount = snapshot.takeCensus({
     29    breakdown: objectClassCount,
     30  });
     31 
     32  const keys = new Set(Object.keys(byClassName));
     33  equal(
     34    keys.size,
     35    Object.keys(byClassNameCount).length,
     36    "Should have the same number of keys."
     37  );
     38  for (const k of Object.keys(byClassNameCount)) {
     39    ok(keys.has(k), "Should not have any unexpected class names");
     40  }
     41 
     42  for (const key of Object.keys(byClassName)) {
     43    equal(
     44      byClassNameCount[key].count,
     45      byClassName[key].length,
     46      "Length of the bucket and count should be equal"
     47    );
     48 
     49    for (const id of byClassName[key]) {
     50      const desc = snapshot.describeNode(objectClassCount, id);
     51      equal(
     52        desc[key].count,
     53        1,
     54        "Describing the bucketed node confirms that it belongs to the category"
     55      );
     56    }
     57  }
     58 
     59  do_test_finished();
     60 }