tor-browser

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

test_individuals_06.js (2342B)


      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 clearing the current individuals' snapshot leaves the individuals
      7 // view.
      8 
      9 const {
     10  censusState,
     11  viewState,
     12  individualsState,
     13 } = require("resource://devtools/client/memory/constants.js");
     14 const {
     15  fetchIndividuals,
     16  takeSnapshotAndCensus,
     17  clearSnapshots,
     18 } = require("resource://devtools/client/memory/actions/snapshot.js");
     19 const {
     20  changeView,
     21 } = require("resource://devtools/client/memory/actions/view.js");
     22 
     23 const EXPECTED_INDIVIDUAL_STATES = [
     24  individualsState.COMPUTING_DOMINATOR_TREE,
     25  individualsState.FETCHING,
     26  individualsState.FETCHED,
     27 ];
     28 
     29 add_task(async function () {
     30  const front = new StubbedMemoryFront();
     31  const heapWorker = new HeapAnalysesClient();
     32  await front.attach();
     33  const store = Store();
     34  const { getState, dispatch } = store;
     35 
     36  dispatch(changeView(viewState.CENSUS));
     37 
     38  // Take a snapshot and wait for the census to finish.
     39 
     40  dispatch(takeSnapshotAndCensus(front, heapWorker));
     41  await waitUntilCensusState(store, s => s.census, [censusState.SAVED]);
     42 
     43  // Fetch individuals.
     44 
     45  const root = getState().snapshots[0].census.report;
     46  ok(root, "Should have a census");
     47 
     48  const reportLeafIndex = findReportLeafIndex(root);
     49  ok(reportLeafIndex, "Should get a reportLeafIndex");
     50 
     51  const snapshotId = getState().snapshots[0].id;
     52  ok(snapshotId, "Should have a snapshot id");
     53 
     54  const breakdown = getState().censusDisplay.breakdown;
     55  ok(breakdown, "Should have a breakdown");
     56 
     57  dispatch(
     58    fetchIndividuals(heapWorker, snapshotId, breakdown, reportLeafIndex)
     59  );
     60 
     61  for (const state of EXPECTED_INDIVIDUAL_STATES) {
     62    await waitUntilState(store, s => {
     63      return (
     64        s.view.state === viewState.INDIVIDUALS &&
     65        s.individuals &&
     66        s.individuals.state === state
     67      );
     68    });
     69    ok(true, `Reached state = ${state}`);
     70  }
     71 
     72  ok(getState().individuals, "Should have individuals state");
     73  ok(getState().individuals.nodes, "Should have individuals nodes");
     74  ok(
     75    !!getState().individuals.nodes.length,
     76    "Should have a positive number of nodes"
     77  );
     78 
     79  dispatch(clearSnapshots(heapWorker));
     80 
     81  equal(getState().view.state, viewState.CENSUS, "Went back to census view");
     82 
     83  heapWorker.destroy();
     84  await front.detach();
     85 });