1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
6 var { BrowserLoader } = ChromeUtils.importESModule(
7 "resource://devtools/shared/loader/browser-loader.sys.mjs"
9 var { require } = BrowserLoader({
10 baseURI: "resource://devtools/client/memory/",
13 var { Assert } = ChromeUtils.importESModule(
14 "resource://testing-common/Assert.sys.mjs"
17 var EXPECTED_DTU_ASSERT_FAILURE_COUNT = 0;
19 SimpleTest.registerCleanupFunction(function () {
21 DevToolsUtils.assertionFailureCount !== EXPECTED_DTU_ASSERT_FAILURE_COUNT
25 "Should have had the expected number of DevToolsUtils.assert() failures." +
27 EXPECTED_DTU_ASSERT_FAILURE_COUNT +
29 DevToolsUtils.assertionFailureCount
34 var DevToolsUtils = require("resource://devtools/shared/DevToolsUtils.js");
35 var { immutableUpdate } = DevToolsUtils;
37 var constants = require("resource://devtools/client/memory/constants.js");
48 const { L10N } = require("resource://devtools/client/memory/utils.js");
50 var models = require("resource://devtools/client/memory/models.js");
52 var Immutable = require("resource://devtools/client/shared/vendor/immutable.js");
53 var React = require("resource://devtools/client/shared/vendor/react.js");
54 const dom = require("resource://devtools/client/shared/vendor/react-dom-factories.js");
55 var ReactDOM = require("resource://devtools/client/shared/vendor/react-dom.js");
56 var { createFactory } = React;
57 var Heap = createFactory(
58 require("resource://devtools/client/memory/components/Heap.js")
60 var CensusTreeItem = createFactory(
61 require("resource://devtools/client/memory/components/CensusTreeItem.js")
63 var DominatorTreeComponent = createFactory(
64 require("resource://devtools/client/memory/components/DominatorTree.js")
66 var DominatorTreeItem = createFactory(
67 require("resource://devtools/client/memory/components/DominatorTreeItem.js")
69 var ShortestPaths = createFactory(
70 require("resource://devtools/client/memory/components/ShortestPaths.js")
72 var TreeMap = createFactory(
73 require("resource://devtools/client/memory/components/TreeMap.js")
75 var SnapshotListItem = createFactory(
76 require("resource://devtools/client/memory/components/SnapshotListItem.js")
78 var List = createFactory(
79 require("resource://devtools/client/memory/components/List.js")
81 var Toolbar = createFactory(
82 require("resource://devtools/client/memory/components/Toolbar.js")
85 // All tests are asynchronous.
86 SimpleTest.waitForExplicitFinish();
90 var TEST_CENSUS_TREE_ITEM_PROPS = Object.freeze({
110 getPercentBytes: () => 50,
111 getPercentCount: () => 50,
113 onViewSourceInDebugger: noop,
117 // Counter for mock DominatorTreeNode ids.
118 var TEST_NODE_ID_COUNTER = 0;
121 * Create a mock DominatorTreeNode for testing, with sane defaults. Override any
122 * property by providing it on `opts`. Optionally pass child nodes as well.
124 * @param {Object} opts
125 * @param {Array<DominatorTreeNode>?} children
127 * @returns {DominatorTreeNode}
129 function makeTestDominatorTreeNode(opts, children) {
130 const nodeId = TEST_NODE_ID_COUNTER++;
132 const node = Object.assign(
135 label: ["other", "SomeType"],
137 retainedSize: (children || []).reduce(
138 (size, c) => size + c.retainedSize,
143 moreChildrenAvailable: true,
148 if (children && children.length) {
150 c.parentId = node.nodeId;
157 var TEST_DOMINATOR_TREE = Object.freeze({
158 dominatorTreeId: 666,
159 root: (function makeTree(depth = 0) {
168 return makeTestDominatorTreeNode({}, children);
173 display: labelDisplays.coarseType,
174 activeFetchRequestCount: null,
175 state: dominatorTreeState.LOADED,
178 var TEST_DOMINATOR_TREE_PROPS = Object.freeze({
179 dominatorTree: TEST_DOMINATOR_TREE,
180 onLoadMoreSiblings: noop,
181 onViewSourceInDebugger: noop,
186 var TEST_SHORTEST_PATHS_PROPS = Object.freeze({
187 graph: Object.freeze({
189 { id: 1, label: ["other", "SomeType"] },
190 { id: 2, label: ["other", "SomeType"] },
191 { id: 3, label: ["other", "SomeType"] },
194 { from: 1, to: 2, name: "1->2" },
195 { from: 1, to: 3, name: "1->3" },
196 { from: 2, to: 3, name: "2->3" },
201 var TEST_SNAPSHOT = Object.freeze({
204 path: "/fake/path/to/snapshot",
205 census: Object.freeze({
206 report: Object.freeze({
207 objects: Object.freeze({ count: 4, bytes: 400 }),
208 scripts: Object.freeze({ count: 3, bytes: 300 }),
209 strings: Object.freeze({ count: 2, bytes: 200 }),
210 other: Object.freeze({ count: 1, bytes: 100 }),
212 display: Object.freeze({
213 displayName: "Test Display",
214 tooltip: "Test display tooltup",
216 breakdown: Object.freeze({
218 objects: Object.freeze({ by: "count", count: true, bytes: true }),
219 scripts: Object.freeze({ by: "count", count: true, bytes: true }),
220 strings: Object.freeze({ by: "count", count: true, bytes: true }),
221 other: Object.freeze({ by: "count", count: true, bytes: true }),
224 state: censusState.SAVED,
229 parentMap: Object.freeze(Object.create(null)),
231 dominatorTree: TEST_DOMINATOR_TREE,
235 state: snapshotState.READ,
238 var TEST_HEAP_PROPS = Object.freeze({
239 onSnapshotClick: noop,
240 onLoadMoreSiblings: noop,
241 onCensusExpand: noop,
242 onCensusCollapse: noop,
243 onDominatorTreeExpand: noop,
244 onDominatorTreeCollapse: noop,
246 onDominatorTreeFocus: noop,
247 onViewSourceInDebugger: noop,
249 view: { state: viewState.CENSUS },
250 snapshot: TEST_SNAPSHOT,
251 sizes: Object.freeze({ shortestPathsSize: 0.5 }),
252 onShortestPathsResize: noop,
255 var TEST_TOOLBAR_PROPS = Object.freeze({
257 censusDisplays.coarseType,
258 censusDisplays.allocationStack,
259 censusDisplays.invertedAllocationStack,
261 censusDisplay: censusDisplays.coarseType,
262 onTakeSnapshotClick: noop,
264 onCensusDisplayChange: noop,
265 onToggleRecordAllocationStacks: noop,
266 allocations: models.allocations,
267 onToggleInverted: noop,
270 setFilterString: noop,
272 onToggleDiffing: noop,
273 view: { state: viewState.CENSUS },
275 labelDisplays: [labelDisplays.coarseType, labelDisplays.allocationStack],
276 labelDisplay: labelDisplays.coarseType,
277 onLabelDisplayChange: noop,
281 function makeTestCensusNode() {
292 var TEST_TREE_MAP_PROPS = Object.freeze({
293 treeMap: Object.freeze({
307 children: [makeTestCensusNode(), makeTestCensusNode()],
315 children: [makeTestCensusNode(), makeTestCensusNode()],
322 var TEST_SNAPSHOT_LIST_ITEM_PROPS = Object.freeze({
330 function onNextAnimationFrame(fn) {
331 return () => requestAnimationFrame(() => requestAnimationFrame(fn));
335 * Render the provided ReactElement in the provided HTML container.
336 * Returns a Promise that will resolve the rendered element as a React
339 function renderComponent(element, container) {
340 return new Promise(resolve => {
341 const component = ReactDOM.render(
344 onNextAnimationFrame(() => {
345 dumpn("Rendered = " + container.innerHTML);
352 function dumpn(msg) {
353 dump(`MEMORY-TEST: ${msg}\n`);