tor-browser

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

test_HeapAnalyses_getImmediatelyDominated_01.js (2679B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 // Test the HeapAnalyses{Client,Worker} "getImmediatelyDominated" request.
      6 
      7 const breakdown = {
      8  by: "coarseType",
      9  objects: { by: "count", count: true, bytes: true },
     10  scripts: { by: "count", count: true, bytes: true },
     11  strings: { by: "count", count: true, bytes: true },
     12  other: { by: "count", count: true, bytes: true },
     13  domNode: { by: "count", count: true, bytes: true },
     14 };
     15 
     16 add_task(async function () {
     17  const client = new HeapAnalysesClient();
     18 
     19  const snapshotFilePath = saveNewHeapSnapshot();
     20  await client.readHeapSnapshot(snapshotFilePath);
     21  const dominatorTreeId = await client.computeDominatorTree(snapshotFilePath);
     22 
     23  const partialTree = await client.getDominatorTree({
     24    dominatorTreeId,
     25    breakdown,
     26  });
     27  ok(
     28    !!partialTree.children.length,
     29    "root should immediately dominate some nodes"
     30  );
     31 
     32  // First, test getting a subset of children available.
     33  const response = await client.getImmediatelyDominated({
     34    dominatorTreeId,
     35    breakdown,
     36    nodeId: partialTree.nodeId,
     37    startIndex: 0,
     38    maxCount: partialTree.children.length - 1,
     39  });
     40 
     41  ok(Array.isArray(response.nodes));
     42  ok(response.nodes.every(node => node.parentId === partialTree.nodeId));
     43  ok(response.moreChildrenAvailable);
     44  equal(response.path.length, 1);
     45  equal(response.path[0], partialTree.nodeId);
     46 
     47  for (const node of response.nodes) {
     48    equal(typeof node.shortestPaths, "object", "Should have shortest paths");
     49    equal(
     50      typeof node.shortestPaths.nodes,
     51      "object",
     52      "Should have shortest paths' nodes"
     53    );
     54    equal(
     55      typeof node.shortestPaths.edges,
     56      "object",
     57      "Should have shortest paths' edges"
     58    );
     59  }
     60 
     61  // Next, test getting a subset of children available.
     62  const secondResponse = await client.getImmediatelyDominated({
     63    dominatorTreeId,
     64    breakdown,
     65    nodeId: partialTree.nodeId,
     66    startIndex: 0,
     67    maxCount: Infinity,
     68  });
     69 
     70  ok(Array.isArray(secondResponse.nodes));
     71  ok(secondResponse.nodes.every(node => node.parentId === partialTree.nodeId));
     72  ok(!secondResponse.moreChildrenAvailable);
     73  equal(secondResponse.path.length, 1);
     74  equal(secondResponse.path[0], partialTree.nodeId);
     75 
     76  for (const node of secondResponse.nodes) {
     77    equal(typeof node.shortestPaths, "object", "Should have shortest paths");
     78    equal(
     79      typeof node.shortestPaths.nodes,
     80      "object",
     81      "Should have shortest paths' nodes"
     82    );
     83    equal(
     84      typeof node.shortestPaths.edges,
     85      "object",
     86      "Should have shortest paths' edges"
     87    );
     88  }
     89 
     90  client.destroy();
     91 });