diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /services/sync/tests/unit/test_bookmark_record.js | |
parent | Initial commit. (diff) | |
download | firefox-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 'services/sync/tests/unit/test_bookmark_record.js')
-rw-r--r-- | services/sync/tests/unit/test_bookmark_record.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/services/sync/tests/unit/test_bookmark_record.js b/services/sync/tests/unit/test_bookmark_record.js new file mode 100644 index 0000000000..c261027ed9 --- /dev/null +++ b/services/sync/tests/unit/test_bookmark_record.js @@ -0,0 +1,64 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +const { Bookmark, BookmarkQuery, PlacesItem } = ChromeUtils.importESModule( + "resource://services-sync/engines/bookmarks.sys.mjs" +); +const { Service } = ChromeUtils.importESModule( + "resource://services-sync/service.sys.mjs" +); + +function prepareBookmarkItem(collection, id) { + let b = new Bookmark(collection, id); + b.cleartext.stuff = "my payload here"; + return b; +} + +add_task(async function test_bookmark_record() { + await configureIdentity(); + + await generateNewKeys(Service.collectionKeys); + let keyBundle = Service.identity.syncKeyBundle; + + _("Creating a record"); + + let placesItem = new PlacesItem("bookmarks", "foo", "bookmark"); + let bookmarkItem = prepareBookmarkItem("bookmarks", "foo"); + + _("Checking getTypeObject"); + Assert.equal(placesItem.getTypeObject(placesItem.type), Bookmark); + Assert.equal(bookmarkItem.getTypeObject(bookmarkItem.type), Bookmark); + + await bookmarkItem.encrypt(keyBundle); + _("Ciphertext is " + bookmarkItem.ciphertext); + Assert.ok(bookmarkItem.ciphertext != null); + + _("Decrypting the record"); + + let payload = await bookmarkItem.decrypt(keyBundle); + Assert.equal(payload.stuff, "my payload here"); + Assert.equal(bookmarkItem.getTypeObject(bookmarkItem.type), Bookmark); + Assert.notEqual(payload, bookmarkItem.payload); // wrap.data.payload is the encrypted one +}); + +add_task(async function test_query_foldername() { + // Bug 1443388 + let checks = [ + ["foo", "foo"], + ["", undefined], + ]; + for (let [inVal, outVal] of checks) { + let bmk1 = new BookmarkQuery("bookmarks", Utils.makeGUID()); + bmk1.fromSyncBookmark({ + url: Services.io.newURI("https://example.com"), + folder: inVal, + }); + Assert.strictEqual(bmk1.folderName, outVal); + + // other direction + let bmk2 = new BookmarkQuery("bookmarks", Utils.makeGUID()); + bmk2.folderName = inVal; + let record = bmk2.toSyncBookmark(); + Assert.strictEqual(record.folder, outVal); + } +}); |