toolkit/components/places/tests/bookmarks/test_992901-backup-unsorted-hierarchy.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/. */
     5 /**
     6  * Checks that backups properly include all of the bookmarks if the hierarchy
     7  * in the database is unordered so that a hierarchy is defined before its
     8  * ancestor in the bookmarks table.
     9  */
    10 function run_test() {
    11   run_next_test();
    12 }
    14 add_task(function() {
    15   let bm = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
    16                                                 NetUtil.newURI("http://mozilla.org/"),
    17                                                 PlacesUtils.bookmarks.DEFAULT_INDEX,
    18                                                 "bookmark");
    19   let f2 = PlacesUtils.bookmarks.createFolder(PlacesUtils.unfiledBookmarksFolderId, "f2",
    20                                               PlacesUtils.bookmarks.DEFAULT_INDEX);
    21   PlacesUtils.bookmarks.moveItem(bm, f2, PlacesUtils.bookmarks.DEFAULT_INDEX);
    22   let f1 = PlacesUtils.bookmarks.createFolder(PlacesUtils.unfiledBookmarksFolderId, "f1",
    23                                               PlacesUtils.bookmarks.DEFAULT_INDEX);
    24   PlacesUtils.bookmarks.moveItem(f2, f1, PlacesUtils.bookmarks.DEFAULT_INDEX);
    26   // Create a backup.
    27   yield PlacesBackups.create();
    29   // Remove the bookmarks, then restore the backup.
    30   PlacesUtils.bookmarks.removeItem(f1);
    31   yield BookmarkJSONUtils.importFromFile((yield PlacesBackups.getMostRecentBackup()), true);
    33   do_log_info("Checking first level");
    34   let root = PlacesUtils.getFolderContents(PlacesUtils.unfiledBookmarksFolderId).root;
    35   let level1 = root.getChild(0);
    36   do_check_eq(level1.title, "f1");
    37   do_log_info("Checking second level");
    38   PlacesUtils.asContainer(level1).containerOpen = true
    39   let level2 = level1.getChild(0);
    40   do_check_eq(level2.title, "f2");
    41   do_log_info("Checking bookmark");
    42   PlacesUtils.asContainer(level2).containerOpen = true
    43   let bookmark = level2.getChild(0);
    44   do_check_eq(bookmark.title, "bookmark");
    45   level2.containerOpen = false;
    46   level1.containerOpen = false;
    47   root.containerOpen = false;
    48 });

mercurial