tor-browser

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

test_action-take-snapshot-and-census.js (1965B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Tests the task creator `takeSnapshotAndCensus()` for the whole flow of
      8 * taking a snapshot, and its sub-actions.
      9 */
     10 
     11 const {
     12  snapshotState: states,
     13  treeMapState,
     14 } = require("resource://devtools/client/memory/constants.js");
     15 const actions = require("resource://devtools/client/memory/actions/snapshot.js");
     16 
     17 add_task(async function () {
     18  const front = new StubbedMemoryFront();
     19  const heapWorker = new HeapAnalysesClient();
     20  await front.attach();
     21  const store = Store();
     22 
     23  let snapshotI = 0;
     24  let censusI = 0;
     25  const snapshotStates = ["SAVING", "SAVED", "READING", "READ"];
     26  const censusStates = ["SAVING", "SAVED"];
     27  const expectStates = () => {
     28    const snapshot = store.getState().snapshots[0];
     29    if (!snapshot) {
     30      return;
     31    }
     32    if (snapshotI < snapshotStates.length) {
     33      const isCorrectState =
     34        snapshot.state === states[snapshotStates[snapshotI]];
     35      if (isCorrectState) {
     36        ok(true, `Found expected snapshot state ${snapshotStates[snapshotI]}`);
     37        snapshotI++;
     38      }
     39    }
     40    if (snapshot.treeMap && censusI < censusStates.length) {
     41      if (snapshot.treeMap.state === treeMapState[censusStates[censusI]]) {
     42        ok(true, `Found expected census state ${censusStates[censusI]}`);
     43        censusI++;
     44      }
     45    }
     46  };
     47 
     48  const unsubscribe = store.subscribe(expectStates);
     49  store.dispatch(actions.takeSnapshotAndCensus(front, heapWorker));
     50 
     51  await waitUntilState(store, () => {
     52    return (
     53      snapshotI === snapshotStates.length && censusI === censusStates.length
     54    );
     55  });
     56  unsubscribe();
     57 
     58  ok(
     59    true,
     60    "takeSnapshotAndCensus() produces the correct sequence of states in a snapshot"
     61  );
     62  const snapshot = store.getState().snapshots[0];
     63  ok(snapshot.treeMap, "snapshot has tree map census data");
     64  ok(snapshot.selected, "snapshot is selected");
     65 });