diff --git a/toolkit/components/crashes/CrashManager.jsm b/toolkit/components/crashes/CrashManager.jsm index aecd58e422d6..ca1ab77ee1a3 100644 --- a/toolkit/components/crashes/CrashManager.jsm +++ b/toolkit/components/crashes/CrashManager.jsm @@ -386,6 +386,15 @@ this.CrashManager.prototype = Object.freeze({ } }), + /** + * Generate a submission ID for use with addSubmission{Attempt,Result}. + */ + generateSubmissionID() { + return "sub-" + Cc["@mozilla.org/uuid-generator;1"] + .getService(Ci.nsIUUIDGenerator) + .generateUUID().toString().slice(1, -1); + }, + /** * Record the occurrence of a submission attempt for a crash. * @@ -521,12 +530,8 @@ this.CrashManager.prototype = Object.freeze({ store.addCrash(this.PROCESS_TYPE_MAIN, this.CRASH_TYPE_CRASH, crashID, date); - let submissionID = "sub-" + Cc["@mozilla.org/uuid-generator;1"] - .getService(Ci.nsIUUIDGenerator) - .generateUUID().toString() - .slice(1, -1); + let submissionID = this.generateSubmissionID(); let succeeded = result === "true"; - store.addSubmissionAttempt(crashID, submissionID, date); store.addSubmissionResult(crashID, submissionID, date, succeeded ? this.SUBMISSION_RESULT_OK : diff --git a/toolkit/components/crashes/tests/xpcshell/test_crash_manager.js b/toolkit/components/crashes/tests/xpcshell/test_crash_manager.js index 9a46d362b7a0..a7fb702af144 100644 --- a/toolkit/components/crashes/tests/xpcshell/test_crash_manager.js +++ b/toolkit/components/crashes/tests/xpcshell/test_crash_manager.js @@ -371,6 +371,15 @@ add_task(function* test_addCrash() { Assert.ok(crash.isOfType(m.PROCESS_TYPE_CONTENT, m.CRASH_TYPE_HANG)); }); +add_task(function* test_generateSubmissionID() { + let m = yield getManager(); + + const SUBMISSION_ID_REGEX = + /^(sub-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/i; + let id = m.generateSubmissionID(); + Assert.ok(SUBMISSION_ID_REGEX.test(id)); +}); + add_task(function* test_addSubmissionAttemptAndResult() { let m = yield getManager(); diff --git a/toolkit/crashreporter/CrashSubmit.jsm b/toolkit/crashreporter/CrashSubmit.jsm index 605cce36eecf..2742559f2416 100644 --- a/toolkit/crashreporter/CrashSubmit.jsm +++ b/toolkit/crashreporter/CrashSubmit.jsm @@ -298,10 +298,8 @@ Submitter.prototype = { } } - let submissionID = "sub-" + Cc["@mozilla.org/uuid-generator;1"] - .getService(Ci.nsIUUIDGenerator) - .generateUUID().toString().slice(1, -1); let manager = Services.crashmanager; + let submissionID = manager.generateSubmissionID(); let self = this; xhr.addEventListener("readystatechange", function (aEvt) {