services/sync/tests/unit/test_bookmark_places_query_rewriting.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 _("Rewrite place: URIs.");
michael@0 5 Cu.import("resource://gre/modules/PlacesUtils.jsm");
michael@0 6 Cu.import("resource://services-sync/engines/bookmarks.js");
michael@0 7 Cu.import("resource://services-sync/service.js");
michael@0 8 Cu.import("resource://services-sync/util.js");
michael@0 9
michael@0 10 let engine = new BookmarksEngine(Service);
michael@0 11 let store = engine._store;
michael@0 12
michael@0 13 function run_test() {
michael@0 14 initTestLogging("Trace");
michael@0 15 Log.repository.getLogger("Sync.Engine.Bookmarks").level = Log.Level.Trace;
michael@0 16 Log.repository.getLogger("Sync.Store.Bookmarks").level = Log.Level.Trace;
michael@0 17
michael@0 18 let tagRecord = new BookmarkQuery("bookmarks", "abcdefabcdef");
michael@0 19 let uri = "place:folder=499&type=7&queryType=1";
michael@0 20 tagRecord.queryId = "MagicTags";
michael@0 21 tagRecord.parentName = "Bookmarks Toolbar";
michael@0 22 tagRecord.bmkUri = uri;
michael@0 23 tagRecord.title = "tagtag";
michael@0 24 tagRecord.folderName = "bar";
michael@0 25
michael@0 26 _("Type: " + tagRecord.type);
michael@0 27 _("Folder name: " + tagRecord.folderName);
michael@0 28 store.preprocessTagQuery(tagRecord);
michael@0 29
michael@0 30 _("Verify that the URI has been rewritten.");
michael@0 31 do_check_neq(tagRecord.bmkUri, uri);
michael@0 32
michael@0 33 let tags = store._getNode(PlacesUtils.tagsFolderId);
michael@0 34 tags.containerOpen = true;
michael@0 35 let tagID;
michael@0 36 for (let i = 0; i < tags.childCount; ++i) {
michael@0 37 let child = tags.getChild(i);
michael@0 38 if (child.title == "bar")
michael@0 39 tagID = child.itemId;
michael@0 40 }
michael@0 41 tags.containerOpen = false;
michael@0 42
michael@0 43 _("Tag ID: " + tagID);
michael@0 44 do_check_eq(tagRecord.bmkUri, uri.replace("499", tagID));
michael@0 45
michael@0 46 _("... but not if the type is wrong.");
michael@0 47 let wrongTypeURI = "place:folder=499&type=2&queryType=1";
michael@0 48 tagRecord.bmkUri = wrongTypeURI;
michael@0 49 store.preprocessTagQuery(tagRecord);
michael@0 50 do_check_eq(tagRecord.bmkUri, wrongTypeURI);
michael@0 51 }

mercurial