Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim:set ts=2 sw=2 sts=2 et: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | function run_test() { |
michael@0 | 8 | do_test_pending(); |
michael@0 | 9 | |
michael@0 | 10 | Task.spawn(function() { |
michael@0 | 11 | let backupFolder = yield PlacesBackups.getBackupFolder(); |
michael@0 | 12 | let bookmarksBackupDir = new FileUtils.File(backupFolder); |
michael@0 | 13 | // Remove all files from backups folder. |
michael@0 | 14 | let files = bookmarksBackupDir.directoryEntries; |
michael@0 | 15 | while (files.hasMoreElements()) { |
michael@0 | 16 | let entry = files.getNext().QueryInterface(Ci.nsIFile); |
michael@0 | 17 | entry.remove(false); |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | // Create a json dummy backup in the future. |
michael@0 | 21 | let dateObj = new Date(); |
michael@0 | 22 | dateObj.setYear(dateObj.getFullYear() + 1); |
michael@0 | 23 | let name = PlacesBackups.getFilenameForDate(dateObj); |
michael@0 | 24 | do_check_eq(name, "bookmarks-" + dateObj.toLocaleFormat("%Y-%m-%d") + ".json"); |
michael@0 | 25 | let files = bookmarksBackupDir.directoryEntries; |
michael@0 | 26 | while (files.hasMoreElements()) { |
michael@0 | 27 | let entry = files.getNext().QueryInterface(Ci.nsIFile); |
michael@0 | 28 | if (PlacesBackups.filenamesRegex.test(entry.leafName)) |
michael@0 | 29 | entry.remove(false); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | let futureBackupFile = bookmarksBackupDir.clone(); |
michael@0 | 33 | futureBackupFile.append(name); |
michael@0 | 34 | futureBackupFile.create(Ci.nsILocalFile.NORMAL_FILE_TYPE, 0600); |
michael@0 | 35 | do_check_true(futureBackupFile.exists()); |
michael@0 | 36 | |
michael@0 | 37 | do_check_eq((yield PlacesBackups.getBackupFiles()).length, 0); |
michael@0 | 38 | |
michael@0 | 39 | yield PlacesBackups.create(); |
michael@0 | 40 | // Check that a backup for today has been created. |
michael@0 | 41 | do_check_eq((yield PlacesBackups.getBackupFiles()).length, 1); |
michael@0 | 42 | let mostRecentBackupFile = yield PlacesBackups.getMostRecentBackup(); |
michael@0 | 43 | do_check_neq(mostRecentBackupFile, null); |
michael@0 | 44 | let todayFilename = PlacesBackups.getFilenameForDate(); |
michael@0 | 45 | do_check_true(PlacesBackups.filenamesRegex.test(OS.Path.basename(mostRecentBackupFile))); |
michael@0 | 46 | |
michael@0 | 47 | // Check that future backup has been removed. |
michael@0 | 48 | do_check_false(futureBackupFile.exists()); |
michael@0 | 49 | |
michael@0 | 50 | // Cleanup. |
michael@0 | 51 | mostRecentBackupFile = new FileUtils.File(mostRecentBackupFile); |
michael@0 | 52 | mostRecentBackupFile.remove(false); |
michael@0 | 53 | do_check_false(mostRecentBackupFile.exists()); |
michael@0 | 54 | |
michael@0 | 55 | do_test_finished() |
michael@0 | 56 | }); |
michael@0 | 57 | } |