summaryrefslogtreecommitdiffstats
path: root/toolkit/components/places/tests/unit/test_PlacesUtils_invalidateCachedGuids.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /toolkit/components/places/tests/unit/test_PlacesUtils_invalidateCachedGuids.js
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/places/tests/unit/test_PlacesUtils_invalidateCachedGuids.js')
-rw-r--r--toolkit/components/places/tests/unit/test_PlacesUtils_invalidateCachedGuids.js86
1 files changed, 86 insertions, 0 deletions
diff --git a/toolkit/components/places/tests/unit/test_PlacesUtils_invalidateCachedGuids.js b/toolkit/components/places/tests/unit/test_PlacesUtils_invalidateCachedGuids.js
new file mode 100644
index 0000000000..33bf696a29
--- /dev/null
+++ b/toolkit/components/places/tests/unit/test_PlacesUtils_invalidateCachedGuids.js
@@ -0,0 +1,86 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+async function changeGuid(db, id, newGuid) {
+ await db.execute(
+ `UPDATE moz_bookmarks SET
+ guid = :newGuid
+ WHERE id = :id`,
+ { id, newGuid }
+ );
+}
+
+add_task(async function test_invalidateCachedGuids() {
+ info("Add bookmarks");
+ await PlacesUtils.bookmarks.insertTree({
+ guid: PlacesUtils.bookmarks.unfiledGuid,
+ children: [
+ {
+ guid: "bookmarkAAAA",
+ url: "http://example.com/a",
+ title: "A",
+ },
+ {
+ guid: "bookmarkBBBB",
+ url: "http://example.com/b",
+ title: "B",
+ },
+ ],
+ });
+
+ let ids = await PlacesUtils.promiseManyItemIds([
+ "bookmarkAAAA",
+ "bookmarkBBBB",
+ ]);
+ Assert.equal(
+ await PlacesUtils.promiseItemGuid(ids.get("bookmarkAAAA")),
+ "bookmarkAAAA"
+ );
+ Assert.equal(
+ await PlacesUtils.promiseItemGuid(ids.get("bookmarkBBBB")),
+ "bookmarkBBBB"
+ );
+
+ info("Change GUIDs");
+ await PlacesUtils.withConnectionWrapper(
+ "test_invalidateCachedGuids",
+ async function(db) {
+ await db.executeTransaction(async function() {
+ await changeGuid(db, ids.get("bookmarkAAAA"), "bookmarkCCCC");
+ await changeGuid(db, ids.get("bookmarkBBBB"), "bookmarkDDDD");
+ });
+ }
+ );
+ Assert.equal(
+ await PlacesUtils.promiseItemId("bookmarkAAAA"),
+ ids.get("bookmarkAAAA")
+ );
+ Assert.equal(
+ await PlacesUtils.promiseItemId("bookmarkBBBB"),
+ ids.get("bookmarkBBBB")
+ );
+
+ info("Invalidate the cache");
+ PlacesUtils.invalidateCachedGuids();
+
+ let newIds = await PlacesUtils.promiseManyItemIds([
+ "bookmarkCCCC",
+ "bookmarkDDDD",
+ ]);
+ Assert.equal(
+ await PlacesUtils.promiseItemGuid(newIds.get("bookmarkCCCC")),
+ "bookmarkCCCC"
+ );
+ Assert.equal(
+ await PlacesUtils.promiseItemGuid(newIds.get("bookmarkDDDD")),
+ "bookmarkDDDD"
+ );
+ await Assert.rejects(
+ PlacesUtils.promiseItemId("bookmarkAAAA"),
+ /no item found for the given GUID/
+ );
+ await Assert.rejects(
+ PlacesUtils.promiseItemId("bookmarkBBBB"),
+ /no item found for the given GUID/
+ );
+});