tor-browser

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

test_DominatorTreeNode_getNodeByIdAlongPath_01.js (1345B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 // Test that we can find the node with the given id along the specified path.
      6 
      7 const node3000 = makeTestDominatorTreeNode({ nodeId: 3000 });
      8 
      9 const node2000 = makeTestDominatorTreeNode({ nodeId: 2000 }, [
     10  makeTestDominatorTreeNode({}),
     11  node3000,
     12  makeTestDominatorTreeNode({}),
     13 ]);
     14 
     15 const node1000 = makeTestDominatorTreeNode({ nodeId: 1000 }, [
     16  makeTestDominatorTreeNode({}),
     17  node2000,
     18  makeTestDominatorTreeNode({}),
     19 ]);
     20 
     21 const tree = node1000;
     22 
     23 const path = [1000, 2000, 3000];
     24 
     25 const tests = [
     26  { id: 1000, expected: node1000 },
     27  { id: 2000, expected: node2000 },
     28  { id: 3000, expected: node3000 },
     29 ];
     30 
     31 function run_test() {
     32  for (const { id, expected } of tests) {
     33    const actual = DominatorTreeNode.getNodeByIdAlongPath(id, tree, path);
     34    equal(actual, expected, `We should have got the node with id = ${id}`);
     35  }
     36 
     37  equal(
     38    null,
     39    DominatorTreeNode.getNodeByIdAlongPath(999999999999, tree, path),
     40    "null is returned for nodes that are not even in the tree"
     41  );
     42 
     43  const lastNodeId = tree.children[tree.children.length - 1].nodeId;
     44  equal(
     45    null,
     46    DominatorTreeNode.getNodeByIdAlongPath(lastNodeId, tree, path),
     47    "null is returned for nodes that are not along the path"
     48  );
     49 }