summaryrefslogtreecommitdiffstats
path: root/toolkit/crashreporter/test/unit/test_event_files.js
blob: d57978e23d6d4a1e72fa8ad763ca30f194f52727 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

var {utils: Cu} = Components;

Cu.import("resource://gre/modules/Promise.jsm", this);
Cu.import("resource://gre/modules/Services.jsm", this);
Cu.import("resource://testing-common/AppData.jsm", this);

function run_test() {
  run_next_test();
}

add_task(function* test_setup() {
  do_get_profile();
  yield makeFakeAppDir();
});

add_task(function* test_main_process_crash() {
  let cm = Services.crashmanager;
  Assert.ok(cm, "CrashManager available.");

  let basename;
  let deferred = Promise.defer();
  do_crash(
    function() {
      // TelemetrySession setup will trigger the session annotation
      let scope = {};
      Components.utils.import("resource://gre/modules/TelemetryController.jsm", scope);
      scope.TelemetryController.testSetup();
      crashType = CrashTestUtils.CRASH_RUNTIMEABORT;
      crashReporter.annotateCrashReport("ShutdownProgress", "event-test");
    },
    (minidump, extra) => {
      basename = minidump.leafName;
      cm._eventsDirs = [getEventDir()];
      cm.aggregateEventsFiles().then(deferred.resolve, deferred.reject);
    },
    true);

  let count = yield deferred.promise;
  Assert.equal(count, 1, "A single crash event file was seen.");
  let crashes = yield cm.getCrashes();
  Assert.equal(crashes.length, 1);
  let crash = crashes[0];
  Assert.ok(crash.isOfType(cm.PROCESS_TYPE_MAIN, cm.CRASH_TYPE_CRASH));
  Assert.equal(crash.id + ".dmp", basename, "ID recorded properly");
  Assert.equal(crash.metadata.ShutdownProgress, "event-test");
  Assert.ok("TelemetrySessionId" in crash.metadata);
  Assert.ok("UptimeTS" in crash.metadata);
  Assert.ok(/^[0-9a-f]{8}\-([0-9a-f]{4}\-){3}[0-9a-f]{12}$/.test(crash.metadata.TelemetrySessionId));
  Assert.ok("CrashTime" in crash.metadata);
  Assert.ok(/^\d+$/.test(crash.metadata.CrashTime));
});