commit 8cbfe02375ec6976b9109adc82bab1dc87dab1eb
parent f3d29c586150a019fa9ed3352a2111d52ee54fc5
Author: Harsheet <hsohaney@mozilla.com>
Date: Fri, 5 Dec 2025 19:22:00 +0000
Bug 1996815 - Ensure we don't chain prefixes when updating profile names after a restore. r=kpatenio
Differential Revision: https://phabricator.services.mozilla.com/D274444
Diffstat:
3 files changed, 64 insertions(+), 5 deletions(-)
diff --git a/browser/components/backup/BackupService.sys.mjs b/browser/components/backup/BackupService.sys.mjs
@@ -3397,8 +3397,12 @@ export class BackupService extends EventTarget {
profileSvc.defaultProfile = profile;
}
- // let's rename the old profile with a prefix old-[profile_name]
- profileSvc.currentProfile.name = `old-${profileSvc.currentProfile.name}`;
+ // If the profile already has an [old-] prefix, let's skip adding new prefixes
+ if (!profileSvc.currentProfile.name.startsWith("old-")) {
+ // Looks like this is a new restoration of this profile,
+ // add the prefix old-[profile_name]
+ profileSvc.currentProfile.name = `old-${profileSvc.currentProfile.name}`;
+ }
}
await profileSvc.asyncFlush();
diff --git a/browser/components/backup/tests/xpcshell/test_BackupService.js b/browser/components/backup/tests/xpcshell/test_BackupService.js
@@ -324,9 +324,8 @@ async function testCreateBackupHelper(sandbox, taskFn) {
"Should maintain profile name across backup and restore"
);
- Assert.strictEqual(
- currentProfile.name,
- `old-${originalProfileName}`,
+ Assert.ok(
+ currentProfile.name.startsWith("old-"),
"The old profile should be prefixed with old-"
);
diff --git a/browser/components/backup/tests/xpcshell/test_BackupService_recoverFromSnapshotFolder.js b/browser/components/backup/tests/xpcshell/test_BackupService_recoverFromSnapshotFolder.js
@@ -10,6 +10,11 @@ const { JsonSchema } = ChromeUtils.importESModule(
"resource://gre/modules/JsonSchema.sys.mjs"
);
+let currentProfile;
+add_setup(() => {
+ currentProfile = setupProfile();
+});
+
/**
* Tests that if the backup-manifest.json provides an appName different from
* AppConstants.MOZ_APP_NAME of the currently running application, then
@@ -96,3 +101,54 @@ add_task(async function test_newer_appVersion() {
await IOUtils.remove(testRecoveryPath, { recursive: true });
});
+
+add_task(async function test_profile_naming() {
+ let testRecoveryPath = await IOUtils.createUniqueDirectory(
+ PathUtils.tempDir,
+ "testProfileNaming"
+ );
+
+ let meta = Object.assign({}, FAKE_METADATA);
+ let manifest = {
+ version: ArchiveUtils.SCHEMA_VERSION,
+ meta,
+ resources: {},
+ };
+ let schema = await BackupService.MANIFEST_SCHEMA;
+ let validationResult = JsonSchema.validate(manifest, schema);
+ Assert.ok(validationResult.valid, "Schema matches manifest");
+
+ await IOUtils.writeJSON(
+ PathUtils.join(testRecoveryPath, BackupService.MANIFEST_FILE_NAME),
+ manifest
+ );
+
+ let currentName = `original-profile-that-was-backed-up`;
+ currentProfile.name = currentName;
+
+ let bs = new BackupService();
+
+ await bs.recoverFromSnapshotFolder(testRecoveryPath, false);
+
+ Assert.equal(
+ currentProfile.name,
+ `old-${currentName}`,
+ "The old profile prefix was added"
+ );
+ currentName = currentProfile.name;
+
+ // Let's make sure that we don't end up chaining the prefix
+ await bs.recoverFromSnapshotFolder(testRecoveryPath, false);
+ Assert.notEqual(
+ currentProfile.name,
+ `old-${currentName}`,
+ "The old profile prefix was not added again"
+ );
+ Assert.equal(
+ currentProfile.name,
+ currentName,
+ "The name of the profile did not change"
+ );
+
+ await IOUtils.remove(testRecoveryPath, { recursive: true });
+});