Bug 1548080 - Add a policy to control Firefox Home r=Mardak,flod
authorMichael Kaply <mozilla@kaply.com>
Thu, 02 May 2019 15:40:41 +0000
changeset 531132 735a7dedf5c4a46dcc0ae1b95202455b056f614b
parent 531131 f5f8345a5c873fc99459f53d2eb14247cbc5473a
child 531133 92678c01ead789b2951fe1880c30d5251d2e5785
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMardak, flod
bugs1548080
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 1548080 - Add a policy to control Firefox Home r=Mardak,flod Differential Revision: https://phabricator.services.mozilla.com/D29396
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_policies_simple_pref_policies.js
browser/components/enterprisepolicies/tests/browser/browser_policy_firefoxhome.js
browser/locales/en-US/browser/policies/policies-descriptions.ftl
--- a/browser/components/enterprisepolicies/Policies.jsm
+++ b/browser/components/enterprisepolicies/Policies.jsm
@@ -604,16 +604,37 @@ var Policies = {
   "ExtensionUpdate": {
     onBeforeAddons(manager, param) {
       if (!param) {
         setAndLockPref("extensions.update.enabled", param);
       }
     },
   },
 
+  "FirefoxHome": {
+    onBeforeAddons(manager, param) {
+      let locked = param.Locked || false;
+      if ("Search" in param) {
+        setDefaultPref("browser.newtabpage.activity-stream.showSearch", param.Search, locked);
+      }
+      if ("TopSites" in param) {
+        setDefaultPref("browser.newtabpage.activity-stream.feeds.topsites", param.TopSites, locked);
+      }
+      if ("Highlights" in param) {
+        setDefaultPref("browser.newtabpage.activity-stream.feeds.section.highlights", param.Highlights, locked);
+      }
+      if ("Pocket" in param) {
+        setDefaultPref("browser.newtabpage.activity-stream.feeds.section.topstories", param.Pocket, locked);
+      }
+      if ("Snippets" in param) {
+        setDefaultPref("browser.newtabpage.activity-stream.feeds.snippets", param.Snippets, locked);
+      }
+    },
+  },
+
   "FlashPlugin": {
     onBeforeUIStartup(manager, param) {
       addAllowDenyPermissions("plugin:flash", param.Allow, param.Block);
 
       const FLASH_NEVER_ACTIVATE = 0;
       const FLASH_ASK_TO_ACTIVATE = 1;
       const FLASH_ALWAYS_ACTIVATE = 2;
 
--- a/browser/components/enterprisepolicies/schemas/policies-schema.json
+++ b/browser/components/enterprisepolicies/schemas/policies-schema.json
@@ -326,16 +326,40 @@
         }
       }
     },
 
     "ExtensionUpdate": {
       "type": "boolean"
     },
 
+    "FirefoxHome": {
+      "type": "object",
+      "properties": {
+        "Search": {
+          "type": "boolean"
+        },
+        "TopSites": {
+          "type": "boolean"
+        },
+        "Highlights": {
+          "type": "boolean"
+        },
+        "Pocket": {
+          "type": "boolean"
+        },
+        "Snippets": {
+          "type": "boolean"
+        },
+        "Locked": {
+          "type": "boolean"
+        }
+      }
+    },
+
     "FlashPlugin": {
       "type": "object",
       "properties": {
         "Allow": {
           "type": "array",
           "strict": false,
           "items": {
             "type": "origin"
--- a/browser/components/enterprisepolicies/tests/browser/browser.ini
+++ b/browser/components/enterprisepolicies/tests/browser/browser.ini
@@ -46,16 +46,17 @@ skip-if = (verify && debug && (os == 'ma
 [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_extensionsettings.js]
 [browser_policy_locale.js]
+[browser_policy_firefoxhome.js]
 [browser_policy_override_postupdatepage.js]
 [browser_policy_permissions.js]
 [browser_policy_proxy.js]
 [browser_policy_preferences.js]
 [browser_policy_search_engine.js]
 [browser_policy_searchbar.js]
 [browser_policy_set_homepage.js]
 [browser_policy_support_menu.js]
--- a/browser/components/enterprisepolicies/tests/browser/browser_policies_simple_pref_policies.js
+++ b/browser/components/enterprisepolicies/tests/browser/browser_policies_simple_pref_policies.js
@@ -422,16 +422,31 @@ const POLICIES_TESTS = [
   {
     policies: {
       "SearchSuggestEnabled": false,
     },
     lockedPrefs: {
       "browser.urlbar.suggest.searches": false,
     },
   },
+
+  // POLICY: FirefoxHome
+  {
+    policies: {
+      "FirefoxHome": {
+        "Pocket": false,
+        "Snippets": false,
+        "Locked": true,
+      },
+    },
+    lockedPrefs: {
+      "browser.newtabpage.activity-stream.feeds.snippets": false,
+      "browser.newtabpage.activity-stream.feeds.section.topstories": false,
+    },
+  },
 ];
 
 add_task(async function test_policy_simple_prefs() {
   for (let test of POLICIES_TESTS) {
     await setupPolicyEngineWithJson({
       "policies": test.policies,
     });
 
new file mode 100644
--- /dev/null
+++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_firefoxhome.js
@@ -0,0 +1,48 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_task(async function test_firefox_home_without_policy_without_pocket() {
+  let tab = await BrowserTestUtils.openNewForegroundTab({gBrowser,
+    opening: "about:home",
+    waitForStateStop: true});
+
+  await ContentTask.spawn(tab.linkedBrowser, {}, function() {
+    let search = content.document.querySelector(".search-wrapper");
+    isnot(search, null, "Search section should be there.");
+    let topsites = content.document.querySelector("section[data-section-id='topsites']");
+    isnot(topsites, null, "Top Sites section should be there.");
+    let highlights = content.document.querySelector("section[data-section-id='highlights']");
+    isnot(highlights, null, "Highlights section should be there.");
+  });
+  BrowserTestUtils.removeTab(tab);
+  await SpecialPowers.popPrefEnv();
+});
+
+add_task(async function test_firefox_home_with_policy() {
+  await setupPolicyEngineWithJson({
+    "policies": {
+      "FirefoxHome": {
+        "Search": false,
+        "TopSites": false,
+        "Highlights": false,
+        "Snippets": false,
+      },
+    },
+  });
+
+  let tab = await BrowserTestUtils.openNewForegroundTab({gBrowser,
+    opening: "about:home",
+    waitForStateStop: true});
+
+  await ContentTask.spawn(tab.linkedBrowser, {}, function() {
+    let search = content.document.querySelector(".search-wrapper");
+    is(search, null, "Search section should not be there.");
+    let topsites = content.document.querySelector("section[data-section-id='topsites']");
+    is(topsites, null, "Top Sites section should not be there.");
+    let highlights = content.document.querySelector("section[data-section-id='highlights']");
+    is(highlights, null, "Highlights section should not be there.");
+  });
+  BrowserTestUtils.removeTab(tab);
+});
--- a/browser/locales/en-US/browser/policies/policies-descriptions.ftl
+++ b/browser/locales/en-US/browser/policies/policies-descriptions.ftl
@@ -83,16 +83,18 @@ policy-EnableTrackingProtection = Enable
 
 # A “locked” extension can’t be disabled or removed by the user. This policy
 # takes 3 keys (“Install”, ”Uninstall”, ”Locked”), you can either keep them in
 # English or translate them as verbs.
 policy-Extensions = Install, uninstall or lock extensions. The Install option takes URLs or paths as parameters. The Uninstall and Locked options take extension IDs.
 
 policy-ExtensionUpdate = Enable or disable automatic extension updates.
 
+policy-FirefoxHome = Configure Firefox Home.
+
 policy-FlashPlugin = Allow or deny usage of the Flash plugin.
 
 policy-HardwareAcceleration = If false, turn off hardware acceleration.
 
 # “lock” means that the user won’t be able to change this setting
 policy-Homepage = Set and optionally lock the homepage.
 
 policy-InstallAddonsPermission = Allow certain websites to install add-ons.