tor-browser

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

test_action-clear-snapshots_05.js (1606B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test clearSnapshots deletes several 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 
     17 add_task(async function () {
     18  const front = new StubbedMemoryFront();
     19  const heapWorker = new HeapAnalysesClient();
     20  await front.attach();
     21  const store = Store();
     22  const { getState, dispatch } = store;
     23 
     24  ok(true, "create 2 snapshots with a saved census");
     25  dispatch(takeSnapshotAndCensus(front, heapWorker));
     26  dispatch(takeSnapshotAndCensus(front, heapWorker));
     27  ok(true, "snapshots created with a saved census");
     28  await waitUntilCensusState(store, snapshot => snapshot.treeMap, [
     29    treeMapState.SAVED,
     30    treeMapState.SAVED,
     31  ]);
     32 
     33  const errorHeapWorker = {
     34    deleteHeapSnapshot() {
     35      return Promise.reject("_");
     36    },
     37  };
     38 
     39  ok(true, "dispatch clearSnapshots action");
     40  const deleteEvents = Promise.all([
     41    waitForDispatch(store, actions.DELETE_SNAPSHOTS_START),
     42    waitForDispatch(store, actions.DELETE_SNAPSHOTS_END),
     43    waitForDispatch(store, actions.SNAPSHOT_ERROR),
     44    waitForDispatch(store, actions.SNAPSHOT_ERROR),
     45  ]);
     46  dispatch(clearSnapshots(errorHeapWorker));
     47  await deleteEvents;
     48  ok(true, "received delete snapshots and snapshot error events");
     49  equal(getState().snapshots.length, 0, "no snapshot remaining");
     50 
     51  heapWorker.destroy();
     52  await front.detach();
     53 });