summaryrefslogtreecommitdiffstats
path: root/ipc/glue/test/browser/browser_utility_memoryReport.js
blob: 8cec61b8be0183ec1b6f1288fc0d97bc8a6b76c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// When running full suite, previous audio decoding tests might have left some
// running and this might interfere with our testing
add_setup(async function ensureNoExistingProcess() {
  await killUtilityProcesses();
});

add_task(async () => {
  const utilityPid = await startUtilityProcess();

  const gMgr = Cc["@mozilla.org/memory-reporter-manager;1"].getService(
    Ci.nsIMemoryReporterManager
  );
  ok(utilityPid !== undefined, `Utility process is running as ${utilityPid}`);

  var utilityReports = [];

  const performCollection = new Promise((resolve, reject) => {
    // Record the reports from the live memory reporters then process them.
    let handleReport = function (
      aProcess,
      aUnsafePath,
      aKind,
      aUnits,
      aAmount,
      aDescription
    ) {
      const expectedProcess = `Utility (pid ${utilityPid}, sandboxingKind ${kGenericUtilitySandbox})`;
      if (aProcess !== expectedProcess) {
        return;
      }

      let report = {
        process: aProcess,
        path: aUnsafePath,
        kind: aKind,
        units: aUnits,
        amount: aAmount,
        description: aDescription,
      };

      utilityReports.push(report);
    };

    info("Memory report: Perform the call");
    gMgr.getReports(handleReport, null, resolve, null, false);
  });

  await performCollection;

  info(
    `Collected ${utilityReports.length} reports from utility process ${utilityPid}`
  );
  ok(!!utilityReports.length, "Collected some reports");
  ok(
    utilityReports.filter(r => r.path === "vsize" && r.amount > 0).length === 1,
    "Collected vsize report"
  );
  ok(
    utilityReports.filter(r => r.path === "resident" && r.amount > 0).length ===
      1,
    "Collected resident report"
  );
  ok(
    !!utilityReports.filter(
      r => r.path.search(/^explicit\/.*/) >= 0 && r.amount > 0
    ).length,
    "Collected some explicit/ report"
  );

  await cleanUtilityProcessShutdown();
});