tor-browser

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

test_dominator_trees_03.js (2233B)


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