Bug 1890427 - Part 3: Use a PlacesObserver to regenerate backups when a bookmark is deleted. r=backup-reviewers,kpatenio

Differential Revision: https://phabricator.services.mozilla.com/D218886
This commit is contained in:
Mike Conley
2024-09-04 17:56:56 +00:00
parent a534022f9b
commit b54ccf35a1
2 changed files with 39 additions and 2 deletions

View File

@@ -3155,7 +3155,7 @@ export class BackupService extends EventTarget {
this.onPlacesEvents.bind(this)
);
PlacesObservers.addListener(
["history-cleared", "page-removed"],
["history-cleared", "page-removed", "bookmark-removed"],
this.#placesObserver
);
@@ -3182,7 +3182,7 @@ export class BackupService extends EventTarget {
);
PlacesObservers.removeListener(
["history-cleared", "page-removed"],
["history-cleared", "page-removed", "bookmark-removed"],
this.#placesObserver
);
@@ -3323,6 +3323,8 @@ export class BackupService extends EventTarget {
}
break;
}
case "bookmark-removed":
// Intentional fall-through
case "history-cleared": {
this.#debounceRegeneration();
return;

View File

@@ -327,3 +327,38 @@ add_task(async function test_all_passwords_removed() {
Services.logins.removeAllLogins();
}, "Saw regeneration on all passwords removed.");
});
/**
* Tests that backup regeneration occurs when removing a bookmark.
*/
add_task(async function test_bookmark_removed() {
let bookmark = await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: "data:text/plain,Content",
title: "Regeneration Test Bookmark",
});
await expectRegeneration(async () => {
await PlacesUtils.bookmarks.remove(bookmark);
}, "Saw regeneration on bookmark removed.");
});
/**
* Tests that backup regeneration occurs when all bookmarks are removed.
*/
add_task(async function test_all_bookmarks_removed() {
await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: "data:text/plain,Content",
title: "Regeneration Test Bookmark 1",
});
await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: "data:text/plain,Content2",
title: "Regeneration Test Bookmark 2",
});
await expectRegeneration(async () => {
await PlacesUtils.bookmarks.eraseEverything();
}, "Saw regeneration on all bookmarks removed.");
});