toolkit/crashreporter/test/unit/test_crash_AsyncShutdown.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/crashreporter/test/unit/test_crash_AsyncShutdown.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,95 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +// Test that AsyncShutdown report errors correctly
     1.8 +
     1.9 +function setup_crash() {
    1.10 +  Components.utils.import("resource://gre/modules/AsyncShutdown.jsm", this);
    1.11 +  Components.utils.import("resource://gre/modules/Services.jsm", this);
    1.12 +  Components.utils.import("resource://gre/modules/Promise.jsm", this);
    1.13 +
    1.14 +  Services.prefs.setBoolPref("toolkit.asyncshutdown.testing", true);
    1.15 +  Services.prefs.setIntPref("toolkit.asyncshutdown.crash_timeout", 10);
    1.16 +
    1.17 +  let TOPIC = "testing-async-shutdown-crash";
    1.18 +  let phase = AsyncShutdown._getPhase(TOPIC);
    1.19 +  phase.addBlocker("A blocker that is never satisfied", function() {
    1.20 +    dump("Installing blocker\n");
    1.21 +    let deferred = Promise.defer();
    1.22 +    return deferred.promise;
    1.23 +  });
    1.24 +
    1.25 +  Services.obs.notifyObservers(null, TOPIC, null);
    1.26 +  dump("Waiting for crash\n");
    1.27 +}
    1.28 +
    1.29 +function after_crash(mdump, extra) {
    1.30 +  do_print("after crash: " + extra.AsyncShutdownTimeout);
    1.31 +  let info = JSON.parse(extra.AsyncShutdownTimeout);
    1.32 +  do_check_eq(info.phase, "testing-async-shutdown-crash");
    1.33 +  do_print("Condition: " + JSON.stringify(info.conditions));
    1.34 +  do_check_true(JSON.stringify(info.conditions).indexOf("A blocker that is never satisfied") != -1);
    1.35 +}
    1.36 +
    1.37 +// Test that AsyncShutdown + OS.File reports errors correctly, in a case in which
    1.38 +// the latest operation succeeded
    1.39 +
    1.40 +function setup_osfile_crash_noerror() {
    1.41 +  Components.utils.import("resource://gre/modules/Services.jsm", this);
    1.42 +  Components.utils.import("resource://gre/modules/osfile.jsm", this);
    1.43 +
    1.44 +  Services.prefs.setBoolPref("toolkit.osfile.debug.failshutdown", true);
    1.45 +  Services.prefs.setIntPref("toolkit.asyncshutdown.crash_timeout", 1);
    1.46 +  Services.prefs.setBoolPref("toolkit.osfile.native", false);
    1.47 +
    1.48 +  OS.File.getCurrentDirectory();
    1.49 +  Services.obs.notifyObservers(null, "profile-before-change", null);
    1.50 +  dump("Waiting for crash\n");
    1.51 +};
    1.52 +
    1.53 +function after_osfile_crash_noerror(mdump, extra) {
    1.54 +  do_print("after OS.File crash: " + JSON.stringify(extra.AsyncShutdownTimeout));
    1.55 +  let info = JSON.parse(extra.AsyncShutdownTimeout);
    1.56 +  let state = info.conditions[0].state;
    1.57 +  do_print("Keys: " + Object.keys(state).join(", "));
    1.58 +  do_check_eq(info.phase, "profile-before-change");
    1.59 +  do_check_true(state.launched);
    1.60 +  do_check_false(state.shutdown);
    1.61 +  do_check_true(state.worker);
    1.62 +  do_check_true(!!state.latestSent);
    1.63 +  do_check_eq(state.latestSent[1], "getCurrentDirectory");
    1.64 +}
    1.65 +
    1.66 +// Test that AsyncShutdown + OS.File reports errors correctly, in a case in which
    1.67 +// the latest operation failed
    1.68 +
    1.69 +function setup_osfile_crash_exn() {
    1.70 +  Components.utils.import("resource://gre/modules/Services.jsm", this);
    1.71 +  Components.utils.import("resource://gre/modules/osfile.jsm", this);
    1.72 +
    1.73 +  Services.prefs.setBoolPref("toolkit.osfile.debug.failshutdown", true);
    1.74 +  Services.prefs.setIntPref("toolkit.asyncshutdown.crash_timeout", 1);
    1.75 +  Services.prefs.setBoolPref("toolkit.osfile.native", false);
    1.76 +
    1.77 +  OS.File.read("I do not exist");
    1.78 +  Services.obs.notifyObservers(null, "profile-before-change", null);
    1.79 +  dump("Waiting for crash\n");
    1.80 +};
    1.81 +
    1.82 +function after_osfile_crash_exn(mdump, extra) {
    1.83 +  do_print("after OS.File crash: " + JSON.stringify(extra.AsyncShutdownTimeout));
    1.84 +  let info = JSON.parse(extra.AsyncShutdownTimeout);
    1.85 +  let state = info.conditions[0].state;
    1.86 +  do_print("Keys: " + Object.keys(state).join(", "));
    1.87 +  do_check_eq(info.phase, "profile-before-change");
    1.88 +  do_check_false(state.shutdown);
    1.89 +  do_check_true(state.worker);
    1.90 +  do_check_true(!!state.latestSent);
    1.91 +  do_check_eq(state.latestSent[1], "read");
    1.92 +}
    1.93 +
    1.94 +function run_test() {
    1.95 +  do_crash(setup_crash, after_crash);
    1.96 +  do_crash(setup_osfile_crash_noerror, after_osfile_crash_noerror);
    1.97 +  do_crash(setup_osfile_crash_exn, after_osfile_crash_exn);
    1.98 +}

mercurial