|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 function run_test() { |
|
5 do_test_pending(); |
|
6 |
|
7 const TEST_URI = NetUtil.newURI("http://moz.org/") |
|
8 let observer = { |
|
9 QueryInterface: XPCOMUtils.generateQI([ |
|
10 Ci.nsINavBookmarkObserver, |
|
11 ]), |
|
12 |
|
13 onBeginUpdateBatch: function () {}, |
|
14 onEndUpdateBatch: function () {}, |
|
15 onItemAdded: function (aItemId, aParentId, aIndex, aItemType, aURI) { |
|
16 do_check_true(aURI.equals(TEST_URI)); |
|
17 PlacesUtils.removeLazyBookmarkObserver(this); |
|
18 do_test_finished(); |
|
19 }, |
|
20 onItemRemoved: function () {}, |
|
21 onItemChanged: function () {}, |
|
22 onItemVisited: function () {}, |
|
23 onItemMoved: function () {}, |
|
24 }; |
|
25 |
|
26 // Check registration and removal with uninitialized bookmarks service. |
|
27 PlacesUtils.addLazyBookmarkObserver(observer); |
|
28 PlacesUtils.removeLazyBookmarkObserver(observer); |
|
29 |
|
30 // Add a proper lazy observer we will test. |
|
31 PlacesUtils.addLazyBookmarkObserver(observer); |
|
32 |
|
33 // Check that we don't leak when adding and removing an observer while the |
|
34 // bookmarks service is instantiated but no change happened (bug 721319). |
|
35 PlacesUtils.bookmarks; |
|
36 PlacesUtils.addLazyBookmarkObserver(observer); |
|
37 PlacesUtils.removeLazyBookmarkObserver(observer); |
|
38 try { |
|
39 PlacesUtils.bookmarks.removeObserver(observer); |
|
40 do_throw("Trying to remove a nonexisting observer should throw!"); |
|
41 } catch (ex) {} |
|
42 |
|
43 PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, |
|
44 TEST_URI, |
|
45 PlacesUtils.bookmarks.DEFAULT_INDEX, |
|
46 "Bookmark title"); |
|
47 } |