summaryrefslogtreecommitdiffstats
path: root/testing/condprofile/condprof/scenarii/bookmark.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /testing/condprofile/condprof/scenarii/bookmark.js
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/condprofile/condprof/scenarii/bookmark.js')
-rw-r--r--testing/condprofile/condprof/scenarii/bookmark.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/testing/condprofile/condprof/scenarii/bookmark.js b/testing/condprofile/condprof/scenarii/bookmark.js
new file mode 100644
index 0000000000..70ef028320
--- /dev/null
+++ b/testing/condprofile/condprof/scenarii/bookmark.js
@@ -0,0 +1,52 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+// 'arguments' is defined by the marionette harness.
+/* global arguments */
+
+const { PlacesUtils } = ChromeUtils.importESModule(
+ "resource://gre/modules/PlacesUtils.sys.mjs"
+);
+
+let resolve = arguments[3];
+
+try {
+ // Get the number of current bookmarks
+ PlacesUtils.promiseBookmarksTree(PlacesUtils.bookmarks.unfiledGuid, {
+ includeItemIds: true,
+ }).then(root => {
+ let count = root.itemsCount;
+ let maxBookmarks = arguments[2];
+ // making sure we don't exceed the maximum number of bookmarks
+ if (count >= maxBookmarks) {
+ let toRemove = count - maxBookmarks + 1;
+ console.log("We've reached the maximum number of bookmarks");
+ console.log("Removing " + toRemove);
+ let children = root.children;
+ for (let i = 0, p = Promise.resolve(); i < toRemove; i++) {
+ p = p.then(
+ _ =>
+ new Promise(resolve =>
+ PlacesUtils.bookmarks.remove(children[i].guid).then(res => {
+ console.log("removed one bookmark");
+ resolve(res);
+ })
+ )
+ );
+ }
+ }
+ // now adding the bookmark
+ PlacesUtils.bookmarks
+ .insert({
+ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+ url: arguments[0],
+ title: arguments[1],
+ })
+ .then(res => {
+ resolve(res);
+ });
+ });
+} catch (error) {
+ let res = { logs: {}, result: 1, result_message: error.toString() };
+ resolve(res);
+}