Bug 1445660 - Add policy for enabling the search bar. r=Felipe
authorMichael Kaply <mozilla@kaply.com>
Thu, 29 Mar 2018 15:20:36 -0500
changeset 410780 c0da25f5a46221b87d390b6b13b0b75b3544d6a2
parent 410779 1e3e1229efde6921e8f82863725842bd92444ea2
child 410781 523d310f551d5de194041fec635b8048d4d68aa2
push id33739
push usernbeleuzu@mozilla.com
push dateFri, 30 Mar 2018 21:47:45 +0000
treeherdermozilla-central@10c662d8416e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFelipe
bugs1445660
milestone61.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 1445660 - Add policy for enabling the search bar. r=Felipe MozReview-Commit-ID: 8rYmgL4ZZMp
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_searchbar.js
--- a/browser/components/enterprisepolicies/Policies.jsm
+++ b/browser/components/enterprisepolicies/Policies.jsm
@@ -9,16 +9,17 @@ ChromeUtils.import("resource://gre/modul
 XPCOMUtils.defineLazyServiceGetter(this, "gXulStore",
                                    "@mozilla.org/xul/xulstore;1",
                                    "nsIXULStore");
 
 XPCOMUtils.defineLazyModuleGetters(this, {
   BookmarksPolicies: "resource:///modules/policies/BookmarksPolicies.jsm",
   ProxyPolicies: "resource:///modules/policies/ProxyPolicies.jsm",
   AddonManager: "resource://gre/modules/AddonManager.jsm",
+  CustomizableUI: "resource:///modules/CustomizableUI.jsm",
 });
 
 const PREF_LOGLEVEL           = "browser.policies.loglevel";
 const BROWSER_DOCUMENT_URL    = "chrome://browser/content/browser.xul";
 
 XPCOMUtils.defineLazyGetter(this, "log", () => {
   let { ConsoleAPI } = ChromeUtils.import("resource://gre/modules/Console.jsm", {});
   return new ConsoleAPI({
@@ -430,16 +431,32 @@ var Policies = {
   },
 
   "RememberPasswords": {
     onBeforeUIStartup(manager, param) {
       setAndLockPref("signon.rememberSignons", param);
     }
   },
 
+  "SearchBar": {
+    onAllWindowsRestored(manager, param) {
+      // This policy is meant to change the default behavior, not to force it.
+      // If this policy was already applied and the user chose move the search
+      // bar, don't move it again.
+      runOncePerModification("searchInNavBar", param, () => {
+        if (param == "separate") {
+          CustomizableUI.addWidgetToArea("search-container", CustomizableUI.AREA_NAVBAR,
+          CustomizableUI.getPlacementOfWidget("urlbar-container").position + 1);
+        } else if (param == "unified") {
+          CustomizableUI.removeWidgetFromArea("search-container");
+        }
+      });
+    }
+  },
+
   "SearchEngines": {
     onBeforeUIStartup(manager, param) {
       if (param.PreventInstalls) {
         manager.disallowFeature("installSearchEngine", true);
       }
     },
     onAllWindowsRestored(manager, param) {
       Services.search.init(() => {
--- a/browser/components/enterprisepolicies/schemas/policies-schema.json
+++ b/browser/components/enterprisepolicies/schemas/policies-schema.json
@@ -400,16 +400,24 @@
 
     "RememberPasswords": {
       "description": "Enforces the setting to allow Firefox to remember saved logins and passwords. Both true and false values are accepted.",
       "first_available": "60.0",
 
       "type": "boolean"
     },
 
+    "SearchBar": {
+      "description": "Sets the default location of the search bar. Only applies on firtrun, but can be changed.",
+      "first_available": "60.0",
+
+      "type": "string",
+      "enum": ["unified", "separate"]
+    },
+
     "SearchEngines": {
       "description": "Modifies the list of search engines built into Firefox",
       "first_available": "60.0",
       "enterprise_only": true,
 
       "type": "object",
       "properties": {
         "Add": {
--- a/browser/components/enterprisepolicies/tests/browser/browser.ini
+++ b/browser/components/enterprisepolicies/tests/browser/browser.ini
@@ -35,9 +35,10 @@ support-files =
 [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_proxy.js]
 [browser_policy_search_engine.js]
+[browser_policy_searchbar.js]
 [browser_policy_set_homepage.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/enterprisepolicies/tests/browser/browser_policy_searchbar.js
@@ -0,0 +1,35 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_task(async function setup() {
+  await setupPolicyEngineWithJson({
+    "policies": {
+      "SearchBar": "separate"
+    }
+  });
+});
+
+add_task(async function test_menu_shown() {
+  let newWin = await BrowserTestUtils.openNewBrowserWindow();
+  let placement =  CustomizableUI.getPlacementOfWidget("search-container");
+  isnot(placement, null, "Search bar has a placement");
+  is(placement.area, CustomizableUI.AREA_NAVBAR, "Search bar is in the nav bar");
+  await BrowserTestUtils.closeWindow(newWin);
+});
+
+add_task(async function setup() {
+  await setupPolicyEngineWithJson({
+    "policies": {
+      "SearchBar": "unified"
+    }
+  });
+});
+
+add_task(async function test_menu_shown() {
+  let newWin = await BrowserTestUtils.openNewBrowserWindow();
+  let placement =  CustomizableUI.getPlacementOfWidget("search-container");
+  is(placement, null, "Search bar has no placement");
+  await BrowserTestUtils.closeWindow(newWin);
+});