test_action-clear-snapshots_02.js (1817B)
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 preserves snapshots with state != READ or ERROR 7 8 const { 9 takeSnapshotAndCensus, 10 clearSnapshots, 11 takeSnapshot, 12 } = require("resource://devtools/client/memory/actions/snapshot.js"); 13 const { 14 snapshotState: states, 15 treeMapState, 16 actions, 17 } = require("resource://devtools/client/memory/constants.js"); 18 19 add_task(async function () { 20 const front = new StubbedMemoryFront(); 21 const heapWorker = new HeapAnalysesClient(); 22 await front.attach(); 23 const store = Store(); 24 const { getState, dispatch } = store; 25 26 ok(true, "create a snapshot with a census in SAVED state"); 27 dispatch(takeSnapshotAndCensus(front, heapWorker)); 28 ok(true, "create a snapshot in SAVED state"); 29 dispatch(takeSnapshot(front)); 30 await waitUntilSnapshotState(store, [states.SAVED, states.SAVED]); 31 await waitUntilCensusState(store, snapshot => snapshot.treeMap, [ 32 treeMapState.SAVED, 33 null, 34 ]); 35 ok(true, "snapshots created with expected states"); 36 37 ok(true, "dispatch clearSnapshots action"); 38 const deleteEvents = Promise.all([ 39 waitForDispatch(store, actions.DELETE_SNAPSHOTS_START), 40 waitForDispatch(store, actions.DELETE_SNAPSHOTS_END), 41 ]); 42 dispatch(clearSnapshots(heapWorker)); 43 await deleteEvents; 44 ok(true, "received delete snapshots events"); 45 46 equal(getState().snapshots.length, 1, "one snapshot remaining"); 47 const remainingSnapshot = getState().snapshots[0]; 48 equal( 49 remainingSnapshot.treeMap, 50 undefined, 51 "remaining snapshot doesn't have a treeMap property" 52 ); 53 equal( 54 remainingSnapshot.census, 55 undefined, 56 "remaining snapshot doesn't have a census property" 57 ); 58 59 heapWorker.destroy(); 60 await front.detach(); 61 });