summaryrefslogtreecommitdiffstats
path: root/toolkit/crashreporter/test/unit/test_crash_after_js_oom_reported.js
blob: 8796aee3c079c321c48839162d6d2ff86b90a40c (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
add_task(async function run_test() {
  if (!("@mozilla.org/toolkit/crash-reporter;1" in Cc)) {
    dump(
      "INFO | test_crash_after_js_oom_reported.js | Can't test crashreporter in a non-libxul build.\n"
    );
    return;
  }

  await do_crash(
    function () {
      crashType = CrashTestUtils.CRASH_MOZ_CRASH;
      crashReporter.annotateCrashReport("TestKey", "Yes");

      // GC now to avoid having it happen randomly later, which would make the
      // test bogusly fail. See comment below.
      Cu.forceGC();

      Cu.getJSTestingFunctions().reportOutOfMemory();
    },
    function (mdump, extra) {
      Assert.equal(extra.TestKey, "Yes");

      // The JSOutOfMemory field is absent if the JS engine never reported OOM,
      // "Reported" if it did, and "Recovered" if it reported OOM but
      // subsequently completed a full GC cycle. Since this test calls
      // reportOutOfMemory() and then crashes, we expect "Reported".
      //
      // Theoretically, GC can happen any time, so it is just possible that
      // this property could be "Recovered" even if the implementation is
      // correct. More likely, though, that indicates a bug, so only accept
      // "Reported".
      Assert.equal(extra.JSOutOfMemory, "Reported");
    },
    true
  );
});