Bug 1126559 - don't allow resetting when that is not possible, r=MattN, a=ritu
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 18 May 2016 15:25:00 +0100
changeset 332989 a6138313bed92c7755f7f6ec38e9033a7abd88b2
parent 332988 9b9a73a98de81f22189dd3972c922459bce28393
child 332990 c2d6ad2297e3ee19433e6cb541a427c249bb51f7
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN, ritu
bugs1126559
milestone48.0a2
Bug 1126559 - don't allow resetting when that is not possible, r=MattN, a=ritu MozReview-Commit-ID: F0m70XKQtT7
browser/components/uitour/UITour.jsm
browser/components/uitour/test/browser_UITour_resetProfile.js
--- a/browser/components/uitour/UITour.jsm
+++ b/browser/components/uitour/UITour.jsm
@@ -617,17 +617,19 @@ this.UITour = {
 
         // We want to replace the current tab.
         browser.loadURI("about:accounts?" + p.toString());
         break;
       }
 
       case "resetFirefox": {
         // Open a reset profile dialog window.
-        ResetProfile.openConfirmationDialog(window);
+        if (ResetProfile.resetSupported()) {
+          ResetProfile.openConfirmationDialog(window);
+        }
         break;
       }
 
       case "addNavBarWidget": {
         // Add a widget to the toolbar
         let targetPromise = this.getTarget(window, data.name);
         targetPromise.then(target => {
           this.addNavBarWidget(target, messageManager, data.callbackID);
@@ -1934,16 +1936,19 @@ this.UITour = {
           this.sendPageCallback(aMessageManager, aCallbackID, data);
         });
         break;
       case "sync":
         this.sendPageCallback(aMessageManager, aCallbackID, {
           setup: Services.prefs.prefHasUserValue("services.sync.username"),
         });
         break;
+      case "canReset":
+        this.sendPageCallback(aMessageManager, aCallbackID, ResetProfile.resetSupported());
+        break;
       default:
         log.error("getConfiguration: Unknown configuration requested: " + aConfiguration);
         break;
     }
   },
 
   setConfiguration: function(aWindow, aConfiguration, aValue) {
     switch (aConfiguration) {
--- a/browser/components/uitour/test/browser_UITour_resetProfile.js
+++ b/browser/components/uitour/test/browser_UITour_resetProfile.js
@@ -1,18 +1,42 @@
 "use strict";
 
 var gTestTab;
 var gContentAPI;
 var gContentWindow;
 
 add_task(setup_UITourTest);
 
+let formerSelectedProfile, formerDefaultProfile;
+registerCleanupFunction(function() {
+  let profileService = Cc["@mozilla.org/toolkit/profile-service;1"].
+                       getService(Ci.nsIToolkitProfileService);
+  if (formerSelectedProfile) {
+    info("Restoring selected profile");
+    profileService.selectedProfile = formerSelectedProfile;
+  }
+  if (formerDefaultProfile) {
+    info("Restoring default profile");
+    profileService.defaultProfile = formerDefaultProfile;
+  }
+});
+
 // Test that a reset profile dialog appears when "resetFirefox" event is triggered
 add_UITour_task(function* test_resetFirefox() {
+  let profileService = Cc["@mozilla.org/toolkit/profile-service;1"].
+                       getService(Ci.nsIToolkitProfileService);
+  try {
+    formerSelectedProfile = profileService.selectedProfile;
+  } catch (ex) {}
+  try {
+    formerDefaultProfile = profileService.defaultProfile;
+  } catch (ex) {}
+  let canReset = yield getConfigurationPromise("canReset");
+  ok(!canReset, "Shouldn't be able to reset from mochitest's temporary profile.");
   let dialogPromise = new Promise((resolve) => {
     let winWatcher = Cc["@mozilla.org/embedcomp/window-watcher;1"].
                      getService(Ci.nsIWindowWatcher);
     winWatcher.registerNotification(function onOpen(subj, topic, data) {
       if (topic == "domwindowopened" && subj instanceof Ci.nsIDOMWindow) {
         subj.addEventListener("load", function onLoad() {
           subj.removeEventListener("load", onLoad);
           if (subj.document.documentURI ==
@@ -23,12 +47,23 @@ add_UITour_task(function* test_resetFire
                "Reset Firefox event opened a reset profile window.");
             subj.close();
             resolve();
           }
         });
       }
     });
   });
+
+  // make reset possible.
+  let currentProfileDir = Services.dirsvc.get("ProfD", Ci.nsIFile);
+  let profileName = "mochitest-test-profile-temp-" + Date.now();
+  let tempProfile = profileService.createProfile(currentProfileDir, profileName);
+  profileService.defaultProfile = profileService.selectedProfile = tempProfile;
+  canReset = yield getConfigurationPromise("canReset");
+  ok(canReset, "Should be able to reset from mochitest's temporary profile once it's in the profile manager.");
   yield gContentAPI.resetFirefox();
   yield dialogPromise;
+  tempProfile.remove(false);
+  canReset = yield getConfigurationPromise("canReset");
+  ok(!canReset, "Shouldn't be able to reset from mochitest's temporary profile once removed from the profile manager.");
 });