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: /** michael@0: * Requests information to the service, so that bookmark's data is cached. michael@0: * @param aItemId michael@0: * Id of the bookmark to be cached. michael@0: */ michael@0: function forceBookmarkCaching(aItemId) { michael@0: PlacesUtils.bookmarks.getFolderIdForItem(aItemId); michael@0: } michael@0: michael@0: let observer = { michael@0: onBeginUpdateBatch: function() forceBookmarkCaching(itemId1), michael@0: onEndUpdateBatch: function() forceBookmarkCaching(itemId1), michael@0: onItemAdded: forceBookmarkCaching, michael@0: onItemChanged: forceBookmarkCaching, michael@0: onItemMoved: forceBookmarkCaching, michael@0: onItemRemoved: function(id) { michael@0: try { michael@0: forceBookmarkCaching(id); michael@0: do_throw("trying to fetch a removed bookmark should throw"); michael@0: } catch (ex) {} michael@0: }, michael@0: onItemVisited: forceBookmarkCaching, michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver]) michael@0: }; michael@0: PlacesUtils.bookmarks.addObserver(observer, false); michael@0: michael@0: let folderId1 = PlacesUtils.bookmarks michael@0: .createFolder(PlacesUtils.bookmarksMenuFolderId, michael@0: "Bookmarks", michael@0: PlacesUtils.bookmarks.DEFAULT_INDEX); michael@0: let itemId1 = PlacesUtils.bookmarks michael@0: .insertBookmark(folderId1, michael@0: NetUtil.newURI("http:/www.wired.com/wiredscience"), michael@0: PlacesUtils.bookmarks.DEFAULT_INDEX, michael@0: "Wired Science"); michael@0: michael@0: PlacesUtils.bookmarks.removeItem(folderId1); michael@0: michael@0: let folderId2 = PlacesUtils.bookmarks michael@0: .createFolder(PlacesUtils.bookmarksMenuFolderId, michael@0: "Science", michael@0: PlacesUtils.bookmarks.DEFAULT_INDEX); michael@0: let folderId3 = PlacesUtils.bookmarks michael@0: .createFolder(folderId2, michael@0: "Blogs", michael@0: PlacesUtils.bookmarks.DEFAULT_INDEX); michael@0: // Check title is correctly reported. michael@0: do_check_eq(PlacesUtils.bookmarks.getItemTitle(folderId3), "Blogs"); michael@0: do_check_eq(PlacesUtils.bookmarks.getItemTitle(folderId2), "Science"); michael@0: michael@0: PlacesUtils.bookmarks.removeObserver(observer, false); michael@0: }