Bug 1890427 - Part 8: Use an observer to regenerate backups on permission removal. r=backup-reviewers,kpatenio

Differential Revision: https://phabricator.services.mozilla.com/D218878
This commit is contained in:
Mike Conley
2024-09-04 17:56:58 +00:00
parent 7ca5c1c77a
commit b9636f86f1
2 changed files with 28 additions and 0 deletions

View File

@@ -3167,6 +3167,7 @@ export class BackupService extends EventTarget {
Services.obs.addObserver(this.#observer, "passwordmgr-storage-changed");
Services.obs.addObserver(this.#observer, "formautofill-storage-changed");
Services.obs.addObserver(this.#observer, "sanitizer-sanitization-complete");
Services.obs.addObserver(this.#observer, "perm-changed");
Services.obs.addObserver(this.#observer, "quit-application-granted");
}
@@ -3197,6 +3198,7 @@ export class BackupService extends EventTarget {
Services.obs.removeObserver(this.#observer, "passwordmgr-storage-changed");
Services.obs.removeObserver(this.#observer, "formautofill-storage-changed");
Services.obs.removeObserver(this.#observer, "perm-changed");
Services.obs.removeObserver(this.#observer, "quit-application-granted");
this.#observer = null;
@@ -3247,6 +3249,12 @@ export class BackupService extends EventTarget {
this.#debounceRegeneration();
break;
}
case "perm-changed": {
if (data == "deleted") {
this.#debounceRegeneration();
}
break;
}
}
}

View File

@@ -455,3 +455,23 @@ add_task(async function test_sanitization() {
await Sanitizer.sanitize(["siteSettings"]);
}, "Saw regeneration on sanitization of site settings.");
});
/**
* Tests that backup regeneration occurs after a permission is removed.
*/
add_task(async function test_permission_removed() {
let principal =
Services.scriptSecurityManager.createContentPrincipalFromOrigin(
"https://test-permission-site.com"
);
const PERMISSION_TYPE = "desktop-notification";
Services.perms.addFromPrincipal(
principal,
PERMISSION_TYPE,
Services.perms.ALLOW_ACTION
);
await expectRegeneration(async () => {
Services.perms.removeFromPrincipal(principal, PERMISSION_TYPE);
}, "Saw regeneration on permission removal.");
});