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