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 | /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim:set ts=2 sw=2 sts=2 et: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | let bmsvc = PlacesUtils.bookmarks; |
michael@0 | 8 | let tagssvc = PlacesUtils.tagging; |
michael@0 | 9 | let annosvc = PlacesUtils.annotations; |
michael@0 | 10 | let txnManager = PlacesUtils.transactionManager; |
michael@0 | 11 | const DESCRIPTION_ANNO = "bookmarkProperties/description"; |
michael@0 | 12 | |
michael@0 | 13 | // create and add bookmarks observer |
michael@0 | 14 | let observer = { |
michael@0 | 15 | |
michael@0 | 16 | onBeginUpdateBatch: function() { |
michael@0 | 17 | this._beginUpdateBatch = true; |
michael@0 | 18 | }, |
michael@0 | 19 | _beginUpdateBatch: false, |
michael@0 | 20 | |
michael@0 | 21 | onEndUpdateBatch: function() { |
michael@0 | 22 | this._endUpdateBatch = true; |
michael@0 | 23 | }, |
michael@0 | 24 | _endUpdateBatch: false, |
michael@0 | 25 | |
michael@0 | 26 | onItemAdded: function(id, folder, index, itemType, uri) { |
michael@0 | 27 | this._itemAddedId = id; |
michael@0 | 28 | this._itemAddedParent = folder; |
michael@0 | 29 | this._itemAddedIndex = index; |
michael@0 | 30 | this._itemAddedType = itemType; |
michael@0 | 31 | }, |
michael@0 | 32 | _itemAddedId: null, |
michael@0 | 33 | _itemAddedParent: null, |
michael@0 | 34 | _itemAddedIndex: null, |
michael@0 | 35 | _itemAddedType: null, |
michael@0 | 36 | |
michael@0 | 37 | onItemRemoved: function(id, folder, index, itemType) { |
michael@0 | 38 | this._itemRemovedId = id; |
michael@0 | 39 | this._itemRemovedFolder = folder; |
michael@0 | 40 | this._itemRemovedIndex = index; |
michael@0 | 41 | }, |
michael@0 | 42 | _itemRemovedId: null, |
michael@0 | 43 | _itemRemovedFolder: null, |
michael@0 | 44 | _itemRemovedIndex: null, |
michael@0 | 45 | |
michael@0 | 46 | onItemChanged: function(id, property, isAnnotationProperty, newValue, |
michael@0 | 47 | lastModified, itemType) { |
michael@0 | 48 | // The transaction manager is being rewritten in bug 891303, so just |
michael@0 | 49 | // skip checking this for now. |
michael@0 | 50 | if (property == "tags") |
michael@0 | 51 | return; |
michael@0 | 52 | this._itemChangedId = id; |
michael@0 | 53 | this._itemChangedProperty = property; |
michael@0 | 54 | this._itemChanged_isAnnotationProperty = isAnnotationProperty; |
michael@0 | 55 | this._itemChangedValue = newValue; |
michael@0 | 56 | }, |
michael@0 | 57 | _itemChangedId: null, |
michael@0 | 58 | _itemChangedProperty: null, |
michael@0 | 59 | _itemChanged_isAnnotationProperty: null, |
michael@0 | 60 | _itemChangedValue: null, |
michael@0 | 61 | |
michael@0 | 62 | onItemVisited: function(id, visitID, time) { |
michael@0 | 63 | this._itemVisitedId = id; |
michael@0 | 64 | this._itemVisitedVistId = visitID; |
michael@0 | 65 | this._itemVisitedTime = time; |
michael@0 | 66 | }, |
michael@0 | 67 | _itemVisitedId: null, |
michael@0 | 68 | _itemVisitedVistId: null, |
michael@0 | 69 | _itemVisitedTime: null, |
michael@0 | 70 | |
michael@0 | 71 | onItemMoved: function(id, oldParent, oldIndex, newParent, newIndex, |
michael@0 | 72 | itemType) { |
michael@0 | 73 | this._itemMovedId = id; |
michael@0 | 74 | this._itemMovedOldParent = oldParent; |
michael@0 | 75 | this._itemMovedOldIndex = oldIndex; |
michael@0 | 76 | this._itemMovedNewParent = newParent; |
michael@0 | 77 | this._itemMovedNewIndex = newIndex; |
michael@0 | 78 | }, |
michael@0 | 79 | _itemMovedId: null, |
michael@0 | 80 | _itemMovedOldParent: null, |
michael@0 | 81 | _itemMovedOldIndex: null, |
michael@0 | 82 | _itemMovedNewParent: null, |
michael@0 | 83 | _itemMovedNewIndex: null, |
michael@0 | 84 | |
michael@0 | 85 | QueryInterface: function(iid) { |
michael@0 | 86 | if (iid.equals(Ci.nsINavBookmarkObserver) || |
michael@0 | 87 | iid.equals(Ci.nsISupports)) { |
michael@0 | 88 | return this; |
michael@0 | 89 | } |
michael@0 | 90 | throw Cr.NS_ERROR_NO_INTERFACE; |
michael@0 | 91 | } |
michael@0 | 92 | }; |
michael@0 | 93 | |
michael@0 | 94 | // index at which items should begin |
michael@0 | 95 | let bmStartIndex = 0; |
michael@0 | 96 | |
michael@0 | 97 | // get bookmarks root id |
michael@0 | 98 | let root = PlacesUtils.bookmarksMenuFolderId; |
michael@0 | 99 | |
michael@0 | 100 | function run_test() { |
michael@0 | 101 | bmsvc.addObserver(observer, false); |
michael@0 | 102 | do_register_cleanup(function () { |
michael@0 | 103 | bmsvc.removeObserver(observer); |
michael@0 | 104 | }); |
michael@0 | 105 | |
michael@0 | 106 | run_next_test(); |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | add_test(function test_create_folder_with_description() { |
michael@0 | 110 | const TEST_FOLDERNAME = "Test creating a folder with a description"; |
michael@0 | 111 | const TEST_DESCRIPTION = "this is my test description"; |
michael@0 | 112 | |
michael@0 | 113 | let annos = [{ name: DESCRIPTION_ANNO, |
michael@0 | 114 | type: annosvc.TYPE_STRING, |
michael@0 | 115 | flags: 0, |
michael@0 | 116 | value: TEST_DESCRIPTION, |
michael@0 | 117 | expires: annosvc.EXPIRE_NEVER }]; |
michael@0 | 118 | let txn = new PlacesCreateFolderTransaction(TEST_FOLDERNAME, root, bmStartIndex, annos); |
michael@0 | 119 | txnManager.doTransaction(txn); |
michael@0 | 120 | |
michael@0 | 121 | // This checks that calling undoTransaction on an "empty batch" doesn't |
michael@0 | 122 | // undo the previous transaction (getItemTitle will fail) |
michael@0 | 123 | txnManager.beginBatch(null); |
michael@0 | 124 | txnManager.endBatch(false); |
michael@0 | 125 | txnManager.undoTransaction(); |
michael@0 | 126 | |
michael@0 | 127 | let folderId = observer._itemAddedId; |
michael@0 | 128 | do_check_eq(bmsvc.getItemTitle(folderId), TEST_FOLDERNAME); |
michael@0 | 129 | do_check_eq(observer._itemAddedIndex, bmStartIndex); |
michael@0 | 130 | do_check_eq(observer._itemAddedParent, root); |
michael@0 | 131 | do_check_eq(observer._itemAddedId, folderId); |
michael@0 | 132 | do_check_eq(TEST_DESCRIPTION, annosvc.getItemAnnotation(folderId, DESCRIPTION_ANNO)); |
michael@0 | 133 | |
michael@0 | 134 | txn.undoTransaction(); |
michael@0 | 135 | do_check_eq(observer._itemRemovedId, folderId); |
michael@0 | 136 | do_check_eq(observer._itemRemovedFolder, root); |
michael@0 | 137 | do_check_eq(observer._itemRemovedIndex, bmStartIndex); |
michael@0 | 138 | |
michael@0 | 139 | txn.redoTransaction(); |
michael@0 | 140 | do_check_eq(observer._itemAddedIndex, bmStartIndex); |
michael@0 | 141 | do_check_eq(observer._itemAddedParent, root); |
michael@0 | 142 | do_check_eq(observer._itemAddedId, folderId); |
michael@0 | 143 | |
michael@0 | 144 | txn.undoTransaction(); |
michael@0 | 145 | do_check_eq(observer._itemRemovedId, folderId); |
michael@0 | 146 | do_check_eq(observer._itemRemovedFolder, root); |
michael@0 | 147 | do_check_eq(observer._itemRemovedIndex, bmStartIndex); |
michael@0 | 148 | |
michael@0 | 149 | run_next_test(); |
michael@0 | 150 | }); |
michael@0 | 151 | |
michael@0 | 152 | add_test(function test_create_item() { |
michael@0 | 153 | let testURI = NetUtil.newURI("http://test_create_item.com"); |
michael@0 | 154 | |
michael@0 | 155 | let txn = new PlacesCreateBookmarkTransaction(testURI, root, bmStartIndex, |
michael@0 | 156 | "Test creating an item"); |
michael@0 | 157 | |
michael@0 | 158 | txnManager.doTransaction(txn); |
michael@0 | 159 | let id = bmsvc.getBookmarkIdsForURI(testURI)[0]; |
michael@0 | 160 | do_check_eq(observer._itemAddedId, id); |
michael@0 | 161 | do_check_eq(observer._itemAddedIndex, bmStartIndex); |
michael@0 | 162 | do_check_true(bmsvc.isBookmarked(testURI)); |
michael@0 | 163 | |
michael@0 | 164 | txn.undoTransaction(); |
michael@0 | 165 | do_check_eq(observer._itemRemovedId, id); |
michael@0 | 166 | do_check_eq(observer._itemRemovedIndex, bmStartIndex); |
michael@0 | 167 | do_check_false(bmsvc.isBookmarked(testURI)); |
michael@0 | 168 | |
michael@0 | 169 | txn.redoTransaction(); |
michael@0 | 170 | do_check_true(bmsvc.isBookmarked(testURI)); |
michael@0 | 171 | let newId = bmsvc.getBookmarkIdsForURI(testURI)[0]; |
michael@0 | 172 | do_check_eq(observer._itemAddedIndex, bmStartIndex); |
michael@0 | 173 | do_check_eq(observer._itemAddedParent, root); |
michael@0 | 174 | do_check_eq(observer._itemAddedId, newId); |
michael@0 | 175 | |
michael@0 | 176 | txn.undoTransaction(); |
michael@0 | 177 | do_check_eq(observer._itemRemovedId, newId); |
michael@0 | 178 | do_check_eq(observer._itemRemovedFolder, root); |
michael@0 | 179 | do_check_eq(observer._itemRemovedIndex, bmStartIndex); |
michael@0 | 180 | |
michael@0 | 181 | run_next_test(); |
michael@0 | 182 | }); |
michael@0 | 183 | |
michael@0 | 184 | add_test(function test_create_item_to_folder() { |
michael@0 | 185 | const TEST_FOLDERNAME = "Test creating item to a folder"; |
michael@0 | 186 | let testURI = NetUtil.newURI("http://test_create_item_to_folder.com"); |
michael@0 | 187 | let folderId = bmsvc.createFolder(root, TEST_FOLDERNAME, bmsvc.DEFAULT_INDEX); |
michael@0 | 188 | |
michael@0 | 189 | let txn = new PlacesCreateBookmarkTransaction(testURI, folderId, bmStartIndex, |
michael@0 | 190 | "Test creating item"); |
michael@0 | 191 | txnManager.doTransaction(txn); |
michael@0 | 192 | let bkmId = bmsvc.getBookmarkIdsForURI(testURI)[0]; |
michael@0 | 193 | do_check_eq(observer._itemAddedId, bkmId); |
michael@0 | 194 | do_check_eq(observer._itemAddedIndex, bmStartIndex); |
michael@0 | 195 | do_check_true(bmsvc.isBookmarked(testURI)); |
michael@0 | 196 | |
michael@0 | 197 | txn.undoTransaction(); |
michael@0 | 198 | do_check_eq(observer._itemRemovedId, bkmId); |
michael@0 | 199 | do_check_eq(observer._itemRemovedIndex, bmStartIndex); |
michael@0 | 200 | |
michael@0 | 201 | txn.redoTransaction(); |
michael@0 | 202 | let newBkmId = bmsvc.getBookmarkIdsForURI(testURI)[0]; |
michael@0 | 203 | do_check_eq(observer._itemAddedIndex, bmStartIndex); |
michael@0 | 204 | do_check_eq(observer._itemAddedParent, folderId); |
michael@0 | 205 | do_check_eq(observer._itemAddedId, newBkmId); |
michael@0 | 206 | |
michael@0 | 207 | txn.undoTransaction(); |
michael@0 | 208 | do_check_eq(observer._itemRemovedId, newBkmId); |
michael@0 | 209 | do_check_eq(observer._itemRemovedFolder, folderId); |
michael@0 | 210 | do_check_eq(observer._itemRemovedIndex, bmStartIndex); |
michael@0 | 211 | |
michael@0 | 212 | run_next_test(); |
michael@0 | 213 | }); |
michael@0 | 214 | |
michael@0 | 215 | add_test(function test_move_items_to_folder() { |
michael@0 | 216 | let testFolderId = bmsvc.createFolder(root, "Test move items", bmsvc.DEFAULT_INDEX); |
michael@0 | 217 | let testURI = NetUtil.newURI("http://test_move_items.com"); |
michael@0 | 218 | let testBkmId = bmsvc.insertBookmark(testFolderId, testURI, bmsvc.DEFAULT_INDEX, "1: Test move items"); |
michael@0 | 219 | bmsvc.insertBookmark(testFolderId, testURI, bmsvc.DEFAULT_INDEX, "2: Test move items"); |
michael@0 | 220 | |
michael@0 | 221 | // Moving items between the same folder |
michael@0 | 222 | let sameTxn = new PlacesMoveItemTransaction(testBkmId, testFolderId, bmsvc.DEFAULT_INDEX); |
michael@0 | 223 | |
michael@0 | 224 | sameTxn.doTransaction(); |
michael@0 | 225 | do_check_eq(observer._itemMovedId, testBkmId); |
michael@0 | 226 | do_check_eq(observer._itemMovedOldParent, testFolderId); |
michael@0 | 227 | do_check_eq(observer._itemMovedOldIndex, 0); |
michael@0 | 228 | do_check_eq(observer._itemMovedNewParent, testFolderId); |
michael@0 | 229 | do_check_eq(observer._itemMovedNewIndex, 1); |
michael@0 | 230 | |
michael@0 | 231 | sameTxn.undoTransaction(); |
michael@0 | 232 | do_check_eq(observer._itemMovedId, testBkmId); |
michael@0 | 233 | do_check_eq(observer._itemMovedOldParent, testFolderId); |
michael@0 | 234 | do_check_eq(observer._itemMovedOldIndex, 1); |
michael@0 | 235 | do_check_eq(observer._itemMovedNewParent, testFolderId); |
michael@0 | 236 | do_check_eq(observer._itemMovedNewIndex, 0); |
michael@0 | 237 | |
michael@0 | 238 | sameTxn.redoTransaction(); |
michael@0 | 239 | do_check_eq(observer._itemMovedId, testBkmId); |
michael@0 | 240 | do_check_eq(observer._itemMovedOldParent, testFolderId); |
michael@0 | 241 | do_check_eq(observer._itemMovedOldIndex, 0); |
michael@0 | 242 | do_check_eq(observer._itemMovedNewParent, testFolderId); |
michael@0 | 243 | do_check_eq(observer._itemMovedNewIndex, 1); |
michael@0 | 244 | |
michael@0 | 245 | sameTxn.undoTransaction(); |
michael@0 | 246 | do_check_eq(observer._itemMovedId, testBkmId); |
michael@0 | 247 | do_check_eq(observer._itemMovedOldParent, testFolderId); |
michael@0 | 248 | do_check_eq(observer._itemMovedOldIndex, 1); |
michael@0 | 249 | do_check_eq(observer._itemMovedNewParent, testFolderId); |
michael@0 | 250 | do_check_eq(observer._itemMovedNewIndex, 0); |
michael@0 | 251 | |
michael@0 | 252 | // Moving items between different folders |
michael@0 | 253 | let folderId = bmsvc.createFolder(testFolderId, |
michael@0 | 254 | "Test move items between different folders", |
michael@0 | 255 | bmsvc.DEFAULT_INDEX); |
michael@0 | 256 | let diffTxn = new PlacesMoveItemTransaction(testBkmId, folderId, bmsvc.DEFAULT_INDEX); |
michael@0 | 257 | |
michael@0 | 258 | diffTxn.doTransaction(); |
michael@0 | 259 | do_check_eq(observer._itemMovedId, testBkmId); |
michael@0 | 260 | do_check_eq(observer._itemMovedOldParent, testFolderId); |
michael@0 | 261 | do_check_eq(observer._itemMovedOldIndex, 0); |
michael@0 | 262 | do_check_eq(observer._itemMovedNewParent, folderId); |
michael@0 | 263 | do_check_eq(observer._itemMovedNewIndex, 0); |
michael@0 | 264 | |
michael@0 | 265 | sameTxn.undoTransaction(); |
michael@0 | 266 | do_check_eq(observer._itemMovedId, testBkmId); |
michael@0 | 267 | do_check_eq(observer._itemMovedOldParent, folderId); |
michael@0 | 268 | do_check_eq(observer._itemMovedOldIndex, 0); |
michael@0 | 269 | do_check_eq(observer._itemMovedNewParent, testFolderId); |
michael@0 | 270 | do_check_eq(observer._itemMovedNewIndex, 0); |
michael@0 | 271 | |
michael@0 | 272 | diffTxn.redoTransaction(); |
michael@0 | 273 | do_check_eq(observer._itemMovedId, testBkmId); |
michael@0 | 274 | do_check_eq(observer._itemMovedOldParent, testFolderId); |
michael@0 | 275 | do_check_eq(observer._itemMovedOldIndex, 0); |
michael@0 | 276 | do_check_eq(observer._itemMovedNewParent, folderId); |
michael@0 | 277 | do_check_eq(observer._itemMovedNewIndex, 0); |
michael@0 | 278 | |
michael@0 | 279 | sameTxn.undoTransaction(); |
michael@0 | 280 | do_check_eq(observer._itemMovedId, testBkmId); |
michael@0 | 281 | do_check_eq(observer._itemMovedOldParent, folderId); |
michael@0 | 282 | do_check_eq(observer._itemMovedOldIndex, 0); |
michael@0 | 283 | do_check_eq(observer._itemMovedNewParent, testFolderId); |
michael@0 | 284 | do_check_eq(observer._itemMovedNewIndex, 0); |
michael@0 | 285 | |
michael@0 | 286 | run_next_test(); |
michael@0 | 287 | }); |
michael@0 | 288 | |
michael@0 | 289 | add_test(function test_remove_folder() { |
michael@0 | 290 | let testFolder = bmsvc.createFolder(root, "Test Removing a Folder", bmsvc.DEFAULT_INDEX); |
michael@0 | 291 | let folderId = bmsvc.createFolder(testFolder, "Removed Folder", bmsvc.DEFAULT_INDEX); |
michael@0 | 292 | |
michael@0 | 293 | let txn = new PlacesRemoveItemTransaction(folderId); |
michael@0 | 294 | |
michael@0 | 295 | txn.doTransaction(); |
michael@0 | 296 | do_check_eq(observer._itemRemovedId, folderId); |
michael@0 | 297 | do_check_eq(observer._itemRemovedFolder, testFolder); |
michael@0 | 298 | do_check_eq(observer._itemRemovedIndex, 0); |
michael@0 | 299 | |
michael@0 | 300 | txn.undoTransaction(); |
michael@0 | 301 | do_check_eq(observer._itemAddedId, folderId); |
michael@0 | 302 | do_check_eq(observer._itemAddedParent, testFolder); |
michael@0 | 303 | do_check_eq(observer._itemAddedIndex, 0); |
michael@0 | 304 | |
michael@0 | 305 | txn.redoTransaction(); |
michael@0 | 306 | do_check_eq(observer._itemRemovedId, folderId); |
michael@0 | 307 | do_check_eq(observer._itemRemovedFolder, testFolder); |
michael@0 | 308 | do_check_eq(observer._itemRemovedIndex, 0); |
michael@0 | 309 | |
michael@0 | 310 | txn.undoTransaction(); |
michael@0 | 311 | do_check_eq(observer._itemAddedId, folderId); |
michael@0 | 312 | do_check_eq(observer._itemAddedParent, testFolder); |
michael@0 | 313 | do_check_eq(observer._itemAddedIndex, 0); |
michael@0 | 314 | |
michael@0 | 315 | run_next_test(); |
michael@0 | 316 | }); |
michael@0 | 317 | |
michael@0 | 318 | add_test(function test_remove_item_with_keyword_and_tag() { |
michael@0 | 319 | // Notice in this case the tag persists since other bookmarks have same uri. |
michael@0 | 320 | let testFolder = bmsvc.createFolder(root, "Test removing an item with a keyword and a tag", |
michael@0 | 321 | bmsvc.DEFAULT_INDEX); |
michael@0 | 322 | |
michael@0 | 323 | const KEYWORD = "test: test removing an item with a keyword and a tag"; |
michael@0 | 324 | const TAG_NAME = "tag-test_remove_item_with_keyword_and_tag"; |
michael@0 | 325 | let testURI = NetUtil.newURI("http://test_remove_item_with_keyword_and_tag.com"); |
michael@0 | 326 | let testBkmId = bmsvc.insertBookmark(testFolder, testURI, bmsvc.DEFAULT_INDEX, "test-item1"); |
michael@0 | 327 | |
michael@0 | 328 | // create bookmark for not removing tag. |
michael@0 | 329 | bmsvc.insertBookmark(testFolder, testURI, bmsvc.DEFAULT_INDEX, "test-item2"); |
michael@0 | 330 | |
michael@0 | 331 | // set tag & keyword |
michael@0 | 332 | bmsvc.setKeywordForBookmark(testBkmId, KEYWORD); |
michael@0 | 333 | tagssvc.tagURI(testURI, [TAG_NAME]); |
michael@0 | 334 | |
michael@0 | 335 | let txn = new PlacesRemoveItemTransaction(testBkmId); |
michael@0 | 336 | |
michael@0 | 337 | txn.doTransaction(); |
michael@0 | 338 | do_check_eq(observer._itemRemovedId, testBkmId); |
michael@0 | 339 | do_check_eq(observer._itemRemovedFolder, testFolder); |
michael@0 | 340 | do_check_eq(observer._itemRemovedIndex, 0); |
michael@0 | 341 | do_check_eq(bmsvc.getKeywordForBookmark(testBkmId), null); |
michael@0 | 342 | do_check_eq(tagssvc.getTagsForURI(testURI)[0], TAG_NAME); |
michael@0 | 343 | |
michael@0 | 344 | txn.undoTransaction(); |
michael@0 | 345 | let newbkmk2Id = observer._itemAddedId; |
michael@0 | 346 | do_check_eq(observer._itemAddedParent, testFolder); |
michael@0 | 347 | do_check_eq(observer._itemAddedIndex, 0); |
michael@0 | 348 | do_check_eq(bmsvc.getKeywordForBookmark(newbkmk2Id), KEYWORD); |
michael@0 | 349 | do_check_eq(tagssvc.getTagsForURI(testURI)[0], TAG_NAME); |
michael@0 | 350 | |
michael@0 | 351 | txn.redoTransaction(); |
michael@0 | 352 | do_check_eq(observer._itemRemovedId, newbkmk2Id); |
michael@0 | 353 | do_check_eq(observer._itemRemovedFolder, testFolder); |
michael@0 | 354 | do_check_eq(observer._itemRemovedIndex, 0); |
michael@0 | 355 | do_check_eq(bmsvc.getKeywordForBookmark(newbkmk2Id), null); |
michael@0 | 356 | do_check_eq(tagssvc.getTagsForURI(testURI)[0], TAG_NAME); |
michael@0 | 357 | |
michael@0 | 358 | txn.undoTransaction(); |
michael@0 | 359 | do_check_eq(observer._itemAddedParent, testFolder); |
michael@0 | 360 | do_check_eq(observer._itemAddedIndex, 0); |
michael@0 | 361 | do_check_eq(tagssvc.getTagsForURI(testURI)[0], TAG_NAME); |
michael@0 | 362 | |
michael@0 | 363 | run_next_test(); |
michael@0 | 364 | }); |
michael@0 | 365 | |
michael@0 | 366 | add_test(function test_remove_item_with_tag() { |
michael@0 | 367 | const TAG_NAME = "tag-test_remove_item_with_tag"; |
michael@0 | 368 | let testURI = NetUtil.newURI("http://test_remove_item_with_tag.com/"); |
michael@0 | 369 | let itemId = bmsvc.insertBookmark(root, testURI, bmsvc.DEFAULT_INDEX, "Test removing an item with a tag"); |
michael@0 | 370 | tagssvc.tagURI(testURI, [TAG_NAME]); |
michael@0 | 371 | |
michael@0 | 372 | let txn = new PlacesRemoveItemTransaction(itemId); |
michael@0 | 373 | |
michael@0 | 374 | txn.doTransaction(); |
michael@0 | 375 | do_check_true(tagssvc.getTagsForURI(testURI).length == 0); |
michael@0 | 376 | |
michael@0 | 377 | txn.undoTransaction(); |
michael@0 | 378 | do_check_eq(tagssvc.getTagsForURI(testURI)[0], TAG_NAME); |
michael@0 | 379 | |
michael@0 | 380 | txn.redoTransaction(); |
michael@0 | 381 | do_check_true(tagssvc.getTagsForURI(testURI).length == 0); |
michael@0 | 382 | |
michael@0 | 383 | txn.undoTransaction(); |
michael@0 | 384 | do_check_eq(tagssvc.getTagsForURI(testURI)[0], TAG_NAME); |
michael@0 | 385 | |
michael@0 | 386 | txn.redoTransaction(); |
michael@0 | 387 | |
michael@0 | 388 | run_next_test(); |
michael@0 | 389 | }); |
michael@0 | 390 | |
michael@0 | 391 | add_test(function test_creating_separator() { |
michael@0 | 392 | let testFolder = bmsvc.createFolder(root, "Test creating a separator", bmsvc.DEFAULT_INDEX); |
michael@0 | 393 | |
michael@0 | 394 | let txn = new PlacesCreateSeparatorTransaction(testFolder, 0); |
michael@0 | 395 | txn.doTransaction(); |
michael@0 | 396 | |
michael@0 | 397 | let sepId = observer._itemAddedId; |
michael@0 | 398 | do_check_eq(observer._itemAddedIndex, 0); |
michael@0 | 399 | do_check_eq(observer._itemAddedParent, testFolder); |
michael@0 | 400 | |
michael@0 | 401 | txn.undoTransaction(); |
michael@0 | 402 | do_check_eq(observer._itemRemovedId, sepId); |
michael@0 | 403 | do_check_eq(observer._itemRemovedFolder, testFolder); |
michael@0 | 404 | do_check_eq(observer._itemRemovedIndex, 0); |
michael@0 | 405 | |
michael@0 | 406 | txn.redoTransaction(); |
michael@0 | 407 | let newSepId = observer._itemAddedId; |
michael@0 | 408 | do_check_eq(observer._itemAddedIndex, 0); |
michael@0 | 409 | do_check_eq(observer._itemAddedParent, testFolder); |
michael@0 | 410 | |
michael@0 | 411 | txn.undoTransaction(); |
michael@0 | 412 | do_check_eq(observer._itemRemovedId, newSepId); |
michael@0 | 413 | do_check_eq(observer._itemRemovedFolder, testFolder); |
michael@0 | 414 | do_check_eq(observer._itemRemovedIndex, 0); |
michael@0 | 415 | |
michael@0 | 416 | run_next_test(); |
michael@0 | 417 | }); |
michael@0 | 418 | |
michael@0 | 419 | add_test(function test_removing_separator() { |
michael@0 | 420 | let testFolder = bmsvc.createFolder(root, "Test removing a separator", bmsvc.DEFAULT_INDEX); |
michael@0 | 421 | |
michael@0 | 422 | let sepId = bmsvc.insertSeparator(testFolder, 0); |
michael@0 | 423 | let txn = new PlacesRemoveItemTransaction(sepId); |
michael@0 | 424 | |
michael@0 | 425 | txn.doTransaction(); |
michael@0 | 426 | do_check_eq(observer._itemRemovedId, sepId); |
michael@0 | 427 | do_check_eq(observer._itemRemovedFolder, testFolder); |
michael@0 | 428 | do_check_eq(observer._itemRemovedIndex, 0); |
michael@0 | 429 | |
michael@0 | 430 | txn.undoTransaction(); |
michael@0 | 431 | do_check_eq(observer._itemAddedId, sepId); //New separator created |
michael@0 | 432 | do_check_eq(observer._itemAddedParent, testFolder); |
michael@0 | 433 | do_check_eq(observer._itemAddedIndex, 0); |
michael@0 | 434 | |
michael@0 | 435 | txn.redoTransaction(); |
michael@0 | 436 | do_check_eq(observer._itemRemovedId, sepId); |
michael@0 | 437 | do_check_eq(observer._itemRemovedFolder, testFolder); |
michael@0 | 438 | do_check_eq(observer._itemRemovedIndex, 0); |
michael@0 | 439 | |
michael@0 | 440 | txn.undoTransaction(); |
michael@0 | 441 | do_check_eq(observer._itemAddedId, sepId); //New separator created |
michael@0 | 442 | do_check_eq(observer._itemAddedParent, testFolder); |
michael@0 | 443 | do_check_eq(observer._itemAddedIndex, 0); |
michael@0 | 444 | |
michael@0 | 445 | run_next_test(); |
michael@0 | 446 | }); |
michael@0 | 447 | |
michael@0 | 448 | add_test(function test_editing_item_title() { |
michael@0 | 449 | const TITLE = "Test editing item title"; |
michael@0 | 450 | const MOD_TITLE = "Mod: Test editing item title"; |
michael@0 | 451 | let testURI = NetUtil.newURI("http://www.test_editing_item_title.com"); |
michael@0 | 452 | let testBkmId = bmsvc.insertBookmark(root, testURI, bmsvc.DEFAULT_INDEX, TITLE); |
michael@0 | 453 | |
michael@0 | 454 | let txn = new PlacesEditItemTitleTransaction(testBkmId, MOD_TITLE); |
michael@0 | 455 | |
michael@0 | 456 | txn.doTransaction(); |
michael@0 | 457 | do_check_eq(observer._itemChangedId, testBkmId); |
michael@0 | 458 | do_check_eq(observer._itemChangedProperty, "title"); |
michael@0 | 459 | do_check_eq(observer._itemChangedValue, MOD_TITLE); |
michael@0 | 460 | |
michael@0 | 461 | txn.undoTransaction(); |
michael@0 | 462 | do_check_eq(observer._itemChangedId, testBkmId); |
michael@0 | 463 | do_check_eq(observer._itemChangedProperty, "title"); |
michael@0 | 464 | do_check_eq(observer._itemChangedValue, TITLE); |
michael@0 | 465 | |
michael@0 | 466 | txn.redoTransaction(); |
michael@0 | 467 | do_check_eq(observer._itemChangedId, testBkmId); |
michael@0 | 468 | do_check_eq(observer._itemChangedProperty, "title"); |
michael@0 | 469 | do_check_eq(observer._itemChangedValue, MOD_TITLE); |
michael@0 | 470 | |
michael@0 | 471 | txn.undoTransaction(); |
michael@0 | 472 | do_check_eq(observer._itemChangedId, testBkmId); |
michael@0 | 473 | do_check_eq(observer._itemChangedProperty, "title"); |
michael@0 | 474 | do_check_eq(observer._itemChangedValue, TITLE); |
michael@0 | 475 | |
michael@0 | 476 | run_next_test(); |
michael@0 | 477 | }); |
michael@0 | 478 | |
michael@0 | 479 | add_test(function test_editing_item_uri() { |
michael@0 | 480 | const OLD_TEST_URI = NetUtil.newURI("http://old.test_editing_item_uri.com/"); |
michael@0 | 481 | const NEW_TEST_URI = NetUtil.newURI("http://new.test_editing_item_uri.com/"); |
michael@0 | 482 | let testBkmId = bmsvc.insertBookmark(root, OLD_TEST_URI, bmsvc.DEFAULT_INDEX, |
michael@0 | 483 | "Test editing item title"); |
michael@0 | 484 | tagssvc.tagURI(OLD_TEST_URI, ["tag"]); |
michael@0 | 485 | |
michael@0 | 486 | let txn = new PlacesEditBookmarkURITransaction(testBkmId, NEW_TEST_URI); |
michael@0 | 487 | |
michael@0 | 488 | txn.doTransaction(); |
michael@0 | 489 | do_check_eq(observer._itemChangedId, testBkmId); |
michael@0 | 490 | do_check_eq(observer._itemChangedProperty, "uri"); |
michael@0 | 491 | do_check_eq(observer._itemChangedValue, NEW_TEST_URI.spec); |
michael@0 | 492 | do_check_eq(JSON.stringify(tagssvc.getTagsForURI(NEW_TEST_URI)), JSON.stringify(["tag"])); |
michael@0 | 493 | do_check_eq(JSON.stringify(tagssvc.getTagsForURI(OLD_TEST_URI)), JSON.stringify([])); |
michael@0 | 494 | |
michael@0 | 495 | txn.undoTransaction(); |
michael@0 | 496 | do_check_eq(observer._itemChangedId, testBkmId); |
michael@0 | 497 | do_check_eq(observer._itemChangedProperty, "uri"); |
michael@0 | 498 | do_check_eq(observer._itemChangedValue, OLD_TEST_URI.spec); |
michael@0 | 499 | do_check_eq(JSON.stringify(tagssvc.getTagsForURI(OLD_TEST_URI)), JSON.stringify(["tag"])); |
michael@0 | 500 | do_check_eq(JSON.stringify(tagssvc.getTagsForURI(NEW_TEST_URI)), JSON.stringify([])); |
michael@0 | 501 | |
michael@0 | 502 | txn.redoTransaction(); |
michael@0 | 503 | do_check_eq(observer._itemChangedId, testBkmId); |
michael@0 | 504 | do_check_eq(observer._itemChangedProperty, "uri"); |
michael@0 | 505 | do_check_eq(observer._itemChangedValue, NEW_TEST_URI.spec); |
michael@0 | 506 | do_check_eq(JSON.stringify(tagssvc.getTagsForURI(NEW_TEST_URI)), JSON.stringify(["tag"])); |
michael@0 | 507 | do_check_eq(JSON.stringify(tagssvc.getTagsForURI(OLD_TEST_URI)), JSON.stringify([])); |
michael@0 | 508 | |
michael@0 | 509 | txn.undoTransaction(); |
michael@0 | 510 | do_check_eq(observer._itemChangedId, testBkmId); |
michael@0 | 511 | do_check_eq(observer._itemChangedProperty, "uri"); |
michael@0 | 512 | do_check_eq(observer._itemChangedValue, OLD_TEST_URI.spec); |
michael@0 | 513 | do_check_eq(JSON.stringify(tagssvc.getTagsForURI(OLD_TEST_URI)), JSON.stringify(["tag"])); |
michael@0 | 514 | do_check_eq(JSON.stringify(tagssvc.getTagsForURI(NEW_TEST_URI)), JSON.stringify([])); |
michael@0 | 515 | |
michael@0 | 516 | run_next_test(); |
michael@0 | 517 | }); |
michael@0 | 518 | |
michael@0 | 519 | add_test(function test_edit_description_transaction() { |
michael@0 | 520 | let testURI = NetUtil.newURI("http://test_edit_description_transaction.com"); |
michael@0 | 521 | let testBkmId = bmsvc.insertBookmark(root, testURI, bmsvc.DEFAULT_INDEX, "Test edit description transaction"); |
michael@0 | 522 | |
michael@0 | 523 | let anno = { |
michael@0 | 524 | name: DESCRIPTION_ANNO, |
michael@0 | 525 | type: Ci.nsIAnnotationService.TYPE_STRING, |
michael@0 | 526 | flags: 0, |
michael@0 | 527 | value: "Test edit Description", |
michael@0 | 528 | expires: Ci.nsIAnnotationService.EXPIRE_NEVER, |
michael@0 | 529 | }; |
michael@0 | 530 | let txn = new PlacesSetItemAnnotationTransaction(testBkmId, anno); |
michael@0 | 531 | |
michael@0 | 532 | txn.doTransaction(); |
michael@0 | 533 | do_check_eq(observer._itemChangedId, testBkmId); |
michael@0 | 534 | do_check_eq(observer._itemChangedProperty, DESCRIPTION_ANNO); |
michael@0 | 535 | |
michael@0 | 536 | run_next_test(); |
michael@0 | 537 | }); |
michael@0 | 538 | |
michael@0 | 539 | add_test(function test_edit_keyword() { |
michael@0 | 540 | const KEYWORD = "keyword-test_edit_keyword"; |
michael@0 | 541 | |
michael@0 | 542 | let testURI = NetUtil.newURI("http://test_edit_keyword.com"); |
michael@0 | 543 | let testBkmId = bmsvc.insertBookmark(root, testURI, bmsvc.DEFAULT_INDEX, "Test edit keyword"); |
michael@0 | 544 | |
michael@0 | 545 | let txn = new PlacesEditBookmarkKeywordTransaction(testBkmId, KEYWORD); |
michael@0 | 546 | |
michael@0 | 547 | txn.doTransaction(); |
michael@0 | 548 | do_check_eq(observer._itemChangedId, testBkmId); |
michael@0 | 549 | do_check_eq(observer._itemChangedProperty, "keyword"); |
michael@0 | 550 | do_check_eq(observer._itemChangedValue, KEYWORD); |
michael@0 | 551 | |
michael@0 | 552 | txn.undoTransaction(); |
michael@0 | 553 | do_check_eq(observer._itemChangedId, testBkmId); |
michael@0 | 554 | do_check_eq(observer._itemChangedProperty, "keyword"); |
michael@0 | 555 | do_check_eq(observer._itemChangedValue, ""); |
michael@0 | 556 | |
michael@0 | 557 | run_next_test(); |
michael@0 | 558 | }); |
michael@0 | 559 | |
michael@0 | 560 | add_test(function test_LoadInSidebar_transaction() { |
michael@0 | 561 | let testURI = NetUtil.newURI("http://test_LoadInSidebar_transaction.com"); |
michael@0 | 562 | let testBkmId = bmsvc.insertBookmark(root, testURI, bmsvc.DEFAULT_INDEX, "Test LoadInSidebar transaction"); |
michael@0 | 563 | |
michael@0 | 564 | const LOAD_IN_SIDEBAR_ANNO = "bookmarkProperties/loadInSidebar"; |
michael@0 | 565 | let anno = { name: LOAD_IN_SIDEBAR_ANNO, |
michael@0 | 566 | type: Ci.nsIAnnotationService.TYPE_INT32, |
michael@0 | 567 | flags: 0, |
michael@0 | 568 | value: true, |
michael@0 | 569 | expires: Ci.nsIAnnotationService.EXPIRE_NEVER }; |
michael@0 | 570 | let txn = new PlacesSetItemAnnotationTransaction(testBkmId, anno); |
michael@0 | 571 | |
michael@0 | 572 | txn.doTransaction(); |
michael@0 | 573 | do_check_eq(observer._itemChangedId, testBkmId); |
michael@0 | 574 | do_check_eq(observer._itemChangedProperty, LOAD_IN_SIDEBAR_ANNO); |
michael@0 | 575 | do_check_eq(observer._itemChanged_isAnnotationProperty, true); |
michael@0 | 576 | |
michael@0 | 577 | txn.undoTransaction(); |
michael@0 | 578 | do_check_eq(observer._itemChangedId, testBkmId); |
michael@0 | 579 | do_check_eq(observer._itemChangedProperty, LOAD_IN_SIDEBAR_ANNO); |
michael@0 | 580 | do_check_eq(observer._itemChanged_isAnnotationProperty, true); |
michael@0 | 581 | |
michael@0 | 582 | run_next_test(); |
michael@0 | 583 | }); |
michael@0 | 584 | |
michael@0 | 585 | add_test(function test_generic_item_annotation() { |
michael@0 | 586 | let testURI = NetUtil.newURI("http://test_generic_item_annotation.com"); |
michael@0 | 587 | let testBkmId = bmsvc.insertBookmark(root, testURI, bmsvc.DEFAULT_INDEX, "Test generic item annotation"); |
michael@0 | 588 | |
michael@0 | 589 | let itemAnnoObj = { name: "testAnno/testInt", |
michael@0 | 590 | type: Ci.nsIAnnotationService.TYPE_INT32, |
michael@0 | 591 | flags: 0, |
michael@0 | 592 | value: 123, |
michael@0 | 593 | expires: Ci.nsIAnnotationService.EXPIRE_NEVER }; |
michael@0 | 594 | let txn = new PlacesSetItemAnnotationTransaction(testBkmId, itemAnnoObj); |
michael@0 | 595 | |
michael@0 | 596 | txn.doTransaction(); |
michael@0 | 597 | do_check_eq(observer._itemChangedId, testBkmId); |
michael@0 | 598 | do_check_eq(observer._itemChangedProperty, "testAnno/testInt"); |
michael@0 | 599 | do_check_eq(observer._itemChanged_isAnnotationProperty, true); |
michael@0 | 600 | |
michael@0 | 601 | txn.undoTransaction(); |
michael@0 | 602 | do_check_eq(observer._itemChangedId, testBkmId); |
michael@0 | 603 | do_check_eq(observer._itemChangedProperty, "testAnno/testInt"); |
michael@0 | 604 | do_check_eq(observer._itemChanged_isAnnotationProperty, true); |
michael@0 | 605 | |
michael@0 | 606 | txn.redoTransaction(); |
michael@0 | 607 | do_check_eq(observer._itemChangedId, testBkmId); |
michael@0 | 608 | do_check_eq(observer._itemChangedProperty, "testAnno/testInt"); |
michael@0 | 609 | do_check_eq(observer._itemChanged_isAnnotationProperty, true); |
michael@0 | 610 | |
michael@0 | 611 | run_next_test(); |
michael@0 | 612 | }); |
michael@0 | 613 | |
michael@0 | 614 | add_test(function test_editing_item_date_added() { |
michael@0 | 615 | let testURI = NetUtil.newURI("http://test_editing_item_date_added.com"); |
michael@0 | 616 | let testBkmId = bmsvc.insertBookmark(root, testURI, bmsvc.DEFAULT_INDEX, |
michael@0 | 617 | "Test editing item date added"); |
michael@0 | 618 | |
michael@0 | 619 | let oldAdded = bmsvc.getItemDateAdded(testBkmId); |
michael@0 | 620 | let newAdded = Date.now() + 1000; |
michael@0 | 621 | let txn = new PlacesEditItemDateAddedTransaction(testBkmId, newAdded); |
michael@0 | 622 | |
michael@0 | 623 | txn.doTransaction(); |
michael@0 | 624 | do_check_eq(newAdded, bmsvc.getItemDateAdded(testBkmId)); |
michael@0 | 625 | |
michael@0 | 626 | txn.undoTransaction(); |
michael@0 | 627 | do_check_eq(oldAdded, bmsvc.getItemDateAdded(testBkmId)); |
michael@0 | 628 | |
michael@0 | 629 | run_next_test(); |
michael@0 | 630 | }); |
michael@0 | 631 | |
michael@0 | 632 | add_test(function test_edit_item_last_modified() { |
michael@0 | 633 | let testURI = NetUtil.newURI("http://test_edit_item_last_modified.com"); |
michael@0 | 634 | let testBkmId = bmsvc.insertBookmark(root, testURI, bmsvc.DEFAULT_INDEX, |
michael@0 | 635 | "Test editing item last modified"); |
michael@0 | 636 | |
michael@0 | 637 | let oldModified = bmsvc.getItemLastModified(testBkmId); |
michael@0 | 638 | let newModified = Date.now() + 1000; |
michael@0 | 639 | let txn = new PlacesEditItemLastModifiedTransaction(testBkmId, newModified); |
michael@0 | 640 | |
michael@0 | 641 | txn.doTransaction(); |
michael@0 | 642 | do_check_eq(newModified, bmsvc.getItemLastModified(testBkmId)); |
michael@0 | 643 | |
michael@0 | 644 | txn.undoTransaction(); |
michael@0 | 645 | do_check_eq(oldModified, bmsvc.getItemLastModified(testBkmId)); |
michael@0 | 646 | |
michael@0 | 647 | run_next_test(); |
michael@0 | 648 | }); |
michael@0 | 649 | |
michael@0 | 650 | add_test(function test_generic_page_annotation() { |
michael@0 | 651 | const TEST_ANNO = "testAnno/testInt"; |
michael@0 | 652 | let testURI = NetUtil.newURI("http://www.mozilla.org/"); |
michael@0 | 653 | promiseAddVisits(testURI).then(function () { |
michael@0 | 654 | let pageAnnoObj = { name: TEST_ANNO, |
michael@0 | 655 | type: Ci.nsIAnnotationService.TYPE_INT32, |
michael@0 | 656 | flags: 0, |
michael@0 | 657 | value: 123, |
michael@0 | 658 | expires: Ci.nsIAnnotationService.EXPIRE_NEVER }; |
michael@0 | 659 | let txn = new PlacesSetPageAnnotationTransaction(testURI, pageAnnoObj); |
michael@0 | 660 | |
michael@0 | 661 | txn.doTransaction(); |
michael@0 | 662 | do_check_true(annosvc.pageHasAnnotation(testURI, TEST_ANNO)); |
michael@0 | 663 | |
michael@0 | 664 | txn.undoTransaction(); |
michael@0 | 665 | do_check_false(annosvc.pageHasAnnotation(testURI, TEST_ANNO)); |
michael@0 | 666 | |
michael@0 | 667 | txn.redoTransaction(); |
michael@0 | 668 | do_check_true(annosvc.pageHasAnnotation(testURI, TEST_ANNO)); |
michael@0 | 669 | |
michael@0 | 670 | run_next_test(); |
michael@0 | 671 | }); |
michael@0 | 672 | }); |
michael@0 | 673 | |
michael@0 | 674 | add_test(function test_sort_folder_by_name() { |
michael@0 | 675 | let testFolder = bmsvc.createFolder(root, "Test PlacesSortFolderByNameTransaction", |
michael@0 | 676 | bmsvc.DEFAULT_INDEX); |
michael@0 | 677 | let testURI = NetUtil.newURI("http://test_sort_folder_by_name.com"); |
michael@0 | 678 | |
michael@0 | 679 | bmsvc.insertBookmark(testFolder, testURI, bmsvc.DEFAULT_INDEX, "bookmark3"); |
michael@0 | 680 | bmsvc.insertBookmark(testFolder, testURI, bmsvc.DEFAULT_INDEX, "bookmark2"); |
michael@0 | 681 | bmsvc.insertBookmark(testFolder, testURI, bmsvc.DEFAULT_INDEX, "bookmark1"); |
michael@0 | 682 | |
michael@0 | 683 | let bkmIds = bmsvc.getBookmarkIdsForURI(testURI); |
michael@0 | 684 | bkmIds.sort(); |
michael@0 | 685 | |
michael@0 | 686 | let b1 = bkmIds[0]; |
michael@0 | 687 | let b2 = bkmIds[1]; |
michael@0 | 688 | let b3 = bkmIds[2]; |
michael@0 | 689 | |
michael@0 | 690 | do_check_eq(0, bmsvc.getItemIndex(b1)); |
michael@0 | 691 | do_check_eq(1, bmsvc.getItemIndex(b2)); |
michael@0 | 692 | do_check_eq(2, bmsvc.getItemIndex(b3)); |
michael@0 | 693 | |
michael@0 | 694 | let txn = new PlacesSortFolderByNameTransaction(testFolder); |
michael@0 | 695 | |
michael@0 | 696 | txn.doTransaction(); |
michael@0 | 697 | do_check_eq(2, bmsvc.getItemIndex(b1)); |
michael@0 | 698 | do_check_eq(1, bmsvc.getItemIndex(b2)); |
michael@0 | 699 | do_check_eq(0, bmsvc.getItemIndex(b3)); |
michael@0 | 700 | |
michael@0 | 701 | txn.undoTransaction(); |
michael@0 | 702 | do_check_eq(0, bmsvc.getItemIndex(b1)); |
michael@0 | 703 | do_check_eq(1, bmsvc.getItemIndex(b2)); |
michael@0 | 704 | do_check_eq(2, bmsvc.getItemIndex(b3)); |
michael@0 | 705 | |
michael@0 | 706 | txn.redoTransaction(); |
michael@0 | 707 | do_check_eq(2, bmsvc.getItemIndex(b1)); |
michael@0 | 708 | do_check_eq(1, bmsvc.getItemIndex(b2)); |
michael@0 | 709 | do_check_eq(0, bmsvc.getItemIndex(b3)); |
michael@0 | 710 | |
michael@0 | 711 | txn.undoTransaction(); |
michael@0 | 712 | do_check_eq(0, bmsvc.getItemIndex(b1)); |
michael@0 | 713 | do_check_eq(1, bmsvc.getItemIndex(b2)); |
michael@0 | 714 | do_check_eq(2, bmsvc.getItemIndex(b3)); |
michael@0 | 715 | |
michael@0 | 716 | run_next_test(); |
michael@0 | 717 | }); |
michael@0 | 718 | |
michael@0 | 719 | add_test(function test_edit_postData() { |
michael@0 | 720 | const POST_DATA_ANNO = "bookmarkProperties/POSTData"; |
michael@0 | 721 | let postData = "post-test_edit_postData"; |
michael@0 | 722 | let testURI = NetUtil.newURI("http://test_edit_postData.com"); |
michael@0 | 723 | let testBkmId = bmsvc.insertBookmark(root, testURI, bmsvc.DEFAULT_INDEX, "Test edit Post Data"); |
michael@0 | 724 | |
michael@0 | 725 | let txn = new PlacesEditBookmarkPostDataTransaction(testBkmId, postData); |
michael@0 | 726 | |
michael@0 | 727 | txn.doTransaction(); |
michael@0 | 728 | do_check_true(annosvc.itemHasAnnotation(testBkmId, POST_DATA_ANNO)); |
michael@0 | 729 | do_check_eq(annosvc.getItemAnnotation(testBkmId, POST_DATA_ANNO), postData); |
michael@0 | 730 | |
michael@0 | 731 | txn.undoTransaction(); |
michael@0 | 732 | do_check_false(annosvc.itemHasAnnotation(testBkmId, POST_DATA_ANNO)); |
michael@0 | 733 | |
michael@0 | 734 | run_next_test(); |
michael@0 | 735 | }); |
michael@0 | 736 | |
michael@0 | 737 | add_test(function test_tagURI_untagURI() { |
michael@0 | 738 | const TAG_1 = "tag-test_tagURI_untagURI-bar"; |
michael@0 | 739 | const TAG_2 = "tag-test_tagURI_untagURI-foo"; |
michael@0 | 740 | let tagURI = NetUtil.newURI("http://test_tagURI_untagURI.com"); |
michael@0 | 741 | |
michael@0 | 742 | // Test tagURI |
michael@0 | 743 | let tagTxn = new PlacesTagURITransaction(tagURI, [TAG_1, TAG_2]); |
michael@0 | 744 | |
michael@0 | 745 | tagTxn.doTransaction(); |
michael@0 | 746 | do_check_eq(JSON.stringify(tagssvc.getTagsForURI(tagURI)), JSON.stringify([TAG_1,TAG_2])); |
michael@0 | 747 | |
michael@0 | 748 | tagTxn.undoTransaction(); |
michael@0 | 749 | do_check_eq(tagssvc.getTagsForURI(tagURI).length, 0); |
michael@0 | 750 | |
michael@0 | 751 | tagTxn.redoTransaction(); |
michael@0 | 752 | do_check_eq(JSON.stringify(tagssvc.getTagsForURI(tagURI)), JSON.stringify([TAG_1,TAG_2])); |
michael@0 | 753 | |
michael@0 | 754 | // Test untagURI |
michael@0 | 755 | let untagTxn = new PlacesUntagURITransaction(tagURI, [TAG_1]); |
michael@0 | 756 | |
michael@0 | 757 | untagTxn.doTransaction(); |
michael@0 | 758 | do_check_eq(JSON.stringify(tagssvc.getTagsForURI(tagURI)), JSON.stringify([TAG_2])); |
michael@0 | 759 | |
michael@0 | 760 | untagTxn.undoTransaction(); |
michael@0 | 761 | do_check_eq(JSON.stringify(tagssvc.getTagsForURI(tagURI)), JSON.stringify([TAG_1,TAG_2])); |
michael@0 | 762 | |
michael@0 | 763 | untagTxn.redoTransaction(); |
michael@0 | 764 | do_check_eq(JSON.stringify(tagssvc.getTagsForURI(tagURI)), JSON.stringify([TAG_2])); |
michael@0 | 765 | |
michael@0 | 766 | run_next_test(); |
michael@0 | 767 | }); |
michael@0 | 768 | |
michael@0 | 769 | add_test(function test_aggregate_removeItem_Txn() { |
michael@0 | 770 | let testFolder = bmsvc.createFolder(root, "Test aggregate removeItem transaction", bmsvc.DEFAULT_INDEX); |
michael@0 | 771 | |
michael@0 | 772 | const TEST_URL = "http://test_aggregate_removeitem_txn.com/"; |
michael@0 | 773 | const FOLDERNAME = "Folder"; |
michael@0 | 774 | let testURI = NetUtil.newURI(TEST_URL); |
michael@0 | 775 | |
michael@0 | 776 | let bkmk1Id = bmsvc.insertBookmark(testFolder, testURI, 0, "Mozilla"); |
michael@0 | 777 | let bkmk2Id = bmsvc.insertSeparator(testFolder, 1); |
michael@0 | 778 | let bkmk3Id = bmsvc.createFolder(testFolder, FOLDERNAME, 2); |
michael@0 | 779 | |
michael@0 | 780 | let bkmk3_1Id = bmsvc.insertBookmark(bkmk3Id, testURI, 0, "Mozilla"); |
michael@0 | 781 | let bkmk3_2Id = bmsvc.insertSeparator(bkmk3Id, 1); |
michael@0 | 782 | let bkmk3_3Id = bmsvc.createFolder(bkmk3Id, FOLDERNAME, 2); |
michael@0 | 783 | |
michael@0 | 784 | let childTxn1 = new PlacesRemoveItemTransaction(bkmk1Id); |
michael@0 | 785 | let childTxn2 = new PlacesRemoveItemTransaction(bkmk2Id); |
michael@0 | 786 | let childTxn3 = new PlacesRemoveItemTransaction(bkmk3Id); |
michael@0 | 787 | let transactions = [childTxn1, childTxn2, childTxn3]; |
michael@0 | 788 | let txn = new PlacesAggregatedTransaction("RemoveItems", transactions); |
michael@0 | 789 | |
michael@0 | 790 | txn.doTransaction(); |
michael@0 | 791 | do_check_eq(bmsvc.getItemIndex(bkmk1Id), -1); |
michael@0 | 792 | do_check_eq(bmsvc.getItemIndex(bkmk2Id), -1); |
michael@0 | 793 | do_check_eq(bmsvc.getItemIndex(bkmk3Id), -1); |
michael@0 | 794 | do_check_eq(bmsvc.getItemIndex(bkmk3_1Id), -1); |
michael@0 | 795 | do_check_eq(bmsvc.getItemIndex(bkmk3_2Id), -1); |
michael@0 | 796 | do_check_eq(bmsvc.getItemIndex(bkmk3_3Id), -1); |
michael@0 | 797 | // Check last removed item id. |
michael@0 | 798 | do_check_eq(observer._itemRemovedId, bkmk3Id); |
michael@0 | 799 | |
michael@0 | 800 | txn.undoTransaction(); |
michael@0 | 801 | let newBkmk1Id = bmsvc.getIdForItemAt(testFolder, 0); |
michael@0 | 802 | let newBkmk2Id = bmsvc.getIdForItemAt(testFolder, 1); |
michael@0 | 803 | let newBkmk3Id = bmsvc.getIdForItemAt(testFolder, 2); |
michael@0 | 804 | let newBkmk3_1Id = bmsvc.getIdForItemAt(newBkmk3Id, 0); |
michael@0 | 805 | let newBkmk3_2Id = bmsvc.getIdForItemAt(newBkmk3Id, 1); |
michael@0 | 806 | let newBkmk3_3Id = bmsvc.getIdForItemAt(newBkmk3Id, 2); |
michael@0 | 807 | do_check_eq(bmsvc.getItemType(newBkmk1Id), bmsvc.TYPE_BOOKMARK); |
michael@0 | 808 | do_check_eq(bmsvc.getBookmarkURI(newBkmk1Id).spec, TEST_URL); |
michael@0 | 809 | do_check_eq(bmsvc.getItemType(newBkmk2Id), bmsvc.TYPE_SEPARATOR); |
michael@0 | 810 | do_check_eq(bmsvc.getItemType(newBkmk3Id), bmsvc.TYPE_FOLDER); |
michael@0 | 811 | do_check_eq(bmsvc.getItemTitle(newBkmk3Id), FOLDERNAME); |
michael@0 | 812 | do_check_eq(bmsvc.getFolderIdForItem(newBkmk3_1Id), newBkmk3Id); |
michael@0 | 813 | do_check_eq(bmsvc.getItemType(newBkmk3_1Id), bmsvc.TYPE_BOOKMARK); |
michael@0 | 814 | do_check_eq(bmsvc.getBookmarkURI(newBkmk3_1Id).spec, TEST_URL); |
michael@0 | 815 | do_check_eq(bmsvc.getFolderIdForItem(newBkmk3_2Id), newBkmk3Id); |
michael@0 | 816 | do_check_eq(bmsvc.getItemType(newBkmk3_2Id), bmsvc.TYPE_SEPARATOR); |
michael@0 | 817 | do_check_eq(bmsvc.getFolderIdForItem(newBkmk3_3Id), newBkmk3Id); |
michael@0 | 818 | do_check_eq(bmsvc.getItemType(newBkmk3_3Id), bmsvc.TYPE_FOLDER); |
michael@0 | 819 | do_check_eq(bmsvc.getItemTitle(newBkmk3_3Id), FOLDERNAME); |
michael@0 | 820 | // Check last added back item id. |
michael@0 | 821 | // Notice items are restored in reverse order. |
michael@0 | 822 | do_check_eq(observer._itemAddedId, newBkmk1Id); |
michael@0 | 823 | |
michael@0 | 824 | txn.redoTransaction(); |
michael@0 | 825 | do_check_eq(bmsvc.getItemIndex(newBkmk1Id), -1); |
michael@0 | 826 | do_check_eq(bmsvc.getItemIndex(newBkmk2Id), -1); |
michael@0 | 827 | do_check_eq(bmsvc.getItemIndex(newBkmk3Id), -1); |
michael@0 | 828 | do_check_eq(bmsvc.getItemIndex(newBkmk3_1Id), -1); |
michael@0 | 829 | do_check_eq(bmsvc.getItemIndex(newBkmk3_2Id), -1); |
michael@0 | 830 | do_check_eq(bmsvc.getItemIndex(newBkmk3_3Id), -1); |
michael@0 | 831 | // Check last removed item id. |
michael@0 | 832 | do_check_eq(observer._itemRemovedId, newBkmk3Id); |
michael@0 | 833 | |
michael@0 | 834 | txn.undoTransaction(); |
michael@0 | 835 | newBkmk1Id = bmsvc.getIdForItemAt(testFolder, 0); |
michael@0 | 836 | newBkmk2Id = bmsvc.getIdForItemAt(testFolder, 1); |
michael@0 | 837 | newBkmk3Id = bmsvc.getIdForItemAt(testFolder, 2); |
michael@0 | 838 | newBkmk3_1Id = bmsvc.getIdForItemAt(newBkmk3Id, 0); |
michael@0 | 839 | newBkmk3_2Id = bmsvc.getIdForItemAt(newBkmk3Id, 1); |
michael@0 | 840 | newBkmk3_3Id = bmsvc.getIdForItemAt(newBkmk3Id, 2); |
michael@0 | 841 | do_check_eq(bmsvc.getItemType(newBkmk1Id), bmsvc.TYPE_BOOKMARK); |
michael@0 | 842 | do_check_eq(bmsvc.getBookmarkURI(newBkmk1Id).spec, TEST_URL); |
michael@0 | 843 | do_check_eq(bmsvc.getItemType(newBkmk2Id), bmsvc.TYPE_SEPARATOR); |
michael@0 | 844 | do_check_eq(bmsvc.getItemType(newBkmk3Id), bmsvc.TYPE_FOLDER); |
michael@0 | 845 | do_check_eq(bmsvc.getItemTitle(newBkmk3Id), FOLDERNAME); |
michael@0 | 846 | do_check_eq(bmsvc.getFolderIdForItem(newBkmk3_1Id), newBkmk3Id); |
michael@0 | 847 | do_check_eq(bmsvc.getItemType(newBkmk3_1Id), bmsvc.TYPE_BOOKMARK); |
michael@0 | 848 | do_check_eq(bmsvc.getBookmarkURI(newBkmk3_1Id).spec, TEST_URL); |
michael@0 | 849 | do_check_eq(bmsvc.getFolderIdForItem(newBkmk3_2Id), newBkmk3Id); |
michael@0 | 850 | do_check_eq(bmsvc.getItemType(newBkmk3_2Id), bmsvc.TYPE_SEPARATOR); |
michael@0 | 851 | do_check_eq(bmsvc.getFolderIdForItem(newBkmk3_3Id), newBkmk3Id); |
michael@0 | 852 | do_check_eq(bmsvc.getItemType(newBkmk3_3Id), bmsvc.TYPE_FOLDER); |
michael@0 | 853 | do_check_eq(bmsvc.getItemTitle(newBkmk3_3Id), FOLDERNAME); |
michael@0 | 854 | // Check last added back item id. |
michael@0 | 855 | // Notice items are restored in reverse order. |
michael@0 | 856 | do_check_eq(observer._itemAddedId, newBkmk1Id); |
michael@0 | 857 | |
michael@0 | 858 | run_next_test(); |
michael@0 | 859 | }); |
michael@0 | 860 | |
michael@0 | 861 | add_test(function test_create_item_with_childTxn() { |
michael@0 | 862 | let testFolder = bmsvc.createFolder(root, "Test creating an item with childTxns", bmsvc.DEFAULT_INDEX); |
michael@0 | 863 | |
michael@0 | 864 | const BOOKMARK_TITLE = "parent item"; |
michael@0 | 865 | let testURI = NetUtil.newURI("http://test_create_item_with_childTxn.com"); |
michael@0 | 866 | let childTxns = []; |
michael@0 | 867 | let newDateAdded = Date.now() - 20000; |
michael@0 | 868 | let editDateAdddedTxn = new PlacesEditItemDateAddedTransaction(null, newDateAdded); |
michael@0 | 869 | childTxns.push(editDateAdddedTxn); |
michael@0 | 870 | |
michael@0 | 871 | let itemChildAnnoObj = { name: "testAnno/testInt", |
michael@0 | 872 | type: Ci.nsIAnnotationService.TYPE_INT32, |
michael@0 | 873 | flags: 0, |
michael@0 | 874 | value: 123, |
michael@0 | 875 | expires: Ci.nsIAnnotationService.EXPIRE_NEVER }; |
michael@0 | 876 | let annoTxn = new PlacesSetItemAnnotationTransaction(null, itemChildAnnoObj); |
michael@0 | 877 | childTxns.push(annoTxn); |
michael@0 | 878 | |
michael@0 | 879 | let itemWChildTxn = new PlacesCreateBookmarkTransaction(testURI, testFolder, bmStartIndex, |
michael@0 | 880 | BOOKMARK_TITLE, null, null, |
michael@0 | 881 | childTxns); |
michael@0 | 882 | try { |
michael@0 | 883 | txnManager.doTransaction(itemWChildTxn); |
michael@0 | 884 | let itemId = bmsvc.getBookmarkIdsForURI(testURI)[0]; |
michael@0 | 885 | do_check_eq(observer._itemAddedId, itemId); |
michael@0 | 886 | do_check_eq(newDateAdded, bmsvc.getItemDateAdded(itemId)); |
michael@0 | 887 | do_check_eq(observer._itemChangedProperty, "testAnno/testInt"); |
michael@0 | 888 | do_check_eq(observer._itemChanged_isAnnotationProperty, true); |
michael@0 | 889 | do_check_true(annosvc.itemHasAnnotation(itemId, itemChildAnnoObj.name)) |
michael@0 | 890 | do_check_eq(annosvc.getItemAnnotation(itemId, itemChildAnnoObj.name), itemChildAnnoObj.value); |
michael@0 | 891 | |
michael@0 | 892 | itemWChildTxn.undoTransaction(); |
michael@0 | 893 | do_check_eq(observer._itemRemovedId, itemId); |
michael@0 | 894 | |
michael@0 | 895 | itemWChildTxn.redoTransaction(); |
michael@0 | 896 | do_check_true(bmsvc.isBookmarked(testURI)); |
michael@0 | 897 | let newId = bmsvc.getBookmarkIdsForURI(testURI)[0]; |
michael@0 | 898 | do_check_eq(newDateAdded, bmsvc.getItemDateAdded(newId)); |
michael@0 | 899 | do_check_eq(observer._itemAddedId, newId); |
michael@0 | 900 | do_check_eq(observer._itemChangedProperty, "testAnno/testInt"); |
michael@0 | 901 | do_check_eq(observer._itemChanged_isAnnotationProperty, true); |
michael@0 | 902 | do_check_true(annosvc.itemHasAnnotation(newId, itemChildAnnoObj.name)) |
michael@0 | 903 | do_check_eq(annosvc.getItemAnnotation(newId, itemChildAnnoObj.name), itemChildAnnoObj.value); |
michael@0 | 904 | |
michael@0 | 905 | itemWChildTxn.undoTransaction(); |
michael@0 | 906 | do_check_eq(observer._itemRemovedId, newId); |
michael@0 | 907 | } |
michael@0 | 908 | catch (ex) { |
michael@0 | 909 | do_throw("Setting a child transaction in a createItem transaction did throw: " + ex); |
michael@0 | 910 | } |
michael@0 | 911 | |
michael@0 | 912 | run_next_test(); |
michael@0 | 913 | }); |
michael@0 | 914 | |
michael@0 | 915 | add_test(function test_create_folder_with_child_itemTxn() { |
michael@0 | 916 | let childURI = NetUtil.newURI("http://test_create_folder_with_child_itemTxn.com"); |
michael@0 | 917 | let childItemTxn = new PlacesCreateBookmarkTransaction(childURI, root, |
michael@0 | 918 | bmStartIndex, "childItem"); |
michael@0 | 919 | let txn = new PlacesCreateFolderTransaction("Test creating a folder with child itemTxns", |
michael@0 | 920 | root, bmStartIndex, null, [childItemTxn]); |
michael@0 | 921 | try { |
michael@0 | 922 | txnManager.doTransaction(txn); |
michael@0 | 923 | let childItemId = bmsvc.getBookmarkIdsForURI(childURI)[0]; |
michael@0 | 924 | do_check_eq(observer._itemAddedId, childItemId); |
michael@0 | 925 | do_check_eq(observer._itemAddedIndex, 0); |
michael@0 | 926 | do_check_true(bmsvc.isBookmarked(childURI)); |
michael@0 | 927 | |
michael@0 | 928 | txn.undoTransaction(); |
michael@0 | 929 | do_check_false(bmsvc.isBookmarked(childURI)); |
michael@0 | 930 | |
michael@0 | 931 | txn.redoTransaction(); |
michael@0 | 932 | let newchildItemId = bmsvc.getBookmarkIdsForURI(childURI)[0]; |
michael@0 | 933 | do_check_eq(observer._itemAddedIndex, 0); |
michael@0 | 934 | do_check_eq(observer._itemAddedId, newchildItemId); |
michael@0 | 935 | do_check_true(bmsvc.isBookmarked(childURI)); |
michael@0 | 936 | |
michael@0 | 937 | txn.undoTransaction(); |
michael@0 | 938 | do_check_false(bmsvc.isBookmarked(childURI)); |
michael@0 | 939 | } |
michael@0 | 940 | catch (ex) { |
michael@0 | 941 | do_throw("Setting a child item transaction in a createFolder transaction did throw: " + ex); |
michael@0 | 942 | } |
michael@0 | 943 | |
michael@0 | 944 | run_next_test(); |
michael@0 | 945 | }); |