Bug 1555117: Ignore attempts to reset the profile when a new profile had to be created for the install. r=froydnj, a=jcristau
authorDave Townsend <dtownsend@oxymoronical.com>
Fri, 31 May 2019 16:49:56 +0000
changeset 536873 f7ba85dff0ee0d5bed92f83c2f2e3c97c86a2ce3
parent 536872 065339c2d869fa75c5bbfb033f44a9d3effbd8ec
child 536874 55f38f0869b195d7f7e0cb3aff198d48e273129d
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj, jcristau
bugs1555117, 1518587
milestone68.0
Bug 1555117: Ignore attempts to reset the profile when a new profile had to be created for the install. r=froydnj, a=jcristau Since bug 1518587 when a command line argument or environment variable requests a profile refresh but no existing profile is selected we would just exit thinking that there is some problem here. But it turns out that the installer sometimes passes this argument when it doesn't know that the new install will not use the existing profiles. So instead we just ignore attempts to refresh when we create a new profile. To do this we just have to remove the checks that bail out and continue to create the new profile, nsAppRunner will see that a new profile has been created and cancel the attempted refresh anyway: https://searchfox.org/mozilla-central/rev/ddb81c7a43ffada1f6cb4200c4f625e50e44dcf3/toolkit/xre/nsAppRunner.cpp#2021 Differential Revision: https://phabricator.services.mozilla.com/D32891
toolkit/profile/nsToolkitProfileService.cpp
toolkit/profile/xpcshell/test_profile_reset.js
--- a/toolkit/profile/nsToolkitProfileService.cpp
+++ b/toolkit/profile/nsToolkitProfileService.cpp
@@ -1174,24 +1174,16 @@ nsresult nsToolkitProfileService::Select
         bool result;
         rv = MaybeMakeDefaultDedicatedProfile(profile, &result);
         NS_ENSURE_SUCCESS(rv, rv);
         if (result) {
           mStartupReason = NS_LITERAL_STRING("restart-claimed-default");
 
           mCurrent = profile;
         } else {
-          if (aIsResetting) {
-            // We don't want to create a fresh profile when we're attempting a
-            // profile reset so just bail out here, the calling code will handle
-            // it.
-            *aProfile = nullptr;
-            return NS_OK;
-          }
-
           rv = CreateDefaultProfile(getter_AddRefs(mCurrent));
           if (NS_FAILED(rv)) {
             *aProfile = nullptr;
             return rv;
           }
 
           rv = Flush();
           NS_ENSURE_SUCCESS(rv, rv);
@@ -1350,23 +1342,16 @@ nsresult nsToolkitProfileService::Select
     return NS_ERROR_FAILURE;
   }
   if (ar == ARG_FOUND) {
     return NS_ERROR_SHOW_PROFILE_MANAGER;
   }
 
   // If this is a first run then create a new profile.
   if (mIsFirstRun) {
-    if (aIsResetting) {
-      // We don't want to create a fresh profile when we're attempting a
-      // profile reset so just bail out here, the calling code will handle it.
-      *aProfile = nullptr;
-      return NS_OK;
-    }
-
     // If we're configured to always show the profile manager then don't create
     // a new profile to use.
     if (!mStartWithLast) {
       return NS_ERROR_SHOW_PROFILE_MANAGER;
     }
 
     if (mUseDedicatedProfile) {
       // This is the first run of a dedicated profile install. We have to decide
--- a/toolkit/profile/xpcshell/test_profile_reset.js
+++ b/toolkit/profile/xpcshell/test_profile_reset.js
@@ -1,20 +1,36 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /*
- * Tests that from an empty database profile reset doesn't create a new profile.
+ * Tests that from an empty database with profile terset requested a new profile
+ * is still created.
  */
 
 add_task(async () => {
   let service = getProfileService();
 
-  let { profile, didCreate } = selectStartupProfile([], true);
-  // Profile reset will normally end up in a restart.
-  checkStartupReason("unknown");
+  let { profile: selectedProfile, didCreate } = selectStartupProfile([], true);
+  // With no profile we're just create a new profile and skip resetting it.
+  checkStartupReason("firstrun-created-default");
   checkProfileService();
 
-  Assert.ok(!didCreate, "Should not have created a new profile.");
-  Assert.ok(!profile, "Should not be a returned profile.");
-  Assert.equal(service.profileCount, 0, "Still should be no profiles.");
+  let hash = xreDirProvider.getInstallHash();
+  let profileData = readProfilesIni();
+
+  Assert.ok(profileData.options.startWithLastProfile, "Should be set to start with the last profile.");
+  Assert.equal(profileData.profiles.length, 2, "Should have the right number of profiles, ours and the old-style default.");
+
+  let profile = profileData.profiles[AppConstants.MOZ_DEV_EDITION ? 0 : 1];
+  Assert.equal(profile.name, DEDICATED_NAME, "Should have the right name.");
+  Assert.ok(!profile.default, "Should not be marked as the old-style default.");
+
+  Assert.equal(Object.keys(profileData.installs).length, 1, "Should only be one known installs.");
+  Assert.equal(profileData.installs[hash].default, profile.path, "Should have taken the new profile as the default for the current install.");
+  Assert.ok(profileData.installs[hash].locked, "Should have locked as we created this profile.");
+
+  checkProfileService(profileData);
+
+  Assert.ok(didCreate, "Should have created a new profile.");
   Assert.ok(!service.createdAlternateProfile, "Should not have created an alternate profile.");
+  Assert.equal(selectedProfile.name, profile.name, "Should be using the right profile.");
 });