michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // Test that AsyncShutdown report errors correctly michael@0: michael@0: function setup_crash() { michael@0: Components.utils.import("resource://gre/modules/AsyncShutdown.jsm", this); michael@0: Components.utils.import("resource://gre/modules/Services.jsm", this); michael@0: Components.utils.import("resource://gre/modules/Promise.jsm", this); michael@0: michael@0: Services.prefs.setBoolPref("toolkit.asyncshutdown.testing", true); michael@0: Services.prefs.setIntPref("toolkit.asyncshutdown.crash_timeout", 10); michael@0: michael@0: let TOPIC = "testing-async-shutdown-crash"; michael@0: let phase = AsyncShutdown._getPhase(TOPIC); michael@0: phase.addBlocker("A blocker that is never satisfied", function() { michael@0: dump("Installing blocker\n"); michael@0: let deferred = Promise.defer(); michael@0: return deferred.promise; michael@0: }); michael@0: michael@0: Services.obs.notifyObservers(null, TOPIC, null); michael@0: dump("Waiting for crash\n"); michael@0: } michael@0: michael@0: function after_crash(mdump, extra) { michael@0: do_print("after crash: " + extra.AsyncShutdownTimeout); michael@0: let info = JSON.parse(extra.AsyncShutdownTimeout); michael@0: do_check_eq(info.phase, "testing-async-shutdown-crash"); michael@0: do_print("Condition: " + JSON.stringify(info.conditions)); michael@0: do_check_true(JSON.stringify(info.conditions).indexOf("A blocker that is never satisfied") != -1); michael@0: } michael@0: michael@0: // Test that AsyncShutdown + OS.File reports errors correctly, in a case in which michael@0: // the latest operation succeeded michael@0: michael@0: function setup_osfile_crash_noerror() { michael@0: Components.utils.import("resource://gre/modules/Services.jsm", this); michael@0: Components.utils.import("resource://gre/modules/osfile.jsm", this); michael@0: michael@0: Services.prefs.setBoolPref("toolkit.osfile.debug.failshutdown", true); michael@0: Services.prefs.setIntPref("toolkit.asyncshutdown.crash_timeout", 1); michael@0: Services.prefs.setBoolPref("toolkit.osfile.native", false); michael@0: michael@0: OS.File.getCurrentDirectory(); michael@0: Services.obs.notifyObservers(null, "profile-before-change", null); michael@0: dump("Waiting for crash\n"); michael@0: }; michael@0: michael@0: function after_osfile_crash_noerror(mdump, extra) { michael@0: do_print("after OS.File crash: " + JSON.stringify(extra.AsyncShutdownTimeout)); michael@0: let info = JSON.parse(extra.AsyncShutdownTimeout); michael@0: let state = info.conditions[0].state; michael@0: do_print("Keys: " + Object.keys(state).join(", ")); michael@0: do_check_eq(info.phase, "profile-before-change"); michael@0: do_check_true(state.launched); michael@0: do_check_false(state.shutdown); michael@0: do_check_true(state.worker); michael@0: do_check_true(!!state.latestSent); michael@0: do_check_eq(state.latestSent[1], "getCurrentDirectory"); michael@0: } michael@0: michael@0: // Test that AsyncShutdown + OS.File reports errors correctly, in a case in which michael@0: // the latest operation failed michael@0: michael@0: function setup_osfile_crash_exn() { michael@0: Components.utils.import("resource://gre/modules/Services.jsm", this); michael@0: Components.utils.import("resource://gre/modules/osfile.jsm", this); michael@0: michael@0: Services.prefs.setBoolPref("toolkit.osfile.debug.failshutdown", true); michael@0: Services.prefs.setIntPref("toolkit.asyncshutdown.crash_timeout", 1); michael@0: Services.prefs.setBoolPref("toolkit.osfile.native", false); michael@0: michael@0: OS.File.read("I do not exist"); michael@0: Services.obs.notifyObservers(null, "profile-before-change", null); michael@0: dump("Waiting for crash\n"); michael@0: }; michael@0: michael@0: function after_osfile_crash_exn(mdump, extra) { michael@0: do_print("after OS.File crash: " + JSON.stringify(extra.AsyncShutdownTimeout)); michael@0: let info = JSON.parse(extra.AsyncShutdownTimeout); michael@0: let state = info.conditions[0].state; michael@0: do_print("Keys: " + Object.keys(state).join(", ")); michael@0: do_check_eq(info.phase, "profile-before-change"); michael@0: do_check_false(state.shutdown); michael@0: do_check_true(state.worker); michael@0: do_check_true(!!state.latestSent); michael@0: do_check_eq(state.latestSent[1], "read"); michael@0: } michael@0: michael@0: function run_test() { michael@0: do_crash(setup_crash, after_crash); michael@0: do_crash(setup_osfile_crash_noerror, after_osfile_crash_noerror); michael@0: do_crash(setup_osfile_crash_exn, after_osfile_crash_exn); michael@0: }