1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/crashreporter/test/unit/test_crashreporter_crash.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,49 @@ 1.4 +function run_test() 1.5 +{ 1.6 + if (!("@mozilla.org/toolkit/crash-reporter;1" in Components.classes)) { 1.7 + dump("INFO | test_crashreporter.js | Can't test crashreporter in a non-libxul build.\n"); 1.8 + return; 1.9 + } 1.10 + 1.11 + var is_win7_or_newer = false; 1.12 + var is_windows = false; 1.13 + var ph = Components.classes["@mozilla.org/network/protocol;1?name=http"] 1.14 + .getService(Components.interfaces.nsIHttpProtocolHandler); 1.15 + var match = ph.userAgent.match(/Windows NT (\d+).(\d+)/); 1.16 + if (match) { 1.17 + is_windows = true; 1.18 + } 1.19 + if (match && (parseInt(match[1]) > 6 || 1.20 + parseInt(match[1]) == 6 && parseInt(match[2]) >= 1)) { 1.21 + is_win7_or_newer = true; 1.22 + } 1.23 + 1.24 + // try a basic crash 1.25 + do_crash(null, function(mdump, extra) { 1.26 + do_check_true(mdump.exists()); 1.27 + do_check_true(mdump.fileSize > 0); 1.28 + do_check_true('StartupTime' in extra); 1.29 + do_check_true('CrashTime' in extra); 1.30 + do_check_true(CrashTestUtils.dumpHasStream(mdump.path, CrashTestUtils.MD_THREAD_LIST_STREAM)); 1.31 + do_check_true(CrashTestUtils.dumpHasInstructionPointerMemory(mdump.path)); 1.32 + if (is_windows) { 1.33 + ['SystemMemoryUsePercentage', 'TotalVirtualMemory', 'AvailableVirtualMemory', 1.34 + 'AvailablePageFile', 'AvailablePhysicalMemory'].forEach(function(prop) { 1.35 + do_check_true(/^\d+$/.test(extra[prop].toString())); 1.36 + }); 1.37 + } 1.38 + if (is_win7_or_newer) 1.39 + do_check_true(CrashTestUtils.dumpHasStream(mdump.path, CrashTestUtils.MD_MEMORY_INFO_LIST_STREAM)); 1.40 + }); 1.41 + 1.42 + // check setting some basic data 1.43 + do_crash(function() { 1.44 + crashReporter.annotateCrashReport("TestKey", "TestValue"); 1.45 + crashReporter.appendAppNotesToCrashReport("Junk"); 1.46 + crashReporter.appendAppNotesToCrashReport("MoreJunk"); 1.47 + }, 1.48 + function(mdump, extra) { 1.49 + do_check_eq(extra.TestKey, "TestValue"); 1.50 + do_check_eq(extra.Notes, "JunkMoreJunk"); 1.51 + }); 1.52 +}