Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
/* Any copyright is dedicated to the Public Domain.
"use strict";
const { sinon } = ChromeUtils.importESModule(
);
const { BookmarkList } = ChromeUtils.importESModule(
"resource://gre/modules/BookmarkList.sys.mjs"
);
registerCleanupFunction(
async () => await PlacesUtils.bookmarks.eraseEverything()
);
add_task(async function test_url_tracking() {
const firstBookmark = await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
});
const secondBookmark = await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
});
let deferredUpdate;
const bookmarkList = new BookmarkList(
[
],
() => deferredUpdate?.resolve()
);
async function waitForUpdateBookmarksTask(updateTask) {
deferredUpdate = Promise.withResolvers();
await updateTask();
return deferredUpdate.promise;
}
info("Check bookmark status of tracked URLs.");
info("Add a bookmark.");
await waitForUpdateBookmarksTask(() =>
PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
})
);
info("Remove a bookmark.");
await waitForUpdateBookmarksTask(() =>
PlacesUtils.bookmarks.remove(firstBookmark.guid)
);
info("Update a bookmark's URL.");
await waitForUpdateBookmarksTask(() =>
PlacesUtils.bookmarks.update({
guid: secondBookmark.guid,
})
);
info("Add a bookmark after removing listeners.");
bookmarkList.removeListeners();
await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
});
info("Reinitialize the list and validate bookmark status.");
bookmarkList.addListeners();
info("Cleanup.");
bookmarkList.removeListeners();
await PlacesUtils.bookmarks.eraseEverything();
});
add_task(async function test_no_unnecessary_observer_notifications() {
const spy = sinon.spy();
const bookmarkList = new BookmarkList(
spy,
0,
0
);
info("Add a bookmark with an untracked URL.");
await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
});
await new Promise(resolve => ChromeUtils.idleDispatch(resolve));
ok(spy.notCalled, "Observer was not notified.");
info("Add a bookmark after removing listeners.");
bookmarkList.removeListeners();
await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
});
await new Promise(resolve => ChromeUtils.idleDispatch(resolve));
ok(spy.notCalled, "Observer was not notified.");
});