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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/places/tests/unit/test_PlacesUtils_lazyobservers.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,47 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +function run_test() {
     1.8 +  do_test_pending();
     1.9 +  
    1.10 +  const TEST_URI = NetUtil.newURI("http://moz.org/")
    1.11 +  let observer = {
    1.12 +    QueryInterface: XPCOMUtils.generateQI([
    1.13 +      Ci.nsINavBookmarkObserver,
    1.14 +    ]),
    1.15 +
    1.16 +    onBeginUpdateBatch: function () {},
    1.17 +    onEndUpdateBatch: function () {},
    1.18 +    onItemAdded: function (aItemId, aParentId, aIndex, aItemType, aURI) {
    1.19 +      do_check_true(aURI.equals(TEST_URI));
    1.20 +      PlacesUtils.removeLazyBookmarkObserver(this);
    1.21 +      do_test_finished();
    1.22 +    },
    1.23 +    onItemRemoved: function () {},
    1.24 +    onItemChanged: function () {},
    1.25 +    onItemVisited: function () {},
    1.26 +    onItemMoved: function () {},
    1.27 +  };
    1.28 +
    1.29 +  // Check registration and removal with uninitialized bookmarks service.
    1.30 +  PlacesUtils.addLazyBookmarkObserver(observer);
    1.31 +  PlacesUtils.removeLazyBookmarkObserver(observer);
    1.32 +
    1.33 +  // Add a proper lazy observer we will test.
    1.34 +  PlacesUtils.addLazyBookmarkObserver(observer);
    1.35 +
    1.36 +  // Check that we don't leak when adding and removing an observer while the
    1.37 +  // bookmarks service is instantiated but no change happened (bug 721319).
    1.38 +  PlacesUtils.bookmarks;
    1.39 +  PlacesUtils.addLazyBookmarkObserver(observer);
    1.40 +  PlacesUtils.removeLazyBookmarkObserver(observer);
    1.41 +  try {
    1.42 +    PlacesUtils.bookmarks.removeObserver(observer);
    1.43 +    do_throw("Trying to remove a nonexisting observer should throw!");
    1.44 +  } catch (ex) {}
    1.45 +
    1.46 +  PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
    1.47 +                                       TEST_URI,
    1.48 +                                       PlacesUtils.bookmarks.DEFAULT_INDEX,
    1.49 +                                       "Bookmark title");
    1.50 +}

mercurial