Bug 581341 - Part 5: Test. r=ted

This commit is contained in:
Josh Matthews 2011-06-08 16:21:20 -04:00
parent 038a99e073
commit 4bca65a31f
6 changed files with 85 additions and 3 deletions

View File

@ -78,6 +78,9 @@ skip-if = !debug
[include:toolkit/crashreporter/test/unit/xpcshell.ini]
skip-if = os == "linux" || !crashreporter
[include:toolkit/crashreporter/test/unit_ipc/xpcshell.ini]
skip-if.os == "linux" || !crashreporter
#XXX: we don't actually set os = maemo
[include:toolkit/crashreporter/client/maemo-unit/xpcshell.ini]
run-if = os == "maemo"

View File

@ -44,7 +44,7 @@ relativesrcdir = toolkit/crashreporter/test
include $(DEPTH)/config/autoconf.mk
MODULE = crashreporter_test
XPCSHELL_TESTS = unit
XPCSHELL_TESTS = unit unit_ipc
LIBRARY_NAME = testcrasher
NO_DIST_INSTALL = 1
@ -95,4 +95,5 @@ endif
libs:: $(SHARED_LIBRARY) $(EXTRA_JS_MODULES)
$(INSTALL) $^ $(DEPTH)/_tests/xpcshell/$(relativesrcdir)/unit/
$(INSTALL) $^ $(DEPTH)/_tests/xpcshell/$(relativesrcdir)/unit_ipc/

View File

@ -2,11 +2,19 @@
let cwd = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("CurWorkD", Components.interfaces.nsILocalFile);
let crashReporter =
Components.classes["@mozilla.org/toolkit/crash-reporter;1"]
.getService(Components.interfaces.nsICrashReporter);
crashReporter.enabled = true;
crashReporter.minidumpPath = cwd;
// the crash reporter is already enabled in content processes,
// and setting the minidump path is not allowed
let processType = Components.classes["@mozilla.org/xre/runtime;1"].
getService(Components.interfaces.nsIXULRuntime).processType;
if (processType == Components.interfaces.nsIXULRuntime.PROCESS_TYPE_DEFAULT) {
crashReporter.enabled = true;
crashReporter.minidumpPath = cwd;
}
let ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);

View File

@ -65,6 +65,11 @@ function do_crash(setup, callback, canReturnZero)
do_check_neq(process.exitValue, 0);
}
handleMinidump(callback);
}
function handleMinidump(callback)
{
// find minidump
let minidump = null;
let en = do_get_cwd().directoryEntries;
@ -101,6 +106,44 @@ function do_crash(setup, callback, canReturnZero)
extrafile.remove(false);
}
function do_content_crash(setup, callback)
{
do_load_child_test_harness();
do_test_pending();
// Setting the minidump path won't work in the child, so we need to do
// that here.
let crashReporter =
Components.classes["@mozilla.org/toolkit/crash-reporter;1"]
.getService(Components.interfaces.nsICrashReporter);
crashReporter.minidumpPath = do_get_cwd();
let headfile = do_get_file("../unit/crasher_subprocess_head.js");
let tailfile = do_get_file("../unit/crasher_subprocess_tail.js");
if (setup) {
if (typeof(setup) == "function")
// funky, but convenient
setup = "("+setup.toSource()+")();";
}
let handleCrash = function() {
try {
handleMinidump(callback);
} catch (x) {
do_report_unexpected_exception(x);
}
do_test_finished();
};
sendCommand("load(\"" + headfile.path.replace(/\\/g, "/") + "\");", function()
sendCommand(setup, function()
sendCommand("load(\"" + tailfile.path.replace(/\\/g, "/") + "\");",
function() do_execute_soon(handleCrash)
)
)
);
}
// Utility functions for parsing .extra files
function parseKeyValuePairs(text) {
var lines = text.split('\n');

View File

@ -0,0 +1,22 @@
load("../unit/head_crashreporter.js");
function run_test()
{
if (!("@mozilla.org/toolkit/crash-reporter;1" in Components.classes)) {
dump("INFO | test_content_annotation.js | Can't test crashreporter in a non-libxul build.\n");
return;
}
// Try crashing with a pure virtual call
do_content_crash(function() {
crashType = CrashTestUtils.CRASH_RUNTIMEABORT;
crashReporter.annotateCrashReport("TestKey", "TestValue");
crashReporter.appendAppNotesToCrashReport("!!!foo!!!");
},
function(mdump, extra) {
do_check_eq(extra.TestKey, "TestValue");
do_check_true('StartupTime' in extra);
do_check_true('ProcessType' in extra);
do_check_neq(extra.Notes.indexOf("!!!foo!!!"), -1);
});
}

View File

@ -0,0 +1,5 @@
[DEFAULT]
head = head_crashreporter.js
tail =
[test_content_annotation.js]