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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Tests the task creator `setCensusDisplayAndRefreshAndRefresh()` for display
* changing. We test this rather than `setCensusDisplayAndRefresh` directly, as
* we use the refresh action in the app itself composed from
* `setCensusDisplayAndRefresh`.
*/
const {
censusDisplays,
censusState,
viewState,
} = require("resource://devtools/client/memory/constants.js");
const {
setCensusDisplayAndRefresh,
} = require("resource://devtools/client/memory/actions/census-display.js");
const {
takeSnapshotAndCensus,
selectSnapshotAndRefresh,
} = require("resource://devtools/client/memory/actions/snapshot.js");
const {
changeView,
} = require("resource://devtools/client/memory/actions/view.js");
// We test setting an invalid display, which triggers an assertion failure.
EXPECTED_DTU_ASSERT_FAILURE_COUNT = 1;
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));
// Test default display with no snapshots
equal(
getState().censusDisplay.breakdown.by,
"coarseType",
"default coarseType display selected at start."
);
dispatch(
setCensusDisplayAndRefresh(heapWorker, censusDisplays.allocationStack)
);
equal(
getState().censusDisplay.breakdown.by,
"allocationStack",
"display changed with no snapshots"
);
// Test invalid displays
ok(getState().errors.length === 0, "No error actions in the queue.");
dispatch(setCensusDisplayAndRefresh(heapWorker, {}));
await waitUntilState(store, () => getState().errors.length === 1);
ok(true, "Emits an error action when passing in an invalid display object");
equal(
getState().censusDisplay.breakdown.by,
"allocationStack",
"current display unchanged when passing invalid display"
);
// Test new snapshots
dispatch(takeSnapshotAndCensus(front, heapWorker));
await waitUntilCensusState(store, snapshot => snapshot.census, [
censusState.SAVED,
]);
equal(
getState().snapshots[0].census.display,
censusDisplays.allocationStack,
"New snapshot's census uses correct display"
);
// Updates when changing display during `SAVING`
dispatch(takeSnapshotAndCensus(front, heapWorker));
await waitUntilCensusState(store, snapshot => snapshot.census, [
censusState.SAVED,
censusState.SAVING,
]);
dispatch(setCensusDisplayAndRefresh(heapWorker, censusDisplays.coarseType));
await waitUntilCensusState(store, snapshot => snapshot.census, [
censusState.SAVED,
censusState.SAVED,
]);
equal(
getState().snapshots[1].census.display,
censusDisplays.coarseType,
"Changing display while saving a snapshot results " +
"in a census using the new display"
);
// Updates when changing display during `SAVING_CENSUS`
dispatch(takeSnapshotAndCensus(front, heapWorker));
await waitUntilCensusState(store, snapshot => snapshot.census, [
censusState.SAVED,
censusState.SAVED,
censusState.SAVING,
]);
dispatch(
setCensusDisplayAndRefresh(heapWorker, censusDisplays.allocationStack)
);
await waitUntilCensusState(store, snapshot => snapshot.census, [
censusState.SAVED,
censusState.SAVED,
censusState.SAVED,
]);
equal(
getState().snapshots[2].census.display,
censusDisplays.allocationStack,
"Display can be changed while saving census, stores updated display in snapshot"
);
// Updates census on currently selected snapshot when changing display
ok(getState().snapshots[2].selected, "Third snapshot currently selected");
dispatch(setCensusDisplayAndRefresh(heapWorker, censusDisplays.coarseType));
await waitUntilState(
store,
state => state.snapshots[2].census.state === censusState.SAVING
);
await waitUntilState(
store,
state => state.snapshots[2].census.state === censusState.SAVED
);
equal(
getState().snapshots[2].census.display,
censusDisplays.coarseType,
"Snapshot census updated when changing displays " +
"after already generating one census"
);
dispatch(
setCensusDisplayAndRefresh(heapWorker, censusDisplays.allocationStack)
);
await waitUntilState(
store,
state => state.snapshots[2].census.state === censusState.SAVED
);
equal(
getState().snapshots[2].census.display,
censusDisplays.allocationStack,
"Snapshot census updated when changing displays " +
"after already generating one census"
);
// Does not update unselected censuses.
ok(!getState().snapshots[1].selected, "Second snapshot selected currently");
equal(
getState().snapshots[1].census.display,
censusDisplays.coarseType,
"Second snapshot using `coarseType` display still and " +
"not yet updated to correct display"
);
// Updates to current display when switching to stale snapshot.
dispatch(selectSnapshotAndRefresh(heapWorker, getState().snapshots[1].id));
await waitUntilCensusState(store, snapshot => snapshot.census, [
censusState.SAVED,
censusState.SAVING,
censusState.SAVED,
]);
await waitUntilCensusState(store, snapshot => snapshot.census, [
censusState.SAVED,
censusState.SAVED,
censusState.SAVED,
]);
ok(getState().snapshots[1].selected, "Second snapshot selected currently");
equal(
getState().snapshots[1].census.display,
censusDisplays.allocationStack,
"Second snapshot using `allocationStack` display and updated to correct display"
);
heapWorker.destroy();
await front.detach();
});
|