Bug 1429164 - Add enterprise policy to prevent showing the profile import wizard draft
authorKirk Steuber <ksteuber@mozilla.com>
Wed, 04 Apr 2018 10:56:20 -0700
changeset 778154 cc1e9a5e849e1facc478ebb410ace0e131e08791
parent 777984 110f32790d38a258cab722064aae40736478ef51
push id105401
push userksteuber@mozilla.com
push dateThu, 05 Apr 2018 21:26:21 +0000
bugs1429164
milestone61.0a1
Bug 1429164 - Add enterprise policy to prevent showing the profile import wizard MozReview-Commit-ID: Lg7r1NrFbKl
browser/components/enterprisepolicies/Policies.jsm
browser/components/enterprisepolicies/schemas/policies-schema.json
browser/components/enterprisepolicies/tests/browser/browser.ini
browser/components/enterprisepolicies/tests/browser/browser_policy_disable_profile_import.js
browser/components/places/content/places.js
--- a/browser/components/enterprisepolicies/Policies.jsm
+++ b/browser/components/enterprisepolicies/Policies.jsm
@@ -286,16 +286,25 @@ var Policies = {
       if (param) {
         manager.disallowFeature("privatebrowsing");
         manager.disallowFeature("about:privatebrowsing", true);
         setAndLockPref("browser.privatebrowsing.autostart", false);
       }
     }
   },
 
+  "DisableProfileImport": {
+    onBeforeUIStartup(manager, param) {
+      if (param) {
+        manager.disallowFeature("profileImport");
+        setAndLockPref("browser.newtabpage.activity-stream.migrationExpired", true);
+      }
+    }
+  },
+
   "DisableProfileRefresh": {
     onBeforeUIStartup(manager, param) {
       if (param) {
         manager.disallowFeature("profileRefresh");
         setAndLockPref("browser.disableResetPrompt", true);
       }
     }
   },
--- a/browser/components/enterprisepolicies/schemas/policies-schema.json
+++ b/browser/components/enterprisepolicies/schemas/policies-schema.json
@@ -229,16 +229,23 @@
 
     "DisablePrivateBrowsing": {
       "description": "Disables private browsing.",
       "first_available": "60.0",
 
       "type": "boolean"
     },
 
+    "DisableProfileImport": {
+      "description": "Disables the Firefox \"Import data from another browser\" button",
+      "first_available": "60.0",
+
+      "type": "boolean"
+    },
+
     "DisableProfileRefresh": {
       "description": "Disables the \"Refresh Firefox\" button in about:support",
       "first_available": "60.0",
 
       "type": "boolean"
     },
 
     "DisableSafeMode": {
--- a/browser/components/enterprisepolicies/tests/browser/browser.ini
+++ b/browser/components/enterprisepolicies/tests/browser/browser.ini
@@ -33,16 +33,17 @@ support-files =
 [browser_policy_disable_flash_plugin.js]
 [browser_policy_disable_fxaccounts.js]
 [browser_policy_disable_masterpassword.js]
 [browser_policy_disable_pdfjs.js]
 [browser_policy_disable_pocket.js]
 [browser_policy_disable_popup_blocker.js]
 [browser_policy_disable_privatebrowsing.js]
 [browser_policy_disable_profile_reset.js]
+[browser_policy_disable_profile_import.js]
 [browser_policy_disable_safemode.js]
 [browser_policy_disable_shield.js]
 [browser_policy_disable_telemetry.js]
 [browser_policy_display_bookmarks.js]
 [browser_policy_display_menu.js]
 [browser_policy_extensions.js]
 [browser_policy_override_postupdatepage.js]
 [browser_policy_proxy.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_disable_profile_import.js
@@ -0,0 +1,36 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+async function openLibrary() {
+  return new Promise(resolve => {
+    let library = window.openDialog("chrome://browser/content/places/places.xul", "",
+                                    "chrome,toolbar=yes,dialog=no,resizable");
+    waitForFocus(() => resolve(library), library);
+  });
+}
+
+add_task(async function test_disable_profile_import() {
+  await setupPolicyEngineWithJson({
+    "policies": {
+      "DisableProfileImport": true
+    }
+  });
+  let library = await openLibrary();
+
+  let menu = library.document.getElementById("maintenanceButtonPopup");
+  let promisePopupShown = BrowserTestUtils.waitForEvent(menu, "popupshown");
+  menu.openPopup();
+  await promisePopupShown;
+
+  let profileImportButton = library.document.getElementById("browserImport");
+  is(profileImportButton.disabled, true, "Profile Import button should be disabled");
+
+  let promisePopupHidden = BrowserTestUtils.waitForEvent(menu, "popuphidden");
+  menu.hidePopup();
+  await promisePopupHidden;
+
+  await BrowserTestUtils.closeWindow(library);
+
+  checkLockedPref("browser.newtabpage.activity-stream.migrationExpired", true);
+});
--- a/browser/components/places/content/places.js
+++ b/browser/components/places/content/places.js
@@ -184,16 +184,20 @@ var PlacesOrganizer = {
         document.getElementById(elements[i]).setAttribute("disabled", "true");
       }
     }
 
     // remove the "Properties" context-menu item, we've our own details pane
     document.getElementById("placesContext")
             .removeChild(document.getElementById("placesContext_show:info"));
 
+    if (!Services.policies.isAllowed("profileImport")) {
+      document.getElementById("OrganizerCommand_browserImport").setAttribute("disabled", true);
+    }
+
     ContentArea.focus();
   },
 
   QueryInterface: function PO_QueryInterface(aIID) {
     if (aIID.equals(Ci.nsIDOMEventListener) ||
         aIID.equals(Ci.nsISupports))
       return this;