1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/bookmarks/test_477583_json-backup-in-future.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,57 @@ 1.4 +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +function run_test() { 1.11 + do_test_pending(); 1.12 + 1.13 + Task.spawn(function() { 1.14 + let backupFolder = yield PlacesBackups.getBackupFolder(); 1.15 + let bookmarksBackupDir = new FileUtils.File(backupFolder); 1.16 + // Remove all files from backups folder. 1.17 + let files = bookmarksBackupDir.directoryEntries; 1.18 + while (files.hasMoreElements()) { 1.19 + let entry = files.getNext().QueryInterface(Ci.nsIFile); 1.20 + entry.remove(false); 1.21 + } 1.22 + 1.23 + // Create a json dummy backup in the future. 1.24 + let dateObj = new Date(); 1.25 + dateObj.setYear(dateObj.getFullYear() + 1); 1.26 + let name = PlacesBackups.getFilenameForDate(dateObj); 1.27 + do_check_eq(name, "bookmarks-" + dateObj.toLocaleFormat("%Y-%m-%d") + ".json"); 1.28 + let files = bookmarksBackupDir.directoryEntries; 1.29 + while (files.hasMoreElements()) { 1.30 + let entry = files.getNext().QueryInterface(Ci.nsIFile); 1.31 + if (PlacesBackups.filenamesRegex.test(entry.leafName)) 1.32 + entry.remove(false); 1.33 + } 1.34 + 1.35 + let futureBackupFile = bookmarksBackupDir.clone(); 1.36 + futureBackupFile.append(name); 1.37 + futureBackupFile.create(Ci.nsILocalFile.NORMAL_FILE_TYPE, 0600); 1.38 + do_check_true(futureBackupFile.exists()); 1.39 + 1.40 + do_check_eq((yield PlacesBackups.getBackupFiles()).length, 0); 1.41 + 1.42 + yield PlacesBackups.create(); 1.43 + // Check that a backup for today has been created. 1.44 + do_check_eq((yield PlacesBackups.getBackupFiles()).length, 1); 1.45 + let mostRecentBackupFile = yield PlacesBackups.getMostRecentBackup(); 1.46 + do_check_neq(mostRecentBackupFile, null); 1.47 + let todayFilename = PlacesBackups.getFilenameForDate(); 1.48 + do_check_true(PlacesBackups.filenamesRegex.test(OS.Path.basename(mostRecentBackupFile))); 1.49 + 1.50 + // Check that future backup has been removed. 1.51 + do_check_false(futureBackupFile.exists()); 1.52 + 1.53 + // Cleanup. 1.54 + mostRecentBackupFile = new FileUtils.File(mostRecentBackupFile); 1.55 + mostRecentBackupFile.remove(false); 1.56 + do_check_false(mostRecentBackupFile.exists()); 1.57 + 1.58 + do_test_finished() 1.59 + }); 1.60 +}