|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 /** |
|
6 * To confirm that metadata i.e. bookmark count is set and retrieved for |
|
7 * automatic backups. |
|
8 */ |
|
9 function run_test() { |
|
10 run_next_test(); |
|
11 } |
|
12 |
|
13 add_task(function test_saveBookmarksToJSONFile_and_create() |
|
14 { |
|
15 // Add a bookmark |
|
16 let uri = NetUtil.newURI("http://getfirefox.com/"); |
|
17 let bookmarkId = |
|
18 PlacesUtils.bookmarks.insertBookmark( |
|
19 PlacesUtils.unfiledBookmarksFolderId, uri, |
|
20 PlacesUtils.bookmarks.DEFAULT_INDEX, "Get Firefox!"); |
|
21 |
|
22 // Test saveBookmarksToJSONFile() |
|
23 let backupFile = FileUtils.getFile("TmpD", ["bookmarks.json"]); |
|
24 backupFile.create(Ci.nsILocalFile.NORMAL_FILE_TYPE, parseInt("0600", 8)); |
|
25 |
|
26 let nodeCount = yield PlacesBackups.saveBookmarksToJSONFile(backupFile, true); |
|
27 do_check_true(nodeCount > 0); |
|
28 do_check_true(backupFile.exists()); |
|
29 do_check_eq(backupFile.leafName, "bookmarks.json"); |
|
30 |
|
31 // Ensure the backup would be copied to our backups folder when the original |
|
32 // backup is saved somewhere else. |
|
33 let recentBackup = yield PlacesBackups.getMostRecentBackup(); |
|
34 let matches = OS.Path.basename(recentBackup).match(PlacesBackups.filenamesRegex); |
|
35 do_check_eq(matches[2], nodeCount); |
|
36 do_check_eq(matches[3].length, 24); |
|
37 |
|
38 // Clear all backups in our backups folder. |
|
39 yield PlacesBackups.create(0); |
|
40 do_check_eq((yield PlacesBackups.getBackupFiles()).length, 0); |
|
41 |
|
42 // Test create() which saves bookmarks with metadata on the filename. |
|
43 yield PlacesBackups.create(); |
|
44 do_check_eq((yield PlacesBackups.getBackupFiles()).length, 1); |
|
45 |
|
46 mostRecentBackupFile = yield PlacesBackups.getMostRecentBackup(); |
|
47 do_check_neq(mostRecentBackupFile, null); |
|
48 matches = OS.Path.basename(recentBackup).match(PlacesBackups.filenamesRegex); |
|
49 do_check_eq(matches[2], nodeCount); |
|
50 do_check_eq(matches[3].length, 24); |
|
51 |
|
52 // Cleanup |
|
53 backupFile.remove(false); |
|
54 yield PlacesBackups.create(0); |
|
55 PlacesUtils.bookmarks.removeItem(bookmarkId); |
|
56 }); |
|
57 |