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