summaryrefslogtreecommitdiffstats
path: root/toolkit/components/places/tests/bookmarks/test_removeFolderTransaction_reinsert.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /toolkit/components/places/tests/bookmarks/test_removeFolderTransaction_reinsert.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/places/tests/bookmarks/test_removeFolderTransaction_reinsert.js')
-rw-r--r--toolkit/components/places/tests/bookmarks/test_removeFolderTransaction_reinsert.js115
1 files changed, 115 insertions, 0 deletions
diff --git a/toolkit/components/places/tests/bookmarks/test_removeFolderTransaction_reinsert.js b/toolkit/components/places/tests/bookmarks/test_removeFolderTransaction_reinsert.js
new file mode 100644
index 0000000000..1c9e55849d
--- /dev/null
+++ b/toolkit/components/places/tests/bookmarks/test_removeFolderTransaction_reinsert.js
@@ -0,0 +1,115 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+/**
+ * This test ensures that reinserting a folder within a transaction gives it
+ * the same GUID, and passes it to the observers.
+ */
+
+add_task(async function test_removeFolderTransaction_reinsert() {
+ let folder = await PlacesUtils.bookmarks.insert({
+ type: PlacesUtils.bookmarks.TYPE_FOLDER,
+ parentGuid: PlacesUtils.bookmarks.menuGuid,
+ title: "Test folder",
+ });
+ let fx = await PlacesUtils.bookmarks.insert({
+ parentGuid: folder.guid,
+ title: "Get Firefox!",
+ url: "http://getfirefox.com",
+ });
+ let tb = await PlacesUtils.bookmarks.insert({
+ parentGuid: folder.guid,
+ title: "Get Thunderbird!",
+ url: "http://getthunderbird.com",
+ });
+
+ let notifications = [];
+ function checkNotifications(expected, message) {
+ deepEqual(notifications, expected, message);
+ notifications.length = 0;
+ }
+
+ let listener = events => {
+ for (let event of events) {
+ notifications.push([
+ event.type,
+ event.id,
+ event.parentId,
+ event.guid,
+ event.parentGuid,
+ ]);
+ }
+ };
+ PlacesUtils.observers.addListener(
+ ["bookmark-added", "bookmark-removed"],
+ listener
+ );
+ PlacesUtils.registerShutdownFunction(function () {
+ PlacesUtils.observers.removeListener(
+ ["bookmark-added", "bookmark-removed"],
+ listener
+ );
+ });
+
+ let transaction = PlacesTransactions.Remove({ guid: folder.guid });
+
+ let folderId = await PlacesUtils.promiseItemId(folder.guid);
+ let fxId = await PlacesUtils.promiseItemId(fx.guid);
+ let tbId = await PlacesUtils.promiseItemId(tb.guid);
+
+ await transaction.transact();
+ let bookmarksMenuItemId = await PlacesUtils.promiseItemId(
+ PlacesUtils.bookmarks.menuGuid
+ );
+ checkNotifications(
+ [
+ ["bookmark-removed", tbId, folderId, tb.guid, folder.guid],
+ ["bookmark-removed", fxId, folderId, fx.guid, folder.guid],
+ [
+ "bookmark-removed",
+ folderId,
+ bookmarksMenuItemId,
+ folder.guid,
+ PlacesUtils.bookmarks.menuGuid,
+ ],
+ ],
+ "Executing transaction should remove folder and its descendants"
+ );
+
+ await PlacesTransactions.undo();
+
+ folderId = await PlacesUtils.promiseItemId(folder.guid);
+ fxId = await PlacesUtils.promiseItemId(fx.guid);
+ tbId = await PlacesUtils.promiseItemId(tb.guid);
+
+ checkNotifications(
+ [
+ [
+ "bookmark-added",
+ folderId,
+ bookmarksMenuItemId,
+ folder.guid,
+ PlacesUtils.bookmarks.menuGuid,
+ ],
+ ["bookmark-added", fxId, folderId, fx.guid, folder.guid],
+ ["bookmark-added", tbId, folderId, tb.guid, folder.guid],
+ ],
+ "Undo should reinsert folder with different id but same GUID"
+ );
+
+ await PlacesTransactions.redo();
+
+ checkNotifications(
+ [
+ ["bookmark-removed", tbId, folderId, tb.guid, folder.guid],
+ ["bookmark-removed", fxId, folderId, fx.guid, folder.guid],
+ [
+ "bookmark-removed",
+ folderId,
+ bookmarksMenuItemId,
+ folder.guid,
+ PlacesUtils.bookmarks.menuGuid,
+ ],
+ ],
+ "Redo should pass the GUID to observer"
+ );
+});