test_HeapAnalyses_deleteHeapSnapshot_03.js (1861B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 // Test other dominatorTrees can still be retrieved after deleting a snapshot 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 async function createSnapshotAndDominatorTree(client) { 17 const snapshotFilePath = saveNewHeapSnapshot(); 18 await client.readHeapSnapshot(snapshotFilePath); 19 const dominatorTreeId = await client.computeDominatorTree(snapshotFilePath); 20 return { dominatorTreeId, snapshotFilePath }; 21 } 22 23 add_task(async function () { 24 const client = new HeapAnalysesClient(); 25 26 const savedSnapshots = [ 27 await createSnapshotAndDominatorTree(client), 28 await createSnapshotAndDominatorTree(client), 29 await createSnapshotAndDominatorTree(client), 30 ]; 31 ok(true, "Create 3 snapshots and dominator trees"); 32 33 await client.deleteHeapSnapshot(savedSnapshots[1].snapshotFilePath); 34 ok(true, "Snapshot deleted"); 35 36 let tree = await client.getDominatorTree({ 37 dominatorTreeId: savedSnapshots[0].dominatorTreeId, 38 breakdown, 39 }); 40 ok(tree, "Should get a valid tree for first snapshot"); 41 42 let threw = false; 43 try { 44 await client.getDominatorTree({ 45 dominatorTreeId: savedSnapshots[1].dominatorTreeId, 46 breakdown, 47 }); 48 } catch (_) { 49 threw = true; 50 } 51 ok(threw, "getDominatorTree on a deleted snapshot should throw an error"); 52 53 tree = await client.getDominatorTree({ 54 dominatorTreeId: savedSnapshots[2].dominatorTreeId, 55 breakdown, 56 }); 57 ok(tree, "Should get a valid tree for third snapshot"); 58 59 client.destroy(); 60 });