test_action-toggle-inverted-and-refresh-02.js (2365B)
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 changing inverted state in the middle of taking a snapshot results 7 // in an inverted census. 8 9 const { 10 censusDisplays, 11 snapshotState: states, 12 censusState, 13 viewState, 14 } = require("resource://devtools/client/memory/constants.js"); 15 const { 16 takeSnapshotAndCensus, 17 } = require("resource://devtools/client/memory/actions/snapshot.js"); 18 const { 19 setCensusDisplay, 20 setCensusDisplayAndRefresh, 21 } = require("resource://devtools/client/memory/actions/census-display.js"); 22 const { 23 changeView, 24 } = require("resource://devtools/client/memory/actions/view.js"); 25 26 add_task(async function () { 27 const front = new StubbedMemoryFront(); 28 const heapWorker = new HeapAnalysesClient(); 29 await front.attach(); 30 const store = Store(); 31 const { getState, dispatch } = store; 32 33 dispatch(changeView(viewState.CENSUS)); 34 35 dispatch(setCensusDisplay(censusDisplays.allocationStack)); 36 equal( 37 getState().censusDisplay.inverted, 38 false, 39 "Should not have an inverted census display" 40 ); 41 42 dispatch(takeSnapshotAndCensus(front, heapWorker)); 43 await waitUntilSnapshotState(store, [states.SAVING]); 44 45 dispatch( 46 setCensusDisplayAndRefresh( 47 heapWorker, 48 censusDisplays.invertedAllocationStack 49 ) 50 ); 51 52 await waitUntilCensusState(store, s => s.census, [censusState.SAVED]); 53 54 ok(getState().censusDisplay.inverted, "should want inverted trees"); 55 ok( 56 getState().snapshots[0].census.display.inverted, 57 "snapshot-we-were-in-the-middle-of-saving's census should be inverted" 58 ); 59 60 dispatch( 61 setCensusDisplayAndRefresh(heapWorker, censusDisplays.allocationStack) 62 ); 63 await waitUntilCensusState(store, s => s.census, [censusState.SAVING]); 64 ok(true, "toggling inverted retriggers census"); 65 ok(!getState().censusDisplay.inverted, "no longer inverted"); 66 67 dispatch( 68 setCensusDisplayAndRefresh( 69 heapWorker, 70 censusDisplays.invertedAllocationStack 71 ) 72 ); 73 await waitUntilCensusState(store, s => s.census, [censusState.SAVED]); 74 ok(getState().censusDisplay.inverted, "inverted again"); 75 ok( 76 getState().snapshots[0].census.display.inverted, 77 "census-we-were-in-the-middle-of-recomputing should be inverted again" 78 ); 79 80 heapWorker.destroy(); 81 await front.detach(); 82 });