~ubuntu-branches/ubuntu/trusty/enigmail/trusty-updates

« back to all changes in this revision

Viewing changes to services/sync/tests/unit/test_bookmark_order.js

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2011-06-07 14:35:53 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: package-import@ubuntu.com-20110607143553-fbgqhhvh8g8h6j1y
Tags: 2:1.2~a2~cvs20110606t2200-0ubuntu1
* Update to latest trunk snapshot for Thunderbird beta compat

* Remove build/pgo/profileserver.py from debian/clean. The new build
  system has a target depending on this
  - update debian/clean
* Drop debian/patches/autoconf.diff, just generate this at build time
* Refresh debian/patches/build_system_dont_link_libxul.diff
* libipc seems to be renamed to libipc-pipe. Fix genxpi and chrome.manifest
  to fix this 
  - add debian/patches/ipc-pipe_rename.diff
  - update debian/patches/series
* The makefiles in extensions/enigmail/ipc have an incorrect DEPTH
  attribute. Fix this so that they can find the rest of the build system
  - add debian/patches/makefile_depth.diff
  - update debian/patches/series
* Drop debian/patches/makefile-in-empty-xpcom-fix.diff - fixed in the
  current version
* Don't register a class ID multiple times, as this breaks enigmail entirely
  - add debian/patches/dont_register_cids_multiple_times.diff
  - update debian/patches/series
* Look for the Thunderbird 5 SDK
  - update debian/rules
  - update debian/control
* Run autoconf2.13 at build time
  - update debian/rules
  - update debian/control
* Add useless mesa-common-dev build-dep, just to satisfy the build system.
  We should just patch this out entirely really, but that's for another upload
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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/util.js");
 
4
 
 
5
function getBookmarks(folderId) {
 
6
  let bookmarks = [];
 
7
 
 
8
  let pos = 0;
 
9
  while (true) {
 
10
    let itemId = Svc.Bookmark.getIdForItemAt(folderId, pos);
 
11
    _("Got itemId", itemId, "under", folderId, "at", pos);
 
12
    if (itemId == -1)
 
13
      break;
 
14
 
 
15
    switch (Svc.Bookmark.getItemType(itemId)) {
 
16
      case Svc.Bookmark.TYPE_BOOKMARK:
 
17
        bookmarks.push(Svc.Bookmark.getItemTitle(itemId));
 
18
        break;
 
19
      case Svc.Bookmark.TYPE_FOLDER:
 
20
        bookmarks.push(getBookmarks(itemId));
 
21
        break;
 
22
      default:
 
23
        _("Unsupported item type..");
 
24
    }
 
25
 
 
26
    pos++;
 
27
  }
 
28
 
 
29
  return bookmarks;
 
30
}
 
31
 
 
32
function check(expected) {
 
33
  let bookmarks = getBookmarks(Svc.Bookmark.unfiledBookmarksFolder);
 
34
 
 
35
  _("Checking if the bookmark structure is", JSON.stringify(expected));
 
36
  _("Got bookmarks:", JSON.stringify(bookmarks));
 
37
  do_check_true(Utils.deepEquals(bookmarks, expected));
 
38
}
 
39
 
 
40
function run_test() {
 
41
  let store = new BookmarksEngine()._store;
 
42
  initTestLogging("Trace");
 
43
 
 
44
  _("Starting with a clean slate of no bookmarks");
 
45
  store.wipe();
 
46
  check([]);
 
47
 
 
48
  function bookmark(name, parent) {
 
49
    let bookmark = new Bookmark("http://weave.server/my-bookmark");
 
50
    bookmark.id = name;
 
51
    bookmark.title = name;
 
52
    bookmark.bmkUri = "http://uri/";
 
53
    bookmark.parentid = parent || "unfiled";
 
54
    bookmark.tags = [];
 
55
    return bookmark;
 
56
  }
 
57
 
 
58
  function folder(name, parent, children) {
 
59
    let folder = new BookmarkFolder("http://weave.server/my-bookmark-folder");
 
60
    folder.id = name;
 
61
    folder.title = name;
 
62
    folder.parentid = parent || "unfiled";
 
63
    folder.children = children;
 
64
    return folder;
 
65
  }
 
66
 
 
67
  function apply(record) {
 
68
    store._childrenToOrder = {};
 
69
    store.applyIncoming(record);
 
70
    store._orderChildren();
 
71
    delete store._childrenToOrder;
 
72
  }
 
73
 
 
74
  _("basic add first bookmark");
 
75
  apply(bookmark("10", ""));
 
76
  check(["10"]);
 
77
 
 
78
  _("basic append behind 10");
 
79
  apply(bookmark("20", ""));
 
80
  check(["10", "20"]);
 
81
 
 
82
  _("basic create in folder");
 
83
  apply(bookmark("31", "f30"));
 
84
  let f30 = folder("f30", "", ["31"]);
 
85
  apply(f30);
 
86
  check(["10", "20", ["31"]]);
 
87
 
 
88
  _("insert missing parent -> append to unfiled");
 
89
  apply(bookmark("41", "f40"));
 
90
  check(["10", "20", ["31"], "41"]);
 
91
 
 
92
  _("insert another missing parent -> append");
 
93
  apply(bookmark("42", "f40"));
 
94
  check(["10", "20", ["31"], "41", "42"]);
 
95
 
 
96
  _("insert folder -> move children and followers");
 
97
  let f40 = folder("f40", "", ["41", "42"]);
 
98
  apply(f40);
 
99
  check(["10", "20", ["31"], ["41", "42"]]);
 
100
 
 
101
  _("Moving 41 behind 42 -> update f40");
 
102
  f40.children = ["42", "41"];
 
103
  apply(f40);
 
104
  check(["10", "20", ["31"], ["42", "41"]]);
 
105
 
 
106
  _("Moving 10 back to front -> update 10, 20");
 
107
  f40.children = ["41", "42"];
 
108
  apply(f40);
 
109
  check(["10", "20", ["31"], ["41", "42"]]);
 
110
 
 
111
  _("Moving 20 behind 42 in f40 -> update 50");
 
112
  apply(bookmark("20", "f40"));
 
113
  check(["10", ["31"], ["41", "42", "20"]]);
 
114
 
 
115
  _("Moving 10 in front of 31 in f30 -> update 10, f30");
 
116
  apply(bookmark("10", "f30"));
 
117
  f30.children = ["10", "31"];
 
118
  apply(f30);
 
119
  check([["10", "31"], ["41", "42", "20"]]);
 
120
 
 
121
  _("Moving 20 from f40 to f30 -> update 20, f30");
 
122
  apply(bookmark("20", "f30"));
 
123
  f30.children = ["10", "20", "31"];
 
124
  apply(f30);
 
125
  check([["10", "20", "31"], ["41", "42"]]);
 
126
 
 
127
  _("Move 20 back to front -> update 20, f30");
 
128
  apply(bookmark("20", ""));
 
129
  f30.children = ["10", "31"];
 
130
  apply(f30);
 
131
  check([["10", "31"], ["41", "42"], "20"]);
 
132
 
 
133
}