test_bookmark_places_query_rewriting.js (1991B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 _("Rewrite place: URIs."); 5 const { BookmarkQuery, BookmarkFolder } = ChromeUtils.importESModule( 6 "resource://services-sync/engines/bookmarks.sys.mjs" 7 ); 8 // `Service` is used as a global in head_helpers.js. 9 // eslint-disable-next-line no-unused-vars 10 const { Service } = ChromeUtils.importESModule( 11 "resource://services-sync/service.sys.mjs" 12 ); 13 14 function makeTagRecord(id, uri) { 15 let tagRecord = new BookmarkQuery("bookmarks", id); 16 tagRecord.queryId = "MagicTags"; 17 tagRecord.parentName = "Bookmarks Toolbar"; 18 tagRecord.bmkUri = uri; 19 tagRecord.title = "tagtag"; 20 tagRecord.folderName = "bar"; 21 tagRecord.parentid = PlacesUtils.bookmarks.toolbarGuid; 22 return tagRecord; 23 } 24 25 add_bookmark_test(async function run_test(engine) { 26 let store = engine._store; 27 28 let toolbar = new BookmarkFolder("bookmarks", "toolbar"); 29 toolbar.parentid = "places"; 30 toolbar.children = ["abcdefabcdef"]; 31 32 let uri = "place:folder=499&type=7&queryType=1"; 33 let tagRecord = makeTagRecord("abcdefabcdef", uri); 34 35 _("Type: " + tagRecord.type); 36 _("Folder name: " + tagRecord.folderName); 37 await store.applyIncoming(toolbar); 38 await store.applyIncoming(tagRecord); 39 await engine._apply(); 40 41 let insertedRecord = await store.createRecord("abcdefabcdef", "bookmarks"); 42 Assert.equal(insertedRecord.bmkUri, "place:tag=bar"); 43 44 _("... but not if the type is wrong."); 45 let wrongTypeURI = "place:folder=499&type=2&queryType=1"; 46 let wrongTypeRecord = makeTagRecord("fedcbafedcba", wrongTypeURI); 47 await store.applyIncoming(wrongTypeRecord); 48 toolbar.children = ["fedcbafedcba"]; 49 await store.applyIncoming(toolbar); 50 let expected = wrongTypeURI; 51 await engine._apply(); 52 // the mirror appends a special param to these. 53 expected += "&excludeItems=1"; 54 55 insertedRecord = await store.createRecord("fedcbafedcba", "bookmarks"); 56 Assert.equal(insertedRecord.bmkUri, expected); 57 });