summaryrefslogtreecommitdiffstats
path: root/devtools/client/memory/test/xpcshell/test_dominator_trees_04.js
blob: d9814590a9d4f2f506324e10cfa4da7efb5e2526 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test that selecting the dominator tree view while in the middle of taking a
// snapshot properly kicks off fetching and computing dominator trees.

const {
  snapshotState: states,
  dominatorTreeState,
  viewState,
} = require("resource://devtools/client/memory/constants.js");
const {
  takeSnapshotAndCensus,
} = require("resource://devtools/client/memory/actions/snapshot.js");
const {
  changeView,
} = require("resource://devtools/client/memory/actions/view.js");

add_task(async function () {
  const front = new StubbedMemoryFront();
  const heapWorker = new HeapAnalysesClient();
  await front.attach();

  for (const intermediateSnapshotState of [
    states.SAVING,
    states.READING,
    states.READ,
  ]) {
    dumpn(
      "Testing switching to the DOMINATOR_TREE view in the middle of the " +
        `${intermediateSnapshotState} snapshot state`
    );

    const store = Store();
    const { getState, dispatch } = store;

    dispatch(takeSnapshotAndCensus(front, heapWorker));
    await waitUntilSnapshotState(store, [intermediateSnapshotState]);

    dispatch(changeView(viewState.DOMINATOR_TREE));
    equal(
      getState().view.state,
      viewState.DOMINATOR_TREE,
      "We should now be in the DOMINATOR_TREE view"
    );

    // Wait for the dominator tree to start being computed.
    await waitUntilState(
      store,
      state => state.snapshots[0] && state.snapshots[0].dominatorTree
    );
    equal(
      getState().snapshots[0].dominatorTree.state,
      dominatorTreeState.COMPUTING,
      "The dominator tree started computing"
    );
    ok(
      !getState().snapshots[0].dominatorTree.root,
      "When the dominator tree is computing, we should not have its root"
    );

    // Wait for the dominator tree to finish computing and start being fetched.
    await waitUntilState(
      store,
      state =>
        state.snapshots[0].dominatorTree.state === dominatorTreeState.FETCHING
    );
    ok(true, "The dominator tree started fetching");
    ok(
      !getState().snapshots[0].dominatorTree.root,
      "When the dominator tree is fetching, we should not have its root"
    );

    // Wait for the dominator tree to finish being fetched.
    await waitUntilState(
      store,
      state =>
        state.snapshots[0].dominatorTree.state === dominatorTreeState.LOADED
    );
    ok(true, "The dominator tree was fetched");
    ok(
      getState().snapshots[0].dominatorTree.root,
      "When the dominator tree is loaded, we should have its root"
    );
  }

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