Bug 1394801 - Ensure livemarks are removed from the PlacesUIUtils livemark cache with async PlacesTransactions turned on. r=mak

MozReview-Commit-ID: B6ubzDhReCE

--HG--
extra : rebase_source : b22b0b878b2a5b5d1a588512e2729a3a9d3989f1
This commit is contained in:
Mark Banner 2017-08-29 17:06:34 +01:00
Родитель a77e898223
Коммит a1ca1b7842
3 изменённых файлов: 62 добавлений и 9 удалений

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

@ -56,25 +56,37 @@ function IsLivemark(aItemId) {
self.ids = new Set(idsVec);
let obs = Object.freeze({
QueryInterface: XPCOMUtils.generateQI(Ci.nsIAnnotationObserver),
QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarksObserver]),
onItemAnnotationSet(itemId, annoName) {
if (annoName == LIVEMARK_ANNO)
// Ci.nsINavBookmarkObserver items.
onItemChanged(itemId, property, isAnnoProperty, newValue, lastModified,
itemType, parentId, guid) {
if (isAnnoProperty && property == LIVEMARK_ANNO) {
self.ids.add(itemId);
}
},
onItemAnnotationRemoved(itemId, annoName) {
// If annoName is set to an empty string, the item is gone.
if (annoName == LIVEMARK_ANNO || annoName == "")
self.ids.delete(itemId);
onItemRemoved(itemId) {
// Since the bookmark is removed, we know we can remove any references
// to it from the cache.
self.ids.delete(itemId);
},
onItemAdded() {},
onBeginUpdateBatch() {},
onEndUpdateBatch() {},
onItemVisited() {},
onItemMoved() {},
onPageAnnotationSet() { },
onPageAnnotationRemoved() { },
skipDescendantsOnItemRemoval: false,
skipTags: false,
});
PlacesUtils.annotations.addObserver(obs);
PlacesUtils.bookmarks.addObserver(obs);
PlacesUtils.registerShutdownFunction(() => {
PlacesUtils.annotations.removeObserver(obs);
PlacesUtils.bookmarks.removeObserver(obs);
});
}
return self.ids.has(aItemId);

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

@ -0,0 +1,40 @@
"use strict";
let {IsLivemark} = Cu.import("resource:///modules/PlacesUIUtils.jsm", {});
add_task(function test_livemark_cache_builtin_folder() {
// This test checks a basic livemark, and also initializes the observer for
// updates to the bookmarks.
Assert.ok(!IsLivemark(PlacesUtils.unfiledBookmarksFolderId),
"unfiled bookmarks should not be seen as a livemark");
});
add_task(async function test_livemark_add_and_remove_items() {
let bookmark = await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
title: "Grandsire",
url: "http://example.com",
});
let bookmarkId = await PlacesUtils.promiseItemId(bookmark.guid);
Assert.ok(!IsLivemark(bookmarkId),
"a simple bookmark should not be seen as a livemark");
let livemark = await PlacesUtils.livemarks.addLivemark({
title: "Stedman",
feedURI: Services.io.newURI("http://livemark.com/"),
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
});
let livemarkId = await PlacesUtils.promiseItemId(livemark.guid);
Assert.ok(IsLivemark(livemarkId),
"a livemark should be reported as a livemark");
// Now remove the livemark.
await PlacesUtils.livemarks.removeLivemark(livemark);
Assert.ok(!IsLivemark(livemarkId),
"the livemark should have been removed from the cache");
});

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

@ -21,4 +21,5 @@ support-files =
[test_browserGlue_urlbar_defaultbehavior_migration.js]
[test_clearHistory_shutdown.js]
[test_leftpane_corruption_handling.js]
[test_PUIU_livemarksCache.js]
[test_PUIU_makeTransaction.js]