tor-browser

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

test_dominator_trees_10.js (2605B)


      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 maintain focus of the selected dominator tree node across
      7 // changing breakdowns for labeling them.
      8 
      9 const {
     10  dominatorTreeState,
     11  labelDisplays,
     12  viewState,
     13 } = require("resource://devtools/client/memory/constants.js");
     14 const {
     15  takeSnapshotAndCensus,
     16  focusDominatorTreeNode,
     17 } = require("resource://devtools/client/memory/actions/snapshot.js");
     18 const {
     19  changeView,
     20 } = require("resource://devtools/client/memory/actions/view.js");
     21 const {
     22  setLabelDisplayAndRefresh,
     23 } = require("resource://devtools/client/memory/actions/label-display.js");
     24 
     25 add_task(async function () {
     26  const front = new StubbedMemoryFront();
     27  const heapWorker = new HeapAnalysesClient();
     28  await front.attach();
     29  const store = Store();
     30  const { getState, dispatch } = store;
     31 
     32  dispatch(changeView(viewState.DOMINATOR_TREE));
     33  dispatch(takeSnapshotAndCensus(front, heapWorker));
     34 
     35  // Wait for the dominator tree to finish being fetched.
     36  await waitUntilState(
     37    store,
     38    state =>
     39      state.snapshots[0] &&
     40      state.snapshots[0].dominatorTree &&
     41      state.snapshots[0].dominatorTree.state === dominatorTreeState.LOADED
     42  );
     43  ok(true, "The dominator tree was fetched");
     44 
     45  const root = getState().snapshots[0].dominatorTree.root;
     46  ok(root, "When the dominator tree is loaded, we should have its root");
     47 
     48  dispatch(focusDominatorTreeNode(getState().snapshots[0].id, root));
     49  equal(
     50    root,
     51    getState().snapshots[0].dominatorTree.focused,
     52    "The root should be focused."
     53  );
     54 
     55  equal(
     56    getState().labelDisplay,
     57    labelDisplays.coarseType,
     58    "Using labelDisplays.coarseType by default"
     59  );
     60  dispatch(
     61    setLabelDisplayAndRefresh(heapWorker, labelDisplays.allocationStack)
     62  );
     63  equal(
     64    getState().labelDisplay,
     65    labelDisplays.allocationStack,
     66    "Using labelDisplays.allocationStack now"
     67  );
     68 
     69  await waitUntilState(
     70    store,
     71    state =>
     72      state.snapshots[0].dominatorTree.state === dominatorTreeState.FETCHING
     73  );
     74  ok(true, "We started re-fetching the dominator tree");
     75 
     76  await waitUntilState(
     77    store,
     78    state =>
     79      state.snapshots[0].dominatorTree.state === dominatorTreeState.LOADED
     80  );
     81  ok(true, "The dominator tree was loaded again");
     82 
     83  ok(
     84    getState().snapshots[0].dominatorTree.focused,
     85    "Still have a focused node"
     86  );
     87  equal(
     88    getState().snapshots[0].dominatorTree.focused.nodeId,
     89    root.nodeId,
     90    "Focused node is the same as before"
     91  );
     92 
     93  heapWorker.destroy();
     94  await front.detach();
     95 });