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
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Ensures that content crashes are reported to the crash service
// (nsICrashService and CrashManager.sys.mjs).
/* eslint-disable mozilla/no-arbitrary-setTimeout */
SimpleTest.requestFlakyTimeout("untriaged");
SimpleTest.requestCompleteLog();
add_task(async function () {
let tab = await BrowserTestUtils.openNewForegroundTab({
gBrowser,
forceNewProcess: true,
});
SimpleTest.expectChildProcessCrash();
let crashMan = Services.crashmanager;
// First, clear the crash record store.
info("Waiting for pruneOldCrashes");
var future = new Date(Date.now() + 1000 * 60 * 60 * 24);
await crashMan.pruneOldCrashes(future);
var crashDateMS = Date.now();
let crashPromise = BrowserTestUtils.crashFrame(tab.linkedBrowser);
// Finally, poll for the new crash record.
await new Promise((resolve, reject) => {
function tryGetCrash() {
info("Waiting for getCrashes");
crashMan.getCrashes().then(
function (crashes) {
if (crashes.length) {
is(crashes.length, 1, "There should be only one record");
var crash = crashes[0];
ok(
crash.isOfType(
crashMan.processTypes[Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT],
crashMan.CRASH_TYPE_CRASH
),
"Record should be a content crash"
);
ok(!!crash.id, "Record should have an ID");
ok(!!crash.crashDate, "Record should have a crash date");
var dateMS = crash.crashDate.valueOf();
var twoMin = 1000 * 60 * 2;
ok(
crashDateMS - twoMin <= dateMS && dateMS <= crashDateMS + twoMin,
`Record's crash date should be nowish: ` +
`now=${crashDateMS} recordDate=${dateMS}`
);
resolve();
} else {
setTimeout(tryGetCrash, 1000);
}
},
function (err) {
reject(err);
}
);
}
setTimeout(tryGetCrash, 1000);
});
await crashPromise;
await BrowserTestUtils.removeTab(tab);
});
|