Bug 1542221: Correctly save the state of nsIToolkitProfileService.startWithLastProfile. r=Gijs a=pascalc
authorDave Townsend <dtownsend@oxymoronical.com>
Mon, 08 Apr 2019 22:50:42 +0000
changeset 523106 8842c0d0cef24b7eff3550daed701ae33cb6ec7d
parent 523105 828f8931afe0bc0f686c5a9143ce953c1f086587
child 523107 e52e74683afcfd9434253927cc54c9081b28a187
push id11057
push userarchaeopteryx@coole-files.de
push dateWed, 10 Apr 2019 14:56:16 +0000
treeherdermozilla-beta@590d0706d113 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs, pascalc
bugs1542221
milestone67.0
Bug 1542221: Correctly save the state of nsIToolkitProfileService.startWithLastProfile. r=Gijs a=pascalc 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);
 });