1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/crashreporter/test/browser/browser_aboutCrashesResubmit.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,146 @@ 1.4 +function cleanup_and_finish() { 1.5 + try { 1.6 + cleanup_fake_appdir(); 1.7 + } catch(ex) {} 1.8 + Services.prefs.clearUserPref("breakpad.reportURL"); 1.9 + gBrowser.removeTab(gBrowser.selectedTab); 1.10 + finish(); 1.11 +} 1.12 + 1.13 +/* 1.14 + * check_crash_list 1.15 + * 1.16 + * Check that the list of crashes displayed by about:crashes matches 1.17 + * the list of crashes that we placed in the pending+submitted directories. 1.18 + */ 1.19 +function check_crash_list(tab, crashes) { 1.20 + let doc = gBrowser.getBrowserForTab(tab).contentDocument; 1.21 + let crashlinks = doc.getElementById("tbody").getElementsByTagName("a"); 1.22 + is(crashlinks.length, crashes.length, 1.23 + "about:crashes lists correct number of crash reports"); 1.24 + // no point in checking this if the lists aren't the same length 1.25 + if (crashlinks.length == crashes.length) { 1.26 + for(let i=0; i<crashes.length; i++) { 1.27 + is(crashlinks[i].id, crashes[i].id, i + ": crash ID is correct"); 1.28 + if (crashes[i].pending) { 1.29 + // we set the breakpad.reportURL pref in test() 1.30 + is(crashlinks[i].getAttribute("href"), 1.31 + "http://example.com/browser/toolkit/crashreporter/about/throttling", 1.32 + "pending URL links to the correct static page"); 1.33 + } 1.34 + } 1.35 + } 1.36 +} 1.37 + 1.38 +/* 1.39 + * check_submit_pending 1.40 + * 1.41 + * Click on a pending crash in about:crashes, wait for it to be submitted (which 1.42 + * should redirect us to the crash report page). Verify that the data provided 1.43 + * by our test crash report server matches the data we submitted. 1.44 + * Additionally, click "back" and verify that the link now points to our new 1.45 + */ 1.46 +function check_submit_pending(tab, crashes) { 1.47 + let browser = gBrowser.getBrowserForTab(tab); 1.48 + let SubmittedCrash = null; 1.49 + let CrashID = null; 1.50 + let CrashURL = null; 1.51 + function csp_onload() { 1.52 + if (browser.contentWindow.location != 'about:crashes') { 1.53 + browser.removeEventListener("load", csp_onload, true); 1.54 + // loaded the crash report page 1.55 + ok(true, 'got submission onload'); 1.56 + // grab the Crash ID here to verify later 1.57 + CrashID = browser.contentWindow.location.search.split("=")[1]; 1.58 + CrashURL = browser.contentWindow.location.toString(); 1.59 + // check the JSON content vs. what we submitted 1.60 + let result = JSON.parse(browser.contentDocument.documentElement.textContent); 1.61 + is(result.upload_file_minidump, "MDMP", "minidump file sent properly"); 1.62 + is(result.Throttleable, 0, "correctly sent as non-throttleable"); 1.63 + // we checked these, they're set by the submission process, 1.64 + // so they won't be in the "extra" data. 1.65 + delete result.upload_file_minidump; 1.66 + delete result.Throttleable; 1.67 + // Likewise, this is discarded before it gets to the server 1.68 + delete SubmittedCrash.extra.ServerURL; 1.69 + 1.70 + for(let x in result) { 1.71 + if (x in SubmittedCrash.extra) 1.72 + is(result[x], SubmittedCrash.extra[x], 1.73 + "submitted value for " + x + " matches expected"); 1.74 + else 1.75 + ok(false, "property " + x + " missing from submitted data!"); 1.76 + } 1.77 + for(let y in SubmittedCrash.extra) { 1.78 + if (!(y in result)) 1.79 + ok(false, "property " + y + " missing from result data!"); 1.80 + } 1.81 + executeSoon(function() { 1.82 + browser.addEventListener("pageshow", csp_pageshow, true); 1.83 + // now navigate back 1.84 + browser.goBack(); 1.85 + }); 1.86 + } 1.87 + } 1.88 + function csp_fail() { 1.89 + browser.removeEventListener("CrashSubmitFailed", csp_fail, true); 1.90 + ok(false, "failed to submit crash report!"); 1.91 + cleanup_and_finish(); 1.92 + } 1.93 + browser.addEventListener("CrashSubmitFailed", csp_fail, true); 1.94 + browser.addEventListener("load", csp_onload, true); 1.95 + function csp_pageshow() { 1.96 + browser.removeEventListener("pageshow", csp_pageshow, true); 1.97 + executeSoon(function () { 1.98 + is(browser.contentWindow.location, "about:crashes", "navigated back successfully"); 1.99 + let link = browser.contentDocument.getElementById(CrashID); 1.100 + isnot(link, null, "crash report link changed correctly"); 1.101 + if (link) 1.102 + is(link.href, CrashURL, "crash report link points to correct href"); 1.103 + cleanup_and_finish(); 1.104 + }); 1.105 + } 1.106 + 1.107 + // try submitting the pending report 1.108 + for each(let crash in crashes) { 1.109 + if (crash.pending) { 1.110 + SubmittedCrash = crash; 1.111 + break; 1.112 + } 1.113 + } 1.114 + EventUtils.sendMouseEvent({type:'click'}, SubmittedCrash.id, 1.115 + browser.contentWindow); 1.116 +} 1.117 + 1.118 +function test() { 1.119 + waitForExplicitFinish(); 1.120 + let appD = make_fake_appdir(); 1.121 + let crD = appD.clone(); 1.122 + crD.append("Crash Reports"); 1.123 + let crashes = add_fake_crashes(crD, 1); 1.124 + // we don't need much data here, it's not going to a real Socorro 1.125 + crashes.push(addPendingCrashreport(crD, 1.126 + crashes[crashes.length - 1].date + 60000, 1.127 + {'ServerURL': 'http://example.com/browser/toolkit/crashreporter/test/browser/crashreport.sjs', 1.128 + 'ProductName': 'Test App', 1.129 + // test that we don't truncate 1.130 + // at = (bug 512853) 1.131 + 'Foo': 'ABC=XYZ' 1.132 + })); 1.133 + crashes.sort(function(a,b) b.date - a.date); 1.134 + 1.135 + // set this pref so we can link to our test server 1.136 + Services.prefs.setCharPref("breakpad.reportURL", 1.137 + "http://example.com/browser/toolkit/crashreporter/test/browser/crashreport.sjs?id="); 1.138 + 1.139 + let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank"); 1.140 + let browser = gBrowser.getBrowserForTab(tab); 1.141 + browser.addEventListener("load", function test_load() { 1.142 + browser.removeEventListener("load", test_load, true); 1.143 + executeSoon(function () { 1.144 + check_crash_list(tab, crashes); 1.145 + check_submit_pending(tab, crashes); 1.146 + }); 1.147 + }, true); 1.148 + browser.loadURI("about:crashes", null, null); 1.149 +}