diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /toolkit/components/places/tests/unit/test_PlacesDBUtils_removeOldCorruptDBs.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/places/tests/unit/test_PlacesDBUtils_removeOldCorruptDBs.js')
-rw-r--r-- | toolkit/components/places/tests/unit/test_PlacesDBUtils_removeOldCorruptDBs.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/toolkit/components/places/tests/unit/test_PlacesDBUtils_removeOldCorruptDBs.js b/toolkit/components/places/tests/unit/test_PlacesDBUtils_removeOldCorruptDBs.js new file mode 100644 index 0000000000..26ec85ffc4 --- /dev/null +++ b/toolkit/components/places/tests/unit/test_PlacesDBUtils_removeOldCorruptDBs.js @@ -0,0 +1,42 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +const TEMP_FILES_TO_CREATE = 5; +const LAST_MODIFICATION_DAY = [5, 10, 15, 20, 25]; +const TEST_CURRENT_TIME = Date.now(); +const MS_PER_DAY = 86400000; +const RETAIN_DAYS = 14; + +async function createfiles() { + for (let i = 0; i < TEMP_FILES_TO_CREATE; i++) { + let setTime = TEST_CURRENT_TIME; + setTime -= LAST_MODIFICATION_DAY[i] * MS_PER_DAY; + let fileName = "places.sqlite" + (i > 0 ? "-" + i : "") + ".corrupt"; + let filePath = PathUtils.join(PathUtils.profileDir, fileName); + await IOUtils.writeUTF8(filePath, "test-file-delete-me", { + tmpPath: filePath + ".tmp", + }); + Assert.ok(await IOUtils.exists(filePath), "file created: " + filePath); + await IOUtils.setModificationTime(filePath, setTime); + } +} + +add_task(async function removefiles() { + await createfiles(); + await PlacesDBUtils.runTasks([PlacesDBUtils.removeOldCorruptDBs]); + for (let i = 0; i < TEMP_FILES_TO_CREATE; i++) { + let fileName = "places.sqlite" + (i > 0 ? "-" + i : "") + ".corrupt"; + let filePath = PathUtils.join(PathUtils.profileDir, fileName); + if (LAST_MODIFICATION_DAY[i] >= RETAIN_DAYS) { + Assert.ok( + !(await IOUtils.exists(filePath)), + "Old corrupt file has been removed" + filePath + ); + } else { + Assert.ok( + await IOUtils.exists(filePath), + "Files that are not old are not removed" + filePath + ); + } + } +}); |