tor-browser

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

test_action-clear-snapshots_06.js (2019B)


      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 clearSnapshots disables diffing when deleting snapshots
      7 
      8 const {
      9  takeSnapshotAndCensus,
     10  clearSnapshots,
     11 } = require("resource://devtools/client/memory/actions/snapshot.js");
     12 const {
     13  actions,
     14  treeMapState,
     15 } = require("resource://devtools/client/memory/constants.js");
     16 const {
     17  toggleDiffing,
     18  selectSnapshotForDiffingAndRefresh,
     19 } = require("resource://devtools/client/memory/actions/diffing.js");
     20 
     21 add_task(async function () {
     22  const front = new StubbedMemoryFront();
     23  const heapWorker = new HeapAnalysesClient();
     24  await front.attach();
     25  const store = Store();
     26  const { getState, dispatch } = store;
     27 
     28  ok(true, "create 2 snapshots with a saved census");
     29  dispatch(takeSnapshotAndCensus(front, heapWorker));
     30  dispatch(takeSnapshotAndCensus(front, heapWorker));
     31  await waitUntilCensusState(store, snapshot => snapshot.treeMap, [
     32    treeMapState.SAVED,
     33    treeMapState.SAVED,
     34  ]);
     35  ok(true, "snapshots created with a saved census");
     36 
     37  dispatch(toggleDiffing());
     38  dispatch(
     39    selectSnapshotForDiffingAndRefresh(heapWorker, getState().snapshots[0])
     40  );
     41  dispatch(
     42    selectSnapshotForDiffingAndRefresh(heapWorker, getState().snapshots[1])
     43  );
     44 
     45  ok(getState().diffing, "We should be in diffing view");
     46 
     47  await waitForDispatch(store, actions.TAKE_CENSUS_DIFF_END);
     48  ok(true, "Received TAKE_CENSUS_DIFF_END action");
     49 
     50  ok(true, "Dispatch clearSnapshots action");
     51  const deleteEvents = Promise.all([
     52    waitForDispatch(store, actions.DELETE_SNAPSHOTS_START),
     53    waitForDispatch(store, actions.DELETE_SNAPSHOTS_END),
     54  ]);
     55  dispatch(clearSnapshots(heapWorker));
     56  await deleteEvents;
     57  ok(true, "received delete snapshots events");
     58 
     59  Assert.strictEqual(
     60    getState().snapshots.length,
     61    0,
     62    "Snapshots array should be empty"
     63  );
     64  ok(!getState().diffing, "We should no longer be diffing");
     65 
     66  heapWorker.destroy();
     67  await front.detach();
     68 });