tor-browser

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

test_action_diffing_05.js (3780B)


      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 we recompute census diffs at the appropriate times.
      7 
      8 const {
      9  diffingState,
     10  snapshotState,
     11  censusDisplays,
     12  viewState,
     13 } = require("resource://devtools/client/memory/constants.js");
     14 const {
     15  setCensusDisplayAndRefresh,
     16 } = require("resource://devtools/client/memory/actions/census-display.js");
     17 const {
     18  toggleDiffing,
     19  selectSnapshotForDiffingAndRefresh,
     20 } = require("resource://devtools/client/memory/actions/diffing.js");
     21 const {
     22  setFilterStringAndRefresh,
     23 } = require("resource://devtools/client/memory/actions/filter.js");
     24 const {
     25  takeSnapshot,
     26  readSnapshot,
     27 } = require("resource://devtools/client/memory/actions/snapshot.js");
     28 const {
     29  changeView,
     30 } = require("resource://devtools/client/memory/actions/view.js");
     31 
     32 add_task(async function () {
     33  const front = new StubbedMemoryFront();
     34  const heapWorker = new HeapAnalysesClient();
     35  await front.attach();
     36  const store = Store();
     37  const { getState, dispatch } = store;
     38  dispatch(changeView(viewState.CENSUS));
     39 
     40  await dispatch(
     41    setCensusDisplayAndRefresh(heapWorker, censusDisplays.allocationStack)
     42  );
     43  equal(getState().censusDisplay.inverted, false, "not inverted at start");
     44 
     45  equal(getState().diffing, null, "not diffing by default");
     46 
     47  const s1 = await dispatch(takeSnapshot(front, heapWorker));
     48  const s2 = await dispatch(takeSnapshot(front, heapWorker));
     49  const s3 = await dispatch(takeSnapshot(front, heapWorker));
     50  dispatch(readSnapshot(heapWorker, s1));
     51  dispatch(readSnapshot(heapWorker, s2));
     52  dispatch(readSnapshot(heapWorker, s3));
     53  await waitUntilSnapshotState(store, [
     54    snapshotState.READ,
     55    snapshotState.READ,
     56    snapshotState.READ,
     57  ]);
     58 
     59  await dispatch(toggleDiffing());
     60  dispatch(
     61    selectSnapshotForDiffingAndRefresh(heapWorker, getState().snapshots[0])
     62  );
     63  dispatch(
     64    selectSnapshotForDiffingAndRefresh(heapWorker, getState().snapshots[1])
     65  );
     66  await waitUntilState(
     67    store,
     68    state => state.diffing.state === diffingState.TOOK_DIFF
     69  );
     70 
     71  const shouldTriggerRecompute = [
     72    {
     73      name: "toggling inversion",
     74      func: () =>
     75        dispatch(
     76          setCensusDisplayAndRefresh(
     77            heapWorker,
     78            censusDisplays.invertedAllocationStack
     79          )
     80        ),
     81    },
     82    {
     83      name: "filtering",
     84      func: () => dispatch(setFilterStringAndRefresh("scr", heapWorker)),
     85    },
     86    {
     87      name: "changing displays",
     88      func: () =>
     89        dispatch(
     90          setCensusDisplayAndRefresh(heapWorker, censusDisplays.coarseType)
     91        ),
     92    },
     93  ];
     94 
     95  for (const { name, func } of shouldTriggerRecompute) {
     96    dumpn(`Testing that "${name}" triggers a diff recompute`);
     97    func();
     98 
     99    await waitUntilState(
    100      store,
    101      state => state.diffing.state === diffingState.TAKING_DIFF
    102    );
    103    ok(true, "triggered diff recompute.");
    104 
    105    await waitUntilState(
    106      store,
    107      state => state.diffing.state === diffingState.TOOK_DIFF
    108    );
    109    ok(true, "And then the diff should complete.");
    110    ok(getState().diffing.census, "And we should have a census.");
    111    ok(
    112      getState().diffing.census.report,
    113      "And that census should have a report."
    114    );
    115    equal(
    116      getState().diffing.census.display,
    117      getState().censusDisplay,
    118      "And that census should have the correct display"
    119    );
    120    equal(
    121      getState().diffing.census.filter,
    122      getState().filter,
    123      "And that census should have the correct filter"
    124    );
    125    equal(
    126      getState().diffing.census.display.inverted,
    127      getState().censusDisplay.inverted,
    128      "And that census should have the correct inversion"
    129    );
    130  }
    131 
    132  heapWorker.destroy();
    133  await front.detach();
    134 });