summaryrefslogtreecommitdiffstats
path: root/devtools/client/memory/test/unit/test_dominator_trees_10.js
blob: f7cf86a108031f0e54f00a8e04c337f64df4791a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

// Test that we maintain focus of the selected dominator tree node across
// changing breakdowns for labeling them.

let {
  snapshotState: states,
  dominatorTreeState,
  labelDisplays,
  viewState,
} = require("devtools/client/memory/constants");
let {
  takeSnapshotAndCensus,
  focusDominatorTreeNode,
} = require("devtools/client/memory/actions/snapshot");
const {
  changeView,
} = require("devtools/client/memory/actions/view");
const {
  setLabelDisplayAndRefresh,
} = require("devtools/client/memory/actions/label-display");

function run_test() {
  run_next_test();
}

add_task(function* () {
  let front = new StubbedMemoryFront();
  let heapWorker = new HeapAnalysesClient();
  yield front.attach();
  let store = Store();
  let { getState, dispatch } = store;

  dispatch(changeView(viewState.DOMINATOR_TREE));
  dispatch(takeSnapshotAndCensus(front, heapWorker));

  // Wait for the dominator tree to finish being fetched.
  yield waitUntilState(store, state =>
    state.snapshots[0] &&
    state.snapshots[0].dominatorTree &&
    state.snapshots[0].dominatorTree.state === dominatorTreeState.LOADED);
  ok(true, "The dominator tree was fetched");

  const root = getState().snapshots[0].dominatorTree.root;
  ok(root, "When the dominator tree is loaded, we should have its root");

  dispatch(focusDominatorTreeNode(getState().snapshots[0].id, root));
  equal(root, getState().snapshots[0].dominatorTree.focused,
        "The root should be focused.");

  equal(getState().labelDisplay, labelDisplays.coarseType,
        "Using labelDisplays.coarseType by default");
  dispatch(setLabelDisplayAndRefresh(heapWorker,
                                             labelDisplays.allocationStack));
  equal(getState().labelDisplay, labelDisplays.allocationStack,
        "Using labelDisplays.allocationStack now");

  yield waitUntilState(store, state =>
    state.snapshots[0].dominatorTree.state === dominatorTreeState.FETCHING);
  ok(true, "We started re-fetching the dominator tree");

  yield waitUntilState(store, state =>
    state.snapshots[0].dominatorTree.state === dominatorTreeState.LOADED);
  ok(true, "The dominator tree was loaded again");

  ok(getState().snapshots[0].dominatorTree.focused,
     "Still have a focused node");
  equal(getState().snapshots[0].dominatorTree.focused.nodeId, root.nodeId,
        "Focused node is the same as before");

  heapWorker.destroy();
  yield front.detach();
});