toolkit/components/places/tests/bookmarks/test_nsINavBookmarkObserver.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/places/tests/bookmarks/test_nsINavBookmarkObserver.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,375 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +// Tests that each nsINavBookmarksObserver method gets the correct input.
     1.8 +
     1.9 +let gBookmarksObserver = {
    1.10 +  expected: [],
    1.11 +  validate: function (aMethodName, aArguments) {
    1.12 +    do_check_eq(this.expected[0].name, aMethodName);
    1.13 +
    1.14 +    let args = this.expected.shift().args;
    1.15 +    do_check_eq(aArguments.length, args.length);
    1.16 +    for (let i = 0; i < aArguments.length; i++) {
    1.17 +      do_log_info(aMethodName + "(args[" + i + "]: " + args[i].name + ")");
    1.18 +      do_check_true(args[i].check(aArguments[i]));
    1.19 +    }
    1.20 +
    1.21 +    if (this.expected.length == 0) {
    1.22 +      run_next_test();
    1.23 +    }
    1.24 +  },
    1.25 +
    1.26 +  // nsINavBookmarkObserver
    1.27 +  onBeginUpdateBatch: function onBeginUpdateBatch()
    1.28 +    this.validate(arguments.callee.name, arguments),
    1.29 +  onEndUpdateBatch: function onEndUpdateBatch()
    1.30 +    this.validate(arguments.callee.name, arguments),
    1.31 +  onItemAdded: function onItemAdded()
    1.32 +    this.validate(arguments.callee.name, arguments),
    1.33 +  onItemRemoved: function onItemRemoved()
    1.34 +    this.validate(arguments.callee.name, arguments),
    1.35 +  onItemChanged: function onItemChanged()
    1.36 +    this.validate(arguments.callee.name, arguments),
    1.37 +  onItemVisited: function onItemVisited()
    1.38 +    this.validate(arguments.callee.name, arguments),
    1.39 +  onItemMoved: function onItemMoved()
    1.40 +    this.validate(arguments.callee.name, arguments),
    1.41 +
    1.42 +  // nsISupports
    1.43 +  QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver]),
    1.44 +}
    1.45 +
    1.46 +add_test(function batch() {
    1.47 +  gBookmarksObserver.expected = [
    1.48 +    { name: "onBeginUpdateBatch",
    1.49 +     args: [] },
    1.50 +    { name: "onEndUpdateBatch",
    1.51 +     args: [] },
    1.52 +  ];
    1.53 +  PlacesUtils.bookmarks.runInBatchMode({
    1.54 +    runBatched: function () {
    1.55 +      // Nothing.
    1.56 +    }
    1.57 +  }, null);
    1.58 +});
    1.59 +
    1.60 +add_test(function onItemAdded_bookmark() {
    1.61 +  const TITLE = "Bookmark 1";
    1.62 +  let uri = NetUtil.newURI("http://1.mozilla.org/");
    1.63 +  gBookmarksObserver.expected = [
    1.64 +    { name: "onItemAdded",
    1.65 +      args: [
    1.66 +        { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 },
    1.67 +        { name: "parentId", check: function (v) v === PlacesUtils.unfiledBookmarksFolderId },
    1.68 +        { name: "index", check: function (v) v === 0 },
    1.69 +        { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_BOOKMARK },
    1.70 +        { name: "uri", check: function (v) v instanceof Ci.nsIURI && v.equals(uri) },
    1.71 +        { name: "title", check: function (v) v === TITLE },
    1.72 +        { name: "dateAdded", check: function (v) typeof(v) == "number" && v > 0 },
    1.73 +        { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
    1.74 +        { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
    1.75 +      ] },
    1.76 +  ];
    1.77 +  PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
    1.78 +                                       uri, PlacesUtils.bookmarks.DEFAULT_INDEX,
    1.79 +                                       TITLE);
    1.80 +});
    1.81 +
    1.82 +add_test(function onItemAdded_separator() {
    1.83 +  gBookmarksObserver.expected = [
    1.84 +    { name: "onItemAdded",
    1.85 +      args: [
    1.86 +        { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 },
    1.87 +        { name: "parentId", check: function (v) v === PlacesUtils.unfiledBookmarksFolderId },
    1.88 +        { name: "index", check: function (v) v === 1 },
    1.89 +        { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_SEPARATOR },
    1.90 +        { name: "uri", check: function (v) v === null },
    1.91 +        { name: "title", check: function (v) v === null },
    1.92 +        { name: "dateAdded", check: function (v) typeof(v) == "number" && v > 0 },
    1.93 +        { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
    1.94 +        { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
    1.95 +      ] },
    1.96 +  ];
    1.97 +  PlacesUtils.bookmarks.insertSeparator(PlacesUtils.unfiledBookmarksFolderId,
    1.98 +                                        PlacesUtils.bookmarks.DEFAULT_INDEX);
    1.99 +});
   1.100 +
   1.101 +add_test(function onItemAdded_folder() {
   1.102 +  const TITLE = "Folder 1";
   1.103 +  gBookmarksObserver.expected = [
   1.104 +    { name: "onItemAdded",
   1.105 +      args: [
   1.106 +        { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 },
   1.107 +        { name: "parentId", check: function (v) v === PlacesUtils.unfiledBookmarksFolderId },
   1.108 +        { name: "index", check: function (v) v === 2 },
   1.109 +        { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_FOLDER },
   1.110 +        { name: "uri", check: function (v) v === null },
   1.111 +        { name: "title", check: function (v) v === TITLE },
   1.112 +        { name: "dateAdded", check: function (v) typeof(v) == "number" && v > 0 },
   1.113 +        { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.114 +        { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.115 +      ] },
   1.116 +  ];
   1.117 +  PlacesUtils.bookmarks.createFolder(PlacesUtils.unfiledBookmarksFolderId,
   1.118 +                                     TITLE,
   1.119 +                                     PlacesUtils.bookmarks.DEFAULT_INDEX);
   1.120 +});
   1.121 +
   1.122 +add_test(function onItemChanged_title_bookmark() {
   1.123 +  let id = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.unfiledBookmarksFolderId, 0);
   1.124 +  let uri = PlacesUtils.bookmarks.getBookmarkURI(id);
   1.125 +  const TITLE = "New title";
   1.126 +  gBookmarksObserver.expected = [
   1.127 +    { name: "onItemChanged", // This is an unfortunate effect of bug 653910.
   1.128 +      args: [
   1.129 +        { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 },
   1.130 +        { name: "property", check: function (v) v === "title" },
   1.131 +        { name: "isAnno", check: function (v) v === false },
   1.132 +        { name: "newValue", check: function (v) v === TITLE },
   1.133 +        { name: "lastModified", check: function (v) typeof(v) == "number" && v > 0 },
   1.134 +        { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_BOOKMARK },
   1.135 +        { name: "parentId", check: function (v) v === PlacesUtils.unfiledBookmarksFolderId },
   1.136 +        { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.137 +        { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.138 +      ] },
   1.139 +  ];
   1.140 +  PlacesUtils.bookmarks.setItemTitle(id, TITLE);
   1.141 +});
   1.142 +
   1.143 +add_test(function onItemChanged_tags_bookmark() {
   1.144 +  let id = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.unfiledBookmarksFolderId, 0);
   1.145 +  let uri = PlacesUtils.bookmarks.getBookmarkURI(id);
   1.146 +  const TITLE = "New title";
   1.147 +  const TAG = "tag"
   1.148 +  gBookmarksObserver.expected = [
   1.149 +    { name: "onBeginUpdateBatch", // Tag addition uses a batch.
   1.150 +     args: [] },
   1.151 +    { name: "onItemAdded", // This is the tag folder.
   1.152 +      args: [
   1.153 +        { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 },
   1.154 +        { name: "parentId", check: function (v) v === PlacesUtils.tagsFolderId },
   1.155 +        { name: "index", check: function (v) v === 0 },
   1.156 +        { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_FOLDER },
   1.157 +        { name: "uri", check: function (v) v === null },
   1.158 +        { name: "title", check: function (v) v === TAG },
   1.159 +        { name: "dateAdded", check: function (v) typeof(v) == "number" && v > 0 },
   1.160 +        { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.161 +        { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.162 +      ] },
   1.163 +    { name: "onItemAdded", // This is the tag.
   1.164 +      args: [
   1.165 +        { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 },
   1.166 +        { name: "parentId", check: function (v) typeof(v) == "number" && v > 0 },
   1.167 +        { name: "index", check: function (v) v === 0 },
   1.168 +        { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_BOOKMARK },
   1.169 +        { name: "uri", check: function (v) v instanceof Ci.nsIURI && v.equals(uri) },
   1.170 +        { name: "title", check: function (v) v === null },
   1.171 +        { name: "dateAdded", check: function (v) typeof(v) == "number" && v > 0 },
   1.172 +        { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.173 +        { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.174 +      ] },
   1.175 +    { name: "onItemChanged",
   1.176 +      args: [
   1.177 +        { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 },
   1.178 +        { name: "property", check: function (v) v === "tags" },
   1.179 +        { name: "isAnno", check: function (v) v === false },
   1.180 +        { name: "newValue", check: function (v) v === "" },
   1.181 +        { name: "lastModified", check: function (v) typeof(v) == "number" && v > 0 },
   1.182 +        { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_BOOKMARK },
   1.183 +        { name: "parentId", check: function (v) v === PlacesUtils.unfiledBookmarksFolderId },
   1.184 +        { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.185 +        { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.186 +      ] },
   1.187 +    { name: "onEndUpdateBatch",
   1.188 +      args: [] },
   1.189 +    { name: "onBeginUpdateBatch", // Tag removal uses a batch.
   1.190 +     args: [] },
   1.191 +    { name: "onItemRemoved", // This is the tag.
   1.192 +      args: [
   1.193 +        { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 },
   1.194 +        { name: "parentId", check: function (v) typeof(v) == "number" && v > 0 },
   1.195 +        { name: "index", check: function (v) v === 0 },
   1.196 +        { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_BOOKMARK },
   1.197 +        { name: "uri", check: function (v) v instanceof Ci.nsIURI && v.equals(uri) },
   1.198 +        { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.199 +        { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.200 +      ] },
   1.201 +    { name: "onItemRemoved", // This is the tag folder.
   1.202 +      args: [
   1.203 +        { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 },
   1.204 +        { name: "parentId", check: function (v) v === PlacesUtils.tagsFolderId },
   1.205 +        { name: "index", check: function (v) v === 0 },
   1.206 +        { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_FOLDER },
   1.207 +        { name: "uri", check: function (v) v === null },
   1.208 +        { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.209 +        { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.210 +      ] },
   1.211 +    { name: "onItemChanged",
   1.212 +      args: [
   1.213 +        { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 },
   1.214 +        { name: "property", check: function (v) v === "tags" },
   1.215 +        { name: "isAnno", check: function (v) v === false },
   1.216 +        { name: "newValue", check: function (v) v === "" },
   1.217 +        { name: "lastModified", check: function (v) typeof(v) == "number" && v > 0 },
   1.218 +        { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_BOOKMARK },
   1.219 +        { name: "parentId", check: function (v) v === PlacesUtils.unfiledBookmarksFolderId },
   1.220 +        { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.221 +        { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.222 +      ] },
   1.223 +    { name: "onEndUpdateBatch",
   1.224 +      args: [] },
   1.225 +  ];
   1.226 +  PlacesUtils.tagging.tagURI(uri, [TAG]);
   1.227 +  PlacesUtils.tagging.untagURI(uri, [TAG]);
   1.228 +});
   1.229 +
   1.230 +add_test(function onItemMoved_bookmark() {
   1.231 +  let id = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.unfiledBookmarksFolderId, 0);
   1.232 +  let uri = PlacesUtils.bookmarks.getBookmarkURI(id);
   1.233 +  gBookmarksObserver.expected = [
   1.234 +    { name: "onItemMoved",
   1.235 +      args: [
   1.236 +        { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 },
   1.237 +        { name: "oldParentId", check: function (v) v === PlacesUtils.unfiledBookmarksFolderId },
   1.238 +        { name: "oldIndex", check: function (v) v === 0 },
   1.239 +        { name: "newParentId", check: function (v) v === PlacesUtils.toolbarFolderId },
   1.240 +        { name: "newIndex", check: function (v) v === 0 },
   1.241 +        { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_BOOKMARK },
   1.242 +        { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.243 +        { name: "oldParentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.244 +        { name: "newParentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.245 +      ] },
   1.246 +    { name: "onItemMoved",
   1.247 +      args: [
   1.248 +        { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 },
   1.249 +        { name: "oldParentId", check: function (v) v === PlacesUtils.toolbarFolderId },
   1.250 +        { name: "oldIndex", check: function (v) v === 0 },
   1.251 +        { name: "newParentId", check: function (v) v === PlacesUtils.unfiledBookmarksFolderId },
   1.252 +        { name: "newIndex", check: function (v) v === 0 },
   1.253 +        { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_BOOKMARK },
   1.254 +        { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.255 +        { name: "oldParentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.256 +        { name: "newParentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.257 +      ] },
   1.258 +  ];
   1.259 +  PlacesUtils.bookmarks.moveItem(id, PlacesUtils.toolbarFolderId, 0);
   1.260 +  PlacesUtils.bookmarks.moveItem(id, PlacesUtils.unfiledBookmarksFolderId, 0);
   1.261 +});
   1.262 +
   1.263 +add_test(function onItemMoved_bookmark() {
   1.264 +  let id = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.unfiledBookmarksFolderId, 0);
   1.265 +  let uri = PlacesUtils.bookmarks.getBookmarkURI(id);
   1.266 +  gBookmarksObserver.expected = [
   1.267 +    { name: "onItemVisited",
   1.268 +      args: [
   1.269 +        { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 },
   1.270 +        { name: "visitId", check: function (v) typeof(v) == "number" && v > 0 },
   1.271 +        { name: "time", check: function (v) typeof(v) == "number" && v > 0 },
   1.272 +        { name: "transitionType", check: function (v) v === PlacesUtils.history.TRANSITION_TYPED },
   1.273 +        { name: "uri", check: function (v) v instanceof Ci.nsIURI && v.equals(uri) },
   1.274 +        { name: "parentId", check: function (v) v === PlacesUtils.unfiledBookmarksFolderId },
   1.275 +        { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.276 +        { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.277 +      ] },
   1.278 +  ];
   1.279 +  promiseAddVisits({ uri: uri, transition: TRANSITION_TYPED });
   1.280 +});
   1.281 +
   1.282 +add_test(function onItemRemoved_bookmark() {
   1.283 +  let id = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.unfiledBookmarksFolderId, 0);
   1.284 +  let uri = PlacesUtils.bookmarks.getBookmarkURI(id);
   1.285 +  gBookmarksObserver.expected = [
   1.286 +    { name: "onItemChanged", // This is an unfortunate effect of bug 653910.
   1.287 +      args: [
   1.288 +        { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 },
   1.289 +        { name: "property", check: function (v) v === "" },
   1.290 +        { name: "isAnno", check: function (v) v === true },
   1.291 +        { name: "newValue", check: function (v) v === "" },
   1.292 +        { name: "lastModified", check: function (v) typeof(v) == "number" && v > 0 },
   1.293 +        { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_BOOKMARK },
   1.294 +        { name: "parentId", check: function (v) v === PlacesUtils.unfiledBookmarksFolderId },
   1.295 +        { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.296 +        { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.297 +      ] },
   1.298 +    { name: "onItemRemoved",
   1.299 +      args: [
   1.300 +        { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 },
   1.301 +        { name: "parentId", check: function (v) v === PlacesUtils.unfiledBookmarksFolderId },
   1.302 +        { name: "index", check: function (v) v === 0 },
   1.303 +        { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_BOOKMARK },
   1.304 +        { name: "uri", check: function (v) v instanceof Ci.nsIURI && v.equals(uri) },
   1.305 +        { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.306 +        { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.307 +      ] },
   1.308 +  ];
   1.309 +  PlacesUtils.bookmarks.removeItem(id);
   1.310 +});
   1.311 +
   1.312 +add_test(function onItemRemoved_separator() {
   1.313 +  let id = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.unfiledBookmarksFolderId, 0);
   1.314 +  gBookmarksObserver.expected = [
   1.315 +    { name: "onItemChanged", // This is an unfortunate effect of bug 653910.
   1.316 +      args: [
   1.317 +        { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 },
   1.318 +        { name: "property", check: function (v) v === "" },
   1.319 +        { name: "isAnno", check: function (v) v === true },
   1.320 +        { name: "newValue", check: function (v) v === "" },
   1.321 +        { name: "lastModified", check: function (v) typeof(v) == "number" && v > 0 },
   1.322 +        { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_SEPARATOR },
   1.323 +        { name: "parentId", check: function (v) typeof(v) == "number" && v > 0 },
   1.324 +        { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.325 +        { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.326 +      ] },
   1.327 +    { name: "onItemRemoved",
   1.328 +      args: [
   1.329 +        { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 },
   1.330 +        { name: "parentId", check: function (v) typeof(v) == "number" && v > 0 },
   1.331 +        { name: "index", check: function (v) v === 0 },
   1.332 +        { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_SEPARATOR },
   1.333 +        { name: "uri", check: function (v) v === null },
   1.334 +        { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.335 +        { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.336 +      ] },
   1.337 +  ];
   1.338 +  PlacesUtils.bookmarks.removeItem(id);
   1.339 +});
   1.340 +
   1.341 +add_test(function onItemRemoved_folder() {
   1.342 +  let id = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.unfiledBookmarksFolderId, 0);
   1.343 +  const TITLE = "Folder 2";
   1.344 +  gBookmarksObserver.expected = [
   1.345 +    { name: "onItemChanged", // This is an unfortunate effect of bug 653910.
   1.346 +      args: [
   1.347 +        { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 },
   1.348 +        { name: "property", check: function (v) v === "" },
   1.349 +        { name: "isAnno", check: function (v) v === true },
   1.350 +        { name: "newValue", check: function (v) v === "" },
   1.351 +        { name: "lastModified", check: function (v) typeof(v) == "number" && v > 0 },
   1.352 +        { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_FOLDER },
   1.353 +        { name: "parentId", check: function (v) typeof(v) == "number" && v > 0 },
   1.354 +        { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.355 +        { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.356 +      ] },
   1.357 +    { name: "onItemRemoved",
   1.358 +      args: [
   1.359 +        { name: "itemId", check: function (v) typeof(v) == "number" && v > 0 },
   1.360 +        { name: "parentId", check: function (v) typeof(v) == "number" && v > 0 },
   1.361 +        { name: "index", check: function (v) v === 0 },
   1.362 +        { name: "itemType", check: function (v) v === PlacesUtils.bookmarks.TYPE_FOLDER },
   1.363 +        { name: "uri", check: function (v) v === null },
   1.364 +        { name: "guid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.365 +        { name: "parentGuid", check: function (v) typeof(v) == "string" && /^[a-zA-Z0-9\-_]{12}$/.test(v) },
   1.366 +      ] },
   1.367 +  ];
   1.368 +  PlacesUtils.bookmarks.removeItem(id);
   1.369 +});
   1.370 +
   1.371 +function run_test() {
   1.372 +  PlacesUtils.bookmarks.addObserver(gBookmarksObserver, false);
   1.373 +  run_next_test();
   1.374 +}
   1.375 +
   1.376 +do_register_cleanup(function () {
   1.377 +  PlacesUtils.bookmarks.removeObserver(gBookmarksObserver);
   1.378 +});

mercurial