michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: _("Rewrite place: URIs."); michael@0: Cu.import("resource://gre/modules/PlacesUtils.jsm"); michael@0: Cu.import("resource://services-sync/engines/bookmarks.js"); michael@0: Cu.import("resource://services-sync/service.js"); michael@0: Cu.import("resource://services-sync/util.js"); michael@0: michael@0: let engine = new BookmarksEngine(Service); michael@0: let store = engine._store; michael@0: michael@0: function run_test() { michael@0: initTestLogging("Trace"); michael@0: Log.repository.getLogger("Sync.Engine.Bookmarks").level = Log.Level.Trace; michael@0: Log.repository.getLogger("Sync.Store.Bookmarks").level = Log.Level.Trace; michael@0: michael@0: let tagRecord = new BookmarkQuery("bookmarks", "abcdefabcdef"); michael@0: let uri = "place:folder=499&type=7&queryType=1"; michael@0: tagRecord.queryId = "MagicTags"; michael@0: tagRecord.parentName = "Bookmarks Toolbar"; michael@0: tagRecord.bmkUri = uri; michael@0: tagRecord.title = "tagtag"; michael@0: tagRecord.folderName = "bar"; michael@0: michael@0: _("Type: " + tagRecord.type); michael@0: _("Folder name: " + tagRecord.folderName); michael@0: store.preprocessTagQuery(tagRecord); michael@0: michael@0: _("Verify that the URI has been rewritten."); michael@0: do_check_neq(tagRecord.bmkUri, uri); michael@0: michael@0: let tags = store._getNode(PlacesUtils.tagsFolderId); michael@0: tags.containerOpen = true; michael@0: let tagID; michael@0: for (let i = 0; i < tags.childCount; ++i) { michael@0: let child = tags.getChild(i); michael@0: if (child.title == "bar") michael@0: tagID = child.itemId; michael@0: } michael@0: tags.containerOpen = false; michael@0: michael@0: _("Tag ID: " + tagID); michael@0: do_check_eq(tagRecord.bmkUri, uri.replace("499", tagID)); michael@0: michael@0: _("... but not if the type is wrong."); michael@0: let wrongTypeURI = "place:folder=499&type=2&queryType=1"; michael@0: tagRecord.bmkUri = wrongTypeURI; michael@0: store.preprocessTagQuery(tagRecord); michael@0: do_check_eq(tagRecord.bmkUri, wrongTypeURI); michael@0: }