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