toolkit/components/places/tests/unit/test_PlacesUtils_lazyobservers.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial