browser_memory_percents_01.js (1875B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // Sanity test that we calculate percentages in the tree. 5 6 "use strict"; 7 8 const { 9 takeSnapshotAndCensus, 10 } = require("resource://devtools/client/memory/actions/snapshot.js"); 11 const { viewState } = require("resource://devtools/client/memory/constants.js"); 12 const { 13 changeView, 14 } = require("resource://devtools/client/memory/actions/view.js"); 15 16 const TEST_URL = 17 "http://example.com/browser/devtools/client/memory/test/browser/doc_steady_allocation.html"; 18 19 function checkCells(cells) { 20 Assert.greater(cells.length, 1, "Should have found some"); 21 // Ignore the first header cell. 22 for (const cell of cells.slice(1)) { 23 const percent = cell.querySelector(".heap-tree-percent"); 24 ok(percent, "should have a percent cell"); 25 ok( 26 percent.textContent.match(/^\d?\d%$/), 27 "should be of the form nn% or n%" 28 ); 29 } 30 } 31 32 this.test = makeMemoryTest(TEST_URL, async function ({ panel }) { 33 const heapWorker = panel.panelWin.gHeapAnalysesClient; 34 const { getState, dispatch } = panel.panelWin.gStore; 35 const front = getState().front; 36 const doc = panel.panelWin.document; 37 38 dispatch(changeView(viewState.CENSUS)); 39 40 await dispatch(takeSnapshotAndCensus(front, heapWorker)); 41 is( 42 getState().censusDisplay.breakdown.by, 43 "coarseType", 44 "Should be using coarse type breakdown" 45 ); 46 47 const bytesCells = [...doc.querySelectorAll(".heap-tree-item-bytes")]; 48 checkCells(bytesCells); 49 50 const totalBytesCells = [ 51 ...doc.querySelectorAll(".heap-tree-item-total-bytes"), 52 ]; 53 checkCells(totalBytesCells); 54 55 const countCells = [...doc.querySelectorAll(".heap-tree-item-count")]; 56 checkCells(countCells); 57 58 const totalCountCells = [ 59 ...doc.querySelectorAll(".heap-tree-item-total-count"), 60 ]; 61 checkCells(totalCountCells); 62 });