Bug 1424373 - Don't set crash reporting prefs when showing about:tabcrashed for a crash without a report. r=Mossop

--HG--
extra : rebase_source : 3330154807a268c5cc85bfbf19c64f3a790d4aee
This commit is contained in:
Mike Conley 2017-12-18 11:19:53 -05:00
Родитель 001b4325b4
Коммит b27c33fa9d
5 изменённых файлов: 80 добавлений и 13 удалений

Просмотреть файл

@ -303,6 +303,7 @@ var AboutTabCrashed = {
includeURL,
URL,
autoSubmit,
hasReport: this.hasReport,
});
},
};

Просмотреть файл

@ -21,7 +21,7 @@ add_task(async function test_show_form() {
set: [[AUTOSUBMIT_PREF, false]],
});
return BrowserTestUtils.withNewTab({
await BrowserTestUtils.withNewTab({
gBrowser,
url: PAGE,
}, async function(browser) {
@ -69,7 +69,7 @@ add_task(async function test_show_form() {
set: [[AUTOSUBMIT_PREF, true]],
});
return BrowserTestUtils.withNewTab({
await BrowserTestUtils.withNewTab({
gBrowser,
url: PAGE,
}, async function(browser) {
@ -97,3 +97,58 @@ add_task(async function test_show_form() {
"Autosubmission pref should have been set.");
});
});
/**
* Tests that we properly set the autoSubmit preference if the user is
* presented with a tabcrashed page without a crash report.
*/
add_task(async function test_no_offer() {
// We should default to sending the report.
Assert.ok(TabCrashHandler.prefs.getBoolPref("sendReport"));
await SpecialPowers.pushPrefEnv({
set: [[AUTOSUBMIT_PREF, false]],
});
await BrowserTestUtils.withNewTab({
gBrowser,
url: PAGE,
}, async function(browser) {
await TabStateFlusher.flush(browser);
// Make it so that it seems like no dump is available for the next crash.
prepareNoDump();
// Now crash the browser.
await BrowserTestUtils.crashBrowser(browser);
// eslint-disable-next-line mozilla/no-cpows-in-tests
let doc = browser.contentDocument;
// Ensure the request to autosubmit is invisible, since there's no report.
let requestRect = doc.getElementById("requestAutoSubmit")
.getBoundingClientRect();
Assert.equal(0, requestRect.height,
"Request for autosubmission has no height");
Assert.equal(0, requestRect.width,
"Request for autosubmission has no width");
// Since the pref is set to false, the checkbox should be
// unchecked.
let autoSubmit = doc.getElementById("autoSubmit");
Assert.ok(!autoSubmit.checked,
"Checkbox for autosubmission is not checked.");
let restoreButton = doc.getElementById("restoreTab");
restoreButton.click();
await BrowserTestUtils.browserLoaded(browser, false, PAGE);
// The autosubmission pref should now be set.
Assert.ok(!Services.prefs.getBoolPref(AUTOSUBMIT_PREF),
"Autosubmission pref should not have changed.");
});
// We should not have changed the default value for sending the report.
Assert.ok(TabCrashHandler.prefs.getBoolPref("sendReport"));
});

Просмотреть файл

@ -2,16 +2,8 @@
const PAGE = "data:text/html,<html><body>A%20regular,%20everyday,%20normal%20page.";
/**
* Monkey patches TabCrashHandler.getDumpID to return null in order to test
* about:tabcrashed when a dump is not available.
*/
add_task(async function setup() {
let originalGetDumpID = TabCrashHandler.getDumpID;
TabCrashHandler.getDumpID = function(browser) { return null; };
registerCleanupFunction(() => {
TabCrashHandler.getDumpID = originalGetDumpID;
});
prepareNoDump();
});
/**

Просмотреть файл

@ -121,3 +121,15 @@ async function setupLocalCrashReportServer() {
env.set("MOZ_CRASHREPORTER_URL", serverUrl);
});
}
/**
* Monkey patches TabCrashHandler.getDumpID to return null in order to test
* about:tabcrashed when a dump is not available.
*/
function prepareNoDump() {
let originalGetDumpID = TabCrashHandler.getDumpID;
TabCrashHandler.getDumpID = function(browser) { return null; };
registerCleanupFunction(() => {
TabCrashHandler.getDumpID = originalGetDumpID;
});
}

Просмотреть файл

@ -368,8 +368,14 @@ this.TabCrashHandler = {
* even if they are empty.
*/
maybeSendCrashReport(message) {
if (!AppConstants.MOZ_CRASHREPORTER)
if (!AppConstants.MOZ_CRASHREPORTER) {
return;
}
if (!message.data.hasReport) {
// There was no report, so nothing to do.
return;
}
let browser = message.target.browser;
@ -381,8 +387,9 @@ this.TabCrashHandler = {
let childID = this.browserMap.get(browser);
let dumpID = this.childMap.get(childID);
if (!dumpID)
if (!dumpID) {
return;
}
if (!message.data.sendReport) {
Services.telemetry.getHistogramById("FX_CONTENT_CRASH_NOT_SUBMITTED").add(1);