test_individuals_03.js (3149B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test switching to the individuals view when we are in the diffing view. 7 8 const { 9 censusState, 10 diffingState, 11 viewState, 12 individualsState, 13 } = require("resource://devtools/client/memory/constants.js"); 14 const { 15 fetchIndividuals, 16 takeSnapshotAndCensus, 17 } = require("resource://devtools/client/memory/actions/snapshot.js"); 18 const { 19 changeView, 20 popViewAndRefresh, 21 } = require("resource://devtools/client/memory/actions/view.js"); 22 const { 23 selectSnapshotForDiffingAndRefresh, 24 } = require("resource://devtools/client/memory/actions/diffing.js"); 25 26 const EXPECTED_INDIVIDUAL_STATES = [ 27 individualsState.COMPUTING_DOMINATOR_TREE, 28 individualsState.FETCHING, 29 individualsState.FETCHED, 30 ]; 31 32 add_task(async function () { 33 const front = new StubbedMemoryFront(); 34 const heapWorker = new HeapAnalysesClient(); 35 await front.attach(); 36 const store = Store(); 37 const { getState, dispatch } = store; 38 39 dispatch(changeView(viewState.CENSUS)); 40 41 // Take two snapshots and diff them from each other. 42 43 dispatch(takeSnapshotAndCensus(front, heapWorker)); 44 dispatch(takeSnapshotAndCensus(front, heapWorker)); 45 await waitUntilCensusState(store, s => s.census, [ 46 censusState.SAVED, 47 censusState.SAVED, 48 ]); 49 50 dispatch(changeView(viewState.DIFFING)); 51 dispatch( 52 selectSnapshotForDiffingAndRefresh(heapWorker, getState().snapshots[0]) 53 ); 54 dispatch( 55 selectSnapshotForDiffingAndRefresh(heapWorker, getState().snapshots[1]) 56 ); 57 58 await waitUntilState(store, state => { 59 return state.diffing && state.diffing.state === diffingState.TOOK_DIFF; 60 }); 61 ok(getState().diffing.census); 62 63 // Fetch individuals. 64 65 const root = getState().diffing.census.report; 66 ok(root, "Should have a census"); 67 68 const reportLeafIndex = findReportLeafIndex(root); 69 ok(reportLeafIndex, "Should get a reportLeafIndex"); 70 71 const snapshotId = getState().diffing.secondSnapshotId; 72 ok(snapshotId, "Should have a snapshot id"); 73 74 const breakdown = getState().censusDisplay.breakdown; 75 ok(breakdown, "Should have a breakdown"); 76 77 dispatch( 78 fetchIndividuals(heapWorker, snapshotId, breakdown, reportLeafIndex) 79 ); 80 81 for (const state of EXPECTED_INDIVIDUAL_STATES) { 82 await waitUntilState(store, s => { 83 return ( 84 s.view.state === viewState.INDIVIDUALS && 85 s.individuals && 86 s.individuals.state === state 87 ); 88 }); 89 ok(true, `Reached state = ${state}`); 90 } 91 92 ok(getState().individuals, "Should have individuals state"); 93 ok(getState().individuals.nodes, "Should have individuals nodes"); 94 ok( 95 !!getState().individuals.nodes.length, 96 "Should have a positive number of nodes" 97 ); 98 99 // Pop the view back to the diffing. 100 101 dispatch(popViewAndRefresh(heapWorker)); 102 103 await waitUntilState(store, state => { 104 return state.diffing && state.diffing.state === diffingState.TOOK_DIFF; 105 }); 106 107 ok( 108 getState().diffing.census.report, 109 "We have our census diff again after popping back to the last view" 110 ); 111 112 heapWorker.destroy(); 113 await front.detach(); 114 });