1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/crashreporter/test/unit/test_crashreporter.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,85 @@ 1.4 +function run_test() 1.5 +{ 1.6 + dump("INFO | test_crashreporter.js | Get crashreporter service.\n"); 1.7 + var cr = Components.classes["@mozilla.org/toolkit/crash-reporter;1"] 1.8 + .getService(Components.interfaces.nsICrashReporter); 1.9 + do_check_neq(cr, null); 1.10 + 1.11 + do_check_true(cr.enabled); 1.12 + 1.13 + try { 1.14 + let su = cr.serverURL; 1.15 + do_throw("Getting serverURL when not set should have thrown!"); 1.16 + } 1.17 + catch (ex) { 1.18 + do_check_eq(ex.result, Components.results.NS_ERROR_FAILURE); 1.19 + } 1.20 + 1.21 + // check setting/getting serverURL 1.22 + var ios = Components.classes["@mozilla.org/network/io-service;1"] 1.23 + .getService(Components.interfaces.nsIIOService); 1.24 + 1.25 + // try it with two different URLs, just for kicks 1.26 + var testspecs = ["http://example.com/submit", 1.27 + "https://example.org/anothersubmit"]; 1.28 + for (var i = 0; i < testspecs.length; ++i) { 1.29 + cr.serverURL = ios.newURI(testspecs[i], null, null); 1.30 + do_check_eq(cr.serverURL.spec, testspecs[i]); 1.31 + } 1.32 + 1.33 + // should not allow setting non-http/https URLs 1.34 + try { 1.35 + cr.serverURL = ios.newURI("ftp://example.com/submit", null, null); 1.36 + do_throw("Setting serverURL to a non-http(s) URL should have thrown!"); 1.37 + } 1.38 + catch (ex) { 1.39 + do_check_eq(ex.result, Components.results.NS_ERROR_INVALID_ARG); 1.40 + } 1.41 + 1.42 + // check getting/setting minidumpPath 1.43 + // it should be $TEMP by default, but I'm not sure if we can exactly test that 1.44 + // this will at least test that it doesn't throw 1.45 + do_check_neq(cr.minidumpPath.path, ""); 1.46 + var cwd = do_get_cwd(); 1.47 + cr.minidumpPath = cwd; 1.48 + do_check_eq(cr.minidumpPath.path, cwd.path); 1.49 + 1.50 + try { 1.51 + cr.annotateCrashReport("equal=equal", ""); 1.52 + do_throw("Calling annotateCrashReport() with an '=' in key should have thrown!"); 1.53 + } 1.54 + catch (ex) { 1.55 + do_check_eq(ex.result, Components.results.NS_ERROR_INVALID_ARG); 1.56 + } 1.57 + try { 1.58 + cr.annotateCrashReport("new\nline", ""); 1.59 + do_throw("Calling annotateCrashReport() with a '\\n' in key should have thrown!"); 1.60 + } 1.61 + catch (ex) { 1.62 + do_check_eq(ex.result, Components.results.NS_ERROR_INVALID_ARG); 1.63 + } 1.64 + try { 1.65 + cr.annotateCrashReport("", "da\0ta"); 1.66 + do_throw("Calling annotateCrashReport() with a '\\0' in data should have thrown!"); 1.67 + } 1.68 + catch (ex) { 1.69 + do_check_eq(ex.result, Components.results.NS_ERROR_INVALID_ARG); 1.70 + } 1.71 + cr.annotateCrashReport("testKey", "testData1"); 1.72 + // Replace previous data. 1.73 + cr.annotateCrashReport("testKey", "testData2"); 1.74 + 1.75 + try { 1.76 + cr.appendAppNotesToCrashReport("da\0ta"); 1.77 + do_throw("Calling appendAppNotesToCrashReport() with a '\\0' in data should have thrown!"); 1.78 + } 1.79 + catch (ex) { 1.80 + do_check_eq(ex.result, Components.results.NS_ERROR_INVALID_ARG); 1.81 + } 1.82 + cr.appendAppNotesToCrashReport("additional testData3"); 1.83 + // Add more data. 1.84 + cr.appendAppNotesToCrashReport("additional testData4"); 1.85 + 1.86 + cr.minidumpPath = cwd; 1.87 + do_check_eq(cr.minidumpPath.path, cwd.path); 1.88 +}