tor-browser

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

test_pop_view_01.js (2320B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test popping views from each intermediate individuals model state.
      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  popViewAndRefresh,
     20 } = require("resource://devtools/client/memory/actions/view.js");
     21 
     22 const TEST_STATES = [
     23  individualsState.COMPUTING_DOMINATOR_TREE,
     24  individualsState.FETCHING,
     25  individualsState.FETCHED,
     26 ];
     27 
     28 add_task(async function () {
     29  const front = new StubbedMemoryFront();
     30  const heapWorker = new HeapAnalysesClient();
     31  await front.attach();
     32  const store = Store();
     33  const { getState, dispatch } = store;
     34 
     35  equal(getState().individuals, null, "no individuals state by default");
     36 
     37  dispatch(changeView(viewState.CENSUS));
     38  dispatch(takeSnapshotAndCensus(front, heapWorker));
     39  await waitUntilCensusState(store, s => s.census, [censusState.SAVED]);
     40 
     41  const root = getState().snapshots[0].census.report;
     42  ok(root, "Should have a census");
     43 
     44  const reportLeafIndex = findReportLeafIndex(root);
     45  ok(reportLeafIndex, "Should get a reportLeafIndex");
     46 
     47  const snapshotId = getState().snapshots[0].id;
     48  ok(snapshotId, "Should have a snapshot id");
     49 
     50  const breakdown = getState().snapshots[0].census.display.breakdown;
     51  ok(breakdown, "Should have a breakdown");
     52 
     53  for (const state of TEST_STATES) {
     54    dumpn(`Testing popping back to the old view from state = ${state}`);
     55 
     56    dispatch(
     57      fetchIndividuals(heapWorker, snapshotId, breakdown, reportLeafIndex)
     58    );
     59 
     60    // Wait for the expected test state.
     61    await waitUntilState(store, s => {
     62      return (
     63        s.view.state === viewState.INDIVIDUALS &&
     64        s.individuals &&
     65        s.individuals.state === state
     66      );
     67    });
     68    ok(true, `Reached state = ${state}`);
     69 
     70    // Pop back to the CENSUS state.
     71    dispatch(popViewAndRefresh(heapWorker));
     72    await waitUntilState(store, s => {
     73      return s.view.state === viewState.CENSUS;
     74    });
     75    ok(!getState().individuals, "Should no longer have individuals");
     76  }
     77 
     78  heapWorker.destroy();
     79  await front.detach();
     80 });