Bug 1059940 - Part 1: Expose CrashStore.reset() to clear all data. r=bsmedberg

This commit is contained in:
Birunthan Mohanathas 2014-08-29 13:39:01 -07:00
parent cf3f9993c4
commit 890e39639a
2 changed files with 23 additions and 7 deletions

View File

@ -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();

View File

@ -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();