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