michael@0: /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et: */ 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 michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: function run_test() { michael@0: do_test_pending(); michael@0: michael@0: Task.spawn(function() { michael@0: let backupFolder = yield PlacesBackups.getBackupFolder(); michael@0: let bookmarksBackupDir = new FileUtils.File(backupFolder); michael@0: // Remove all files from backups folder. michael@0: let files = bookmarksBackupDir.directoryEntries; michael@0: while (files.hasMoreElements()) { michael@0: let entry = files.getNext().QueryInterface(Ci.nsIFile); michael@0: entry.remove(false); michael@0: } michael@0: michael@0: // Create a json dummy backup in the future. michael@0: let dateObj = new Date(); michael@0: dateObj.setYear(dateObj.getFullYear() + 1); michael@0: let name = PlacesBackups.getFilenameForDate(dateObj); michael@0: do_check_eq(name, "bookmarks-" + dateObj.toLocaleFormat("%Y-%m-%d") + ".json"); michael@0: let files = bookmarksBackupDir.directoryEntries; michael@0: while (files.hasMoreElements()) { michael@0: let entry = files.getNext().QueryInterface(Ci.nsIFile); michael@0: if (PlacesBackups.filenamesRegex.test(entry.leafName)) michael@0: entry.remove(false); michael@0: } michael@0: michael@0: let futureBackupFile = bookmarksBackupDir.clone(); michael@0: futureBackupFile.append(name); michael@0: futureBackupFile.create(Ci.nsILocalFile.NORMAL_FILE_TYPE, 0600); michael@0: do_check_true(futureBackupFile.exists()); michael@0: michael@0: do_check_eq((yield PlacesBackups.getBackupFiles()).length, 0); michael@0: michael@0: yield PlacesBackups.create(); michael@0: // Check that a backup for today has been created. michael@0: do_check_eq((yield PlacesBackups.getBackupFiles()).length, 1); michael@0: let mostRecentBackupFile = yield PlacesBackups.getMostRecentBackup(); michael@0: do_check_neq(mostRecentBackupFile, null); michael@0: let todayFilename = PlacesBackups.getFilenameForDate(); michael@0: do_check_true(PlacesBackups.filenamesRegex.test(OS.Path.basename(mostRecentBackupFile))); michael@0: michael@0: // Check that future backup has been removed. michael@0: do_check_false(futureBackupFile.exists()); michael@0: michael@0: // Cleanup. michael@0: mostRecentBackupFile = new FileUtils.File(mostRecentBackupFile); michael@0: mostRecentBackupFile.remove(false); michael@0: do_check_false(mostRecentBackupFile.exists()); michael@0: michael@0: do_test_finished() michael@0: }); michael@0: }