Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | function run_test() |
michael@0 | 2 | { |
michael@0 | 3 | dump("INFO | test_crashreporter.js | Get crashreporter service.\n"); |
michael@0 | 4 | var cr = Components.classes["@mozilla.org/toolkit/crash-reporter;1"] |
michael@0 | 5 | .getService(Components.interfaces.nsICrashReporter); |
michael@0 | 6 | do_check_neq(cr, null); |
michael@0 | 7 | |
michael@0 | 8 | do_check_true(cr.enabled); |
michael@0 | 9 | |
michael@0 | 10 | try { |
michael@0 | 11 | let su = cr.serverURL; |
michael@0 | 12 | do_throw("Getting serverURL when not set should have thrown!"); |
michael@0 | 13 | } |
michael@0 | 14 | catch (ex) { |
michael@0 | 15 | do_check_eq(ex.result, Components.results.NS_ERROR_FAILURE); |
michael@0 | 16 | } |
michael@0 | 17 | |
michael@0 | 18 | // check setting/getting serverURL |
michael@0 | 19 | var ios = Components.classes["@mozilla.org/network/io-service;1"] |
michael@0 | 20 | .getService(Components.interfaces.nsIIOService); |
michael@0 | 21 | |
michael@0 | 22 | // try it with two different URLs, just for kicks |
michael@0 | 23 | var testspecs = ["http://example.com/submit", |
michael@0 | 24 | "https://example.org/anothersubmit"]; |
michael@0 | 25 | for (var i = 0; i < testspecs.length; ++i) { |
michael@0 | 26 | cr.serverURL = ios.newURI(testspecs[i], null, null); |
michael@0 | 27 | do_check_eq(cr.serverURL.spec, testspecs[i]); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | // should not allow setting non-http/https URLs |
michael@0 | 31 | try { |
michael@0 | 32 | cr.serverURL = ios.newURI("ftp://example.com/submit", null, null); |
michael@0 | 33 | do_throw("Setting serverURL to a non-http(s) URL should have thrown!"); |
michael@0 | 34 | } |
michael@0 | 35 | catch (ex) { |
michael@0 | 36 | do_check_eq(ex.result, Components.results.NS_ERROR_INVALID_ARG); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | // check getting/setting minidumpPath |
michael@0 | 40 | // it should be $TEMP by default, but I'm not sure if we can exactly test that |
michael@0 | 41 | // this will at least test that it doesn't throw |
michael@0 | 42 | do_check_neq(cr.minidumpPath.path, ""); |
michael@0 | 43 | var cwd = do_get_cwd(); |
michael@0 | 44 | cr.minidumpPath = cwd; |
michael@0 | 45 | do_check_eq(cr.minidumpPath.path, cwd.path); |
michael@0 | 46 | |
michael@0 | 47 | try { |
michael@0 | 48 | cr.annotateCrashReport("equal=equal", ""); |
michael@0 | 49 | do_throw("Calling annotateCrashReport() with an '=' in key should have thrown!"); |
michael@0 | 50 | } |
michael@0 | 51 | catch (ex) { |
michael@0 | 52 | do_check_eq(ex.result, Components.results.NS_ERROR_INVALID_ARG); |
michael@0 | 53 | } |
michael@0 | 54 | try { |
michael@0 | 55 | cr.annotateCrashReport("new\nline", ""); |
michael@0 | 56 | do_throw("Calling annotateCrashReport() with a '\\n' in key should have thrown!"); |
michael@0 | 57 | } |
michael@0 | 58 | catch (ex) { |
michael@0 | 59 | do_check_eq(ex.result, Components.results.NS_ERROR_INVALID_ARG); |
michael@0 | 60 | } |
michael@0 | 61 | try { |
michael@0 | 62 | cr.annotateCrashReport("", "da\0ta"); |
michael@0 | 63 | do_throw("Calling annotateCrashReport() with a '\\0' in data should have thrown!"); |
michael@0 | 64 | } |
michael@0 | 65 | catch (ex) { |
michael@0 | 66 | do_check_eq(ex.result, Components.results.NS_ERROR_INVALID_ARG); |
michael@0 | 67 | } |
michael@0 | 68 | cr.annotateCrashReport("testKey", "testData1"); |
michael@0 | 69 | // Replace previous data. |
michael@0 | 70 | cr.annotateCrashReport("testKey", "testData2"); |
michael@0 | 71 | |
michael@0 | 72 | try { |
michael@0 | 73 | cr.appendAppNotesToCrashReport("da\0ta"); |
michael@0 | 74 | do_throw("Calling appendAppNotesToCrashReport() with a '\\0' in data should have thrown!"); |
michael@0 | 75 | } |
michael@0 | 76 | catch (ex) { |
michael@0 | 77 | do_check_eq(ex.result, Components.results.NS_ERROR_INVALID_ARG); |
michael@0 | 78 | } |
michael@0 | 79 | cr.appendAppNotesToCrashReport("additional testData3"); |
michael@0 | 80 | // Add more data. |
michael@0 | 81 | cr.appendAppNotesToCrashReport("additional testData4"); |
michael@0 | 82 | |
michael@0 | 83 | cr.minidumpPath = cwd; |
michael@0 | 84 | do_check_eq(cr.minidumpPath.path, cwd.path); |
michael@0 | 85 | } |