test_HeapAnalyses_getDominatorTree_01.js (2369B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 // Test the HeapAnalyses{Client,Worker} "getDominatorTree" request. 6 7 const breakdown = { 8 by: "coarseType", 9 objects: { by: "count", count: true, bytes: true }, 10 scripts: { by: "count", count: true, bytes: true }, 11 strings: { by: "count", count: true, bytes: true }, 12 other: { by: "count", count: true, bytes: true }, 13 domNode: { by: "count", count: true, bytes: true }, 14 }; 15 16 add_task(async function () { 17 const client = new HeapAnalysesClient(); 18 19 const snapshotFilePath = saveNewHeapSnapshot(); 20 await client.readHeapSnapshot(snapshotFilePath); 21 ok(true, "Should have read the heap snapshot"); 22 23 const dominatorTreeId = await client.computeDominatorTree(snapshotFilePath); 24 equal( 25 typeof dominatorTreeId, 26 "number", 27 "should get a dominator tree id, and it should be a number" 28 ); 29 30 const partialTree = await client.getDominatorTree({ 31 dominatorTreeId, 32 breakdown, 33 }); 34 ok(partialTree, "Should get a partial tree"); 35 equal(typeof partialTree, "object", "partialTree should be an object"); 36 37 function checkTree(node) { 38 equal(typeof node.nodeId, "number", "each node should have an id"); 39 40 if (node === partialTree) { 41 equal(node.parentId, undefined, "the root has no parent"); 42 } else { 43 equal( 44 typeof node.parentId, 45 "number", 46 "each node should have a parent id" 47 ); 48 } 49 50 equal( 51 typeof node.retainedSize, 52 "number", 53 "each node should have a retained size" 54 ); 55 56 ok( 57 node.children === undefined || Array.isArray(node.children), 58 "each node either has a list of children, " + 59 "or undefined meaning no children loaded" 60 ); 61 equal( 62 typeof node.moreChildrenAvailable, 63 "boolean", 64 "each node should indicate if there are more children available or not" 65 ); 66 67 equal(typeof node.shortestPaths, "object", "Should have shortest paths"); 68 equal( 69 typeof node.shortestPaths.nodes, 70 "object", 71 "Should have shortest paths' nodes" 72 ); 73 equal( 74 typeof node.shortestPaths.edges, 75 "object", 76 "Should have shortest paths' edges" 77 ); 78 79 if (node.children) { 80 node.children.forEach(checkTree); 81 } 82 } 83 84 checkTree(partialTree); 85 86 client.destroy(); 87 });