1
_("Making sure after processing incoming bookmarks, they show up in the right order");
2
Cu.import("resource://services-sync/engines/bookmarks.js");
3
Cu.import("resource://services-sync/type_records/bookmark.js");
4
Cu.import("resource://services-sync/util.js");
6
function getBookmarks(folderId) {
11
let itemId = Svc.Bookmark.getIdForItemAt(folderId, pos);
12
_("Got itemId", itemId, "under", folderId, "at", pos);
16
switch (Svc.Bookmark.getItemType(itemId)) {
17
case Svc.Bookmark.TYPE_BOOKMARK:
18
bookmarks.push(Svc.Bookmark.getItemTitle(itemId));
20
case Svc.Bookmark.TYPE_FOLDER:
21
bookmarks.push(getBookmarks(itemId));
24
_("Unsupported item type..");
33
function check(expected) {
34
let bookmarks = getBookmarks(Svc.Bookmark.unfiledBookmarksFolder);
36
_("Checking if the bookmark structure is", JSON.stringify(expected));
37
_("Got bookmarks:", JSON.stringify(bookmarks));
38
do_check_true(Utils.deepEquals(bookmarks, expected));
42
_("Starting with a clean slate of no bookmarks");
43
let store = new (new BookmarksEngine())._storeObj();
47
function $B(name, parent, pred) {
48
let bookmark = new Bookmark();
50
bookmark.title = name;
51
bookmark.bmkUri = "http://uri/";
52
bookmark.parentid = parent || "unfiled";
53
bookmark.predecessorid = pred;
55
store.applyIncoming(bookmark);
58
function $F(name, parent, pred) {
59
let folder = new BookmarkFolder();
62
folder.parentid = parent || "unfiled";
63
folder.predecessorid = pred;
64
store.applyIncoming(folder);
67
_("basic add first bookmark");
71
_("basic append behind 10");
75
_("basic create in folder");
78
check(["10", "20", ["31"]]);
80
_("insert missing predecessor -> append");
82
check(["10", "20", ["31"], "50"]);
84
_("insert missing parent -> append");
86
check(["10", "20", ["31"], "50", "41"]);
88
_("insert another missing parent -> append");
89
$B("42", "f40", "41");
90
check(["10", "20", ["31"], "50", "41", "42"]);
92
_("insert folder -> move children and followers");
94
check(["10", "20", ["31"], ["41", "42"], "50"]);
96
_("Moving 10 behind 50 -> update 10, 20");
99
check(["20", ["31"], ["41", "42"], "50", "10"]);
101
_("Moving 10 back to front -> update 10, 20");
104
check(["10", "20", ["31"], ["41", "42"], "50"]);
106
_("Moving 10 behind 50 in different order -> update 20, 10");
109
check(["20", ["31"], ["41", "42"], "50", "10"]);
111
_("Moving 10 back to front in different order -> update 20, 10");
114
check(["10", "20", ["31"], ["41", "42"], "50"]);
116
_("Moving 50 behind 42 in f40 -> update 50");
117
$B("50", "f40", "42");
118
check(["10", "20", ["31"], ["41", "42", "50"]]);
120
_("Moving 10 in front of 31 in f30 -> update 10, 20, 31");
123
$B("31", "f30", "10");
124
check(["20", ["10", "31"], ["41", "42", "50"]]);
126
_("Moving 20 between 10 and 31 -> update 20, f30, 31");
127
$B("20", "f30", "10");
129
$B("31", "f30", "20");
130
check([["10", "20", "31"], ["41", "42", "50"]]);
132
_("Move 20 back to front -> update 20, f30, 31");
135
$B("31", "f30", "10");
136
check(["20", ["10", "31"], ["41", "42", "50"]]);
138
_("Moving 20 between 10 and 31 different order -> update f30, 20, 31");
140
$B("20", "f30", "10");
141
$B("31", "f30", "20");
142
check([["10", "20", "31"], ["41", "42", "50"]]);
144
_("Move 20 back to front different order -> update f30, 31, 20");
146
$B("31", "f30", "10");
148
check(["20", ["10", "31"], ["41", "42", "50"]]);
150
_("Moving 20 between 10 and 31 different order 2 -> update 31, f30, 20");
151
$B("31", "f30", "20");
153
$B("20", "f30", "10");
154
check([["10", "20", "31"], ["41", "42", "50"]]);
156
_("Move 20 back to front different order 2 -> update 31, f30, 20");
157
$B("31", "f30", "10");
160
check(["20", ["10", "31"], ["41", "42", "50"]]);
162
_("Move 10, 31 to f40 but update in reverse -> update 41, 31, 10");
163
$B("41", "f40", "31");
164
$B("31", "f40", "10");
166
check(["20", [], ["10", "31", "41", "42", "50"]]);
168
_("Reparent f40 into f30");
170
check(["20", [["10", "31", "41", "42", "50"]]]);