From 890e39639acb0f13f9b3fed802bb027e545afb6c Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Fri, 29 Aug 2014 13:39:01 -0700 Subject: [PATCH] Bug 1059940 - Part 1: Expose CrashStore.reset() to clear all data. r=bsmedberg --- toolkit/components/crashes/CrashManager.jsm | 21 ++++++++++++------- .../tests/xpcshell/test_crash_store.js | 9 ++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/toolkit/components/crashes/CrashManager.jsm b/toolkit/components/crashes/CrashManager.jsm index 473325939e2..e5ef4130840 100644 --- a/toolkit/components/crashes/CrashManager.jsm +++ b/toolkit/components/crashes/CrashManager.jsm @@ -706,6 +706,18 @@ CrashStore.prototype = Object.freeze({ // ceiling on the per-type/per-day records that will be stored. HIGH_WATER_DAILY_THRESHOLD: 100, + /** + * Reset all data. + */ + reset() { + this._data = { + v: 1, + crashes: new Map(), + corruptDate: null, + }; + this._countsByDay = new Map(); + }, + /** * Load data from disk. * @@ -713,13 +725,8 @@ CrashStore.prototype = Object.freeze({ */ load: function () { return Task.spawn(function* () { - // Loading replaces data. So reset data structures. - this._data = { - v: 1, - crashes: new Map(), - corruptDate: null, - }; - this._countsByDay = new Map(); + // Loading replaces data. + this.reset(); try { let decoder = new TextDecoder(); diff --git a/toolkit/components/crashes/tests/xpcshell/test_crash_store.js b/toolkit/components/crashes/tests/xpcshell/test_crash_store.js index 9f86c2d4579..3ff06f60c3e 100644 --- a/toolkit/components/crashes/tests/xpcshell/test_crash_store.js +++ b/toolkit/components/crashes/tests/xpcshell/test_crash_store.js @@ -79,6 +79,15 @@ add_task(function test_add_crash() { Assert.equal(s.crashesCount, 2); }); +add_task(function test_reset() { + let s = yield getStore(); + + Assert.ok(s.addCrash(PROCESS_TYPE_MAIN, CRASH_TYPE_CRASH, "id1", DUMMY_DATE)); + Assert.equal(s.crashes.length, 1); + s.reset(); + Assert.equal(s.crashes.length, 0); +}); + add_task(function test_save_load() { let s = yield getStore();