tor-browser

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

test_dominator_trees_01.js (2394B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test that we can compute and fetch the dominator tree for a snapshot.
      7 
      8 const {
      9  dominatorTreeState,
     10  treeMapState,
     11 } = require("resource://devtools/client/memory/constants.js");
     12 const {
     13  takeSnapshotAndCensus,
     14  computeAndFetchDominatorTree,
     15 } = require("resource://devtools/client/memory/actions/snapshot.js");
     16 
     17 add_task(async function () {
     18  const front = new StubbedMemoryFront();
     19  const heapWorker = new HeapAnalysesClient();
     20  await front.attach();
     21  const store = Store();
     22  const { getState, dispatch } = store;
     23 
     24  dispatch(takeSnapshotAndCensus(front, heapWorker));
     25  await waitUntilCensusState(store, s => s.treeMap, [treeMapState.SAVED]);
     26  ok(
     27    !getState().snapshots[0].dominatorTree,
     28    "There shouldn't be a dominator tree model yet since it is not computed " +
     29      "until we switch to the dominators view."
     30  );
     31 
     32  // Change to the dominator tree view.
     33  dispatch(
     34    computeAndFetchDominatorTree(heapWorker, getState().snapshots[0].id)
     35  );
     36  ok(
     37    getState().snapshots[0].dominatorTree,
     38    "Should now have a dominator tree model for the selected snapshot"
     39  );
     40 
     41  // Wait for the dominator tree to start being computed.
     42  await waitUntilState(
     43    store,
     44    state =>
     45      state.snapshots[0].dominatorTree.state === dominatorTreeState.COMPUTING
     46  );
     47  ok(true, "The dominator tree started computing");
     48  ok(
     49    !getState().snapshots[0].dominatorTree.root,
     50    "When the dominator tree is computing, we should not have its root"
     51  );
     52 
     53  // Wait for the dominator tree to finish computing and start being fetched.
     54  await waitUntilState(
     55    store,
     56    state =>
     57      state.snapshots[0].dominatorTree.state === dominatorTreeState.FETCHING
     58  );
     59  ok(true, "The dominator tree started fetching");
     60  ok(
     61    !getState().snapshots[0].dominatorTree.root,
     62    "When the dominator tree is fetching, we should not have its root"
     63  );
     64 
     65  // Wait for the dominator tree to finish being fetched.
     66  await waitUntilState(
     67    store,
     68    state =>
     69      state.snapshots[0].dominatorTree.state === dominatorTreeState.LOADED
     70  );
     71  ok(true, "The dominator tree was fetched");
     72  ok(
     73    getState().snapshots[0].dominatorTree.root,
     74    "When the dominator tree is loaded, we should have its root"
     75  );
     76 
     77  heapWorker.destroy();
     78  await front.detach();
     79 });