michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: function run_test() { michael@0: do_test_pending(); michael@0: michael@0: const TEST_URI = NetUtil.newURI("http://moz.org/") michael@0: let observer = { michael@0: QueryInterface: XPCOMUtils.generateQI([ michael@0: Ci.nsINavBookmarkObserver, michael@0: ]), michael@0: michael@0: onBeginUpdateBatch: function () {}, michael@0: onEndUpdateBatch: function () {}, michael@0: onItemAdded: function (aItemId, aParentId, aIndex, aItemType, aURI) { michael@0: do_check_true(aURI.equals(TEST_URI)); michael@0: PlacesUtils.removeLazyBookmarkObserver(this); michael@0: do_test_finished(); michael@0: }, michael@0: onItemRemoved: function () {}, michael@0: onItemChanged: function () {}, michael@0: onItemVisited: function () {}, michael@0: onItemMoved: function () {}, michael@0: }; michael@0: michael@0: // Check registration and removal with uninitialized bookmarks service. michael@0: PlacesUtils.addLazyBookmarkObserver(observer); michael@0: PlacesUtils.removeLazyBookmarkObserver(observer); michael@0: michael@0: // Add a proper lazy observer we will test. michael@0: PlacesUtils.addLazyBookmarkObserver(observer); michael@0: michael@0: // Check that we don't leak when adding and removing an observer while the michael@0: // bookmarks service is instantiated but no change happened (bug 721319). michael@0: PlacesUtils.bookmarks; michael@0: PlacesUtils.addLazyBookmarkObserver(observer); michael@0: PlacesUtils.removeLazyBookmarkObserver(observer); michael@0: try { michael@0: PlacesUtils.bookmarks.removeObserver(observer); michael@0: do_throw("Trying to remove a nonexisting observer should throw!"); michael@0: } catch (ex) {} michael@0: michael@0: PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, michael@0: TEST_URI, michael@0: PlacesUtils.bookmarks.DEFAULT_INDEX, michael@0: "Bookmark title"); michael@0: }