This test can be run via: ./mach marionette-test browser/components/backup/test/marionette/test_backup.py This also makes it so that BackupResource.copySqliteDatabases does not throw if one of the passed in database files doesn't exist - it'll just ignore it and move on. This required me to update some tests in order to create some fake SQLite databases to ensure that the fake Sqlite connection was made and the backup stub was called for the SQLite databases being copied. Finally, this also fixes something I noticed - some of our BackupResource's weren't returning null or objects as their ManifestEntry. This fixes that and adds tests to cover that case. Differential Revision: https://phabricator.services.mozilla.com/D207811
71 lines
2.2 KiB
JavaScript
71 lines
2.2 KiB
JavaScript
/* 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 https://mozilla.org/MPL/2.0/. */
|
|
|
|
import {
|
|
BackupResource,
|
|
bytesToFuzzyKilobytes,
|
|
} from "resource:///modules/backup/BackupResource.sys.mjs";
|
|
|
|
const lazy = {};
|
|
|
|
ChromeUtils.defineESModuleGetters(lazy, {
|
|
SessionStore: "resource:///modules/sessionstore/SessionStore.sys.mjs",
|
|
});
|
|
|
|
/**
|
|
* Class representing Session store related files within a user profile.
|
|
*/
|
|
export class SessionStoreBackupResource extends BackupResource {
|
|
static get key() {
|
|
return "sessionstore";
|
|
}
|
|
|
|
static get requiresEncryption() {
|
|
// Session store data does not require encryption, but if encryption is
|
|
// disabled, then session cookies will be cleared from the backup before
|
|
// writing it to the disk.
|
|
return false;
|
|
}
|
|
|
|
async backup(stagingPath, profilePath = PathUtils.profileDir) {
|
|
let sessionStoreState = lazy.SessionStore.getCurrentState(true);
|
|
let sessionStorePath = PathUtils.join(stagingPath, "sessionstore.jsonlz4");
|
|
|
|
/* Bug 1891854 - remove cookies from session store state if the backup file is
|
|
* not encrypted. */
|
|
|
|
await IOUtils.writeJSON(sessionStorePath, sessionStoreState, {
|
|
compress: true,
|
|
});
|
|
await BackupResource.copyFiles(profilePath, stagingPath, [
|
|
"sessionstore-backups",
|
|
]);
|
|
|
|
return null;
|
|
}
|
|
|
|
async measure(profilePath = PathUtils.profileDir) {
|
|
// Get the current state of the session store JSON and
|
|
// measure it's uncompressed size.
|
|
let sessionStoreJson = lazy.SessionStore.getCurrentState(true);
|
|
let sessionStoreSize = new TextEncoder().encode(
|
|
JSON.stringify(sessionStoreJson)
|
|
).byteLength;
|
|
let sessionStoreNearestTenthKb = bytesToFuzzyKilobytes(sessionStoreSize);
|
|
|
|
Glean.browserBackup.sessionStoreSize.set(sessionStoreNearestTenthKb);
|
|
|
|
let sessionStoreBackupsDirectoryPath = PathUtils.join(
|
|
profilePath,
|
|
"sessionstore-backups"
|
|
);
|
|
let sessionStoreBackupsDirectorySize =
|
|
await BackupResource.getDirectorySize(sessionStoreBackupsDirectoryPath);
|
|
|
|
Glean.browserBackup.sessionStoreBackupsDirectorySize.set(
|
|
sessionStoreBackupsDirectorySize
|
|
);
|
|
}
|
|
}
|