commit d3820fa60d5aef5caeef3f892e4f2462b241d37a
parent c41e8cbc9278967392559e42dce29626c0173c64
Author: Duncan McIntosh <dmcintosh@mozilla.com>
Date: Fri, 7 Nov 2025 16:52:05 +0000
Bug 1997642 - Don't check if dialogs are open before closing them. r=sthompson
Differential Revision: https://phabricator.services.mozilla.com/D271292
Diffstat:
2 files changed, 58 insertions(+), 10 deletions(-)
diff --git a/browser/components/backup/content/backup-settings.mjs b/browser/components/backup/content/backup-settings.mjs
@@ -77,6 +77,16 @@ export default class BackupSettings extends MozLitElement {
};
}
+ get dialogs() {
+ return [
+ this.disableBackupEncryptionDialogEl,
+ this.enableBackupEncryptionDialogEl,
+ this.turnOnScheduledBackupsDialogEl,
+ this.turnOffScheduledBackupsDialogEl,
+ this.restoreFromBackupDialogEl,
+ ];
+ }
+
/**
* Creates a BackupPreferences instance and sets the initial default
* state.
@@ -154,16 +164,8 @@ export default class BackupSettings extends MozLitElement {
handleEvent(event) {
switch (event.type) {
case "dialogCancel":
- if (this.turnOnScheduledBackupsDialogEl.open) {
- this.turnOnScheduledBackupsDialogEl.close();
- } else if (this.turnOffScheduledBackupsDialogEl.open) {
- this.turnOffScheduledBackupsDialogEl.close();
- } else if (this.restoreFromBackupDialogEl.open) {
- this.restoreFromBackupDialogEl.close();
- } else if (this.disableBackupEncryptionDialogEl.open) {
- this.disableBackupEncryptionDialogEl.close();
- } else if (this.enableBackupEncryptionDialogEl.open) {
- this.enableBackupEncryptionDialogEl.close();
+ for (let dialog of this.dialogs) {
+ dialog?.close();
}
break;
case "restoreFromBackupConfirm":
diff --git a/browser/components/backup/tests/browser/browser_settings.js b/browser/components/backup/tests/browser/browser_settings.js
@@ -479,3 +479,49 @@ add_task(async function test_last_backup_info_and_location() {
});
await SpecialPowers.popPrefEnv();
});
+
+add_task(async function test_dialogs_close_on_cancel_with_restore_disabled() {
+ await SpecialPowers.pushPrefEnv({
+ set: [
+ [BACKUP_ARCHIVE_ENABLED_PREF, true],
+ [BACKUP_RESTORE_ENABLED_PREF, false],
+ ],
+ });
+
+ await BrowserTestUtils.withNewTab("about:preferences#sync", async browser => {
+ let settings = browser.contentDocument.querySelector("backup-settings");
+ await settings.updateComplete;
+
+ for (let dialog of settings.dialogs.filter(element => !!element)) {
+ dialog.showModal();
+ is(dialog.open, true, `${dialog.id} was opened.`);
+ settings.dispatchEvent(new CustomEvent("dialogCancel"));
+ is(dialog.open, false, `${dialog.id} was closed by dialogCancel.`);
+ }
+ });
+
+ await SpecialPowers.popPrefEnv();
+});
+
+add_task(async function test_dialogs_close_on_cancel_with_archive_disabled() {
+ await SpecialPowers.pushPrefEnv({
+ set: [
+ [BACKUP_ARCHIVE_ENABLED_PREF, false],
+ [BACKUP_RESTORE_ENABLED_PREF, true],
+ ],
+ });
+
+ await BrowserTestUtils.withNewTab("about:preferences#sync", async browser => {
+ let settings = browser.contentDocument.querySelector("backup-settings");
+ await settings.updateComplete;
+
+ for (let dialog of settings.dialogs.filter(element => !!element)) {
+ dialog.showModal();
+ is(dialog.open, true, `${dialog.id} was opened.`);
+ settings.dispatchEvent(new CustomEvent("dialogCancel"));
+ is(dialog.open, false, `${dialog.id} was closed by dialogCancel.`);
+ }
+ });
+
+ await SpecialPowers.popPrefEnv();
+});