Bug 1542221: Correctly save the state of nsIToolkitProfileService.startWithLastProfile. r=Gijs
authorDave Townsend <dtownsend@oxymoronical.com>
Mon, 08 Apr 2019 22:50:42 +0000
changeset 468439 707da9fd9d959cd881df8f4899d88b16a2d8635b
parent 468438 57538e81d06b0cb09b086b15c88c826d27124b34
child 468440 9eb55c9bf557d9b683d4808620e26da6e242c4b0
push id35837
push userrmaries@mozilla.com
push dateTue, 09 Apr 2019 03:43:40 +0000
treeherdermozilla-central@9eb55c9bf557 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1542221
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1542221: Correctly save the state of nsIToolkitProfileService.startWithLastProfile. r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D26576
toolkit/profile/nsToolkitProfileService.cpp
toolkit/profile/xpcshell/head.js
toolkit/profile/xpcshell/test_clean.js
--- a/toolkit/profile/nsToolkitProfileService.cpp
+++ b/toolkit/profile/nsToolkitProfileService.cpp
@@ -777,17 +777,17 @@ nsresult nsToolkitProfileService::Init()
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsToolkitProfileService::SetStartWithLastProfile(bool aValue) {
   if (mStartWithLast != aValue) {
     nsresult rv = mProfileDB.SetString("General", "StartWithLastProfile",
-                                       mStartWithLast ? "1" : "0");
+                                       aValue ? "1" : "0");
     NS_ENSURE_SUCCESS(rv, rv);
     mStartWithLast = aValue;
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsToolkitProfileService::GetStartWithLastProfile(bool* aResult) {
--- a/toolkit/profile/xpcshell/head.js
+++ b/toolkit/profile/xpcshell/head.js
@@ -372,16 +372,24 @@ function checkBackup(profileData = readP
 
 /**
  * Checks that the profile service seems to have the right data in it compared
  * to profile and install data structured as in the above functions.
  */
 function checkProfileService(profileData = readProfilesIni(), verifyBackup = true) {
   let service = getProfileService();
 
+  let expectedStartWithLast = true;
+  if ("options" in profileData) {
+    expectedStartWithLast = profileData.options.startWithLastProfile;
+  }
+
+  Assert.equal(service.startWithLastProfile, expectedStartWithLast,
+               "Start with last profile should match.");
+
   let serviceProfiles = Array.from(service.profiles);
 
   Assert.equal(serviceProfiles.length, profileData.profiles.length, "Should be the same number of profiles.");
 
   // Sort to make matching easy.
   serviceProfiles.sort((a, b) => a.name.localeCompare(b.name));
   profileData.profiles.sort((a, b) => a.name.localeCompare(b.name));
 
--- a/toolkit/profile/xpcshell/test_clean.js
+++ b/toolkit/profile/xpcshell/test_clean.js
@@ -14,34 +14,36 @@ add_task(async () => {
   Assert.ok(!target.exists(), "installs.ini should not exist yet.");
 
   // Create a new profile to use.
   let newProfile = service.createProfile(null, "dedicated");
   service.flush();
 
   let profileData = readProfilesIni();
 
-  Assert.ok(profileData.options.startWithLastProfile, "Should be set to start with the last profile.");
   Assert.equal(profileData.profiles.length, 1, "Should have the right number of profiles.");
 
   let profile = profileData.profiles[0];
   Assert.equal(profile.name, "dedicated", "Should have the right name.");
   Assert.ok(!profile.default, "Should not be marked as the old-style default.");
 
   // The new profile hasn't been marked as the default yet!
   Assert.equal(Object.keys(profileData.installs).length, 0, "Should be no defaults for installs yet.");
 
   checkProfileService(profileData);
 
+  Assert.ok(service.startWithLastProfile, "Should be set to start with the last profile.");
+  service.startWithLastProfile = false;
+  Assert.ok(!service.startWithLastProfile, "Should be set to not start with the last profile.");
+
   service.defaultProfile = newProfile;
   service.flush();
 
   profileData = readProfilesIni();
 
-  Assert.ok(profileData.options.startWithLastProfile, "Should be set to start with the last profile.");
   Assert.equal(profileData.profiles.length, 1, "Should have the right number of profiles.");
 
   profile = profileData.profiles[0];
   Assert.equal(profile.name, "dedicated", "Should have the right name.");
   Assert.ok(!profile.default, "Should not be marked as the old-style default.");
 
   let hash = xreDirProvider.getInstallHash();
   Assert.equal(Object.keys(profileData.installs).length, 1, "Should be only one known install.");
@@ -51,17 +53,16 @@ add_task(async () => {
 
   let otherProfile = service.createProfile(null, "another");
   service.defaultProfile = otherProfile;
 
   service.flush();
 
   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.");
 
   profile = profileData.profiles[0];
   Assert.equal(profile.name, "another", "Should have the right name.");
   Assert.ok(!profile.default, "Should not be marked as the old-style default.");
 
   profile = profileData.profiles[1];
   Assert.equal(profile.name, "dedicated", "Should have the right name.");
@@ -72,34 +73,32 @@ add_task(async () => {
 
   checkProfileService(profileData);
 
   newProfile.remove(true);
   service.flush();
 
   profileData = readProfilesIni();
 
-  Assert.ok(profileData.options.startWithLastProfile, "Should be set to start with the last profile.");
   Assert.equal(profileData.profiles.length, 1, "Should have the right number of profiles.");
 
   profile = profileData.profiles[0];
   Assert.equal(profile.name, "another", "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 be only one known install.");
   Assert.equal(profileData.installs[hash].default, profileData.profiles[0].path, "Should have marked the new profile as the default for this install.");
 
   checkProfileService(profileData);
 
   otherProfile.remove(true);
   service.flush();
 
   profileData = readProfilesIni();
 
-  Assert.ok(profileData.options.startWithLastProfile, "Should be set to start with the last profile.");
   Assert.equal(profileData.profiles.length, 0, "Should have the right number of profiles.");
 
   // We leave a reference to the missing profile to stop us trying to steal the
   // old-style default profile on next startup.
   Assert.equal(Object.keys(profileData.installs).length, 1, "Should be only one known install.");
 
   checkProfileService(profileData);
 });