summaryrefslogtreecommitdiffstats
path: root/devtools/client/memory/test/xpcshell/test_action_diffing_04.js
blob: e624a0db7911d1e0ba32fdfca8a4230952ac7afd (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
92
93
94
95
96
97
98
99
100
101
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test that we compute census diffs.

const {
  diffingState,
  snapshotState,
  viewState,
} = require("resource://devtools/client/memory/constants.js");
const {
  toggleDiffing,
  selectSnapshotForDiffingAndRefresh,
} = require("resource://devtools/client/memory/actions/diffing.js");
const {
  takeSnapshot,
  readSnapshot,
} = 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();
  const store = Store();
  const { getState, dispatch } = store;
  dispatch(changeView(viewState.CENSUS));

  equal(getState().diffing, null, "not diffing by default");

  const s1 = await dispatch(takeSnapshot(front, heapWorker));
  const s2 = await dispatch(takeSnapshot(front, heapWorker));
  const s3 = await dispatch(takeSnapshot(front, heapWorker));
  dispatch(readSnapshot(heapWorker, s1));
  dispatch(readSnapshot(heapWorker, s2));
  dispatch(readSnapshot(heapWorker, s3));
  await waitUntilSnapshotState(store, [
    snapshotState.READ,
    snapshotState.READ,
    snapshotState.READ,
  ]);

  dispatch(toggleDiffing());
  dispatch(
    selectSnapshotForDiffingAndRefresh(heapWorker, getState().snapshots[0])
  );
  dispatch(
    selectSnapshotForDiffingAndRefresh(heapWorker, getState().snapshots[1])
  );

  ok(getState().diffing, "We should be diffing.");
  equal(
    getState().diffing.firstSnapshotId,
    getState().snapshots[0].id,
    "First snapshot selected."
  );
  equal(
    getState().diffing.secondSnapshotId,
    getState().snapshots[1].id,
    "Second snapshot selected."
  );

  await waitUntilState(
    store,
    state => state.diffing.state === diffingState.TAKING_DIFF
  );
  ok(
    true,
    "Selecting two snapshots for diffing should trigger computing a diff."
  );

  await waitUntilState(
    store,
    state => state.diffing.state === diffingState.TOOK_DIFF
  );
  ok(true, "And then the diff should complete.");
  ok(getState().diffing.census, "And we should have a census.");
  ok(getState().diffing.census.report, "And that census should have a report.");
  equal(
    getState().diffing.census.display,
    getState().censusDisplay,
    "And that census should have the correct display"
  );
  equal(
    getState().diffing.census.filter,
    getState().filter,
    "And that census should have the correct filter"
  );
  equal(
    getState().diffing.census.display.inverted,
    getState().censusDisplay.inverted,
    "And that census should have the correct inversion"
  );

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