tor-browser

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

test_HeapSnapshot_getObjectNodeId_01.js (1711B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 // Test ChromeUtils.getObjectNodeId()
      6 
      7 function run_test() {
      8  // Create a test object, which we want to analyse
      9  const testObject = {
     10    foo: {
     11      bar: {},
     12    },
     13  };
     14 
     15  const path = ChromeUtils.saveHeapSnapshot({ runtime: true });
     16  const snapshot = ChromeUtils.readHeapSnapshot(path);
     17 
     18  // Get the NodeId for our test object
     19  const objectNodeIdRoot = ChromeUtils.getObjectNodeId(testObject);
     20  const objectNodeIdFoo = ChromeUtils.getObjectNodeId(testObject.foo);
     21  const objectNodeIdBar = ChromeUtils.getObjectNodeId(testObject.foo.bar);
     22 
     23  // Also try to ensure that this is the right object via its retained path
     24  const shortestPaths = snapshot.computeShortestPaths(
     25    objectNodeIdRoot,
     26    [objectNodeIdBar],
     27    50
     28  );
     29  ok(shortestPaths);
     30  ok(shortestPaths instanceof Map);
     31  Assert.equal(
     32    shortestPaths.size,
     33    1,
     34    "We get only one path between the root object and bar object"
     35  );
     36 
     37  const paths = shortestPaths.get(objectNodeIdBar);
     38  Assert.equal(paths.length, 1, "There is only one path between root and bar");
     39  Assert.equal(
     40    paths[0].length,
     41    2,
     42    "The shortest path is made of two edges: foo and bar"
     43  );
     44 
     45  const [path1, path2] = paths[0];
     46  Assert.equal(
     47    path1.predecessor,
     48    objectNodeIdRoot,
     49    "The first edge goes from the root object"
     50  );
     51  Assert.equal(path1.edge, "foo", "The first edge is the foo attribute");
     52 
     53  Assert.equal(
     54    path2.predecessor,
     55    objectNodeIdFoo,
     56    "The second edge goes from the foo object"
     57  );
     58  Assert.equal(path2.edge, "bar", "The first edge is the bar attribute");
     59 
     60  do_test_finished();
     61 }