Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 | // Tests that each nsINavBookmarksObserver method gets the correct input. |
michael@0 | 5 | |
michael@0 | 6 | let gBookmarksObserver = { |
michael@0 | 7 | expected: [], |
michael@0 | 8 | validate: function (aMethodName, aArguments) { |
michael@0 | 9 | do_check_eq(this.expected[0].name, aMethodName); |
michael@0 | 10 | |
michael@0 | 11 | let args = this.expected.shift().args; |
michael@0 | 12 | do_check_eq(aArguments.length, args.length); |
michael@0 | 13 | for (let i = 0; i < aArguments.length; i++) { |
michael@0 | 14 | do_log_info(aMethodName + "(args[" + i + "]: " + args[i].name + ")"); |
michael@0 | 15 | do_check_true(args[i].check(aArguments[i])); |
michael@0 | 16 | } |
michael@0 | 17 | |
michael@0 | 18 | if (this.expected.length == 0) { |
michael@0 | 19 | run_next_test(); |
michael@0 | 20 | } |
michael@0 | 21 | }, |
michael@0 | 22 | |
michael@0 | 23 | // nsINavBookmarkObserver |
michael@0 | 24 | onBeginUpdateBatch: function onBeginUpdateBatch() |
michael@0 | 25 | this.validate(arguments.callee.name, arguments), |
michael@0 | 26 | onEndUpdateBatch: function onEndUpdateBatch() |
michael@0 | 27 | this.validate(arguments.callee.name, arguments), |
michael@0 | 28 | onItemAdded: function onItemAdded() |
michael@0 | 29 | this.validate(arguments.callee.name, arguments), |
michael@0 | 30 | onItemRemoved: function onItemRemoved() |
michael@0 | 31 | this.validate(arguments.callee.name, arguments), |
michael@0 | 32 | onItemChanged: function onItemChanged() |
michael@0 | 33 | this.validate(arguments.callee.name, arguments), |
michael@0 | 34 | onItemVisited: function onItemVisited() |
michael@0 | 35 | this.validate(arguments.callee.name, arguments), |
michael@0 | 36 | onItemMoved: function onItemMoved() |
michael@0 | 37 | this.validate(arguments.callee.name, arguments), |
michael@0 | 38 | |
michael@0 | 39 | // nsISupports |
michael@0 | 40 | QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver]), |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | add_test(function batch() { |
michael@0 | 44 | gBookmarksObserver.expected = [ |
michael@0 | 45 | { name: "onBeginUpdateBatch", |
michael@0 | 46 | args: [] }, |
michael@0 | 47 | { name: "onEndUpdateBatch", |
michael@0 | 48 | args: [] }, |
michael@0 | 49 | ]; |
michael@0 | 50 | PlacesUtils.bookmarks.runInBatchMode({ |
michael@0 | 51 | runBatched: function () { |
michael@0 | 52 | // Nothing. |
michael@0 | 53 | } |
michael@0 | 54 | }, null); |
michael@0 | 55 | }); |
michael@0 | 56 | |
michael@0 | 57 | add_test(function onItemAdded_bookmark() { |
michael@0 | 58 | const TITLE = "Bookmark 1"; |
michael@0 | 59 | let uri = NetUtil.newURI("http://1.mozilla.org/"); |
michael@0 | 60 | gBookmarksObserver.expected = [ |
michael@0 | 61 | { name: "onItemAdded", |
michael@0 | 62 | args: [ |
michael@0 | 63 | { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 64 | { name: "parentId", check: function (v) v === PlacesUtils.unfiledBookmarksFolderId }, |
michael@0 | 65 | { name: "index", check: function (v) v === 0 }, |
michael@0 | 66 | { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_BOOKMARK }, |
michael@0 | 67 | { name: "uri", check: function (v) v instanceof Ci.nsIURI && v.equals(uri) }, |
michael@0 | 68 | { name: "title", check: function (v) v === TITLE }, |
michael@0 | 69 | { name: "dateAdded", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 70 | { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 71 | { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 72 | ] }, |
michael@0 | 73 | ]; |
michael@0 | 74 | PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, |
michael@0 | 75 | uri, PlacesUtils.bookmarks.DEFAULT_INDEX, |
michael@0 | 76 | TITLE); |
michael@0 | 77 | }); |
michael@0 | 78 | |
michael@0 | 79 | add_test(function onItemAdded_separator() { |
michael@0 | 80 | gBookmarksObserver.expected = [ |
michael@0 | 81 | { name: "onItemAdded", |
michael@0 | 82 | args: [ |
michael@0 | 83 | { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 84 | { name: "parentId", check: function (v) v === PlacesUtils.unfiledBookmarksFolderId }, |
michael@0 | 85 | { name: "index", check: function (v) v === 1 }, |
michael@0 | 86 | { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_SEPARATOR }, |
michael@0 | 87 | { name: "uri", check: function (v) v === null }, |
michael@0 | 88 | { name: "title", check: function (v) v === null }, |
michael@0 | 89 | { name: "dateAdded", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 90 | { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 91 | { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 92 | ] }, |
michael@0 | 93 | ]; |
michael@0 | 94 | PlacesUtils.bookmarks.insertSeparator(PlacesUtils.unfiledBookmarksFolderId, |
michael@0 | 95 | PlacesUtils.bookmarks.DEFAULT_INDEX); |
michael@0 | 96 | }); |
michael@0 | 97 | |
michael@0 | 98 | add_test(function onItemAdded_folder() { |
michael@0 | 99 | const TITLE = "Folder 1"; |
michael@0 | 100 | gBookmarksObserver.expected = [ |
michael@0 | 101 | { name: "onItemAdded", |
michael@0 | 102 | args: [ |
michael@0 | 103 | { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 104 | { name: "parentId", check: function (v) v === PlacesUtils.unfiledBookmarksFolderId }, |
michael@0 | 105 | { name: "index", check: function (v) v === 2 }, |
michael@0 | 106 | { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_FOLDER }, |
michael@0 | 107 | { name: "uri", check: function (v) v === null }, |
michael@0 | 108 | { name: "title", check: function (v) v === TITLE }, |
michael@0 | 109 | { name: "dateAdded", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 110 | { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 111 | { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 112 | ] }, |
michael@0 | 113 | ]; |
michael@0 | 114 | PlacesUtils.bookmarks.createFolder(PlacesUtils.unfiledBookmarksFolderId, |
michael@0 | 115 | TITLE, |
michael@0 | 116 | PlacesUtils.bookmarks.DEFAULT_INDEX); |
michael@0 | 117 | }); |
michael@0 | 118 | |
michael@0 | 119 | add_test(function onItemChanged_title_bookmark() { |
michael@0 | 120 | let id = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.unfiledBookmarksFolderId, 0); |
michael@0 | 121 | let uri = PlacesUtils.bookmarks.getBookmarkURI(id); |
michael@0 | 122 | const TITLE = "New title"; |
michael@0 | 123 | gBookmarksObserver.expected = [ |
michael@0 | 124 | { name: "onItemChanged", // This is an unfortunate effect of bug 653910. |
michael@0 | 125 | args: [ |
michael@0 | 126 | { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 127 | { name: "property", check: function (v) v === "title" }, |
michael@0 | 128 | { name: "isAnno", check: function (v) v === false }, |
michael@0 | 129 | { name: "newValue", check: function (v) v === TITLE }, |
michael@0 | 130 | { name: "lastModified", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 131 | { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_BOOKMARK }, |
michael@0 | 132 | { name: "parentId", check: function (v) v === PlacesUtils.unfiledBookmarksFolderId }, |
michael@0 | 133 | { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 134 | { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 135 | ] }, |
michael@0 | 136 | ]; |
michael@0 | 137 | PlacesUtils.bookmarks.setItemTitle(id, TITLE); |
michael@0 | 138 | }); |
michael@0 | 139 | |
michael@0 | 140 | add_test(function onItemChanged_tags_bookmark() { |
michael@0 | 141 | let id = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.unfiledBookmarksFolderId, 0); |
michael@0 | 142 | let uri = PlacesUtils.bookmarks.getBookmarkURI(id); |
michael@0 | 143 | const TITLE = "New title"; |
michael@0 | 144 | const TAG = "tag" |
michael@0 | 145 | gBookmarksObserver.expected = [ |
michael@0 | 146 | { name: "onBeginUpdateBatch", // Tag addition uses a batch. |
michael@0 | 147 | args: [] }, |
michael@0 | 148 | { name: "onItemAdded", // This is the tag folder. |
michael@0 | 149 | args: [ |
michael@0 | 150 | { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 151 | { name: "parentId", check: function (v) v === PlacesUtils.tagsFolderId }, |
michael@0 | 152 | { name: "index", check: function (v) v === 0 }, |
michael@0 | 153 | { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_FOLDER }, |
michael@0 | 154 | { name: "uri", check: function (v) v === null }, |
michael@0 | 155 | { name: "title", check: function (v) v === TAG }, |
michael@0 | 156 | { name: "dateAdded", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 157 | { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 158 | { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 159 | ] }, |
michael@0 | 160 | { name: "onItemAdded", // This is the tag. |
michael@0 | 161 | args: [ |
michael@0 | 162 | { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 163 | { name: "parentId", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 164 | { name: "index", check: function (v) v === 0 }, |
michael@0 | 165 | { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_BOOKMARK }, |
michael@0 | 166 | { name: "uri", check: function (v) v instanceof Ci.nsIURI && v.equals(uri) }, |
michael@0 | 167 | { name: "title", check: function (v) v === null }, |
michael@0 | 168 | { name: "dateAdded", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 169 | { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 170 | { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 171 | ] }, |
michael@0 | 172 | { name: "onItemChanged", |
michael@0 | 173 | args: [ |
michael@0 | 174 | { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 175 | { name: "property", check: function (v) v === "tags" }, |
michael@0 | 176 | { name: "isAnno", check: function (v) v === false }, |
michael@0 | 177 | { name: "newValue", check: function (v) v === "" }, |
michael@0 | 178 | { name: "lastModified", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 179 | { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_BOOKMARK }, |
michael@0 | 180 | { name: "parentId", check: function (v) v === PlacesUtils.unfiledBookmarksFolderId }, |
michael@0 | 181 | { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 182 | { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 183 | ] }, |
michael@0 | 184 | { name: "onEndUpdateBatch", |
michael@0 | 185 | args: [] }, |
michael@0 | 186 | { name: "onBeginUpdateBatch", // Tag removal uses a batch. |
michael@0 | 187 | args: [] }, |
michael@0 | 188 | { name: "onItemRemoved", // This is the tag. |
michael@0 | 189 | args: [ |
michael@0 | 190 | { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 191 | { name: "parentId", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 192 | { name: "index", check: function (v) v === 0 }, |
michael@0 | 193 | { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_BOOKMARK }, |
michael@0 | 194 | { name: "uri", check: function (v) v instanceof Ci.nsIURI && v.equals(uri) }, |
michael@0 | 195 | { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 196 | { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 197 | ] }, |
michael@0 | 198 | { name: "onItemRemoved", // This is the tag folder. |
michael@0 | 199 | args: [ |
michael@0 | 200 | { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 201 | { name: "parentId", check: function (v) v === PlacesUtils.tagsFolderId }, |
michael@0 | 202 | { name: "index", check: function (v) v === 0 }, |
michael@0 | 203 | { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_FOLDER }, |
michael@0 | 204 | { name: "uri", check: function (v) v === null }, |
michael@0 | 205 | { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 206 | { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 207 | ] }, |
michael@0 | 208 | { name: "onItemChanged", |
michael@0 | 209 | args: [ |
michael@0 | 210 | { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 211 | { name: "property", check: function (v) v === "tags" }, |
michael@0 | 212 | { name: "isAnno", check: function (v) v === false }, |
michael@0 | 213 | { name: "newValue", check: function (v) v === "" }, |
michael@0 | 214 | { name: "lastModified", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 215 | { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_BOOKMARK }, |
michael@0 | 216 | { name: "parentId", check: function (v) v === PlacesUtils.unfiledBookmarksFolderId }, |
michael@0 | 217 | { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 218 | { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 219 | ] }, |
michael@0 | 220 | { name: "onEndUpdateBatch", |
michael@0 | 221 | args: [] }, |
michael@0 | 222 | ]; |
michael@0 | 223 | PlacesUtils.tagging.tagURI(uri, [TAG]); |
michael@0 | 224 | PlacesUtils.tagging.untagURI(uri, [TAG]); |
michael@0 | 225 | }); |
michael@0 | 226 | |
michael@0 | 227 | add_test(function onItemMoved_bookmark() { |
michael@0 | 228 | let id = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.unfiledBookmarksFolderId, 0); |
michael@0 | 229 | let uri = PlacesUtils.bookmarks.getBookmarkURI(id); |
michael@0 | 230 | gBookmarksObserver.expected = [ |
michael@0 | 231 | { name: "onItemMoved", |
michael@0 | 232 | args: [ |
michael@0 | 233 | { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 234 | { name: "oldParentId", check: function (v) v === PlacesUtils.unfiledBookmarksFolderId }, |
michael@0 | 235 | { name: "oldIndex", check: function (v) v === 0 }, |
michael@0 | 236 | { name: "newParentId", check: function (v) v === PlacesUtils.toolbarFolderId }, |
michael@0 | 237 | { name: "newIndex", check: function (v) v === 0 }, |
michael@0 | 238 | { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_BOOKMARK }, |
michael@0 | 239 | { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 240 | { name: "oldParentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 241 | { name: "newParentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 242 | ] }, |
michael@0 | 243 | { name: "onItemMoved", |
michael@0 | 244 | args: [ |
michael@0 | 245 | { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 246 | { name: "oldParentId", check: function (v) v === PlacesUtils.toolbarFolderId }, |
michael@0 | 247 | { name: "oldIndex", check: function (v) v === 0 }, |
michael@0 | 248 | { name: "newParentId", check: function (v) v === PlacesUtils.unfiledBookmarksFolderId }, |
michael@0 | 249 | { name: "newIndex", check: function (v) v === 0 }, |
michael@0 | 250 | { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_BOOKMARK }, |
michael@0 | 251 | { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 252 | { name: "oldParentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 253 | { name: "newParentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 254 | ] }, |
michael@0 | 255 | ]; |
michael@0 | 256 | PlacesUtils.bookmarks.moveItem(id, PlacesUtils.toolbarFolderId, 0); |
michael@0 | 257 | PlacesUtils.bookmarks.moveItem(id, PlacesUtils.unfiledBookmarksFolderId, 0); |
michael@0 | 258 | }); |
michael@0 | 259 | |
michael@0 | 260 | add_test(function onItemMoved_bookmark() { |
michael@0 | 261 | let id = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.unfiledBookmarksFolderId, 0); |
michael@0 | 262 | let uri = PlacesUtils.bookmarks.getBookmarkURI(id); |
michael@0 | 263 | gBookmarksObserver.expected = [ |
michael@0 | 264 | { name: "onItemVisited", |
michael@0 | 265 | args: [ |
michael@0 | 266 | { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 267 | { name: "visitId", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 268 | { name: "time", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 269 | { name: "transitionType", check: function (v) v === PlacesUtils.history.TRANSITION_TYPED }, |
michael@0 | 270 | { name: "uri", check: function (v) v instanceof Ci.nsIURI && v.equals(uri) }, |
michael@0 | 271 | { name: "parentId", check: function (v) v === PlacesUtils.unfiledBookmarksFolderId }, |
michael@0 | 272 | { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 273 | { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 274 | ] }, |
michael@0 | 275 | ]; |
michael@0 | 276 | promiseAddVisits({ uri: uri, transition: TRANSITION_TYPED }); |
michael@0 | 277 | }); |
michael@0 | 278 | |
michael@0 | 279 | add_test(function onItemRemoved_bookmark() { |
michael@0 | 280 | let id = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.unfiledBookmarksFolderId, 0); |
michael@0 | 281 | let uri = PlacesUtils.bookmarks.getBookmarkURI(id); |
michael@0 | 282 | gBookmarksObserver.expected = [ |
michael@0 | 283 | { name: "onItemChanged", // This is an unfortunate effect of bug 653910. |
michael@0 | 284 | args: [ |
michael@0 | 285 | { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 286 | { name: "property", check: function (v) v === "" }, |
michael@0 | 287 | { name: "isAnno", check: function (v) v === true }, |
michael@0 | 288 | { name: "newValue", check: function (v) v === "" }, |
michael@0 | 289 | { name: "lastModified", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 290 | { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_BOOKMARK }, |
michael@0 | 291 | { name: "parentId", check: function (v) v === PlacesUtils.unfiledBookmarksFolderId }, |
michael@0 | 292 | { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 293 | { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 294 | ] }, |
michael@0 | 295 | { name: "onItemRemoved", |
michael@0 | 296 | args: [ |
michael@0 | 297 | { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 298 | { name: "parentId", check: function (v) v === PlacesUtils.unfiledBookmarksFolderId }, |
michael@0 | 299 | { name: "index", check: function (v) v === 0 }, |
michael@0 | 300 | { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_BOOKMARK }, |
michael@0 | 301 | { name: "uri", check: function (v) v instanceof Ci.nsIURI && v.equals(uri) }, |
michael@0 | 302 | { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 303 | { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 304 | ] }, |
michael@0 | 305 | ]; |
michael@0 | 306 | PlacesUtils.bookmarks.removeItem(id); |
michael@0 | 307 | }); |
michael@0 | 308 | |
michael@0 | 309 | add_test(function onItemRemoved_separator() { |
michael@0 | 310 | let id = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.unfiledBookmarksFolderId, 0); |
michael@0 | 311 | gBookmarksObserver.expected = [ |
michael@0 | 312 | { name: "onItemChanged", // This is an unfortunate effect of bug 653910. |
michael@0 | 313 | args: [ |
michael@0 | 314 | { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 315 | { name: "property", check: function (v) v === "" }, |
michael@0 | 316 | { name: "isAnno", check: function (v) v === true }, |
michael@0 | 317 | { name: "newValue", check: function (v) v === "" }, |
michael@0 | 318 | { name: "lastModified", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 319 | { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_SEPARATOR }, |
michael@0 | 320 | { name: "parentId", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 321 | { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 322 | { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 323 | ] }, |
michael@0 | 324 | { name: "onItemRemoved", |
michael@0 | 325 | args: [ |
michael@0 | 326 | { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 327 | { name: "parentId", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 328 | { name: "index", check: function (v) v === 0 }, |
michael@0 | 329 | { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_SEPARATOR }, |
michael@0 | 330 | { name: "uri", check: function (v) v === null }, |
michael@0 | 331 | { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 332 | { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 333 | ] }, |
michael@0 | 334 | ]; |
michael@0 | 335 | PlacesUtils.bookmarks.removeItem(id); |
michael@0 | 336 | }); |
michael@0 | 337 | |
michael@0 | 338 | add_test(function onItemRemoved_folder() { |
michael@0 | 339 | let id = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.unfiledBookmarksFolderId, 0); |
michael@0 | 340 | const TITLE = "Folder 2"; |
michael@0 | 341 | gBookmarksObserver.expected = [ |
michael@0 | 342 | { name: "onItemChanged", // This is an unfortunate effect of bug 653910. |
michael@0 | 343 | args: [ |
michael@0 | 344 | { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 345 | { name: "property", check: function (v) v === "" }, |
michael@0 | 346 | { name: "isAnno", check: function (v) v === true }, |
michael@0 | 347 | { name: "newValue", check: function (v) v === "" }, |
michael@0 | 348 | { name: "lastModified", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 349 | { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_FOLDER }, |
michael@0 | 350 | { name: "parentId", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 351 | { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 352 | { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 353 | ] }, |
michael@0 | 354 | { name: "onItemRemoved", |
michael@0 | 355 | args: [ |
michael@0 | 356 | { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 357 | { name: "parentId", check: function (v) typeof(v) == "number" && v > 0 }, |
michael@0 | 358 | { name: "index", check: function (v) v === 0 }, |
michael@0 | 359 | { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_FOLDER }, |
michael@0 | 360 | { name: "uri", check: function (v) v === null }, |
michael@0 | 361 | { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 362 | { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) }, |
michael@0 | 363 | ] }, |
michael@0 | 364 | ]; |
michael@0 | 365 | PlacesUtils.bookmarks.removeItem(id); |
michael@0 | 366 | }); |
michael@0 | 367 | |
michael@0 | 368 | function run_test() { |
michael@0 | 369 | PlacesUtils.bookmarks.addObserver(gBookmarksObserver, false); |
michael@0 | 370 | run_next_test(); |
michael@0 | 371 | } |
michael@0 | 372 | |
michael@0 | 373 | do_register_cleanup(function () { |
michael@0 | 374 | PlacesUtils.bookmarks.removeObserver(gBookmarksObserver); |
michael@0 | 375 | }); |