michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /** michael@0: * To confirm that metadata i.e. bookmark count is set and retrieved for michael@0: * automatic backups. michael@0: */ michael@0: function run_test() { michael@0: run_next_test(); michael@0: } michael@0: michael@0: add_task(function test_saveBookmarksToJSONFile_and_create() michael@0: { michael@0: // Add a bookmark michael@0: let uri = NetUtil.newURI("http://getfirefox.com/"); michael@0: let bookmarkId = michael@0: PlacesUtils.bookmarks.insertBookmark( michael@0: PlacesUtils.unfiledBookmarksFolderId, uri, michael@0: PlacesUtils.bookmarks.DEFAULT_INDEX, "Get Firefox!"); michael@0: michael@0: // Test saveBookmarksToJSONFile() michael@0: let backupFile = FileUtils.getFile("TmpD", ["bookmarks.json"]); michael@0: backupFile.create(Ci.nsILocalFile.NORMAL_FILE_TYPE, parseInt("0600", 8)); michael@0: michael@0: let nodeCount = yield PlacesBackups.saveBookmarksToJSONFile(backupFile, true); michael@0: do_check_true(nodeCount > 0); michael@0: do_check_true(backupFile.exists()); michael@0: do_check_eq(backupFile.leafName, "bookmarks.json"); michael@0: michael@0: // Ensure the backup would be copied to our backups folder when the original michael@0: // backup is saved somewhere else. michael@0: let recentBackup = yield PlacesBackups.getMostRecentBackup(); michael@0: let matches = OS.Path.basename(recentBackup).match(PlacesBackups.filenamesRegex); michael@0: do_check_eq(matches[2], nodeCount); michael@0: do_check_eq(matches[3].length, 24); michael@0: michael@0: // Clear all backups in our backups folder. michael@0: yield PlacesBackups.create(0); michael@0: do_check_eq((yield PlacesBackups.getBackupFiles()).length, 0); michael@0: michael@0: // Test create() which saves bookmarks with metadata on the filename. michael@0: yield PlacesBackups.create(); michael@0: do_check_eq((yield PlacesBackups.getBackupFiles()).length, 1); michael@0: michael@0: mostRecentBackupFile = yield PlacesBackups.getMostRecentBackup(); michael@0: do_check_neq(mostRecentBackupFile, null); michael@0: matches = OS.Path.basename(recentBackup).match(PlacesBackups.filenamesRegex); michael@0: do_check_eq(matches[2], nodeCount); michael@0: do_check_eq(matches[3].length, 24); michael@0: michael@0: // Cleanup michael@0: backupFile.remove(false); michael@0: yield PlacesBackups.create(0); michael@0: PlacesUtils.bookmarks.removeItem(bookmarkId); michael@0: }); michael@0: