services/healthreport/tests/xpcshell/test_provider_crashes.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 "use strict";
michael@0 5
michael@0 6 const {utils: Cu} = Components;
michael@0 7
michael@0 8
michael@0 9 Cu.import("resource://gre/modules/Metrics.jsm");
michael@0 10 Cu.import("resource://gre/modules/services/healthreport/providers.jsm");
michael@0 11 Cu.import("resource://testing-common/AppData.jsm");
michael@0 12 Cu.import("resource://testing-common/services/healthreport/utils.jsm");
michael@0 13 Cu.import("resource://testing-common/CrashManagerTest.jsm");
michael@0 14
michael@0 15
michael@0 16 function run_test() {
michael@0 17 run_next_test();
michael@0 18 }
michael@0 19
michael@0 20 add_task(function* init() {
michael@0 21 do_get_profile();
michael@0 22 yield makeFakeAppDir();
michael@0 23 });
michael@0 24
michael@0 25 add_task(function test_constructor() {
michael@0 26 let provider = new CrashesProvider();
michael@0 27 });
michael@0 28
michael@0 29 add_task(function* test_init() {
michael@0 30 let storage = yield Metrics.Storage("init");
michael@0 31 let provider = new CrashesProvider();
michael@0 32 yield provider.init(storage);
michael@0 33 yield provider.shutdown();
michael@0 34
michael@0 35 yield storage.close();
michael@0 36 });
michael@0 37
michael@0 38 add_task(function* test_collect() {
michael@0 39 let storage = yield Metrics.Storage("collect");
michael@0 40 let provider = new CrashesProvider();
michael@0 41 yield provider.init(storage);
michael@0 42
michael@0 43 // Install custom manager so we don't interfere with other tests.
michael@0 44 let manager = yield getManager();
michael@0 45 provider._manager = manager;
michael@0 46
michael@0 47 let day1 = new Date(2014, 0, 1, 0, 0, 0);
michael@0 48 let day2 = new Date(2014, 0, 3, 0, 0, 0);
michael@0 49
michael@0 50 // FUTURE Bug 982836 CrashManager will grow public APIs for adding crashes.
michael@0 51 // Switch to that here.
michael@0 52 let store = yield manager._getStore();
michael@0 53 store.addMainProcessCrash("id1", day1);
michael@0 54 store.addMainProcessCrash("id2", day1);
michael@0 55 store.addMainProcessCrash("id3", day2);
michael@0 56
michael@0 57 // Flush changes (this may not be needed but it doesn't hurt).
michael@0 58 yield store.save();
michael@0 59
michael@0 60 yield provider.collectDailyData();
michael@0 61
michael@0 62 let m = provider.getMeasurement("crashes", 2);
michael@0 63 let values = yield m.getValues();
michael@0 64 do_check_eq(values.days.size, 2);
michael@0 65 do_check_true(values.days.hasDay(day1));
michael@0 66 do_check_true(values.days.hasDay(day2));
michael@0 67
michael@0 68 let value = values.days.getDay(day1);
michael@0 69 do_check_true(value.has("mainCrash"));
michael@0 70 do_check_eq(value.get("mainCrash"), 2);
michael@0 71
michael@0 72 value = values.days.getDay(day2);
michael@0 73 do_check_eq(value.get("mainCrash"), 1);
michael@0 74
michael@0 75 // Check that adding a new crash increments counter on next collect.
michael@0 76 store = yield manager._getStore();
michael@0 77 store.addMainProcessCrash("id4", day2);
michael@0 78 yield store.save();
michael@0 79
michael@0 80 yield provider.collectDailyData();
michael@0 81 values = yield m.getValues();
michael@0 82 value = values.days.getDay(day2);
michael@0 83 do_check_eq(value.get("mainCrash"), 2);
michael@0 84
michael@0 85 yield provider.shutdown();
michael@0 86 yield storage.close();
michael@0 87 });
michael@0 88

mercurial