tor-browser

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

test_individuals_04.js (2580B)


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