diff options
author | wolfbeast <mcwerewolf@gmail.com> | 2018-10-06 06:57:51 +0200 |
---|---|---|
committer | wolfbeast <mcwerewolf@gmail.com> | 2018-10-06 06:57:51 +0200 |
commit | 0c47c83e1b3b7d95681a43fbb0de0e17b2cd5b25 (patch) | |
tree | c321601f04cbfd02fb6e12878e745dc49a612c86 /services/sync/tests/unit/test_bookmark_order.js | |
parent | 8860eddcee1417483cafd114f3a9ec127e0f1f74 (diff) | |
download | UXP-0c47c83e1b3b7d95681a43fbb0de0e17b2cd5b25.tar UXP-0c47c83e1b3b7d95681a43fbb0de0e17b2cd5b25.tar.gz UXP-0c47c83e1b3b7d95681a43fbb0de0e17b2cd5b25.tar.lz UXP-0c47c83e1b3b7d95681a43fbb0de0e17b2cd5b25.tar.xz UXP-0c47c83e1b3b7d95681a43fbb0de0e17b2cd5b25.zip |
Import Tycho weave client
Diffstat (limited to 'services/sync/tests/unit/test_bookmark_order.js')
-rw-r--r-- | services/sync/tests/unit/test_bookmark_order.js | 519 |
1 files changed, 64 insertions, 455 deletions
diff --git a/services/sync/tests/unit/test_bookmark_order.js b/services/sync/tests/unit/test_bookmark_order.js index 7625a813f..56806dba0 100644 --- a/services/sync/tests/unit/test_bookmark_order.js +++ b/services/sync/tests/unit/test_bookmark_order.js @@ -2,61 +2,53 @@ http://creativecommons.org/publicdomain/zero/1.0/ */ _("Making sure after processing incoming bookmarks, they show up in the right order"); -Cu.import("resource://gre/modules/PlacesUtils.jsm"); -Cu.import("resource://gre/modules/Task.jsm"); +Cu.import("resource://gre/modules/PlacesUtils.jsm", this); Cu.import("resource://services-sync/engines/bookmarks.js"); Cu.import("resource://services-sync/service.js"); Cu.import("resource://services-sync/util.js"); -var check = Task.async(function* (expected, message) { - let root = yield PlacesUtils.promiseBookmarksTree(); +function getBookmarks(folderId) { + let bookmarks = []; + + let pos = 0; + while (true) { + let itemId = PlacesUtils.bookmarks.getIdForItemAt(folderId, pos); + _("Got itemId", itemId, "under", folderId, "at", pos); + if (itemId == -1) + break; + + switch (PlacesUtils.bookmarks.getItemType(itemId)) { + case PlacesUtils.bookmarks.TYPE_BOOKMARK: + bookmarks.push(PlacesUtils.bookmarks.getItemTitle(itemId)); + break; + case PlacesUtils.bookmarks.TYPE_FOLDER: + bookmarks.push(getBookmarks(itemId)); + break; + default: + _("Unsupported item type.."); + } + + pos++; + } + + return bookmarks; +} - let bookmarks = (function mapTree(children) { - return children.map(child => { - let result = { - guid: child.guid, - index: child.index, - }; - if (child.children) { - result.children = mapTree(child.children); - } - if (child.annos) { - let orphanAnno = child.annos.find( - anno => anno.name == "sync/parent"); - if (orphanAnno) { - result.requestedParent = orphanAnno.value; - } - } - return result; - }); - }(root.children)); +function check(expected) { + let bookmarks = getBookmarks(PlacesUtils.bookmarks.unfiledBookmarksFolder); _("Checking if the bookmark structure is", JSON.stringify(expected)); _("Got bookmarks:", JSON.stringify(bookmarks)); - deepEqual(bookmarks, expected); -}); + do_check_true(Utils.deepEquals(bookmarks, expected)); +} -add_task(function* test_bookmark_order() { +function run_test() { let store = new BookmarksEngine(Service)._store; initTestLogging("Trace"); _("Starting with a clean slate of no bookmarks"); store.wipe(); - yield check([{ - guid: PlacesUtils.bookmarks.menuGuid, - index: 0, - }, { - guid: PlacesUtils.bookmarks.toolbarGuid, - index: 1, - }, { - // Index 2 is the tags root. (Root indices depend on the order of the - // `CreateRoot` calls in `Database::CreateBookmarkRoots`). - guid: PlacesUtils.bookmarks.unfiledGuid, - index: 3, - }, { - guid: PlacesUtils.bookmarks.mobileGuid, - index: 4, - }], "clean slate"); + check([]); function bookmark(name, parent) { let bookmark = new Bookmark("http://weave.server/my-bookmark"); @@ -83,447 +75,64 @@ add_task(function* test_bookmark_order() { store._orderChildren(); delete store._childrenToOrder; } - let id10 = "10_aaaaaaaaa"; + _("basic add first bookmark"); - apply(bookmark(id10, "")); - yield check([{ - guid: PlacesUtils.bookmarks.menuGuid, - index: 0, - }, { - guid: PlacesUtils.bookmarks.toolbarGuid, - index: 1, - }, { - guid: PlacesUtils.bookmarks.unfiledGuid, - index: 3, - children: [{ - guid: id10, - index: 0, - }], - }, { - guid: PlacesUtils.bookmarks.mobileGuid, - index: 4, - }], "basic add first bookmark"); - let id20 = "20_aaaaaaaaa"; + apply(bookmark("10", "")); + check(["10"]); + _("basic append behind 10"); - apply(bookmark(id20, "")); - yield check([{ - guid: PlacesUtils.bookmarks.menuGuid, - index: 0, - }, { - guid: PlacesUtils.bookmarks.toolbarGuid, - index: 1, - }, { - guid: PlacesUtils.bookmarks.unfiledGuid, - index: 3, - children: [{ - guid: id10, - index: 0, - }, { - guid: id20, - index: 1, - }], - }, { - guid: PlacesUtils.bookmarks.mobileGuid, - index: 4, - }], "basic append behind 10"); + apply(bookmark("20", "")); + check(["10", "20"]); - let id31 = "31_aaaaaaaaa"; - let id30 = "f30_aaaaaaaa"; _("basic create in folder"); - apply(bookmark(id31, id30)); - let f30 = folder(id30, "", [id31]); + apply(bookmark("31", "f30")); + let f30 = folder("f30", "", ["31"]); apply(f30); - yield check([{ - guid: PlacesUtils.bookmarks.menuGuid, - index: 0, - }, { - guid: PlacesUtils.bookmarks.toolbarGuid, - index: 1, - }, { - guid: PlacesUtils.bookmarks.unfiledGuid, - index: 3, - children: [{ - guid: id10, - index: 0, - }, { - guid: id20, - index: 1, - }, { - guid: id30, - index: 2, - children: [{ - guid: id31, - index: 0, - }], - }], - }, { - guid: PlacesUtils.bookmarks.mobileGuid, - index: 4, - }], "basic create in folder"); + check(["10", "20", ["31"]]); - let id41 = "41_aaaaaaaaa"; - let id40 = "f40_aaaaaaaa"; _("insert missing parent -> append to unfiled"); - apply(bookmark(id41, id40)); - yield check([{ - guid: PlacesUtils.bookmarks.menuGuid, - index: 0, - }, { - guid: PlacesUtils.bookmarks.toolbarGuid, - index: 1, - }, { - guid: PlacesUtils.bookmarks.unfiledGuid, - index: 3, - children: [{ - guid: id10, - index: 0, - }, { - guid: id20, - index: 1, - }, { - guid: id30, - index: 2, - children: [{ - guid: id31, - index: 0, - }], - }, { - guid: id41, - index: 3, - requestedParent: id40, - }], - }, { - guid: PlacesUtils.bookmarks.mobileGuid, - index: 4, - }], "insert missing parent -> append to unfiled"); - - let id42 = "42_aaaaaaaaa"; + apply(bookmark("41", "f40")); + check(["10", "20", ["31"], "41"]); _("insert another missing parent -> append"); - apply(bookmark(id42, id40)); - yield check([{ - guid: PlacesUtils.bookmarks.menuGuid, - index: 0, - }, { - guid: PlacesUtils.bookmarks.toolbarGuid, - index: 1, - }, { - guid: PlacesUtils.bookmarks.unfiledGuid, - index: 3, - children: [{ - guid: id10, - index: 0, - }, { - guid: id20, - index: 1, - }, { - guid: id30, - index: 2, - children: [{ - guid: id31, - index: 0, - }], - }, { - guid: id41, - index: 3, - requestedParent: id40, - }, { - guid: id42, - index: 4, - requestedParent: id40, - }], - }, { - guid: PlacesUtils.bookmarks.mobileGuid, - index: 4, - }], "insert another missing parent -> append"); + apply(bookmark("42", "f40")); + check(["10", "20", ["31"], "41", "42"]); _("insert folder -> move children and followers"); - let f40 = folder(id40, "", [id41, id42]); + let f40 = folder("f40", "", ["41", "42"]); apply(f40); - yield check([{ - guid: PlacesUtils.bookmarks.menuGuid, - index: 0, - }, { - guid: PlacesUtils.bookmarks.toolbarGuid, - index: 1, - }, { - guid: PlacesUtils.bookmarks.unfiledGuid, - index: 3, - children: [{ - guid: id10, - index: 0, - }, { - guid: id20, - index: 1, - }, { - guid: id30, - index: 2, - children: [{ - guid: id31, - index: 0, - }], - }, { - guid: id40, - index: 3, - children: [{ - guid: id41, - index: 0, - }, { - guid: id42, - index: 1, - }] - }], - }, { - guid: PlacesUtils.bookmarks.mobileGuid, - index: 4, - }], "insert folder -> move children and followers"); + check(["10", "20", ["31"], ["41", "42"]]); _("Moving 41 behind 42 -> update f40"); - f40.children = [id42, id41]; + f40.children = ["42", "41"]; apply(f40); - yield check([{ - guid: PlacesUtils.bookmarks.menuGuid, - index: 0, - }, { - guid: PlacesUtils.bookmarks.toolbarGuid, - index: 1, - }, { - guid: PlacesUtils.bookmarks.unfiledGuid, - index: 3, - children: [{ - guid: id10, - index: 0, - }, { - guid: id20, - index: 1, - }, { - guid: id30, - index: 2, - children: [{ - guid: id31, - index: 0, - }], - }, { - guid: id40, - index: 3, - children: [{ - guid: id42, - index: 0, - }, { - guid: id41, - index: 1, - }] - }], - }, { - guid: PlacesUtils.bookmarks.mobileGuid, - index: 4, - }], "Moving 41 behind 42 -> update f40"); + check(["10", "20", ["31"], ["42", "41"]]); _("Moving 10 back to front -> update 10, 20"); - f40.children = [id41, id42]; + f40.children = ["41", "42"]; apply(f40); - yield check([{ - guid: PlacesUtils.bookmarks.menuGuid, - index: 0, - }, { - guid: PlacesUtils.bookmarks.toolbarGuid, - index: 1, - }, { - guid: PlacesUtils.bookmarks.unfiledGuid, - index: 3, - children: [{ - guid: id10, - index: 0, - }, { - guid: id20, - index: 1, - }, { - guid: id30, - index: 2, - children: [{ - guid: id31, - index: 0, - }], - }, { - guid: id40, - index: 3, - children: [{ - guid: id41, - index: 0, - }, { - guid: id42, - index: 1, - }] - }], - }, { - guid: PlacesUtils.bookmarks.mobileGuid, - index: 4, - }], "Moving 10 back to front -> update 10, 20"); + check(["10", "20", ["31"], ["41", "42"]]); _("Moving 20 behind 42 in f40 -> update 50"); - apply(bookmark(id20, id40)); - yield check([{ - guid: PlacesUtils.bookmarks.menuGuid, - index: 0, - }, { - guid: PlacesUtils.bookmarks.toolbarGuid, - index: 1, - }, { - guid: PlacesUtils.bookmarks.unfiledGuid, - index: 3, - children: [{ - guid: id10, - index: 0, - }, { - guid: id30, - index: 1, - children: [{ - guid: id31, - index: 0, - }], - }, { - guid: id40, - index: 2, - children: [{ - guid: id41, - index: 0, - }, { - guid: id42, - index: 1, - }, { - guid: id20, - index: 2, - }] - }], - }, { - guid: PlacesUtils.bookmarks.mobileGuid, - index: 4, - }], "Moving 20 behind 42 in f40 -> update 50"); + apply(bookmark("20", "f40")); + check(["10", ["31"], ["41", "42", "20"]]); _("Moving 10 in front of 31 in f30 -> update 10, f30"); - apply(bookmark(id10, id30)); - f30.children = [id10, id31]; + apply(bookmark("10", "f30")); + f30.children = ["10", "31"]; apply(f30); - yield check([{ - guid: PlacesUtils.bookmarks.menuGuid, - index: 0, - }, { - guid: PlacesUtils.bookmarks.toolbarGuid, - index: 1, - }, { - guid: PlacesUtils.bookmarks.unfiledGuid, - index: 3, - children: [{ - guid: id30, - index: 0, - children: [{ - guid: id10, - index: 0, - }, { - guid: id31, - index: 1, - }], - }, { - guid: id40, - index: 1, - children: [{ - guid: id41, - index: 0, - }, { - guid: id42, - index: 1, - }, { - guid: id20, - index: 2, - }] - }], - }, { - guid: PlacesUtils.bookmarks.mobileGuid, - index: 4, - }], "Moving 10 in front of 31 in f30 -> update 10, f30"); + check([["10", "31"], ["41", "42", "20"]]); _("Moving 20 from f40 to f30 -> update 20, f30"); - apply(bookmark(id20, id30)); - f30.children = [id10, id20, id31]; + apply(bookmark("20", "f30")); + f30.children = ["10", "20", "31"]; apply(f30); - yield check([{ - guid: PlacesUtils.bookmarks.menuGuid, - index: 0, - }, { - guid: PlacesUtils.bookmarks.toolbarGuid, - index: 1, - }, { - guid: PlacesUtils.bookmarks.unfiledGuid, - index: 3, - children: [{ - guid: id30, - index: 0, - children: [{ - guid: id10, - index: 0, - }, { - guid: id20, - index: 1, - }, { - guid: id31, - index: 2, - }], - }, { - guid: id40, - index: 1, - children: [{ - guid: id41, - index: 0, - }, { - guid: id42, - index: 1, - }] - }], - }, { - guid: PlacesUtils.bookmarks.mobileGuid, - index: 4, - }], "Moving 20 from f40 to f30 -> update 20, f30"); + check([["10", "20", "31"], ["41", "42"]]); _("Move 20 back to front -> update 20, f30"); - apply(bookmark(id20, "")); - f30.children = [id10, id31]; + apply(bookmark("20", "")); + f30.children = ["10", "31"]; apply(f30); - yield check([{ - guid: PlacesUtils.bookmarks.menuGuid, - index: 0, - }, { - guid: PlacesUtils.bookmarks.toolbarGuid, - index: 1, - }, { - guid: PlacesUtils.bookmarks.unfiledGuid, - index: 3, - children: [{ - guid: id30, - index: 0, - children: [{ - guid: id10, - index: 0, - }, { - guid: id31, - index: 1, - }], - }, { - guid: id40, - index: 1, - children: [{ - guid: id41, - index: 0, - }, { - guid: id42, - index: 1, - }], - }, { - guid: id20, - index: 2, - }], - }, { - guid: PlacesUtils.bookmarks.mobileGuid, - index: 4, - }], "Move 20 back to front -> update 20, f30"); + check([["10", "31"], ["41", "42"], "20"]); -}); +} |