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

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 /**
michael@0 6 * Checks that backups properly include all of the bookmarks if the hierarchy
michael@0 7 * in the database is unordered so that a hierarchy is defined before its
michael@0 8 * ancestor in the bookmarks table.
michael@0 9 */
michael@0 10 function run_test() {
michael@0 11 run_next_test();
michael@0 12 }
michael@0 13
michael@0 14 add_task(function() {
michael@0 15 let bm = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
michael@0 16 NetUtil.newURI("http://mozilla.org/"),
michael@0 17 PlacesUtils.bookmarks.DEFAULT_INDEX,
michael@0 18 "bookmark");
michael@0 19 let f2 = PlacesUtils.bookmarks.createFolder(PlacesUtils.unfiledBookmarksFolderId, "f2",
michael@0 20 PlacesUtils.bookmarks.DEFAULT_INDEX);
michael@0 21 PlacesUtils.bookmarks.moveItem(bm, f2, PlacesUtils.bookmarks.DEFAULT_INDEX);
michael@0 22 let f1 = PlacesUtils.bookmarks.createFolder(PlacesUtils.unfiledBookmarksFolderId, "f1",
michael@0 23 PlacesUtils.bookmarks.DEFAULT_INDEX);
michael@0 24 PlacesUtils.bookmarks.moveItem(f2, f1, PlacesUtils.bookmarks.DEFAULT_INDEX);
michael@0 25
michael@0 26 // Create a backup.
michael@0 27 yield PlacesBackups.create();
michael@0 28
michael@0 29 // Remove the bookmarks, then restore the backup.
michael@0 30 PlacesUtils.bookmarks.removeItem(f1);
michael@0 31 yield BookmarkJSONUtils.importFromFile((yield PlacesBackups.getMostRecentBackup()), true);
michael@0 32
michael@0 33 do_log_info("Checking first level");
michael@0 34 let root = PlacesUtils.getFolderContents(PlacesUtils.unfiledBookmarksFolderId).root;
michael@0 35 let level1 = root.getChild(0);
michael@0 36 do_check_eq(level1.title, "f1");
michael@0 37 do_log_info("Checking second level");
michael@0 38 PlacesUtils.asContainer(level1).containerOpen = true
michael@0 39 let level2 = level1.getChild(0);
michael@0 40 do_check_eq(level2.title, "f2");
michael@0 41 do_log_info("Checking bookmark");
michael@0 42 PlacesUtils.asContainer(level2).containerOpen = true
michael@0 43 let bookmark = level2.getChild(0);
michael@0 44 do_check_eq(bookmark.title, "bookmark");
michael@0 45 level2.containerOpen = false;
michael@0 46 level1.containerOpen = false;
michael@0 47 root.containerOpen = false;
michael@0 48 });

mercurial