diff options
Diffstat (limited to '')
-rw-r--r-- | devtools/client/memory/test/xpcshell/test_action-clear-snapshots_04.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/devtools/client/memory/test/xpcshell/test_action-clear-snapshots_04.js b/devtools/client/memory/test/xpcshell/test_action-clear-snapshots_04.js new file mode 100644 index 0000000000..723029c90b --- /dev/null +++ b/devtools/client/memory/test/xpcshell/test_action-clear-snapshots_04.js @@ -0,0 +1,55 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Test clearSnapshots deletes several snapshots + +const { + takeSnapshotAndCensus, + clearSnapshots, +} = require("resource://devtools/client/memory/actions/snapshot.js"); +const { + snapshotState: states, + actions, + treeMapState, +} = require("resource://devtools/client/memory/constants.js"); + +add_task(async function () { + const front = new StubbedMemoryFront(); + const heapWorker = new HeapAnalysesClient(); + await front.attach(); + const store = Store(); + const { getState, dispatch } = store; + + ok(true, "create 3 snapshots with a saved census"); + dispatch(takeSnapshotAndCensus(front, heapWorker)); + dispatch(takeSnapshotAndCensus(front, heapWorker)); + dispatch(takeSnapshotAndCensus(front, heapWorker)); + await waitUntilCensusState(store, snapshot => snapshot.treeMap, [ + treeMapState.SAVED, + treeMapState.SAVED, + treeMapState.SAVED, + ]); + ok(true, "snapshots created with a saved census"); + + ok(true, "set first snapshot state to error"); + const id = getState().snapshots[0].id; + dispatch({ type: actions.SNAPSHOT_ERROR, id, error: new Error("_") }); + await waitUntilSnapshotState(store, [states.ERROR, states.READ, states.READ]); + ok(true, "first snapshot set to error state"); + + ok(true, "dispatch clearSnapshots action"); + const deleteEvents = Promise.all([ + waitForDispatch(store, actions.DELETE_SNAPSHOTS_START), + waitForDispatch(store, actions.DELETE_SNAPSHOTS_END), + ]); + dispatch(clearSnapshots(heapWorker)); + await deleteEvents; + ok(true, "received delete snapshots events"); + + equal(getState().snapshots.length, 0, "no snapshot remaining"); + + heapWorker.destroy(); + await front.detach(); +}); |