tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_utility_memoryReport.js (2116B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // When running full suite, previous audio decoding tests might have left some
      7 // running and this might interfere with our testing
      8 add_setup(async function ensureNoExistingProcess() {
      9  await killUtilityProcesses();
     10 });
     11 
     12 add_task(async () => {
     13  const utilityPid = await startUtilityProcess();
     14 
     15  const gMgr = Cc["@mozilla.org/memory-reporter-manager;1"].getService(
     16    Ci.nsIMemoryReporterManager
     17  );
     18  Assert.notStrictEqual(
     19    utilityPid,
     20    undefined,
     21    `Utility process is running as ${utilityPid}`
     22  );
     23 
     24  var utilityReports = [];
     25 
     26  const performCollection = new Promise(resolve => {
     27    // Record the reports from the live memory reporters then process them.
     28    let handleReport = function (
     29      aProcess,
     30      aUnsafePath,
     31      aKind,
     32      aUnits,
     33      aAmount,
     34      aDescription
     35    ) {
     36      const expectedProcess = `Utility (pid ${utilityPid}, sandboxingKind ${kGenericUtilitySandbox})`;
     37      if (aProcess !== expectedProcess) {
     38        return;
     39      }
     40 
     41      let report = {
     42        process: aProcess,
     43        path: aUnsafePath,
     44        kind: aKind,
     45        units: aUnits,
     46        amount: aAmount,
     47        description: aDescription,
     48      };
     49 
     50      utilityReports.push(report);
     51    };
     52 
     53    info("Memory report: Perform the call");
     54    gMgr.getReports(handleReport, null, resolve, null, false);
     55  });
     56 
     57  await performCollection;
     58 
     59  info(
     60    `Collected ${utilityReports.length} reports from utility process ${utilityPid}`
     61  );
     62  ok(!!utilityReports.length, "Collected some reports");
     63  Assert.strictEqual(
     64    utilityReports.filter(r => r.path === "vsize" && r.amount > 0).length,
     65    1,
     66    "Collected vsize report"
     67  );
     68  Assert.strictEqual(
     69    utilityReports.filter(r => r.path === "resident" && r.amount > 0).length,
     70    1,
     71    "Collected resident report"
     72  );
     73  ok(
     74    !!utilityReports.filter(
     75      r => r.path.search(/^explicit\/.*/) >= 0 && r.amount > 0
     76    ).length,
     77    "Collected some explicit/ report"
     78  );
     79 
     80  await cleanUtilityProcessShutdown();
     81 });