test_bookmark_record.js (2048B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 const { Bookmark, BookmarkQuery, PlacesItem } = ChromeUtils.importESModule( 5 "resource://services-sync/engines/bookmarks.sys.mjs" 6 ); 7 const { Service } = ChromeUtils.importESModule( 8 "resource://services-sync/service.sys.mjs" 9 ); 10 11 function prepareBookmarkItem(collection, id) { 12 let b = new Bookmark(collection, id); 13 b.cleartext.stuff = "my payload here"; 14 return b; 15 } 16 17 add_task(async function test_bookmark_record() { 18 await configureIdentity(); 19 20 await generateNewKeys(Service.collectionKeys); 21 let keyBundle = Service.identity.syncKeyBundle; 22 23 _("Creating a record"); 24 25 let placesItem = new PlacesItem("bookmarks", "foo", "bookmark"); 26 let bookmarkItem = prepareBookmarkItem("bookmarks", "foo"); 27 28 _("Checking getTypeObject"); 29 Assert.equal(placesItem.getTypeObject(placesItem.type), Bookmark); 30 Assert.equal(bookmarkItem.getTypeObject(bookmarkItem.type), Bookmark); 31 32 await bookmarkItem.encrypt(keyBundle); 33 _("Ciphertext is " + bookmarkItem.ciphertext); 34 Assert.notEqual(bookmarkItem.ciphertext, null); 35 36 _("Decrypting the record"); 37 38 let payload = await bookmarkItem.decrypt(keyBundle); 39 Assert.equal(payload.stuff, "my payload here"); 40 Assert.equal(bookmarkItem.getTypeObject(bookmarkItem.type), Bookmark); 41 Assert.notEqual(payload, bookmarkItem.payload); // wrap.data.payload is the encrypted one 42 }); 43 44 add_task(async function test_query_foldername() { 45 // Bug 1443388 46 let checks = [ 47 ["foo", "foo"], 48 ["", undefined], 49 ]; 50 for (let [inVal, outVal] of checks) { 51 let bmk1 = new BookmarkQuery("bookmarks", Utils.makeGUID()); 52 bmk1.fromSyncBookmark({ 53 url: Services.io.newURI("https://example.com"), 54 folder: inVal, 55 }); 56 Assert.strictEqual(bmk1.folderName, outVal); 57 58 // other direction 59 let bmk2 = new BookmarkQuery("bookmarks", Utils.makeGUID()); 60 bmk2.folderName = inVal; 61 let record = bmk2.toSyncBookmark(); 62 Assert.strictEqual(record.folder, outVal); 63 } 64 });