Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | function run_test() { |
michael@0 | 6 | /** |
michael@0 | 7 | * Requests information to the service, so that bookmark's data is cached. |
michael@0 | 8 | * @param aItemId |
michael@0 | 9 | * Id of the bookmark to be cached. |
michael@0 | 10 | */ |
michael@0 | 11 | function forceBookmarkCaching(aItemId) { |
michael@0 | 12 | let parent = PlacesUtils.bookmarks.getFolderIdForItem(aItemId); |
michael@0 | 13 | PlacesUtils.bookmarks.getFolderIdForItem(parent); |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | let observer = { |
michael@0 | 17 | onBeginUpdateBatch: function () forceBookmarkCaching(itemId1), |
michael@0 | 18 | onEndUpdateBatch: function () forceBookmarkCaching(itemId1), |
michael@0 | 19 | onItemAdded: forceBookmarkCaching, |
michael@0 | 20 | onItemChanged: forceBookmarkCaching, |
michael@0 | 21 | onItemMoved: forceBookmarkCaching, |
michael@0 | 22 | onItemRemoved: function (id) { |
michael@0 | 23 | try { |
michael@0 | 24 | forceBookmarkCaching(id); |
michael@0 | 25 | do_throw("trying to fetch a removed bookmark should throw"); |
michael@0 | 26 | } catch (ex) {} |
michael@0 | 27 | }, |
michael@0 | 28 | onItemVisited: forceBookmarkCaching, |
michael@0 | 29 | QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver]) |
michael@0 | 30 | }; |
michael@0 | 31 | PlacesUtils.bookmarks.addObserver(observer, false); |
michael@0 | 32 | |
michael@0 | 33 | let folder1 = PlacesUtils.bookmarks |
michael@0 | 34 | .createFolder(PlacesUtils.bookmarksMenuFolderId, |
michael@0 | 35 | "Folder1", |
michael@0 | 36 | PlacesUtils.bookmarks.DEFAULT_INDEX); |
michael@0 | 37 | let folder2 = PlacesUtils.bookmarks |
michael@0 | 38 | .createFolder(folder1, |
michael@0 | 39 | "Folder2", |
michael@0 | 40 | PlacesUtils.bookmarks.DEFAULT_INDEX); |
michael@0 | 41 | let itemId = PlacesUtils.bookmarks |
michael@0 | 42 | .insertBookmark(folder2, |
michael@0 | 43 | NetUtil.newURI("http://mozilla.org/"), |
michael@0 | 44 | PlacesUtils.bookmarks.DEFAULT_INDEX, |
michael@0 | 45 | "Mozilla"); |
michael@0 | 46 | |
michael@0 | 47 | PlacesUtils.bookmarks.removeFolderChildren(folder1); |
michael@0 | 48 | |
michael@0 | 49 | // Check title is correctly reported. |
michael@0 | 50 | do_check_eq(PlacesUtils.bookmarks.getItemTitle(folder1), "Folder1"); |
michael@0 | 51 | try { |
michael@0 | 52 | PlacesUtils.bookmarks.getItemTitle(folder2); |
michael@0 | 53 | do_throw("trying to fetch a removed bookmark should throw"); |
michael@0 | 54 | } catch (ex) {} |
michael@0 | 55 | |
michael@0 | 56 | PlacesUtils.bookmarks.removeObserver(observer, false); |
michael@0 | 57 | } |