toolkit/crashreporter/test/unit/test_crash_AsyncShutdown.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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 // Test that AsyncShutdown report errors correctly
michael@0 5
michael@0 6 function setup_crash() {
michael@0 7 Components.utils.import("resource://gre/modules/AsyncShutdown.jsm", this);
michael@0 8 Components.utils.import("resource://gre/modules/Services.jsm", this);
michael@0 9 Components.utils.import("resource://gre/modules/Promise.jsm", this);
michael@0 10
michael@0 11 Services.prefs.setBoolPref("toolkit.asyncshutdown.testing", true);
michael@0 12 Services.prefs.setIntPref("toolkit.asyncshutdown.crash_timeout", 10);
michael@0 13
michael@0 14 let TOPIC = "testing-async-shutdown-crash";
michael@0 15 let phase = AsyncShutdown._getPhase(TOPIC);
michael@0 16 phase.addBlocker("A blocker that is never satisfied", function() {
michael@0 17 dump("Installing blocker\n");
michael@0 18 let deferred = Promise.defer();
michael@0 19 return deferred.promise;
michael@0 20 });
michael@0 21
michael@0 22 Services.obs.notifyObservers(null, TOPIC, null);
michael@0 23 dump("Waiting for crash\n");
michael@0 24 }
michael@0 25
michael@0 26 function after_crash(mdump, extra) {
michael@0 27 do_print("after crash: " + extra.AsyncShutdownTimeout);
michael@0 28 let info = JSON.parse(extra.AsyncShutdownTimeout);
michael@0 29 do_check_eq(info.phase, "testing-async-shutdown-crash");
michael@0 30 do_print("Condition: " + JSON.stringify(info.conditions));
michael@0 31 do_check_true(JSON.stringify(info.conditions).indexOf("A blocker that is never satisfied") != -1);
michael@0 32 }
michael@0 33
michael@0 34 // Test that AsyncShutdown + OS.File reports errors correctly, in a case in which
michael@0 35 // the latest operation succeeded
michael@0 36
michael@0 37 function setup_osfile_crash_noerror() {
michael@0 38 Components.utils.import("resource://gre/modules/Services.jsm", this);
michael@0 39 Components.utils.import("resource://gre/modules/osfile.jsm", this);
michael@0 40
michael@0 41 Services.prefs.setBoolPref("toolkit.osfile.debug.failshutdown", true);
michael@0 42 Services.prefs.setIntPref("toolkit.asyncshutdown.crash_timeout", 1);
michael@0 43 Services.prefs.setBoolPref("toolkit.osfile.native", false);
michael@0 44
michael@0 45 OS.File.getCurrentDirectory();
michael@0 46 Services.obs.notifyObservers(null, "profile-before-change", null);
michael@0 47 dump("Waiting for crash\n");
michael@0 48 };
michael@0 49
michael@0 50 function after_osfile_crash_noerror(mdump, extra) {
michael@0 51 do_print("after OS.File crash: " + JSON.stringify(extra.AsyncShutdownTimeout));
michael@0 52 let info = JSON.parse(extra.AsyncShutdownTimeout);
michael@0 53 let state = info.conditions[0].state;
michael@0 54 do_print("Keys: " + Object.keys(state).join(", "));
michael@0 55 do_check_eq(info.phase, "profile-before-change");
michael@0 56 do_check_true(state.launched);
michael@0 57 do_check_false(state.shutdown);
michael@0 58 do_check_true(state.worker);
michael@0 59 do_check_true(!!state.latestSent);
michael@0 60 do_check_eq(state.latestSent[1], "getCurrentDirectory");
michael@0 61 }
michael@0 62
michael@0 63 // Test that AsyncShutdown + OS.File reports errors correctly, in a case in which
michael@0 64 // the latest operation failed
michael@0 65
michael@0 66 function setup_osfile_crash_exn() {
michael@0 67 Components.utils.import("resource://gre/modules/Services.jsm", this);
michael@0 68 Components.utils.import("resource://gre/modules/osfile.jsm", this);
michael@0 69
michael@0 70 Services.prefs.setBoolPref("toolkit.osfile.debug.failshutdown", true);
michael@0 71 Services.prefs.setIntPref("toolkit.asyncshutdown.crash_timeout", 1);
michael@0 72 Services.prefs.setBoolPref("toolkit.osfile.native", false);
michael@0 73
michael@0 74 OS.File.read("I do not exist");
michael@0 75 Services.obs.notifyObservers(null, "profile-before-change", null);
michael@0 76 dump("Waiting for crash\n");
michael@0 77 };
michael@0 78
michael@0 79 function after_osfile_crash_exn(mdump, extra) {
michael@0 80 do_print("after OS.File crash: " + JSON.stringify(extra.AsyncShutdownTimeout));
michael@0 81 let info = JSON.parse(extra.AsyncShutdownTimeout);
michael@0 82 let state = info.conditions[0].state;
michael@0 83 do_print("Keys: " + Object.keys(state).join(", "));
michael@0 84 do_check_eq(info.phase, "profile-before-change");
michael@0 85 do_check_false(state.shutdown);
michael@0 86 do_check_true(state.worker);
michael@0 87 do_check_true(!!state.latestSent);
michael@0 88 do_check_eq(state.latestSent[1], "read");
michael@0 89 }
michael@0 90
michael@0 91 function run_test() {
michael@0 92 do_crash(setup_crash, after_crash);
michael@0 93 do_crash(setup_osfile_crash_noerror, after_osfile_crash_noerror);
michael@0 94 do_crash(setup_osfile_crash_exn, after_osfile_crash_exn);
michael@0 95 }

mercurial