diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /toolkit/components/places/tests/bookmarks/test_818593-store-backup-metadata.js | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/places/tests/bookmarks/test_818593-store-backup-metadata.js')
-rw-r--r-- | toolkit/components/places/tests/bookmarks/test_818593-store-backup-metadata.js | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/toolkit/components/places/tests/bookmarks/test_818593-store-backup-metadata.js b/toolkit/components/places/tests/bookmarks/test_818593-store-backup-metadata.js new file mode 100644 index 0000000000..6d280e8cad --- /dev/null +++ b/toolkit/components/places/tests/bookmarks/test_818593-store-backup-metadata.js @@ -0,0 +1,53 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/** + * To confirm that metadata i.e. bookmark count is set and retrieved for + * automatic backups. + */ +add_task(async function test_saveBookmarksToJSONFile_and_create() { + // Add a bookmark + let bookmark = await PlacesUtils.bookmarks.insert({ + parentGuid: PlacesUtils.bookmarks.unfiledGuid, + title: "Get Firefox!", + url: "http://getfirefox.com/", + }); + + // Test saveBookmarksToJSONFile() + let backupFile = PathUtils.join(PathUtils.tempDir, "bookmarks.json"); + + let nodeCount = await PlacesBackups.saveBookmarksToJSONFile(backupFile, true); + Assert.ok(nodeCount > 0); + Assert.ok(await IOUtils.exists(backupFile)); + + // Ensure the backup would be copied to our backups folder when the original + // backup is saved somewhere else. + let recentBackup = await PlacesBackups.getMostRecentBackup(); + let matches = PathUtils.filename(recentBackup).match( + PlacesBackups.filenamesRegex + ); + Assert.equal(matches[2], nodeCount); + Assert.equal(matches[3].length, 24); + + // Clear all backups in our backups folder. + await PlacesBackups.create(0); + Assert.equal((await PlacesBackups.getBackupFiles()).length, 0); + + // Test create() which saves bookmarks with metadata on the filename. + await PlacesBackups.create(); + Assert.equal((await PlacesBackups.getBackupFiles()).length, 1); + + let mostRecentBackupFile = await PlacesBackups.getMostRecentBackup(); + Assert.notEqual(mostRecentBackupFile, null); + matches = PathUtils.filename(recentBackup).match( + PlacesBackups.filenamesRegex + ); + Assert.equal(matches[2], nodeCount); + Assert.equal(matches[3].length, 24); + + // Cleanup + await IOUtils.remove(backupFile); + await PlacesBackups.create(0); + await PlacesUtils.bookmarks.remove(bookmark); +}); |