1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/bookmarks/test_992901-backup-unsorted-hierarchy.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,48 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +/** 1.9 + * Checks that backups properly include all of the bookmarks if the hierarchy 1.10 + * in the database is unordered so that a hierarchy is defined before its 1.11 + * ancestor in the bookmarks table. 1.12 + */ 1.13 +function run_test() { 1.14 + run_next_test(); 1.15 +} 1.16 + 1.17 +add_task(function() { 1.18 + let bm = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, 1.19 + NetUtil.newURI("http://mozilla.org/"), 1.20 + PlacesUtils.bookmarks.DEFAULT_INDEX, 1.21 + "bookmark"); 1.22 + let f2 = PlacesUtils.bookmarks.createFolder(PlacesUtils.unfiledBookmarksFolderId, "f2", 1.23 + PlacesUtils.bookmarks.DEFAULT_INDEX); 1.24 + PlacesUtils.bookmarks.moveItem(bm, f2, PlacesUtils.bookmarks.DEFAULT_INDEX); 1.25 + let f1 = PlacesUtils.bookmarks.createFolder(PlacesUtils.unfiledBookmarksFolderId, "f1", 1.26 + PlacesUtils.bookmarks.DEFAULT_INDEX); 1.27 + PlacesUtils.bookmarks.moveItem(f2, f1, PlacesUtils.bookmarks.DEFAULT_INDEX); 1.28 + 1.29 + // Create a backup. 1.30 + yield PlacesBackups.create(); 1.31 + 1.32 + // Remove the bookmarks, then restore the backup. 1.33 + PlacesUtils.bookmarks.removeItem(f1); 1.34 + yield BookmarkJSONUtils.importFromFile((yield PlacesBackups.getMostRecentBackup()), true); 1.35 + 1.36 + do_log_info("Checking first level"); 1.37 + let root = PlacesUtils.getFolderContents(PlacesUtils.unfiledBookmarksFolderId).root; 1.38 + let level1 = root.getChild(0); 1.39 + do_check_eq(level1.title, "f1"); 1.40 + do_log_info("Checking second level"); 1.41 + PlacesUtils.asContainer(level1).containerOpen = true 1.42 + let level2 = level1.getChild(0); 1.43 + do_check_eq(level2.title, "f2"); 1.44 + do_log_info("Checking bookmark"); 1.45 + PlacesUtils.asContainer(level2).containerOpen = true 1.46 + let bookmark = level2.getChild(0); 1.47 + do_check_eq(bookmark.title, "bookmark"); 1.48 + level2.containerOpen = false; 1.49 + level1.containerOpen = false; 1.50 + root.containerOpen = false; 1.51 +});