Bug 1122124 - fix default profile setting after reset, keep profile name, r?MattN
MozReview-Commit-ID: 9h1ktdUUVZH
--- a/browser/components/migration/tests/marionette/test_refresh_firefox.py
+++ b/browser/components/migration/tests/marionette/test_refresh_firefox.py
@@ -1,10 +1,11 @@
import os
import shutil
+import time
from marionette_harness import MarionetteTestCase
class TestFirefoxRefresh(MarionetteTestCase):
_username = "marionette-test-login"
_password = "marionette-test-password"
_bookmarkURL = "about:mozilla"
@@ -338,31 +339,32 @@ class TestFirefoxRefresh(MarionetteTestC
else:
raise
if self.desktop_backup_path:
shutil.rmtree(self.desktop_backup_path, ignore_errors=False, onerror=handleRemoveReadonly)
if self.reset_profile_path:
# Remove ourselves from profiles.ini
- profileLeafName = os.path.basename(os.path.normpath(self.reset_profile_path))
self.runCode("""
- let [salt, name] = arguments[0].split(".");
+ let name = arguments[0];
let profile = global.profSvc.getProfileByName(name);
profile.remove(false)
global.profSvc.flush();
- """, script_args=[profileLeafName])
+ """, script_args=[self.profileNameToRemove])
# And delete all the files.
shutil.rmtree(self.reset_profile_path, ignore_errors=False, onerror=handleRemoveReadonly)
def doReset(self):
+ profileName = "marionette-test-profile-" + str(int(time.time() * 1000))
+ self.profileNameToRemove = profileName
self.runCode("""
// Ensure the current (temporary) profile is in profiles.ini:
let profD = Services.dirsvc.get("ProfD", Ci.nsIFile);
- let profileName = "marionette-test-profile-" + Date.now();
+ let profileName = arguments[1];
let myProfile = global.profSvc.createProfile(profD, profileName);
global.profSvc.flush()
// Now add the reset parameters:
let env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment);
let allMarionettePrefs = Services.prefs.getChildList("marionette.");
let prefObj = {};
for (let pref of allMarionettePrefs) {
@@ -370,17 +372,17 @@ class TestFirefoxRefresh(MarionetteTestC
let prefVal = global.Preferences.get(pref);
prefObj[prefSuffix] = prefVal;
}
let marionetteInfo = JSON.stringify(prefObj);
env.set("MOZ_MARIONETTE_PREF_STATE_ACROSS_RESTARTS", marionetteInfo);
env.set("MOZ_RESET_PROFILE_RESTART", "1");
env.set("XRE_PROFILE_PATH", arguments[0]);
env.set("XRE_PROFILE_NAME", profileName);
- """, script_args=[self.marionette.instance.profile.profile])
+ """, script_args=[self.marionette.instance.profile.profile, profileName])
profileLeafName = os.path.basename(os.path.normpath(self.marionette.instance.profile.profile))
# Now restart the browser to get it reset:
self.marionette.restart(clean=False, in_app=True)
self.setUpScriptData()
# Determine the new profile path (we'll need to remove it when we're done)
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -2138,43 +2138,47 @@ ShowProfileManager(nsIToolkitProfileServ
if (offline) {
SaveToEnv("XRE_START_OFFLINE=1");
}
return LaunchChild(aNative);
}
/**
- * Set the currently running profile as the default/selected one.
+ * Get the currently running profile using its root directory.
*
+ * @param aProfileSvc The profile service
* @param aCurrentProfileRoot The root directory of the current profile.
- * @return an error if aCurrentProfileRoot is not found or the profile could not
- * be set as the default.
+ * @param aProfile Out-param that returns the profile object.
+ * @return an error if aCurrentProfileRoot is not found
*/
static nsresult
-SetCurrentProfileAsDefault(nsIToolkitProfileService* aProfileSvc,
- nsIFile* aCurrentProfileRoot)
+GetCurrentProfile(nsIToolkitProfileService* aProfileSvc,
+ nsIFile* aCurrentProfileRoot,
+ nsIToolkitProfile** aProfile)
{
NS_ENSURE_ARG_POINTER(aProfileSvc);
+ NS_ENSURE_ARG_POINTER(aProfile);
nsCOMPtr<nsISimpleEnumerator> profiles;
nsresult rv = aProfileSvc->GetProfiles(getter_AddRefs(profiles));
if (NS_FAILED(rv))
return rv;
bool foundMatchingProfile = false;
nsCOMPtr<nsISupports> supports;
rv = profiles->GetNext(getter_AddRefs(supports));
while (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIToolkitProfile> profile = do_QueryInterface(supports);
nsCOMPtr<nsIFile> profileRoot;
profile->GetRootDir(getter_AddRefs(profileRoot));
profileRoot->Equals(aCurrentProfileRoot, &foundMatchingProfile);
if (foundMatchingProfile) {
- return aProfileSvc->SetSelectedProfile(profile);
+ profile.forget(aProfile);
+ return NS_OK;
}
rv = profiles->GetNext(getter_AddRefs(supports));
}
return rv;
}
static bool gDoMigration = false;
static bool gDoProfileReset = false;
@@ -4284,25 +4288,32 @@ XREMain::XRE_mainRun()
pm->Migrate(&mDirProvider, aKey, gResetOldProfileName);
}
}
if (gDoProfileReset) {
nsresult backupCreated = ProfileResetCleanup(profileBeingReset);
if (NS_FAILED(backupCreated)) NS_WARNING("Could not cleanup the profile that was reset");
- // Set the new profile as the default after we're done cleaning up the old profile,
- // iff that profile was already the default
- if (profileWasSelected) {
- // this is actually "broken" - see bug 1122124
- rv = SetCurrentProfileAsDefault(mProfileSvc, mProfD);
- if (NS_FAILED(rv)) NS_WARNING("Could not set current profile as the default");
+ nsCOMPtr<nsIToolkitProfile> newProfile;
+ rv = GetCurrentProfile(mProfileSvc, mProfD, getter_AddRefs(newProfile));
+ if (NS_SUCCEEDED(rv)) {
+ newProfile->SetName(gResetOldProfileName);
+ // Set the new profile as the default after we're done cleaning up the old profile,
+ // iff that profile was already the default
+ if (profileWasSelected) {
+ rv = mProfileSvc->SetDefaultProfile(newProfile);
+ if (NS_FAILED(rv)) NS_WARNING("Could not set current profile as the default");
+ }
+ } else {
+ NS_WARNING("Could not find current profile to set as default / change name.");
}
- // Need to write out the fact that the profile has been removed and potentially
- // that the selected/default profile changed.
+
+ // Need to write out the fact that the profile has been removed, the new profile
+ // renamed, and potentially that the selected/default profile changed.
mProfileSvc->Flush();
}
}
mDirProvider.DoStartup();
OverrideDefaultLocaleIfNeeded();