michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.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: let parent = PlacesUtils.bookmarks.getFolderIdForItem(aItemId); michael@0: PlacesUtils.bookmarks.getFolderIdForItem(parent); 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 folder1 = PlacesUtils.bookmarks michael@0: .createFolder(PlacesUtils.bookmarksMenuFolderId, michael@0: "Folder1", michael@0: PlacesUtils.bookmarks.DEFAULT_INDEX); michael@0: let folder2 = PlacesUtils.bookmarks michael@0: .createFolder(folder1, michael@0: "Folder2", michael@0: PlacesUtils.bookmarks.DEFAULT_INDEX); michael@0: let itemId = PlacesUtils.bookmarks michael@0: .insertBookmark(folder2, michael@0: NetUtil.newURI("http://mozilla.org/"), michael@0: PlacesUtils.bookmarks.DEFAULT_INDEX, michael@0: "Mozilla"); michael@0: michael@0: PlacesUtils.bookmarks.removeFolderChildren(folder1); michael@0: michael@0: // Check title is correctly reported. michael@0: do_check_eq(PlacesUtils.bookmarks.getItemTitle(folder1), "Folder1"); michael@0: try { michael@0: PlacesUtils.bookmarks.getItemTitle(folder2); michael@0: do_throw("trying to fetch a removed bookmark should throw"); michael@0: } catch (ex) {} michael@0: michael@0: PlacesUtils.bookmarks.removeObserver(observer, false); michael@0: }