summaryrefslogtreecommitdiffstats
path: root/toolkit/crashreporter/test/unit/test_kill.js
blob: 3d8830bd2249b4a9e4ee82617f46b10987203484 (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
// Test that calling Services.processtools.kill doesn't create a crash report.
add_task(async function run_test() {
  if (!("@mozilla.org/toolkit/crash-reporter;1" in Cc)) {
    dump(
      "INFO | test_kill.js | Can't test crashreporter in a non-libxul build.\n"
    );
    return;
  }

  // Let's launch a child process and kill it (from within, it's simpler).

  do_load_child_test_harness();

  // Setting the minidump path won't work in the child, so we need to do
  // that here.
  Services.appinfo.minidumpPath = do_get_tempdir();
  let headfile = do_get_file("../unit/crasher_subprocess_head.js");
  const CRASH_THEN_WAIT =
    "const ProcessTools = Cc['@mozilla.org/processtools-service;1'].getService(Ci.nsIProcessToolsService);\
     console.log('Child process commiting ritual self-sacrifice');\
     ProcessTools.kill(ProcessTools.pid);\
     console.error('Oops, I should be dead');\
     while (true) {} ;";
  do_get_profile();
  await makeFakeAppDir();
  await sendCommandAsync('load("' + headfile.path.replace(/\\/g, "/") + '");');
  await sendCommandAsync(CRASH_THEN_WAIT);

  // Let's wait a little to give the child process a chance to create a minidump.
  let { setTimeout } = ChromeUtils.importESModule(
    "resource://gre/modules/Timer.sys.mjs"
  );
  // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
  await new Promise(resolve => setTimeout(resolve, 100));

  // Now make sure that we have no minidump.
  let minidump = getMinidump();
  Assert.equal(
    minidump,
    null,
    `There should be no minidump ${minidump == null ? "null" : minidump.path}`
  );
});