tor-browser

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

test_dominator_trees_05.js (2025B)


      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 changing the currently selected snapshot to a snapshot that does
      7 // not have a dominator tree will automatically compute and fetch one for it.
      8 
      9 const {
     10  dominatorTreeState,
     11  viewState,
     12  treeMapState,
     13 } = require("resource://devtools/client/memory/constants.js");
     14 const {
     15  takeSnapshotAndCensus,
     16  selectSnapshotAndRefresh,
     17 } = require("resource://devtools/client/memory/actions/snapshot.js");
     18 
     19 const {
     20  changeView,
     21 } = require("resource://devtools/client/memory/actions/view.js");
     22 
     23 add_task(async function () {
     24  const front = new StubbedMemoryFront();
     25  const heapWorker = new HeapAnalysesClient();
     26  await front.attach();
     27  const store = Store();
     28  const { getState, dispatch } = store;
     29 
     30  dispatch(takeSnapshotAndCensus(front, heapWorker));
     31  dispatch(takeSnapshotAndCensus(front, heapWorker));
     32  await waitUntilCensusState(store, s => s.treeMap, [
     33    treeMapState.SAVED,
     34    treeMapState.SAVED,
     35  ]);
     36 
     37  ok(getState().snapshots[1].selected, "The second snapshot is selected");
     38 
     39  // Change to the dominator tree view.
     40  dispatch(changeView(viewState.DOMINATOR_TREE));
     41 
     42  // Wait for the dominator tree to finish being fetched.
     43  await waitUntilState(
     44    store,
     45    state =>
     46      state.snapshots[1].dominatorTree &&
     47      state.snapshots[1].dominatorTree.state === dominatorTreeState.LOADED
     48  );
     49  ok(true, "The second snapshot's dominator tree was fetched");
     50 
     51  // Select the first snapshot.
     52  dispatch(selectSnapshotAndRefresh(heapWorker, getState().snapshots[0].id));
     53 
     54  // And now the first snapshot should have its dominator tree fetched and
     55  // computed because of the new selection.
     56  await waitUntilState(
     57    store,
     58    state =>
     59      state.snapshots[0].dominatorTree &&
     60      state.snapshots[0].dominatorTree.state === dominatorTreeState.LOADED
     61  );
     62  ok(true, "The first snapshot's dominator tree was fetched");
     63 
     64  heapWorker.destroy();
     65  await front.detach();
     66 });