toolkit/components/places/tests/unit/test_452777.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_452777.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,36 @@
     1.4 +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * vim:set ts=2 sw=2 sts=2 expandtab
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +/**
    1.11 + * This test ensures that when removing a folder within a transaction, undoing
    1.12 + * the transaction restores it with the same id (as received by the observers).
    1.13 + */
    1.14 +
    1.15 +var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
    1.16 +         getService(Ci.nsINavBookmarksService);
    1.17 +
    1.18 +function run_test()
    1.19 +{
    1.20 +  const TITLE = "test folder";
    1.21 +
    1.22 +  // Create two test folders; remove the first one.  This ensures that undoing
    1.23 +  // the removal will not get the same id by chance (the insert id's can be
    1.24 +  // reused in SQLite).
    1.25 +  let id = bs.createFolder(bs.placesRoot, TITLE, -1);
    1.26 +  bs.createFolder(bs.placesRoot, "test folder 2", -1);
    1.27 +  let transaction = bs.getRemoveFolderTransaction(id);
    1.28 +  transaction.doTransaction();
    1.29 +
    1.30 +  // Now check to make sure it gets added with the right id
    1.31 +  bs.addObserver({
    1.32 +    onItemAdded: function(aItemId, aFolder, aIndex, aItemType, aURI, aTitle)
    1.33 +    {
    1.34 +      do_check_eq(aItemId, id);
    1.35 +      do_check_eq(aTitle, TITLE);
    1.36 +    }
    1.37 +  }, false);
    1.38 +  transaction.undoTransaction();
    1.39 +}

mercurial