michael@0: function run_test() michael@0: { michael@0: dump("INFO | test_crashreporter.js | Get crashreporter service.\n"); michael@0: var cr = Components.classes["@mozilla.org/toolkit/crash-reporter;1"] michael@0: .getService(Components.interfaces.nsICrashReporter); michael@0: do_check_neq(cr, null); michael@0: michael@0: do_check_true(cr.enabled); michael@0: michael@0: try { michael@0: let su = cr.serverURL; michael@0: do_throw("Getting serverURL when not set should have thrown!"); michael@0: } michael@0: catch (ex) { michael@0: do_check_eq(ex.result, Components.results.NS_ERROR_FAILURE); michael@0: } michael@0: michael@0: // check setting/getting serverURL michael@0: var ios = Components.classes["@mozilla.org/network/io-service;1"] michael@0: .getService(Components.interfaces.nsIIOService); michael@0: michael@0: // try it with two different URLs, just for kicks michael@0: var testspecs = ["http://example.com/submit", michael@0: "https://example.org/anothersubmit"]; michael@0: for (var i = 0; i < testspecs.length; ++i) { michael@0: cr.serverURL = ios.newURI(testspecs[i], null, null); michael@0: do_check_eq(cr.serverURL.spec, testspecs[i]); michael@0: } michael@0: michael@0: // should not allow setting non-http/https URLs michael@0: try { michael@0: cr.serverURL = ios.newURI("ftp://example.com/submit", null, null); michael@0: do_throw("Setting serverURL to a non-http(s) URL should have thrown!"); michael@0: } michael@0: catch (ex) { michael@0: do_check_eq(ex.result, Components.results.NS_ERROR_INVALID_ARG); michael@0: } michael@0: michael@0: // check getting/setting minidumpPath michael@0: // it should be $TEMP by default, but I'm not sure if we can exactly test that michael@0: // this will at least test that it doesn't throw michael@0: do_check_neq(cr.minidumpPath.path, ""); michael@0: var cwd = do_get_cwd(); michael@0: cr.minidumpPath = cwd; michael@0: do_check_eq(cr.minidumpPath.path, cwd.path); michael@0: michael@0: try { michael@0: cr.annotateCrashReport("equal=equal", ""); michael@0: do_throw("Calling annotateCrashReport() with an '=' in key should have thrown!"); michael@0: } michael@0: catch (ex) { michael@0: do_check_eq(ex.result, Components.results.NS_ERROR_INVALID_ARG); michael@0: } michael@0: try { michael@0: cr.annotateCrashReport("new\nline", ""); michael@0: do_throw("Calling annotateCrashReport() with a '\\n' in key should have thrown!"); michael@0: } michael@0: catch (ex) { michael@0: do_check_eq(ex.result, Components.results.NS_ERROR_INVALID_ARG); michael@0: } michael@0: try { michael@0: cr.annotateCrashReport("", "da\0ta"); michael@0: do_throw("Calling annotateCrashReport() with a '\\0' in data should have thrown!"); michael@0: } michael@0: catch (ex) { michael@0: do_check_eq(ex.result, Components.results.NS_ERROR_INVALID_ARG); michael@0: } michael@0: cr.annotateCrashReport("testKey", "testData1"); michael@0: // Replace previous data. michael@0: cr.annotateCrashReport("testKey", "testData2"); michael@0: michael@0: try { michael@0: cr.appendAppNotesToCrashReport("da\0ta"); michael@0: do_throw("Calling appendAppNotesToCrashReport() with a '\\0' in data should have thrown!"); michael@0: } michael@0: catch (ex) { michael@0: do_check_eq(ex.result, Components.results.NS_ERROR_INVALID_ARG); michael@0: } michael@0: cr.appendAppNotesToCrashReport("additional testData3"); michael@0: // Add more data. michael@0: cr.appendAppNotesToCrashReport("additional testData4"); michael@0: michael@0: cr.minidumpPath = cwd; michael@0: do_check_eq(cr.minidumpPath.path, cwd.path); michael@0: }