~ubuntu-branches/ubuntu/oneiric/weave/oneiric

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Micah Gersten
  • Date: 2010-08-11 00:35:15 UTC
  • mfrom: (3.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100811003515-o3jbh826bnd1syjv
Tags: 1.4.3-1ubuntu1
* Add -fshort-wchar to CXXFLAGS to fix FTBFS in Ubuntu
  - update debian/rules 

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/type_records/bookmark.js");
 
4
Cu.import("resource://services-sync/util.js");
 
5
 
 
6
function getBookmarks(folderId) {
 
7
  let bookmarks = [];
 
8
 
 
9
  let pos = 0;
 
10
  while (true) {
 
11
    let itemId = Svc.Bookmark.getIdForItemAt(folderId, pos);
 
12
    _("Got itemId", itemId, "under", folderId, "at", pos);
 
13
    if (itemId == -1)
 
14
      break;
 
15
 
 
16
    switch (Svc.Bookmark.getItemType(itemId)) {
 
17
      case Svc.Bookmark.TYPE_BOOKMARK:
 
18
        bookmarks.push(Svc.Bookmark.getItemTitle(itemId));
 
19
        break;
 
20
      case Svc.Bookmark.TYPE_FOLDER:
 
21
        bookmarks.push(getBookmarks(itemId));
 
22
        break;
 
23
      default:
 
24
        _("Unsupported item type..");
 
25
    }
 
26
 
 
27
    pos++;
 
28
  }
 
29
 
 
30
  return bookmarks;
 
31
}
 
32
 
 
33
function check(expected) {
 
34
  let bookmarks = getBookmarks(Svc.Bookmark.unfiledBookmarksFolder);
 
35
 
 
36
  _("Checking if the bookmark structure is", JSON.stringify(expected));
 
37
  _("Got bookmarks:", JSON.stringify(bookmarks));
 
38
  do_check_true(Utils.deepEquals(bookmarks, expected));
 
39
}
 
40
 
 
41
function run_test() {
 
42
  _("Starting with a clean slate of no bookmarks");
 
43
  let store = new (new BookmarksEngine())._storeObj();
 
44
  store.wipe();
 
45
  check([]);
 
46
 
 
47
  function $B(name, parent, pred) {
 
48
    let bookmark = new Bookmark();
 
49
    bookmark.id = name;
 
50
    bookmark.title = name;
 
51
    bookmark.bmkUri = "http://uri/";
 
52
    bookmark.parentid = parent || "unfiled";
 
53
    bookmark.predecessorid = pred;
 
54
    bookmark.tags = [];
 
55
    store.applyIncoming(bookmark);
 
56
  }
 
57
 
 
58
  function $F(name, parent, pred) {
 
59
    let folder = new BookmarkFolder();
 
60
    folder.id = name;
 
61
    folder.title = name;
 
62
    folder.parentid = parent || "unfiled";
 
63
    folder.predecessorid = pred;
 
64
    store.applyIncoming(folder);
 
65
  }
 
66
 
 
67
  _("basic add first bookmark");
 
68
  $B("10", "");
 
69
  check(["10"]);
 
70
 
 
71
  _("basic append behind 10");
 
72
  $B("20", "", "10");
 
73
  check(["10", "20"]);
 
74
 
 
75
  _("basic create in folder");
 
76
  $F("f30", "", "20");
 
77
  $B("31", "f30");
 
78
  check(["10", "20", ["31"]]);
 
79
 
 
80
  _("insert missing predecessor -> append");
 
81
  $B("50", "", "f40");
 
82
  check(["10", "20", ["31"], "50"]);
 
83
 
 
84
  _("insert missing parent -> append");
 
85
  $B("41", "f40");
 
86
  check(["10", "20", ["31"], "50", "41"]);
 
87
 
 
88
  _("insert another missing parent -> append");
 
89
  $B("42", "f40", "41");
 
90
  check(["10", "20", ["31"], "50", "41", "42"]);
 
91
 
 
92
  _("insert folder -> move children and followers");
 
93
  $F("f40", "", "f30");
 
94
  check(["10", "20", ["31"], ["41", "42"], "50"]);
 
95
 
 
96
  _("Moving 10 behind 50 -> update 10, 20");
 
97
  $B("10", "", "50");
 
98
  $B("20", "");
 
99
  check(["20", ["31"], ["41", "42"], "50", "10"]);
 
100
 
 
101
  _("Moving 10 back to front -> update 10, 20");
 
102
  $B("10", "");
 
103
  $B("20", "", "10");
 
104
  check(["10", "20", ["31"], ["41", "42"], "50"]);
 
105
 
 
106
  _("Moving 10 behind 50 in different order -> update 20, 10");
 
107
  $B("20", "");
 
108
  $B("10", "", "50");
 
109
  check(["20", ["31"], ["41", "42"], "50", "10"]);
 
110
 
 
111
  _("Moving 10 back to front in different order -> update 20, 10");
 
112
  $B("20", "", "10");
 
113
  $B("10", "");
 
114
  check(["10", "20", ["31"], ["41", "42"], "50"]);
 
115
 
 
116
  _("Moving 50 behind 42 in f40 -> update 50");
 
117
  $B("50", "f40", "42");
 
118
  check(["10", "20", ["31"], ["41", "42", "50"]]);
 
119
 
 
120
  _("Moving 10 in front of 31 in f30 -> update 10, 20, 31");
 
121
  $B("10", "f30");
 
122
  $B("20", "");
 
123
  $B("31", "f30", "10");
 
124
  check(["20", ["10", "31"], ["41", "42", "50"]]);
 
125
 
 
126
  _("Moving 20 between 10 and 31 -> update 20, f30, 31");
 
127
  $B("20", "f30", "10");
 
128
  $F("f30", "");
 
129
  $B("31", "f30", "20");
 
130
  check([["10", "20", "31"], ["41", "42", "50"]]);
 
131
 
 
132
  _("Move 20 back to front -> update 20, f30, 31");
 
133
  $B("20", "");
 
134
  $F("f30", "", "20");
 
135
  $B("31", "f30", "10");
 
136
  check(["20", ["10", "31"], ["41", "42", "50"]]);
 
137
 
 
138
  _("Moving 20 between 10 and 31 different order -> update f30, 20, 31");
 
139
  $F("f30", "");
 
140
  $B("20", "f30", "10");
 
141
  $B("31", "f30", "20");
 
142
  check([["10", "20", "31"], ["41", "42", "50"]]);
 
143
 
 
144
  _("Move 20 back to front different order -> update f30, 31, 20");
 
145
  $F("f30", "", "20");
 
146
  $B("31", "f30", "10");
 
147
  $B("20", "");
 
148
  check(["20", ["10", "31"], ["41", "42", "50"]]);
 
149
 
 
150
  _("Moving 20 between 10 and 31 different order 2 -> update 31, f30, 20");
 
151
  $B("31", "f30", "20");
 
152
  $F("f30", "");
 
153
  $B("20", "f30", "10");
 
154
  check([["10", "20", "31"], ["41", "42", "50"]]);
 
155
 
 
156
  _("Move 20 back to front different order 2 -> update 31, f30, 20");
 
157
  $B("31", "f30", "10");
 
158
  $F("f30", "", "20");
 
159
  $B("20", "");
 
160
  check(["20", ["10", "31"], ["41", "42", "50"]]);
 
161
 
 
162
  _("Move 10, 31 to f40 but update in reverse -> update 41, 31, 10");
 
163
  $B("41", "f40", "31");
 
164
  $B("31", "f40", "10");
 
165
  $B("10", "f40");
 
166
  check(["20", [], ["10", "31", "41", "42", "50"]]);
 
167
 
 
168
  _("Reparent f40 into f30");
 
169
  $F("f40", "f30");
 
170
  check(["20", [["10", "31", "41", "42", "50"]]]);
 
171
}