tor-browser

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

test_dominator_trees_02.js (2456B)


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