test_individuals_01.js (2210B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Basic test for switching to the individuals view. 7 8 const { 9 censusState, 10 viewState, 11 individualsState, 12 } = require("resource://devtools/client/memory/constants.js"); 13 const { 14 fetchIndividuals, 15 takeSnapshotAndCensus, 16 } = require("resource://devtools/client/memory/actions/snapshot.js"); 17 const { 18 changeView, 19 } = require("resource://devtools/client/memory/actions/view.js"); 20 21 const EXPECTED_INDIVIDUAL_STATES = [ 22 individualsState.COMPUTING_DOMINATOR_TREE, 23 individualsState.FETCHING, 24 individualsState.FETCHED, 25 ]; 26 27 add_task(async function () { 28 const front = new StubbedMemoryFront(); 29 const heapWorker = new HeapAnalysesClient(); 30 await front.attach(); 31 const store = Store(); 32 const { getState, dispatch } = store; 33 34 equal(getState().individuals, null, "no individuals state by default"); 35 36 dispatch(changeView(viewState.CENSUS)); 37 dispatch(takeSnapshotAndCensus(front, heapWorker)); 38 await waitUntilCensusState(store, s => s.census, [censusState.SAVED]); 39 40 const root = getState().snapshots[0].census.report; 41 ok(root, "Should have a census"); 42 43 const reportLeafIndex = findReportLeafIndex(root); 44 ok(reportLeafIndex, "Should get a reportLeafIndex"); 45 46 const snapshotId = getState().snapshots[0].id; 47 ok(snapshotId, "Should have a snapshot id"); 48 49 const breakdown = getState().snapshots[0].census.display.breakdown; 50 ok(breakdown, "Should have a breakdown"); 51 52 dispatch( 53 fetchIndividuals(heapWorker, snapshotId, breakdown, reportLeafIndex) 54 ); 55 56 // Wait for each expected state. 57 for (const state of EXPECTED_INDIVIDUAL_STATES) { 58 await waitUntilState(store, s => { 59 return ( 60 s.view.state === viewState.INDIVIDUALS && 61 s.individuals && 62 s.individuals.state === state 63 ); 64 }); 65 ok(true, `Reached state = ${state}`); 66 } 67 68 ok(getState().individuals, "Should have individuals state"); 69 ok(getState().individuals.nodes, "Should have individuals nodes"); 70 ok( 71 !!getState().individuals.nodes.length, 72 "Should have a positive number of nodes" 73 ); 74 75 heapWorker.destroy(); 76 await front.detach(); 77 });