Bug 1580554 - AbuseReporter.openDialog should close and resolve as user cancelled a previous report dialog. r=mstriemer

Depends on D46019

Differential Revision: https://phabricator.services.mozilla.com/D46362

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Luca Greco 2019-10-07 16:03:20 +00:00
Родитель b6e9ea77e6
Коммит 562194ec83
4 изменённых файлов: 115 добавлений и 1 удалений

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

@ -243,6 +243,20 @@ const AbuseReporter = {
throw new Error("Abuse Reporter dialog cancelled, opener tab closed");
}
const windowName = "addons-abuse-report-dialog";
const dialogWin = Services.ww.getWindowByName(windowName, null);
if (dialogWin) {
// If an abuse report dialog is already open, cancel the
// previous report flow and start a new one.
const {
deferredReport,
promiseReport,
} = dialogWin.arguments[0].wrappedJSObject;
deferredReport.resolve({ userCancelled: true });
await promiseReport;
}
const report = await AbuseReporter.createAbuseReport(addonId, {
reportEntryPoint,
});
@ -296,7 +310,7 @@ const AbuseReporter = {
win = Services.ww.openWindow(
chromeWin,
"chrome://mozapps/content/extensions/abuse-report-frame.html",
"addons-abuse-report-dialog",
windowName,
// Set the dialog window options (including a reasonable initial
// window height size, eventually adjusted by the panel once it
// has been rendered its content).

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

@ -782,6 +782,18 @@ if (IS_DIALOG_WINDOW) {
deferredReportPanel,
} = window.arguments[0].wrappedJSObject;
window.addEventListener(
"unload",
() => {
// If the window has been closed resolve the deferredReport
// promise and reject the deferredReportPanel one, in case
// they haven't been resolved yet.
deferredReport.resolve({ userCancelled: true });
deferredReportPanel.reject(new Error("report dialog closed"));
},
{ once: true }
);
document.l10n.setAttributes(
document.querySelector("head > title"),
"abuse-report-dialog-title",
@ -800,6 +812,11 @@ if (IS_DIALOG_WINDOW) {
el.addEventListener(
"abuse-report:cancel",
() => {
// Resolve the report panel deferred (in case the report
// has been cancelled automatically before it has been fully
// rendered, e.g. in case of non-supported addon types).
deferredReportPanel.resolve(el);
// Resolve the deferred report as cancelled.
deferredReport.resolve({ userCancelled: true });
},
{ once: true }

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

@ -16,3 +16,85 @@ add_task(async function setup() {
// Add all the test tasks shared with browser_html_abuse_report.js.
addCommonAbuseReportTestTasks();
/**
* Test tasks specific to the abuse report opened in its own dialog window.
*/
add_task(async function test_report_triggered_when_report_dialog_is_open() {
const addonId = "addon-to-report@mochi.test";
const extension = await installTestExtension(addonId);
const reportDialog = await AbuseReporter.openDialog(
addonId,
"menu",
gBrowser.selectedBrowser
);
await AbuseReportTestUtils.promiseReportDialogRendered();
let promiseClosedWindow = waitClosedWindow();
const reportDialog2 = await AbuseReporter.openDialog(
addonId,
"menu",
gBrowser.selectedBrowser
);
await promiseClosedWindow;
// Trigger the report submit and check that the second report is
// resolved as expected.
await AbuseReportTestUtils.promiseReportDialogRendered();
ok(
!reportDialog.window || reportDialog.window.closed,
"expect the first dialog to be closed"
);
ok(!!reportDialog2.window, "expect the second dialog to be open");
is(
reportDialog2.window,
AbuseReportTestUtils.getReportDialog(),
"Got a report dialog as expected"
);
AbuseReportTestUtils.triggerSubmit("fake-reason", "fake-message");
// promiseReport is resolved to undefined if the report has been
// cancelled, otherwise it is resolved to a report object.
ok(
!(await reportDialog.promiseReport),
"expect the first report to be cancelled"
);
ok(
!!(await reportDialog2.promiseReport),
"expect the second report to be resolved"
);
await extension.unload();
});
add_task(async function test_report_dialog_window_closed_by_user() {
const addonId = "addon-to-report@mochi.test";
const extension = await installTestExtension(addonId);
const reportDialog = await AbuseReporter.openDialog(
addonId,
"menu",
gBrowser.selectedBrowser
);
await AbuseReportTestUtils.promiseReportDialogRendered();
let promiseClosedWindow = waitClosedWindow();
reportDialog.close();
await promiseClosedWindow;
ok(
!(await reportDialog.promiseReport),
"expect promiseReport to be resolved as user cancelled"
);
await extension.unload();
});

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

@ -4,6 +4,7 @@
/* eslint max-len: ["error", 80] */
/* exported installTestExtension, addCommonAbuseReportTestTasks,
* waitClosedWindow,
* AbuseReporter, AbuseReporterTestUtils, AddonTestUtils */
/* global mockPromptService, MockProvider, loadInitialView, closeView */