tor-browser

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

test_action-clear-snapshots_03.js (1686B)


      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 snapshots with state ERROR
      7 
      8 const {
      9  takeSnapshotAndCensus,
     10  clearSnapshots,
     11 } = require("resource://devtools/client/memory/actions/snapshot.js");
     12 const {
     13  snapshotState: states,
     14  treeMapState,
     15  actions,
     16 } = require("resource://devtools/client/memory/constants.js");
     17 
     18 add_task(async function () {
     19  const front = new StubbedMemoryFront();
     20  const heapWorker = new HeapAnalysesClient();
     21  await front.attach();
     22  const store = Store();
     23  const { getState, dispatch } = store;
     24 
     25  ok(true, "create a snapshot with a treeMap");
     26  dispatch(takeSnapshotAndCensus(front, heapWorker));
     27  await waitUntilSnapshotState(store, [states.SAVED]);
     28  ok(true, "snapshot created with a SAVED state");
     29  await waitUntilCensusState(store, snapshot => snapshot.treeMap, [
     30    treeMapState.SAVED,
     31  ]);
     32  ok(true, "treeMap created with a SAVED state");
     33 
     34  ok(true, "set snapshot state to error");
     35  const id = getState().snapshots[0].id;
     36  dispatch({ type: actions.SNAPSHOT_ERROR, id, error: new Error("_") });
     37  await waitUntilSnapshotState(store, [states.ERROR]);
     38  ok(true, "snapshot set to error state");
     39 
     40  ok(true, "dispatch clearSnapshots action");
     41  const deleteEvents = Promise.all([
     42    waitForDispatch(store, actions.DELETE_SNAPSHOTS_START),
     43    waitForDispatch(store, actions.DELETE_SNAPSHOTS_END),
     44  ]);
     45  dispatch(clearSnapshots(heapWorker));
     46  await deleteEvents;
     47  ok(true, "received delete snapshots events");
     48  equal(getState().snapshots.length, 0, "error snapshot deleted");
     49 
     50  heapWorker.destroy();
     51  await front.detach();
     52 });