tor-browser

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

test_individuals_05.js (2402B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test showing individual objects that do not have allocation stacks.
      7 
      8 const {
      9  censusState,
     10  viewState,
     11  individualsState,
     12  censusDisplays,
     13 } = require("resource://devtools/client/memory/constants.js");
     14 const {
     15  fetchIndividuals,
     16  takeSnapshotAndCensus,
     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  setCensusDisplay,
     23 } = require("resource://devtools/client/memory/actions/census-display.js");
     24 
     25 const EXPECTED_INDIVIDUAL_STATES = [
     26  individualsState.COMPUTING_DOMINATOR_TREE,
     27  individualsState.FETCHING,
     28  individualsState.FETCHED,
     29 ];
     30 
     31 add_task(async function () {
     32  const front = new StubbedMemoryFront();
     33  const heapWorker = new HeapAnalysesClient();
     34  await front.attach();
     35  const store = Store();
     36  const { getState, dispatch } = store;
     37 
     38  dispatch(changeView(viewState.CENSUS));
     39  dispatch(setCensusDisplay(censusDisplays.invertedAllocationStack));
     40 
     41  // Take a snapshot and wait for the census to finish.
     42 
     43  dispatch(takeSnapshotAndCensus(front, heapWorker));
     44  await waitUntilCensusState(store, s => s.census, [censusState.SAVED]);
     45 
     46  // Fetch individuals.
     47 
     48  const root = getState().snapshots[0].census.report;
     49  ok(root, "Should have a census");
     50 
     51  const reportLeafIndex = findReportLeafIndex(root, "noStack");
     52  ok(reportLeafIndex, "Should get a reportLeafIndex for noStack");
     53 
     54  const snapshotId = getState().snapshots[0].id;
     55  ok(snapshotId, "Should have a snapshot id");
     56 
     57  const breakdown = getState().censusDisplay.breakdown;
     58  ok(breakdown, "Should have a breakdown");
     59 
     60  dispatch(
     61    fetchIndividuals(heapWorker, snapshotId, breakdown, reportLeafIndex)
     62  );
     63 
     64  for (const state of EXPECTED_INDIVIDUAL_STATES) {
     65    await waitUntilState(store, s => {
     66      return (
     67        s.view.state === viewState.INDIVIDUALS &&
     68        s.individuals &&
     69        s.individuals.state === state
     70      );
     71    });
     72    ok(true, `Reached state = ${state}`);
     73  }
     74 
     75  ok(getState().individuals, "Should have individuals state");
     76  ok(getState().individuals.nodes, "Should have individuals nodes");
     77  ok(
     78    !!getState().individuals.nodes.length,
     79    "Should have a positive number of nodes"
     80  );
     81 
     82  heapWorker.destroy();
     83  await front.detach();
     84 });