michael@0: function run_test() michael@0: { michael@0: if (!("@mozilla.org/toolkit/crash-reporter;1" in Components.classes)) { michael@0: dump("INFO | test_crashreporter.js | Can't test crashreporter in a non-libxul build.\n"); michael@0: return; michael@0: } michael@0: michael@0: var is_win7_or_newer = false; michael@0: var is_windows = false; michael@0: var ph = Components.classes["@mozilla.org/network/protocol;1?name=http"] michael@0: .getService(Components.interfaces.nsIHttpProtocolHandler); michael@0: var match = ph.userAgent.match(/Windows NT (\d+).(\d+)/); michael@0: if (match) { michael@0: is_windows = true; michael@0: } michael@0: if (match && (parseInt(match[1]) > 6 || michael@0: parseInt(match[1]) == 6 && parseInt(match[2]) >= 1)) { michael@0: is_win7_or_newer = true; michael@0: } michael@0: michael@0: // try a basic crash michael@0: do_crash(null, function(mdump, extra) { michael@0: do_check_true(mdump.exists()); michael@0: do_check_true(mdump.fileSize > 0); michael@0: do_check_true('StartupTime' in extra); michael@0: do_check_true('CrashTime' in extra); michael@0: do_check_true(CrashTestUtils.dumpHasStream(mdump.path, CrashTestUtils.MD_THREAD_LIST_STREAM)); michael@0: do_check_true(CrashTestUtils.dumpHasInstructionPointerMemory(mdump.path)); michael@0: if (is_windows) { michael@0: ['SystemMemoryUsePercentage', 'TotalVirtualMemory', 'AvailableVirtualMemory', michael@0: 'AvailablePageFile', 'AvailablePhysicalMemory'].forEach(function(prop) { michael@0: do_check_true(/^\d+$/.test(extra[prop].toString())); michael@0: }); michael@0: } michael@0: if (is_win7_or_newer) michael@0: do_check_true(CrashTestUtils.dumpHasStream(mdump.path, CrashTestUtils.MD_MEMORY_INFO_LIST_STREAM)); michael@0: }); michael@0: michael@0: // check setting some basic data michael@0: do_crash(function() { michael@0: crashReporter.annotateCrashReport("TestKey", "TestValue"); michael@0: crashReporter.appendAppNotesToCrashReport("Junk"); michael@0: crashReporter.appendAppNotesToCrashReport("MoreJunk"); michael@0: }, michael@0: function(mdump, extra) { michael@0: do_check_eq(extra.TestKey, "TestValue"); michael@0: do_check_eq(extra.Notes, "JunkMoreJunk"); michael@0: }); michael@0: }