test_dominator_trees_04.js (2694B)
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 selecting the dominator tree view while in the middle of taking a 7 // snapshot properly kicks off fetching and computing dominator trees. 8 9 const { 10 snapshotState: states, 11 dominatorTreeState, 12 viewState, 13 } = require("resource://devtools/client/memory/constants.js"); 14 const { 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 add_task(async function () { 22 const front = new StubbedMemoryFront(); 23 const heapWorker = new HeapAnalysesClient(); 24 await front.attach(); 25 26 for (const intermediateSnapshotState of [ 27 states.SAVING, 28 states.READING, 29 states.READ, 30 ]) { 31 dumpn( 32 "Testing switching to the DOMINATOR_TREE view in the middle of the " + 33 `${intermediateSnapshotState} snapshot state` 34 ); 35 36 const store = Store(); 37 const { getState, dispatch } = store; 38 39 dispatch(takeSnapshotAndCensus(front, heapWorker)); 40 await waitUntilSnapshotState(store, [intermediateSnapshotState]); 41 42 dispatch(changeView(viewState.DOMINATOR_TREE)); 43 equal( 44 getState().view.state, 45 viewState.DOMINATOR_TREE, 46 "We should now be in the DOMINATOR_TREE view" 47 ); 48 49 // Wait for the dominator tree to start being computed. 50 await waitUntilState( 51 store, 52 state => state.snapshots[0] && state.snapshots[0].dominatorTree 53 ); 54 equal( 55 getState().snapshots[0].dominatorTree.state, 56 dominatorTreeState.COMPUTING, 57 "The dominator tree started computing" 58 ); 59 ok( 60 !getState().snapshots[0].dominatorTree.root, 61 "When the dominator tree is computing, we should not have its root" 62 ); 63 64 // Wait for the dominator tree to finish computing and start being fetched. 65 await waitUntilState( 66 store, 67 state => 68 state.snapshots[0].dominatorTree.state === dominatorTreeState.FETCHING 69 ); 70 ok(true, "The dominator tree started fetching"); 71 ok( 72 !getState().snapshots[0].dominatorTree.root, 73 "When the dominator tree is fetching, we should not have its root" 74 ); 75 76 // Wait for the dominator tree to finish being fetched. 77 await waitUntilState( 78 store, 79 state => 80 state.snapshots[0].dominatorTree.state === dominatorTreeState.LOADED 81 ); 82 ok(true, "The dominator tree was fetched"); 83 ok( 84 getState().snapshots[0].dominatorTree.root, 85 "When the dominator tree is loaded, we should have its root" 86 ); 87 } 88 89 heapWorker.destroy(); 90 await front.detach(); 91 });