Skip to content

Commit ab1493f

Browse files
Bug 1991953 - Set restored profile as default if old profile was default; rename to old-[profile name]. r=kpatenio
Differential Revision: https://phabricator.services.mozilla.com/D267664
1 parent fccb4d3 commit ab1493f

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

browser/components/backup/BackupService.sys.mjs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2989,6 +2989,19 @@ export class BackupService extends EventTarget {
29892989
);
29902990
await IOUtils.writeJSON(postRecoveryPath, postRecovery);
29912991

2992+
// In a release scenario, this should always be true
2993+
// this makes it easier to get around setting up profiles for testing other functionality
2994+
if (profileSvc.currentProfile) {
2995+
// if our current profile was default, let's make the new one default
2996+
if (profileSvc.currentProfile === profileSvc.defaultProfile) {
2997+
profileSvc.defaultProfile = profile;
2998+
}
2999+
3000+
// let's rename the old profile with a prefix old-[profile_name]
3001+
profile.name = profileSvc.currentProfile.name;
3002+
profileSvc.currentProfile.name = `old-${profileSvc.currentProfile.name}`;
3003+
}
3004+
29923005
await profileSvc.asyncFlush();
29933006

29943007
if (shouldLaunch) {

browser/components/backup/tests/xpcshell/test_BackupService.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,14 @@ async function testCreateBackupHelper(sandbox, taskFn) {
273273
"createBackupTestRecoveredProfile"
274274
);
275275

276+
let originalProfileName = currentProfile.name;
277+
278+
let profileSvc = Cc["@mozilla.org/toolkit/profile-service;1"].getService(
279+
Ci.nsIToolkitProfileService
280+
);
281+
// make our current profile default
282+
profileSvc.defaultProfile = currentProfile;
283+
276284
let recoveredProfile = await bs.recoverFromBackupArchive(
277285
backupFilePath,
278286
null,
@@ -282,10 +290,22 @@ async function testCreateBackupHelper(sandbox, taskFn) {
282290
);
283291

284292
Assert.ok(
285-
recoveredProfile.name.startsWith(currentProfile.name),
293+
recoveredProfile.name.startsWith(originalProfileName),
286294
"Should maintain profile name across backup and restore"
287295
);
288296

297+
Assert.strictEqual(
298+
currentProfile.name,
299+
`old-${originalProfileName}`,
300+
"The old profile should be prefixed with old-"
301+
);
302+
303+
Assert.strictEqual(
304+
profileSvc.defaultProfile,
305+
recoveredProfile,
306+
"The new profile should now be the default"
307+
);
308+
289309
// Check that resources were recovered from highest to lowest backup priority.
290310
sinon.assert.callOrder(
291311
FakeBackupResource3.prototype.recover,

0 commit comments

Comments
 (0)