Bug 1387416 - Place the search bar in the customization palette for new profiles. r=Gijs draft
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Wed, 06 Sep 2017 13:09:27 +0100
changeset 659987 2e02e0a809d08ff26291a027b73a54668d6d5f9d
parent 659873 c959327c6b75cd4930a6ea087583c38b805e7524
child 730111 3433a8bac66fb167b923494a1005c42428f3ffb5
push id78263
push userpaolo.mozmail@amadzone.org
push dateWed, 06 Sep 2017 13:43:28 +0000
reviewersGijs
bugs1387416
milestone57.0a1
Bug 1387416 - Place the search bar in the customization palette for new profiles. r=Gijs MozReview-Commit-ID: Tq8YrZWG6P
browser/app/profile/firefox.js
browser/base/content/browser.xul
browser/base/content/test/about/browser_aboutHome.js
browser/base/content/test/urlbar/browser_urlbarFocusedCmdK.js
browser/components/customizableui/CustomizableUI.jsm
browser/components/customizableui/SearchWidgetTracker.jsm
browser/components/customizableui/test/browser_694291_searchbar_preference.js
browser/components/customizableui/test/browser_901207_searchbar_in_panel.js
browser/components/customizableui/test/browser_909779_overflow_toolbars_new_window.js
browser/components/customizableui/test/browser_913972_currentset_overflow.js
browser/components/customizableui/test/browser_914138_widget_API_overflowable_toolbar.js
browser/components/customizableui/test/browser_923857_customize_mode_event_wrapping_during_reset.js
browser/components/customizableui/test/browser_940307_panel_click_closure_handling.js
browser/components/customizableui/test/browser_962069_drag_to_overflow_chevron.js
browser/components/customizableui/test/browser_976792_insertNodeInWindow.js
browser/components/customizableui/test/browser_980155_add_overflow_toolbar.js
browser/components/customizableui/test/browser_984455_bookmarks_items_reparenting.js
browser/components/customizableui/test/browser_customization_context_menus.js
browser/components/customizableui/test/browser_editcontrols_update.js
browser/components/customizableui/test/browser_overflow_use_subviews.js
browser/components/customizableui/test/head.js
browser/components/downloads/test/browser/browser_overflow_anchor.js
browser/components/search/test/browser_426329.js
browser/components/search/test/browser_google_behavior.js
browser/components/search/test/browser_google_codes.js
browser/components/search/test/browser_google_nocodes.js
browser/components/search/test/browser_healthreport.js
browser/components/search/test/browser_hiddenOneOffs_diacritics.js
browser/components/search/test/browser_oneOffContextMenu.js
browser/components/search/test/browser_oneOffContextMenu_setDefault.js
browser/components/search/test/browser_oneOffHeader.js
browser/components/search/test/browser_private_search_perwindowpb.js
browser/components/search/test/browser_searchEngine_behaviors.js
browser/components/search/test/browser_searchbar_keyboard_navigation.js
browser/components/search/test/browser_searchbar_openpopup.js
browser/components/search/test/browser_searchbar_smallpanel_keyboard_navigation.js
browser/components/search/test/browser_tooManyEnginesOffered.js
browser/components/search/test/browser_yahoo.js
browser/components/uitour/test/browser_UITour.js
browser/components/uitour/test/browser_UITour3.js
browser/components/uitour/test/browser_UITour_availableTargets.js
browser/components/uitour/test/browser_openSearchPanel.js
browser/modules/BrowserUITelemetry.jsm
browser/modules/test/browser/browser_UsageTelemetry_searchbar.js
layout/xul/test/browser_bug1163304.js
toolkit/components/extensions/test/browser/browser_ext_themes_toolbar_fields.js
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -404,21 +404,18 @@ pref("browser.search.order.US.3",       
 pref("browser.search.openintab", false);
 
 // context menu searches open in the foreground
 pref("browser.search.context.loadInBackground", false);
 
 // comma seperated list of of engines to hide in the search panel.
 pref("browser.search.hiddenOneOffs", "");
 
-// Mirrors whether the search-container widget is in the navigation toolbar. The
-// default value of this preference must match the DEFAULT_AREA_PLACEMENTS of
-// UITelemetry.jsm, the navbarPlacements of CustomizableUI.jsm, and the
-// position and attributes of the search-container element in browser.xul.
-pref("browser.search.widget.inNavBar", true);
+// Mirrors whether the search-container widget is in the navigation toolbar.
+pref("browser.search.widget.inNavBar", false);
 
 #ifndef RELEASE_OR_BETA
 pref("browser.search.reset.enabled", true);
 #endif
 
 pref("browser.sessionhistory.max_entries", 50);
 
 // Built-in default permissions.
--- a/browser/base/content/browser.xul
+++ b/browser/base/content/browser.xul
@@ -926,23 +926,16 @@
                            role="button"
                            observes="bookmarkThisPageBroadcaster"/>
                   </hbox>
                 </hbox>
               </hbox>
             </textbox>
         </toolbaritem>
 
-        <toolbaritem id="search-container" title="&searchItem.title;"
-                     align="center" class="chromeclass-toolbar-additional panel-wide-item"
-                     cui-areatype="toolbar"
-                     flex="100" persist="width" removable="true">
-          <searchbar id="searchbar" flex="1"/>
-        </toolbaritem>
-
         <!-- This is a placeholder for the Downloads Indicator.  It is visible
              during the customization of the toolbar, in the palette, and before
              the Downloads Indicator overlay is loaded. -->
         <toolbarbutton id="downloads-button"
                        class="toolbarbutton-1 chromeclass-toolbar-additional badged-button"
                        key="key_openDownloads"
                        oncommand="DownloadsIndicatorView.onCommand(event);"
                        ondrop="DownloadsIndicatorView.onDrop(event);"
@@ -1082,26 +1075,24 @@
       <toolbarbutton id="fullscreen-button" class="toolbarbutton-1 chromeclass-toolbar-additional"
                      observes="View:FullScreen"
                      type="checkbox"
                      label="&fullScreenCmd.label;"
                      tooltip="dynamic-shortcut-tooltip"/>
 
       <toolbarbutton id="bookmarks-menu-button"
                      class="toolbarbutton-1 chromeclass-toolbar-additional"
-                     removable="true"
                      type="menu"
                      label="&bookmarksMenuButton2.label;"
                      tooltip="dynamic-shortcut-tooltip"
                      anchor="dropmarker"
                      ondragenter="PlacesMenuDNDHandler.onDragEnter(event);"
                      ondragover="PlacesMenuDNDHandler.onDragOver(event);"
                      ondragleave="PlacesMenuDNDHandler.onDragLeave(event);"
                      ondrop="PlacesMenuDNDHandler.onDrop(event);"
-                     cui-areatype="toolbar"
                      oncommand="BookmarkingUI.onCommand(event);">
         <observes element="bookmarkThisPageBroadcaster" attribute="starred"/>
         <observes element="bookmarkThisPageBroadcaster" attribute="buttontooltiptext"/>
         <menupopup id="BMB_bookmarksPopup"
                    class="cui-widget-panel cui-widget-panelview cui-widget-panelWithFooter PanelUI-subView"
                    placespopup="true"
                    context="placesContext"
                    openInTabs="children"
@@ -1177,16 +1168,25 @@
           <!-- Bookmarks menu items will go here -->
           <menuitem id="BMB_bookmarksShowAll"
                     class="subviewbutton panel-subview-footer"
                     label="&showAllBookmarks2.label;"
                     command="Browser:ShowAllBookmarks"
                     key="manBookmarkKb"/>
         </menupopup>
       </toolbarbutton>
+
+      <toolbaritem id="search-container"
+                   class="chromeclass-toolbar-additional panel-wide-item"
+                   title="&searchItem.title;"
+                   align="center"
+                   flex="100"
+                   persist="width">
+        <searchbar id="searchbar" flex="1"/>
+      </toolbaritem>
     </toolbarpalette>
     <box id="library-animatable-box" class="toolbarbutton-animatable-box">
       <image class="toolbarbutton-animatable-image"/>
     </box>
   </toolbox>
 
   <hbox id="fullscr-toggler" hidden="true"/>
 
--- a/browser/base/content/test/about/browser_aboutHome.js
+++ b/browser/base/content/test/about/browser_aboutHome.js
@@ -478,27 +478,31 @@ add_task(async function() {
       is(searchInput.value, "a", "Search input should be 'a'.");
     });
   });
 });
 
 add_task(async function() {
   info("Cmd+k should focus the search box in the toolbar when it's present");
 
+  Services.prefs.setBoolPref("browser.search.widget.inNavBar", true);
+
   await BrowserTestUtils.withNewTab({ gBrowser, url: "about:home" }, async function(browser) {
     await BrowserTestUtils.synthesizeMouseAtCenter("#brandLogo", {}, browser);
 
     let doc = window.document;
     let searchInput = doc.getElementById("searchbar").textbox.inputField;
     isnot(searchInput, doc.activeElement, "Search bar should not be the active element.");
 
     EventUtils.synthesizeKey("k", { accelKey: true });
     await promiseWaitForCondition(() => doc.activeElement === searchInput);
     is(searchInput, doc.activeElement, "Search bar should be the active element.");
   });
+
+  Services.prefs.clearUserPref("browser.search.widget.inNavBar");
 });
 
 add_task(async function() {
   info("Sync button should open about:preferences#sync");
 
   await BrowserTestUtils.withNewTab({ gBrowser, url: "about:home" }, async function(browser) {
     let oldOpenPrefs = window.openPreferences;
     let openPrefsPromise = new Promise(resolve => {
--- a/browser/base/content/test/urlbar/browser_urlbarFocusedCmdK.js
+++ b/browser/base/content/test/urlbar/browser_urlbarFocusedCmdK.js
@@ -1,17 +1,11 @@
 /* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 add_task(async function() {
-  // Remove the search bar from toolbar
-  CustomizableUI.removeWidgetFromArea("search-container");
-
   // Test that Ctrl/Cmd + K will focus the url bar
   let focusPromise = BrowserTestUtils.waitForEvent(gURLBar, "focus");
   EventUtils.synthesizeKey("k", { accelKey: true });
   await focusPromise;
   Assert.equal(document.activeElement, gURLBar.inputField, "URL Bar should be focused");
-
-  // Reset changes made to toolbar
-  CustomizableUI.reset();
 });
 
--- a/browser/components/customizableui/CustomizableUI.jsm
+++ b/browser/components/customizableui/CustomizableUI.jsm
@@ -188,17 +188,16 @@ var CustomizableUIInternal = {
 
     let navbarPlacements = [
       "back-button",
       "forward-button",
       "stop-reload-button",
       "home-button",
       "spring",
       "urlbar-container",
-      "search-container",
       "spring",
       "downloads-button",
       "library-button",
       "sidebar-button",
     ];
 
     if (AppConstants.MOZ_DEV_EDITION) {
       navbarPlacements.splice(2, 0, "developer-button");
--- a/browser/components/customizableui/SearchWidgetTracker.jsm
+++ b/browser/components/customizableui/SearchWidgetTracker.jsm
@@ -31,16 +31,20 @@ const SearchWidgetTracker = {
     this.onWidgetReset = this.onWidgetUndoMove = node => {
       if (node.id == WIDGET_ID) {
         this.syncPreferenceWithWidget();
       }
     };
     CustomizableUI.addListener(this);
     Services.prefs.addObserver(PREF_NAME,
                                () => this.syncWidgetWithPreference());
+
+    // The placement of the widget always takes priority, and the preference
+    // should always match the actual placement when the browser starts up.
+    this.syncPreferenceWithWidget();
   },
 
   onCustomizeEnd() {
     // onWidgetUndoMove does not fire when the search container is moved back to
     // the customization palette as a result of an undo, so we sync again here.
     this.syncPreferenceWithWidget();
   },
 
--- a/browser/components/customizableui/test/browser_694291_searchbar_preference.js
+++ b/browser/components/customizableui/test/browser_694291_searchbar_preference.js
@@ -2,45 +2,42 @@
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 const WIDGET_ID = "search-container";
 const PREF_NAME = "browser.search.widget.inNavBar";
 
 function checkDefaults() {
-  // If the following defaults change, then the DEFAULT_AREA_PLACEMENTS of
-  // UITelemetry.jsm, the navbarPlacements of CustomizableUI.jsm, and the
-  // position and attributes of the search-container element in browser.xul
-  // should also change at the same time.
-  ok(Services.prefs.getBoolPref(PREF_NAME));
-  let placement = CustomizableUI.getPlacementOfWidget(WIDGET_ID);
-  is(placement.area, CustomizableUI.AREA_NAVBAR);
-  is(placement.position,
-     CustomizableUI.getPlacementOfWidget("urlbar-container").position + 1);
+  ok(!Services.prefs.getBoolPref(PREF_NAME));
+  is(CustomizableUI.getPlacementOfWidget(WIDGET_ID), null);
 }
 
 add_task(async function test_defaults() {
   // Verify the default state before the first test.
   checkDefaults();
 });
 
 add_task(async function test_syncPreferenceWithWidget() {
+  // Moving the widget to any position in the navigation toolbar should turn the
+  // preference to true.
+  CustomizableUI.addWidgetToArea(WIDGET_ID, CustomizableUI.AREA_NAVBAR);
+  ok(Services.prefs.getBoolPref(PREF_NAME));
+
   // Moving the widget to any position outside of the navigation toolbar should
-  // turn the preference to false.
+  // turn the preference back to false.
   CustomizableUI.addWidgetToArea(WIDGET_ID, CustomizableUI.AREA_FIXED_OVERFLOW_PANEL);
   ok(!Services.prefs.getBoolPref(PREF_NAME));
-
-  // Moving the widget back to any position in the navigation toolbar should
-  // turn the preference to true again.
-  CustomizableUI.addWidgetToArea(WIDGET_ID, CustomizableUI.AREA_NAVBAR);
-  ok(Services.prefs.getBoolPref(PREF_NAME));
 });
 
 add_task(async function test_syncWidgetWithPreference() {
-  // This should move the widget the customization palette.
+  // setting the preference should move the widget to the navigation toolbar and
+  // place it right after the location bar.
+  Services.prefs.setBoolPref(PREF_NAME, true);
+  let placement = CustomizableUI.getPlacementOfWidget(WIDGET_ID);
+  is(placement.area, CustomizableUI.AREA_NAVBAR);
+  is(placement.position,
+     CustomizableUI.getPlacementOfWidget("urlbar-container").position + 1);
+
+  // This should move the widget back to the customization palette.
   Services.prefs.setBoolPref(PREF_NAME, false);
-  is(CustomizableUI.getPlacementOfWidget(WIDGET_ID), null);
-
-  // This should return the widget to its default placement.
-  Services.prefs.setBoolPref(PREF_NAME, true);
   checkDefaults();
 });
--- a/browser/components/customizableui/test/browser_901207_searchbar_in_panel.js
+++ b/browser/components/customizableui/test/browser_901207_searchbar_in_panel.js
@@ -11,39 +11,35 @@ async function waitForSearchBarFocus() {
   await waitForCondition(function() {
     logActiveElement();
     return document.activeElement === searchbar.textbox.inputField;
   });
 }
 
 // Ctrl+K should open the menu panel and focus the search bar if the search bar is in the panel.
 add_task(async function() {
-  let searchbar = document.getElementById("searchbar");
-  gCustomizeMode.addToPanel(searchbar);
-  let placement = CustomizableUI.getPlacementOfWidget("search-container");
-  is(placement.area, CustomizableUI.AREA_FIXED_OVERFLOW_PANEL, "Should be in panel");
+  CustomizableUI.addWidgetToArea("search-container",
+                                 CustomizableUI.AREA_FIXED_OVERFLOW_PANEL);
 
   let shownPanelPromise = promiseOverflowShown(window);
   sendWebSearchKeyCommand();
   await shownPanelPromise;
 
   await waitForSearchBarFocus();
 
   let hiddenPanelPromise = promiseOverflowHidden(window);
   EventUtils.synthesizeKey("VK_ESCAPE", {});
   await hiddenPanelPromise;
   CustomizableUI.reset();
 });
 
 // Ctrl+K should give focus to the searchbar when the searchbar is in the menupanel and the panel is already opened.
 add_task(async function() {
-  let searchbar = document.getElementById("searchbar");
-  gCustomizeMode.addToPanel(searchbar);
-  let placement = CustomizableUI.getPlacementOfWidget("search-container");
-  is(placement.area, CustomizableUI.AREA_FIXED_OVERFLOW_PANEL, "Should be in panel");
+  CustomizableUI.addWidgetToArea("search-container",
+                                 CustomizableUI.AREA_FIXED_OVERFLOW_PANEL);
 
   await document.getElementById("nav-bar").overflowable.show();
 
   sendWebSearchKeyCommand();
 
   await waitForSearchBarFocus();
 
   let hiddenPanelPromise = promiseOverflowHidden(window);
@@ -54,46 +50,54 @@ add_task(async function() {
 
 // Ctrl+K should open the overflow panel and focus the search bar if the search bar is overflowed.
 add_task(async function() {
   this.originalWindowWidth = window.outerWidth;
   let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
   ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar.");
   ok(CustomizableUI.inDefaultState, "Should start in default state.");
 
-  window.resizeTo(360, window.outerHeight);
+  Services.prefs.setBoolPref("browser.search.widget.inNavBar", true);
+
+  window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
   await waitForCondition(() => navbar.getAttribute("overflowing") == "true");
   ok(!navbar.querySelector("#search-container"), "Search container should be overflowing");
 
   let shownPanelPromise = promiseOverflowShown(window);
   sendWebSearchKeyCommand();
   await shownPanelPromise;
 
   let chevron = document.getElementById("nav-bar-overflow-button");
   await waitForCondition(() => chevron.open);
 
   await waitForSearchBarFocus();
 
   let hiddenPanelPromise = promiseOverflowHidden(window);
   EventUtils.synthesizeKey("VK_ESCAPE", {});
   await hiddenPanelPromise;
+
+  Services.prefs.setBoolPref("browser.search.widget.inNavBar", false);
+
   navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
   window.resizeTo(this.originalWindowWidth, window.outerHeight);
   await waitForCondition(() => !navbar.hasAttribute("overflowing"));
   ok(!navbar.hasAttribute("overflowing"), "Should not have an overflowing toolbar.");
 });
 
 // Ctrl+K should focus the search bar if it is in the navbar and not overflowing.
 add_task(async function() {
+  Services.prefs.setBoolPref("browser.search.widget.inNavBar", true);
   let placement = CustomizableUI.getPlacementOfWidget("search-container");
   is(placement.area, CustomizableUI.AREA_NAVBAR, "Should be in nav-bar");
 
   sendWebSearchKeyCommand();
 
   await waitForSearchBarFocus();
+
+  Services.prefs.setBoolPref("browser.search.widget.inNavBar", false);
 });
 
 
 function sendWebSearchKeyCommand() {
   if (Services.appinfo.OS === "Darwin")
     EventUtils.synthesizeKey("k", { accelKey: true });
   else
     EventUtils.synthesizeKey("k", { ctrlKey: true });
--- a/browser/components/customizableui/test/browser_909779_overflow_toolbars_new_window.js
+++ b/browser/components/customizableui/test/browser_909779_overflow_toolbars_new_window.js
@@ -5,17 +5,17 @@
 "use strict";
 
 // Resize to a small window, open a new window, check that new window handles overflow properly
 add_task(async function() {
   let originalWindowWidth = window.outerWidth;
   let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
   ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar.");
   let oldChildCount = navbar.customizationTarget.childElementCount;
-  window.resizeTo(400, window.outerHeight);
+  window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
   await waitForCondition(() => navbar.hasAttribute("overflowing"));
   ok(navbar.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
 
   ok(navbar.customizationTarget.childElementCount < oldChildCount, "Should have fewer children.");
   let newWindow = await openAndLoadWindow();
   let otherNavBar = newWindow.document.getElementById(CustomizableUI.AREA_NAVBAR);
   await waitForCondition(() => otherNavBar.hasAttribute("overflowing"));
   ok(otherNavBar.hasAttribute("overflowing"), "Other window should have an overflowing toolbar.");
--- a/browser/components/customizableui/test/browser_913972_currentset_overflow.js
+++ b/browser/components/customizableui/test/browser_913972_currentset_overflow.js
@@ -8,17 +8,17 @@ var navbar = document.getElementById(Cus
 
 // Resize to a small window, resize back, shouldn't affect currentSet
 add_task(async function() {
   let originalWindowWidth = window.outerWidth;
   let oldCurrentSet = navbar.currentSet;
   ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar.");
   ok(CustomizableUI.inDefaultState, "Should start in default state.");
   let oldChildCount = navbar.customizationTarget.childElementCount;
-  window.resizeTo(400, window.outerHeight);
+  window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
   await waitForCondition(() => navbar.hasAttribute("overflowing"));
   ok(navbar.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
   is(navbar.currentSet, oldCurrentSet, "Currentset should be the same when overflowing.");
   ok(CustomizableUI.inDefaultState, "Should still be in default state when overflowing.");
   ok(navbar.customizationTarget.childElementCount < oldChildCount, "Should have fewer children.");
   window.resizeTo(originalWindowWidth, window.outerHeight);
   await waitForCondition(() => !navbar.hasAttribute("overflowing"));
   ok(!navbar.hasAttribute("overflowing"), "Should no longer have an overflowing toolbar.");
--- a/browser/components/customizableui/test/browser_914138_widget_API_overflowable_toolbar.js
+++ b/browser/components/customizableui/test/browser_914138_widget_API_overflowable_toolbar.js
@@ -18,17 +18,17 @@ var originalWindowWidth;
 
 // Adding a widget should add it next to the widget it's being inserted next to.
 add_task(async function() {
   originalWindowWidth = window.outerWidth;
   createDummyXULButton(kTestBtn1, "Test");
   ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar.");
   ok(CustomizableUI.inDefaultState, "Should start in default state.");
 
-  window.resizeTo(400, window.outerHeight);
+  window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
   await waitForCondition(() => navbar.hasAttribute("overflowing"));
   ok(navbar.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
   ok(!navbar.querySelector("#" + kSidebarBtn), "Sidebar button should no longer be in the navbar");
   let sidebarBtnNode = overflowList.querySelector("#" + kSidebarBtn);
   ok(sidebarBtnNode, "Sidebar button should be overflowing");
   ok(sidebarBtnNode && sidebarBtnNode.getAttribute("overflowedItem") == "true", "Sidebar button should have overflowedItem attribute");
 
   let placementOfSidebarButton = CustomizableUI.getWidgetIdsInArea(navbar.id).indexOf(kSidebarBtn);
@@ -60,17 +60,17 @@ add_task(async function() {
 // Removing a widget should remove it from the overflow list if that is where it is, and update it accordingly.
 add_task(async function() {
   createDummyXULButton(kTestBtn2, "Test");
   ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar.");
   ok(CustomizableUI.inDefaultState, "Should start in default state.");
   CustomizableUI.addWidgetToArea(kTestBtn2, navbar.id);
   ok(!navbar.hasAttribute("overflowing"), "Should still have a non-overflowing toolbar.");
 
-  window.resizeTo(400, window.outerHeight);
+  window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
   await waitForCondition(() => navbar.hasAttribute("overflowing"));
   ok(navbar.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
   ok(!navbar.querySelector("#" + kTestBtn2), "Test button should not be in the navbar");
   ok(overflowList.querySelector("#" + kTestBtn2), "Test button should be overflowing");
 
   CustomizableUI.removeWidgetFromArea(kTestBtn2);
 
   ok(!overflowList.querySelector("#" + kTestBtn2), "Test button should not be overflowing.");
@@ -89,17 +89,17 @@ add_task(async function() {
 });
 
 // Constructing a widget while overflown should set the right class on it.
 add_task(async function() {
   originalWindowWidth = window.outerWidth;
   ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar.");
   ok(CustomizableUI.inDefaultState, "Should start in default state.");
 
-  window.resizeTo(400, window.outerHeight);
+  window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
   await waitForCondition(() => navbar.hasAttribute("overflowing"));
   ok(navbar.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
   ok(!navbar.querySelector("#" + kSidebarBtn), "Sidebar button should no longer be in the navbar");
   let sidebarBtnNode = overflowList.querySelector("#" + kSidebarBtn);
   ok(sidebarBtnNode, "Sidebar button should be overflowing");
   ok(sidebarBtnNode && sidebarBtnNode.getAttribute("overflowedItem") == "true", "Sidebar button should have overflowedItem class");
 
   let testBtnSpec = {id: kTestBtn3, label: "Overflowable widget test", defaultArea: "nav-bar"};
--- a/browser/components/customizableui/test/browser_923857_customize_mode_event_wrapping_during_reset.js
+++ b/browser/components/customizableui/test/browser_923857_customize_mode_event_wrapping_during_reset.js
@@ -4,21 +4,21 @@
 
 "use strict";
 
 // Customize mode reset button should revert correctly
 add_task(async function() {
   await startCustomizing();
   let devButton = document.getElementById("developer-button");
   let downloadsButton = document.getElementById("downloads-button");
-  let searchBox = document.getElementById("search-container");
+  let homeButton = document.getElementById("home-button");
   let palette = document.getElementById("customization-palette");
-  ok(devButton && downloadsButton && searchBox && palette, "Stuff should exist");
+  ok(devButton && downloadsButton && homeButton && palette, "Stuff should exist");
   simulateItemDrag(devButton, downloadsButton);
-  simulateItemDrag(searchBox, palette);
+  simulateItemDrag(homeButton, palette);
   await gCustomizeMode.reset();
   ok(CustomizableUI.inDefaultState, "Should be back in default state");
   await endCustomizing();
 });
 
 add_task(async function asyncCleanup() {
   await resetCustomization();
 });
--- a/browser/components/customizableui/test/browser_940307_panel_click_closure_handling.js
+++ b/browser/components/customizableui/test/browser_940307_panel_click_closure_handling.js
@@ -64,24 +64,24 @@ add_task(async function menu_button_popu
   EventUtils.synthesizeMouseAtCenter(menuItem, {});
   await menuHidden;
   await hiddenAgain;
   CustomizableUI.removeWidgetFromArea(menuButton.id);
   menuButton.remove();
 });
 
 add_task(async function searchbar_in_panel() {
-  let searchbar = document.getElementById("searchbar");
-  gCustomizeMode.addToPanel(searchbar);
-  let placement = CustomizableUI.getPlacementOfWidget("search-container");
-  is(placement.area, CustomizableUI.AREA_FIXED_OVERFLOW_PANEL, "Should be in panel");
+  CustomizableUI.addWidgetToArea("search-container",
+                                 CustomizableUI.AREA_FIXED_OVERFLOW_PANEL);
 
   await waitForOverflowButtonShown();
 
   await document.getElementById("nav-bar").overflowable.show();
+
+  let searchbar = document.getElementById("searchbar");
   await waitForCondition(() => "value" in searchbar && searchbar.value === "");
 
   // Focusing a non-empty searchbox will cause us to open the
   // autocomplete panel and search for suggestions, which would
   // trigger network requests. Temporarily disable suggestions.
   await SpecialPowers.pushPrefEnv({set: [["browser.search.suggest.enabled", false]]});
 
   searchbar.value = "foo";
--- a/browser/components/customizableui/test/browser_962069_drag_to_overflow_chevron.js
+++ b/browser/components/customizableui/test/browser_962069_drag_to_overflow_chevron.js
@@ -7,17 +7,17 @@
 var originalWindowWidth;
 
 // Drag to overflow chevron should open the overflow panel.
 add_task(async function() {
   originalWindowWidth = window.outerWidth;
   let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
   ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar.");
   ok(CustomizableUI.inDefaultState, "Should start in default state.");
-  window.resizeTo(400, window.outerHeight);
+  window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
   await waitForCondition(() => navbar.hasAttribute("overflowing"));
   ok(navbar.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
 
   let widgetOverflowPanel = document.getElementById("widget-overflow");
   let panelShownPromise = promisePanelElementShown(window, widgetOverflowPanel);
   let identityBox = document.getElementById("identity-box");
   let overflowChevron = document.getElementById("nav-bar-overflow-button");
 
--- a/browser/components/customizableui/test/browser_976792_insertNodeInWindow.js
+++ b/browser/components/customizableui/test/browser_976792_insertNodeInWindow.js
@@ -62,17 +62,17 @@ add_task(async function() {
     CustomizableUI.addWidgetToArea(id, "nav-bar");
   }
 
   for (let id of widgetIds) {
     document.getElementById(id).style.minWidth = "200px";
   }
 
   let originalWindowWidth = window.outerWidth;
-  window.resizeTo(400, window.outerHeight);
+  window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
   await waitForCondition(() => navbar.hasAttribute("overflowing"));
 
   let testWidgetId = kTestWidgetPrefix + 3;
 
   CustomizableUI.destroyWidget(testWidgetId);
 
   let btn = createDummyXULButton(testWidgetId, "test");
   CustomizableUI.ensureWidgetPlacedInWindow(testWidgetId, window);
@@ -111,17 +111,17 @@ add_task(async function() {
     CustomizableUI.addWidgetToArea(id, "nav-bar");
   }
 
   for (let id of widgetIds) {
     document.getElementById(id).style.minWidth = "200px";
   }
 
   let originalWindowWidth = window.outerWidth;
-  window.resizeTo(400, window.outerHeight);
+  window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
   await waitForCondition(() => navbar.hasAttribute("overflowing"));
 
   let testWidgetId = kTestWidgetPrefix + 3;
 
   CustomizableUI.destroyWidget(kTestWidgetPrefix + 2);
   CustomizableUI.destroyWidget(testWidgetId);
 
   let btn = createDummyXULButton(testWidgetId, "test");
@@ -161,17 +161,17 @@ add_task(async function() {
     CustomizableUI.addWidgetToArea(id, "nav-bar");
   }
 
   for (let id of widgetIds) {
     document.getElementById(id).style.minWidth = "200px";
   }
 
   let originalWindowWidth = window.outerWidth;
-  window.resizeTo(400, window.outerHeight);
+  window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
   await waitForCondition(() => navbar.hasAttribute("overflowing"));
 
   let testWidgetId = kTestWidgetPrefix + 3;
 
   CustomizableUI.destroyWidget(kTestWidgetPrefix + 2);
   CustomizableUI.destroyWidget(testWidgetId);
   CustomizableUI.destroyWidget(kTestWidgetPrefix + 4);
 
@@ -220,17 +220,17 @@ add_task(async function() {
     CustomizableUI.addWidgetToArea(id, "nav-bar");
   }
 
   for (let id of widgetIds) {
     document.getElementById(id).style.minWidth = "200px";
   }
 
   let originalWindowWidth = window.outerWidth;
-  window.resizeTo(400, window.outerHeight);
+  window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
   await waitForCondition(() => navbar.hasAttribute("overflowing"));
 
   // Find last widget that doesn't allow overflowing
   let nonOverflowing = navbar.customizationTarget.lastChild;
   is(nonOverflowing.getAttribute("overflows"), "false", "Last child is expected to not allow overflowing");
   isnot(nonOverflowing.getAttribute("skipintoolbarset"), "true", "Last child is expected to not be skipintoolbarset");
 
   let testWidgetId = kTestWidgetPrefix + 10;
@@ -281,17 +281,17 @@ add_task(async function() {
     }
   }
 
   let toolbarNode = createOverflowableToolbarWithPlacements(kToolbarName, widgetIds);
   assertAreaPlacements(kToolbarName, widgetIds);
   ok(!toolbarNode.hasAttribute("overflowing"), "Toolbar shouldn't overflow to start with.");
 
   let originalWindowWidth = window.outerWidth;
-  window.resizeTo(400, window.outerHeight);
+  window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
   await waitForCondition(() => toolbarNode.hasAttribute("overflowing"));
   ok(toolbarNode.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
 
   let btnId = kTestWidgetPrefix + missingId;
   let btn = createDummyXULButton(btnId, "test");
   CustomizableUI.ensureWidgetPlacedInWindow(btnId, window);
 
   is(btn.parentNode.id, kToolbarName + "-overflow-list", "New XUL widget should be placed inside new toolbar's overflow");
@@ -332,17 +332,17 @@ add_task(async function() {
     }
   }
 
   let toolbarNode = createOverflowableToolbarWithPlacements(kToolbarName, widgetIds);
   assertAreaPlacements(kToolbarName, widgetIds);
   ok(!toolbarNode.hasAttribute("overflowing"), "Toolbar shouldn't overflow to start with.");
 
   let originalWindowWidth = window.outerWidth;
-  window.resizeTo(400, window.outerHeight);
+  window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
   await waitForCondition(() => toolbarNode.hasAttribute("overflowing"));
   ok(toolbarNode.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
 
   let btnId = kTestWidgetPrefix + missingId;
   let btn = createDummyXULButton(btnId, "test");
   CustomizableUI.ensureWidgetPlacedInWindow(btnId, window);
 
   is(btn.parentNode.id, kToolbarName + "-target", "New XUL widget should be placed inside new toolbar");
@@ -381,17 +381,17 @@ add_task(async function() {
     }
   }
 
   let toolbarNode = createOverflowableToolbarWithPlacements(kToolbarName, widgetIds);
   assertAreaPlacements(kToolbarName, widgetIds);
   ok(!toolbarNode.hasAttribute("overflowing"), "Toolbar shouldn't overflow to start with.");
 
   let originalWindowWidth = window.outerWidth;
-  window.resizeTo(400, window.outerHeight);
+  window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
   await waitForCondition(() => toolbarNode.hasAttribute("overflowing"));
   ok(toolbarNode.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
 
   let btnId = kTestWidgetPrefix + missingId;
   let btn = createDummyXULButton(btnId, "test");
   btn.setAttribute("overflows", false);
   CustomizableUI.ensureWidgetPlacedInWindow(btnId, window);
 
--- a/browser/components/customizableui/test/browser_980155_add_overflow_toolbar.js
+++ b/browser/components/customizableui/test/browser_980155_add_overflow_toolbar.js
@@ -30,17 +30,17 @@ add_task(async function addOverflowingTo
   isnot(toolbarNode.customizationTarget, toolbarNode, "Customization target should not be toolbar node");
 
   let oldChildCount = toolbarNode.customizationTarget.childElementCount;
   let overflowableList = document.getElementById(kToolbarName + "-overflow-list");
   let oldOverflowCount = overflowableList.childElementCount;
 
   isnot(oldChildCount, 0, "Toolbar should have non-overflowing widgets");
 
-  window.resizeTo(400, window.outerHeight);
+  window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
   await waitForCondition(() => toolbarNode.hasAttribute("overflowing"));
   ok(toolbarNode.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
   ok(toolbarNode.customizationTarget.childElementCount < oldChildCount, "Should have fewer children.");
   ok(overflowableList.childElementCount > oldOverflowCount, "Should have more overflowed widgets.");
 
   window.resizeTo(originalWindowWidth, window.outerHeight);
 });
 
--- a/browser/components/customizableui/test/browser_984455_bookmarks_items_reparenting.js
+++ b/browser/components/customizableui/test/browser_984455_bookmarks_items_reparenting.js
@@ -5,17 +5,16 @@
 "use strict";
 
 var gNavBar = document.getElementById(CustomizableUI.AREA_NAVBAR);
 var gOverflowList = document.getElementById(gNavBar.getAttribute("overflowtarget"));
 
 const kBookmarksButton = "bookmarks-menu-button";
 const kBookmarksItems = "personal-bookmarks";
 const kOriginalWindowWidth = window.outerWidth;
-const kSmallWidth = 400;
 
 /**
  * Helper function that opens the bookmarks menu, and returns a Promise that
  * resolves as soon as the menu is ready for interaction.
  */
 function bookmarksMenuPanelShown() {
   return new Promise(resolve => {
     let bookmarksMenuPopup = document.getElementById("BMB_bookmarksPopup");
@@ -136,17 +135,17 @@ function checkBookmarksItemsChevronConte
 
 /**
  * Forces the window to a width that causes the nav-bar to overflow
  * its contents. Returns a Promise that resolves as soon as the
  * overflowable nav-bar is showing its chevron.
  */
 function overflowEverything() {
   info("Waiting for overflow");
-  window.resizeTo(kSmallWidth, window.outerHeight);
+  window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
   return waitForCondition(() => gNavBar.hasAttribute("overflowing"));
 }
 
 /**
  * Returns the window to its original size from the start of the test,
  * and returns a Promise that resolves when the nav-bar is no longer
  * overflowing.
  */
--- a/browser/components/customizableui/test/browser_customization_context_menus.js
+++ b/browser/components/customizableui/test/browser_customization_context_menus.js
@@ -140,16 +140,21 @@ add_task(async function urlbar_context()
   let hiddenPromise = popupHidden(contextMenu);
   contextMenu.hidePopup();
   await hiddenPromise;
 });
 
 // Right-click on the searchbar and moving it to the menu
 // and back should move the search-container instead.
 add_task(async function searchbar_context_move_to_panel_and_back() {
+  // This is specifically testing the addToPanel function for the search bar, so
+  // we have to move it to its correct position in the navigation toolbar first.
+  // The preference will be restored when the customizations are reset later.
+  Services.prefs.setBoolPref("browser.search.widget.inNavBar", true);
+
   let searchbar = document.getElementById("searchbar");
   gCustomizeMode.addToPanel(searchbar);
   let placement = CustomizableUI.getPlacementOfWidget("search-container");
   is(placement.area, CustomizableUI.AREA_FIXED_OVERFLOW_PANEL, "Should be in panel");
 
   await waitForOverflowButtonShown();
 
   let shownPanelPromise = popupShown(overflowPanel);
@@ -162,17 +167,17 @@ add_task(async function searchbar_contex
   gCustomizeMode.addToToolbar(searchbar);
   placement = CustomizableUI.getPlacementOfWidget("search-container");
   is(placement.area, CustomizableUI.AREA_NAVBAR, "Should be in navbar");
   gCustomizeMode.removeFromArea(searchbar);
   placement = CustomizableUI.getPlacementOfWidget("search-container");
   is(placement, null, "Should be in palette");
   CustomizableUI.reset();
   placement = CustomizableUI.getPlacementOfWidget("search-container");
-  is(placement.area, CustomizableUI.AREA_NAVBAR, "Should be in navbar");
+  is(placement, null, "Should be in palette");
 });
 
 // Right-click on an item within the panel should
 // show a context menu with options to move it.
 add_task(async function context_within_panel() {
   CustomizableUI.addWidgetToArea("new-window-button", CustomizableUI.AREA_FIXED_OVERFLOW_PANEL);
 
   await waitForOverflowButtonShown();
--- a/browser/components/customizableui/test/browser_editcontrols_update.js
+++ b/browser/components/customizableui/test/browser_editcontrols_update.js
@@ -123,17 +123,17 @@ add_task(async function test_panelui_cus
   let originalWidth = window.outerWidth;
   registerCleanupFunction(async function() {
     kOverflowPanel.removeAttribute("animate");
     window.resizeTo(originalWidth, window.outerHeight);
     await waitForCondition(() => !navbar.hasAttribute("overflowing"));
     CustomizableUI.reset();
   });
 
-  window.resizeTo(400, window.outerHeight);
+  window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
   await waitForCondition(() => navbar.hasAttribute("overflowing"));
 
   // Mac will update the enabled state even when the buttons are overflowing,
   // so main menubar shortcuts will work properly.
   overridePromise = expectCommandUpdate(isMac ? 1 : 0);
   gURLBar.select();
   await overridePromise;
   checkState(true, "Update when edit-controls is on overflow panel, hidden and selection changed");
--- a/browser/components/customizableui/test/browser_overflow_use_subviews.js
+++ b/browser/components/customizableui/test/browser_overflow_use_subviews.js
@@ -18,17 +18,17 @@ registerCleanupFunction(async function()
 add_task(async function check_developer_subview_in_overflow() {
   kOverflowPanel.setAttribute("animate", "false");
   gOriginalWidth = window.outerWidth;
 
   CustomizableUI.addWidgetToArea("developer-button", CustomizableUI.AREA_NAVBAR);
 
   let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
   ok(!navbar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar.");
-  window.resizeTo(400, window.outerHeight);
+  window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
 
   await waitForCondition(() => navbar.hasAttribute("overflowing"));
 
   let chevron = document.getElementById("nav-bar-overflow-button");
   let shownPanelPromise = promisePanelElementShown(window, kOverflowPanel);
   chevron.click();
   await shownPanelPromise;
 
--- a/browser/components/customizableui/test/head.js
+++ b/browser/components/customizableui/test/head.js
@@ -22,16 +22,18 @@ registerCleanupFunction(() => Services.p
 CustomizableUI.destroyWidget("e10s-button");
 CustomizableUI.removeWidgetFromArea("e10s-button");
 
 var {synthesizeDragStart, synthesizeDrop} = EventUtils;
 
 const kNSXUL = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 const kTabEventFailureTimeoutInMs = 20000;
 
+const kForceOverflowWidthPx = 300;
+
 function createDummyXULButton(id, label, win = window) {
   let btn = document.createElementNS(kNSXUL, "toolbarbutton");
   btn.id = id;
   btn.setAttribute("label", label || id);
   btn.className = "toolbarbutton-1 chromeclass-toolbar-additional";
   win.gNavToolbox.palette.appendChild(btn);
   return btn;
 }
--- a/browser/components/downloads/test/browser/browser_overflow_anchor.js
+++ b/browser/components/downloads/test/browser/browser_overflow_anchor.js
@@ -1,11 +1,14 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
+// This is the same value used by CustomizableUI tests.
+const kForceOverflowWidthPx = 200;
+
 registerCleanupFunction(async function() {
   // Clean up when the test finishes.
   await task_resetState();
 });
 
 /**
  * Make sure the downloads button and indicator overflows into the nav-bar
  * chevron properly, and then when those buttons are clicked in the overflow
@@ -19,26 +22,24 @@ add_task(async function test_overflow_an
   // this test finishes.
   let oldWidth = window.outerWidth;
 
   // The downloads button should not be overflowed to begin with.
   let button = CustomizableUI.getWidget("downloads-button")
                              .forWindow(window);
   ok(!button.overflowed, "Downloads button should not be overflowed.");
 
-  // Hack - we lock the size of the default flex-y items in the nav-bar,
-  // namely, the URL and search inputs. That way we can resize the
-  // window without worrying about them flexing.
-  const kFlexyItems = ["urlbar-container", "search-container"];
+  // Hack - we lock the size of the default flex-y items in the nav-bar, namely,
+  // the URL input. That way we can resize the window without worrying about it
+  // flexing.
+  const kFlexyItems = ["urlbar-container"];
   registerCleanupFunction(() => unlockWidth(kFlexyItems));
   lockWidth(kFlexyItems);
 
-  // Resize the window to half of its original size. That should
-  // be enough to overflow the downloads button.
-  window.resizeTo(oldWidth / 2, window.outerHeight);
+  window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
   await waitForOverflowed(button, true);
 
   let promise = promisePanelOpened();
   button.node.doCommand();
   await promise;
 
   let panel = DownloadsPanel.panel;
   let chevron = document.getElementById("nav-bar-overflow-button");
--- a/browser/components/search/test/browser_426329.js
+++ b/browser/components/search/test/browser_426329.js
@@ -126,16 +126,22 @@ async function prepareTest() {
     return;
 
   let focusPromise = BrowserTestUtils.waitForEvent(searchBar, "focus");
   gURLBar.focus();
   searchBar.focus();
   await focusPromise;
 }
 
+add_task(async function testSetup() {
+  await SpecialPowers.pushPrefEnv({ set: [
+    ["browser.search.widget.inNavBar", true],
+  ]});
+});
+
 add_task(async function testSetupEngine() {
   await promiseSetEngine();
 });
 
 add_task(async function testReturn() {
   await prepareTest();
   EventUtils.synthesizeKey("VK_RETURN", {});
   await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
--- a/browser/components/search/test/browser_google_behavior.js
+++ b/browser/components/search/test/browser_google_behavior.js
@@ -118,23 +118,25 @@ async function testSearchEngine(engineDe
         gURLBar.focus();
         EventUtils.synthesizeKey("VK_RETURN", {});
       }
     },
     {
       name: "search bar search",
       searchURL: base + engineDetails.codes.submission,
       run() {
+        Services.prefs.setBoolPref("browser.search.widget.inNavBar", true);
         let sb = BrowserSearch.searchBar;
         sb.focus();
         sb.value = "foo";
-        registerCleanupFunction(function() {
-          sb.value = "";
-        });
         EventUtils.synthesizeKey("VK_RETURN", {});
+      },
+      postTest() {
+        BrowserSearch.searchBar.value = "";
+        Services.prefs.setBoolPref("browser.search.widget.inNavBar", false);
       }
     },
     {
       name: "new tab search",
       searchURL: base + engineDetails.codes.newTab,
       async preTest(tab) {
         let browser = tab.linkedBrowser
         await BrowserTestUtils.loadURI(browser, "about:newtab");
@@ -164,13 +166,17 @@ async function testSearchEngine(engineDe
 
     let stateChangePromise = promiseStateChangeURI();
 
     await test.run(tab);
 
     let receivedURI = await stateChangePromise;
 
     Assert.equal(receivedURI, test.searchURL);
+
+    if (test.postTest) {
+      await test.postTest(tab);
+    }
   }
 
   engine.alias = undefined;
   await BrowserTestUtils.removeTab(tab);
 }
--- a/browser/components/search/test/browser_google_codes.js
+++ b/browser/components/search/test/browser_google_codes.js
@@ -115,16 +115,22 @@ add_task(async function preparation() {
     waitForSearchNotification("write-cache-to-disk-complete", resolve);
   });
 });
 
 add_task(async function tests() {
   let engine = Services.search.getEngineByName("Google");
   ok(engine, "Google");
 
+  // Show the search bar after initializing the search service, to avoid the
+  // synchronous initialization to interfere.
+  await SpecialPowers.pushPrefEnv({ set: [
+    ["browser.search.widget.inNavBar", true],
+  ]});
+
   let base = "https://www.google.com/search?q=foo&ie=utf-8&oe=utf-8&client=firefox-b";
 
   // Keyword uses a slightly different code
   let keywordBase = base + "-ab";
 
   let url;
 
   // Test search URLs (including purposes).
--- a/browser/components/search/test/browser_google_nocodes.js
+++ b/browser/components/search/test/browser_google_nocodes.js
@@ -115,16 +115,22 @@ add_task(async function preparation() {
     waitForSearchNotification("write-cache-to-disk-complete", resolve);
   });
 });
 
 add_task(async function tests() {
   let engine = Services.search.getEngineByName("Google");
   ok(engine, "Google");
 
+  // Show the search bar after initializing the search service, to avoid the
+  // synchronous initialization to interfere.
+  await SpecialPowers.pushPrefEnv({ set: [
+    ["browser.search.widget.inNavBar", true],
+  ]});
+
   let base = "https://www.google.com/search?q=foo&ie=utf-8&oe=utf-8";
 
   let url;
 
   // Test search URLs (including purposes).
   url = engine.getSubmission("foo", null, "contextmenu").uri.spec;
   is(url, base, "Check context menu search URL for 'foo'");
   url = engine.getSubmission("foo", null, "keyword").uri.spec;
--- a/browser/components/search/test/browser_healthreport.js
+++ b/browser/components/search/test/browser_healthreport.js
@@ -4,17 +4,19 @@
 "use strict";
 
 var Preferences = Cu.import("resource://gre/modules/Preferences.jsm", {}).Preferences;
 
 function test() {
   waitForExplicitFinish();
   resetPreferences();
 
+  let calledTestTelemetry = false;
   function testTelemetry() {
+    calledTestTelemetry = true;
     // Find the right bucket for the "Foo" engine.
     let engine = Services.search.getEngineByName("Foo");
     let histogramKey = (engine.identifier || "other-Foo") + ".searchbar";
     let numSearchesBefore = 0;
     try {
       let hs = Services.telemetry.getKeyedHistogramById("SEARCH_COUNTS").snapshot();
       if (histogramKey in hs) {
         numSearchesBefore = hs[histogramKey].sum;
@@ -53,29 +55,35 @@ function test() {
     switch (data) {
       case "engine-added":
         let engine = Services.search.getEngineByName("Foo");
         ok(engine, "Engine was added.");
         Services.search.currentEngine = engine;
         break;
 
       case "engine-current":
-        is(Services.search.currentEngine.name, "Foo", "Current engine is Foo");
-        testTelemetry();
+        // We may be called again when resetting the engine at the end.
+        if (!calledTestTelemetry) {
+          is(Services.search.currentEngine.name, "Foo", "Current engine is Foo");
+          testTelemetry();
+        }
         break;
 
       case "engine-removed":
         Services.obs.removeObserver(observer, "browser-search-engine-modified");
         finish();
         break;
     }
   }
 
   Services.obs.addObserver(observer, "browser-search-engine-modified");
-  SpecialPowers.pushPrefEnv({set: [["toolkit.telemetry.enabled", true]]}).then(function() {
+  SpecialPowers.pushPrefEnv({set: [
+    ["toolkit.telemetry.enabled", true],
+    ["browser.search.widget.inNavBar", true],
+  ]}).then(function() {
     Services.search.addEngine("http://mochi.test:8888/browser/browser/components/search/test/testEngine.xml",
                               null, "data:image/x-icon,%00", false);
   });
 }
 
 function resetPreferences() {
   Preferences.resetBranch("datareporting.policy.");
   Preferences.set("datareporting.policy.dataSubmissionPolicyBypassNotification", true);
--- a/browser/components/search/test/browser_hiddenOneOffs_diacritics.js
+++ b/browser/components/search/test/browser_hiddenOneOffs_diacritics.js
@@ -1,25 +1,33 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 // Tests that keyboard navigation in the search panel works as designed.
 
-const searchbar = document.getElementById("searchbar");
-const textbox = searchbar._textbox;
 const searchPopup = document.getElementById("PopupSearchAutoComplete");
-const searchIcon = document.getAnonymousElementByAttribute(searchbar, "anonid",
-                                                           "searchbar-search-button");
 
 const diacritic_engine = "Foo \u2661";
 
 var Preferences =
   Cu.import("resource://gre/modules/Preferences.jsm", {}).Preferences;
 
+let searchbar;
+let searchIcon;
+
 add_task(async function init() {
+  await SpecialPowers.pushPrefEnv({ set: [
+    ["browser.search.widget.inNavBar", true],
+  ]});
+
+  searchbar = document.getElementById("searchbar");
+  searchIcon = document.getAnonymousElementByAttribute(
+    searchbar, "anonid", "searchbar-search-button"
+  );
+
   let currentEngine = Services.search.currentEngine;
   await promiseNewEngine("testEngine_diacritics.xml", {setAsCurrent: false});
   registerCleanupFunction(() => {
     Services.search.currentEngine = currentEngine;
     Services.prefs.clearUserPref("browser.search.hiddenOneOffs");
   });
 });
 
--- a/browser/components/search/test/browser_oneOffContextMenu.js
+++ b/browser/components/search/test/browser_oneOffContextMenu.js
@@ -1,32 +1,40 @@
 "use strict";
 
 const TEST_ENGINE_NAME = "Foo";
 const TEST_ENGINE_BASENAME = "testEngine.xml";
 
-const searchbar = document.getElementById("searchbar");
 const searchPopup = document.getElementById("PopupSearchAutoComplete");
-const searchIcon = document.getAnonymousElementByAttribute(
-  searchbar, "anonid", "searchbar-search-button"
-);
 const oneOffBinding = document.getAnonymousElementByAttribute(
   searchPopup, "anonid", "search-one-off-buttons"
 );
 const contextMenu = document.getAnonymousElementByAttribute(
   oneOffBinding, "anonid", "search-one-offs-context-menu"
 );
 const oneOffButtons = document.getAnonymousElementByAttribute(
   oneOffBinding, "anonid", "search-panel-one-offs"
 );
 const searchInNewTabMenuItem = document.getAnonymousElementByAttribute(
   oneOffBinding, "anonid", "search-one-offs-context-open-in-new-tab"
 );
 
+let searchbar;
+let searchIcon;
+
 add_task(async function init() {
+  await SpecialPowers.pushPrefEnv({ set: [
+    ["browser.search.widget.inNavBar", true],
+  ]});
+
+  searchbar = document.getElementById("searchbar");
+  searchIcon = document.getAnonymousElementByAttribute(
+    searchbar, "anonid", "searchbar-search-button"
+  );
+
   await promiseNewEngine(TEST_ENGINE_BASENAME, {
     setAsCurrent: false,
   });
 });
 
 add_task(async function extendedTelemetryDisabled() {
   await SpecialPowers.pushPrefEnv({set: [["toolkit.telemetry.enabled", false]]});
   await doTest();
--- a/browser/components/search/test/browser_oneOffContextMenu_setDefault.js
+++ b/browser/components/search/test/browser_oneOffContextMenu_setDefault.js
@@ -1,39 +1,47 @@
 "use strict";
 
 const TEST_ENGINE_NAME = "Foo";
 const TEST_ENGINE_BASENAME = "testEngine.xml";
 const SEARCHBAR_BASE_ID = "searchbar-engine-one-off-item-";
 const URLBAR_BASE_ID = "urlbar-engine-one-off-item-";
 const ONEOFF_URLBAR_PREF = "browser.urlbar.oneOffSearches";
 
-const searchbar = document.getElementById("searchbar");
 const urlbar = document.getElementById("urlbar");
 const searchPopup = document.getElementById("PopupSearchAutoComplete");
 const urlbarPopup = document.getElementById("PopupAutoCompleteRichResult");
-const searchIcon = document.getAnonymousElementByAttribute(
-  searchbar, "anonid", "searchbar-search-button"
-);
 const searchOneOffBinding = document.getAnonymousElementByAttribute(
   searchPopup, "anonid", "search-one-off-buttons"
 );
 const urlBarOneOffBinding = document.getAnonymousElementByAttribute(
   urlbarPopup, "anonid", "one-off-search-buttons"
 );
 
 let originalEngine = Services.search.currentEngine;
 
 function resetEngine() {
   Services.search.currentEngine = originalEngine;
 }
 
 registerCleanupFunction(resetEngine);
 
+let searchbar;
+let searchIcon;
+
 add_task(async function init() {
+  await SpecialPowers.pushPrefEnv({ set: [
+    ["browser.search.widget.inNavBar", true],
+  ]});
+
+  searchbar = document.getElementById("searchbar");
+  searchIcon = document.getAnonymousElementByAttribute(
+    searchbar, "anonid", "searchbar-search-button"
+  );
+
   await promiseNewEngine(TEST_ENGINE_BASENAME, {
     setAsCurrent: false,
   });
 });
 
 add_task(async function test_searchBarChangeEngine() {
   let oneOffButton = await openPopupAndGetEngineButton(true, searchPopup,
                                                        searchOneOffBinding,
--- a/browser/components/search/test/browser_oneOffHeader.js
+++ b/browser/components/search/test/browser_oneOffHeader.js
@@ -1,20 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 // Tests that keyboard navigation in the search panel works as designed.
 
 const isMac = ("nsILocalFileMac" in Ci);
 
-const searchbar = document.getElementById("searchbar");
-const textbox = searchbar._textbox;
 const searchPopup = document.getElementById("PopupSearchAutoComplete");
-const searchIcon = document.getAnonymousElementByAttribute(searchbar, "anonid",
-                                                           "searchbar-search-button");
 
 const oneOffsContainer =
   document.getAnonymousElementByAttribute(searchPopup, "anonid",
                                           "search-one-off-buttons");
 const searchSettings =
   document.getAnonymousElementByAttribute(oneOffsContainer, "anonid",
                                           "search-settings");
 var header =
@@ -50,18 +46,29 @@ function synthesizeNativeMouseMove(aElem
     }
 
     aElement.addEventListener("mouseover", eventOccurred, true);
 
     utils.sendNativeMouseEvent(x * scale, y * scale, msg, 0, null);
   });
 }
 
+let searchbar;
+let searchIcon;
 
 add_task(async function init() {
+  await SpecialPowers.pushPrefEnv({ set: [
+    ["browser.search.widget.inNavBar", true],
+  ]});
+
+  searchbar = document.getElementById("searchbar");
+  searchIcon = document.getAnonymousElementByAttribute(
+    searchbar, "anonid", "searchbar-search-button"
+  );
+
   await promiseNewEngine("testEngine.xml");
 });
 
 add_task(async function test_notext() {
   let promise = promiseEvent(searchPopup, "popupshown");
   info("Opening search panel");
   EventUtils.synthesizeMouseAtCenter(searchIcon, {});
   await promise;
@@ -87,19 +94,19 @@ add_task(async function test_notext() {
 
   promise = promiseEvent(searchPopup, "popuphidden");
   info("Closing search panel");
   EventUtils.synthesizeKey("VK_ESCAPE", {});
   await promise;
 });
 
 add_task(async function test_text() {
-  textbox.value = "foo";
+  searchbar._textbox.value = "foo";
   registerCleanupFunction(() => {
-    textbox.value = "";
+    searchbar._textbox.value = "";
   });
 
   let promise = promiseEvent(searchPopup, "popupshown");
   info("Opening search panel");
   SimpleTest.executeSoon(() => {
     EventUtils.synthesizeMouseAtCenter(searchIcon, {});
   });
   await promise;
@@ -128,14 +135,15 @@ add_task(async function test_text() {
     document.getAnonymousElementByAttribute(searchPopup, "anonid",
                                             "searchbar-engine");
 
   await synthesizeNativeMouseMove(searchbarEngine);
   SimpleTest.executeSoon(() => {
     EventUtils.synthesizeMouseAtCenter(searchbarEngine, {});
   });
 
-  let url = Services.search.currentEngine.getSubmission(textbox.value).uri.spec;
+  let url = Services.search.currentEngine
+                           .getSubmission(searchbar._textbox.value).uri.spec;
   await promiseTabLoadEvent(gBrowser.selectedTab, url);
 
   // Move the cursor out of the panel area to avoid messing with other tests.
   await synthesizeNativeMouseMove(searchbar);
 });
--- a/browser/components/search/test/browser_private_search_perwindowpb.js
+++ b/browser/components/search/test/browser_private_search_perwindowpb.js
@@ -1,16 +1,16 @@
 // This test performs a search in a public window, then a different
 // search in a private window, and then checks in the public window
 // whether there is an autocomplete entry for the private search.
 
 add_task(async function() {
-  // Don't use about:home as the homepage for new windows
-  Services.prefs.setIntPref("browser.startup.page", 0);
-  registerCleanupFunction(() => Services.prefs.clearUserPref("browser.startup.page"));
+  await SpecialPowers.pushPrefEnv({ set: [
+    ["browser.search.widget.inNavBar", true],
+  ]});
 
   let windowsToClose = [];
 
   function performSearch(aWin, aIsPrivate) {
     let searchBar = aWin.BrowserSearch.searchBar;
     ok(searchBar, "got search bar");
 
     let loadPromise = BrowserTestUtils.browserLoaded(aWin.gBrowser.selectedBrowser);
--- a/browser/components/search/test/browser_searchEngine_behaviors.js
+++ b/browser/components/search/test/browser_searchEngine_behaviors.js
@@ -101,16 +101,22 @@ function promiseContentSearchReady(brows
           content.removeEventListener("ContentSearchService", listener);
           resolve();
         }
       });
     });
   });
 }
 
+add_task(async function() {
+  await SpecialPowers.pushPrefEnv({ set: [
+    ["browser.search.widget.inNavBar", true],
+  ]});
+});
+
 for (let engine of SEARCH_ENGINE_DETAILS) {
   add_task(async function() {
     let previouslySelectedEngine = Services.search.currentEngine;
 
     registerCleanupFunction(function() {
       Services.search.currentEngine = previouslySelectedEngine;
     });
 
--- a/browser/components/search/test/browser_searchbar_keyboard_navigation.js
+++ b/browser/components/search/test/browser_searchbar_keyboard_navigation.js
@@ -1,12 +1,10 @@
 // Tests that keyboard navigation in the search panel works as designed.
 
-const searchbar = document.getElementById("searchbar");
-const textbox = searchbar._textbox;
 const searchPopup = document.getElementById("PopupSearchAutoComplete");
 const oneOffsContainer =
   document.getAnonymousElementByAttribute(searchPopup, "anonid",
                                           "search-one-off-buttons");
 
 const kValues = ["foo1", "foo2", "foo3"];
 const kUserValue = "foo";
 
@@ -17,17 +15,27 @@ function getOpenSearchItems() {
     document.getAnonymousElementByAttribute(oneOffsContainer, "anonid",
                                             "add-engines");
   for (let item = addEngineList.firstChild; item; item = item.nextSibling)
     os.push(item);
 
   return os;
 }
 
+let searchbar;
+let textbox;
+
 add_task(async function init() {
+  await SpecialPowers.pushPrefEnv({ set: [
+    ["browser.search.widget.inNavBar", true],
+  ]});
+
+  searchbar = document.getElementById("searchbar");
+  textbox = searchbar._textbox;
+
   await promiseNewEngine("testEngine.xml");
 
   // First cleanup the form history in case other tests left things there.
   await new Promise((resolve, reject) => {
     info("cleanup the search history");
     searchbar.FormHistory.update({op: "remove", fieldname: "searchbar-history"},
                                  {handleCompletion: resolve,
                                   handleError: reject});
--- a/browser/components/search/test/browser_searchbar_openpopup.js
+++ b/browser/components/search/test/browser_searchbar_openpopup.js
@@ -3,20 +3,16 @@
 
 // Instead of loading EventUtils.js into the test scope in browser-test.js for all tests,
 // we only need EventUtils.js for a few files which is why we are using loadSubScript.
 var EventUtils = {};
 this._scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
                      getService(Ci.mozIJSSubScriptLoader);
 this._scriptLoader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/EventUtils.js", EventUtils);
 
-const searchbar = document.getElementById("searchbar");
-const searchIcon = document.getAnonymousElementByAttribute(searchbar, "anonid", "searchbar-search-button");
-const goButton = document.getAnonymousElementByAttribute(searchbar, "anonid", "search-go-button");
-const textbox = searchbar._textbox;
 const searchPopup = document.getElementById("PopupSearchAutoComplete");
 const kValues = ["long text", "long text 2", "long text 3"];
 
 const isWindows = Services.appinfo.OS == "WINNT";
 const mouseDown = isWindows ? 2 : 1;
 const mouseUp = isWindows ? 4 : 2;
 const utils = window.QueryInterface(Ci.nsIInterfaceRequestor)
                     .getInterface(Ci.nsIDOMWindowUtils);
@@ -57,17 +53,35 @@ async function startCustomizing(aWindow 
     return true;
   }
   await SpecialPowers.pushPrefEnv({set: [["browser.uiCustomization.disableAnimation", true]]});
   let eventPromise = BrowserTestUtils.waitForEvent(aWindow.gNavToolbox, "customizationready");
   aWindow.gCustomizeMode.enter();
   return eventPromise;
 }
 
+let searchbar;
+let textbox;
+let searchIcon;
+let goButton;
+
 add_task(async function init() {
+  await SpecialPowers.pushPrefEnv({ set: [
+    ["browser.search.widget.inNavBar", true],
+  ]});
+
+  searchbar = document.getElementById("searchbar");
+  textbox = searchbar._textbox;
+  searchIcon = document.getAnonymousElementByAttribute(
+    searchbar, "anonid", "searchbar-search-button"
+  );
+  goButton = document.getAnonymousElementByAttribute(
+    searchbar, "anonid", "search-go-button"
+  );
+
   await promiseNewEngine("testEngine.xml");
 
   // First cleanup the form history in case other tests left things there.
   await new Promise((resolve, reject) => {
     info("cleanup the search history");
     searchbar.FormHistory.update({op: "remove", fieldname: "searchbar-history"},
                                  {handleCompletion: resolve,
                                   handleError: reject});
--- a/browser/components/search/test/browser_searchbar_smallpanel_keyboard_navigation.js
+++ b/browser/components/search/test/browser_searchbar_smallpanel_keyboard_navigation.js
@@ -1,34 +1,44 @@
 // Tests that keyboard navigation in the search panel works as designed.
 
-const searchbar = document.getElementById("searchbar");
-const textbox = searchbar._textbox;
 const searchPopup = document.getElementById("PopupSearchAutoComplete");
 const oneOffsContainer =
   document.getAnonymousElementByAttribute(searchPopup, "anonid",
                                           "search-one-off-buttons");
-const searchIcon = document.getAnonymousElementByAttribute(searchbar, "anonid",
-                                                           "searchbar-search-button");
 
 const kValues = ["foo1", "foo2", "foo3"];
 
 function getOpenSearchItems() {
   let os = [];
 
   let addEngineList =
     document.getAnonymousElementByAttribute(oneOffsContainer, "anonid",
                                             "add-engines");
   for (let item = addEngineList.firstChild; item; item = item.nextSibling)
     os.push(item);
 
   return os;
 }
 
+let searchbar;
+let textbox;
+let searchIcon;
+
 add_task(async function init() {
+  await SpecialPowers.pushPrefEnv({ set: [
+    ["browser.search.widget.inNavBar", true],
+  ]});
+
+  searchbar = document.getElementById("searchbar");
+  textbox = searchbar._textbox;
+  searchIcon = document.getAnonymousElementByAttribute(
+    searchbar, "anonid", "searchbar-search-button"
+  );
+
   await promiseNewEngine("testEngine.xml");
 
   // First cleanup the form history in case other tests left things there.
   await new Promise((resolve, reject) => {
     info("cleanup the search history");
     searchbar.FormHistory.update({op: "remove", fieldname: "searchbar-history"},
                                  {handleCompletion: resolve,
                                   handleError: reject});
--- a/browser/components/search/test/browser_tooManyEnginesOffered.js
+++ b/browser/components/search/test/browser_tooManyEnginesOffered.js
@@ -1,21 +1,26 @@
 "use strict";
 
 // This test makes sure that when a page offers many search engines, the search
 // popup shows a submenu that lists them instead of showing them in the popup
 // itself.
 
-const searchbar = document.getElementById("searchbar");
 const searchPopup = document.getElementById("PopupSearchAutoComplete");
 const oneOffsContainer =
   document.getAnonymousElementByAttribute(searchPopup, "anonid",
                                           "search-one-off-buttons");
 
 add_task(async function test() {
+  await SpecialPowers.pushPrefEnv({ set: [
+    ["browser.search.widget.inNavBar", true],
+  ]});
+
+  let searchbar = document.getElementById("searchbar");
+
   let rootDir = getRootDirectory(gTestPath);
   let url = rootDir + "tooManyEnginesOffered.html";
   await BrowserTestUtils.openNewForegroundTab(gBrowser, url);
 
   // Open the search popup.
   let promise = promiseEvent(searchPopup, "popupshown");
   info("Opening search panel");
   searchbar.focus();
--- a/browser/components/search/test/browser_yahoo.js
+++ b/browser/components/search/test/browser_yahoo.js
@@ -4,17 +4,21 @@
 /*
  * Test Yahoo search plugin URLs
  */
 
 "use strict";
 
 const BROWSER_SEARCH_PREF = "browser.search.";
 
-function test() {
+add_task(async function test() {
+  await SpecialPowers.pushPrefEnv({ set: [
+    ["browser.search.widget.inNavBar", true],
+  ]});
+
   let engine = Services.search.getEngineByName("Yahoo");
   ok(engine, "Yahoo");
 
   let base = "https://search.yahoo.com/yhs/search?p=foo&ei=UTF-8&hspart=mozilla";
   let url;
 
   // Test search URLs (including purposes).
   url = engine.getSubmission("foo").uri.spec;
@@ -124,9 +128,9 @@ function test() {
           ],
           mozparams: {},
         },
       ],
     },
   };
 
   isSubObjectOf(EXPECTED_ENGINE, engine, "Yahoo");
-}
+});
--- a/browser/components/uitour/test/browser_UITour.js
+++ b/browser/components/uitour/test/browser_UITour.js
@@ -268,21 +268,28 @@ var tests = [
     await showInfoPromise("urlbar", "urlbar title", "urlbar text");
 
     is(popup.popupBoxObject.anchorNode, document.getElementById("urlbar"), "Popup should be anchored to the urlbar");
     is(title.textContent, "urlbar title", "Popup should have correct title");
     is(desc.textContent, "urlbar text", "Popup should have correct description text");
     is(icon.src, "", "Popup should have no icon");
     is(buttons.hasChildNodes(), false, "Popup should have no buttons");
 
+    // Place the search bar in the navigation toolbar temporarily.
+    await SpecialPowers.pushPrefEnv({ set: [
+      ["browser.search.widget.inNavBar", true],
+    ]});
+
     await showInfoPromise("search", "search title", "search text");
 
     is(popup.popupBoxObject.anchorNode, document.getElementById("searchbar"), "Popup should be anchored to the searchbar");
     is(title.textContent, "search title", "Popup should have correct title");
     is(desc.textContent, "search text", "Popup should have correct description text");
+
+    await SpecialPowers.popPrefEnv();
   }),
   function test_getConfigurationVersion(done) {
     function callback(result) {
       let props = ["defaultUpdateChannel", "version"];
       for (let property of props) {
         ok(typeof(result[property]) !== "undefined", "Check " + property + " isn't undefined.");
         is(result[property], Services.appinfo[property], "Should have the same " + property + " property.");
       }
--- a/browser/components/uitour/test/browser_UITour3.js
+++ b/browser/components/uitour/test/browser_UITour3.js
@@ -157,25 +157,39 @@ add_UITour_task(async function test_getC
       let data = await getConfigurationPromise("selectedSearchEngine");
       is(data.searchEngineIdentifier, engine.identifier, "Correct engine identifier");
       resolve();
     });
   });
 });
 
 add_UITour_task(async function test_setSearchTerm() {
+  // Place the search bar in the navigation toolbar temporarily.
+  await SpecialPowers.pushPrefEnv({ set: [
+    ["browser.search.widget.inNavBar", true],
+  ]});
+
   const TERM = "UITour Search Term";
   await gContentAPI.setSearchTerm(TERM);
 
   let searchbar = document.getElementById("searchbar");
   // The UITour gets to the searchbar element through a promise, so the value setting
   // only happens after a tick.
   await waitForConditionPromise(() => searchbar.value == TERM, "Correct term set");
+
+  await SpecialPowers.popPrefEnv();
 });
 
 add_UITour_task(async function test_clearSearchTerm() {
+  // Place the search bar in the navigation toolbar temporarily.
+  await SpecialPowers.pushPrefEnv({ set: [
+    ["browser.search.widget.inNavBar", true],
+  ]});
+
   await gContentAPI.setSearchTerm("");
 
   let searchbar = document.getElementById("searchbar");
   // The UITour gets to the searchbar element through a promise, so the value setting
   // only happens after a tick.
   await waitForConditionPromise(() => searchbar.value == "", "Search term cleared");
+
+  await SpecialPowers.popPrefEnv();
 });
--- a/browser/components/uitour/test/browser_UITour_availableTargets.js
+++ b/browser/components/uitour/test/browser_UITour_availableTargets.js
@@ -24,18 +24,16 @@ function getExpectedTargets() {
     "pageAction-bookmark",
     "pageAction-copyURL",
     "pageAction-emailLink",
     "pageAction-sendToDevice",
       ...(hasPocket ? ["pocket"] : []),
     "privateWindow",
       ...(hasQuit ? ["quit"] : []),
     "readerMode-urlBar",
-    "search",
-    "searchIcon",
     "trackingProtection",
     "urlbar",
   ];
 }
 
 add_task(setup_UITourTest);
 
 add_UITour_task(async function test_availableTargets() {
@@ -57,27 +55,26 @@ add_UITour_task(async function test_avai
 
   ok(UITour.availableTargetsCache.has(window),
      "Targets should now be cached again");
   CustomizableUI.reset();
   ok(!UITour.availableTargetsCache.has(window),
      "Targets should not be cached after reset");
 });
 
-add_UITour_task(async function test_availableTargets_exceptionFromGetTarget() {
-  // The query function for the "search" target will throw if it's not found.
-  // Make sure the callback still fires with the other available targets.
-  CustomizableUI.removeWidgetFromArea("search-container");
-  let data = await getConfigurationPromise("availableTargets");
-  let expecteds = getExpectedTargets();
-  // Default minus "search" and "searchIcon"
-  expecteds = expecteds.filter(target => target != "search" && target != "searchIcon");
-  ok_targets(data, expecteds);
-
-  CustomizableUI.reset();
+add_UITour_task(async function test_availableTargets_search() {
+  Services.prefs.setBoolPref("browser.search.widget.inNavBar", true);
+  try {
+    let data = await getConfigurationPromise("availableTargets");
+    let expecteds = getExpectedTargets();
+    expecteds = ["search", "searchIcon", ...expecteds];
+    ok_targets(data, expecteds);
+  } finally {
+    Services.prefs.clearUserPref("browser.search.widget.inNavBar");
+  }
 });
 
 add_UITour_task(async function test_availableTargets_removeUrlbarPageActionsAll() {
   pageActionsHelper.setActionsUrlbarState(false);
   UITour.clearAvailableTargetsCache();
   let data = await getConfigurationPromise("availableTargets");
   let expecteds = getExpectedTargets();
   ok_targets(data, expecteds);
--- a/browser/components/uitour/test/browser_openSearchPanel.js
+++ b/browser/components/uitour/test/browser_openSearchPanel.js
@@ -8,25 +8,27 @@ var gContentAPI;
 var gContentWindow;
 
 function test() {
   UITourTest();
 }
 
 var tests = [
   function test_openSearchPanel(done) {
-    let searchbar = document.getElementById("searchbar");
-
-    // If suggestions are enabled, the panel will attempt to use the network to connect
-    // to the suggestions provider, causing the test suite to fail.
+    // If suggestions are enabled, the panel will attempt to use the network to
+    // connect to the suggestions provider, causing the test suite to fail. We
+    // also change the preference to display the search bar during the test.
+    Services.prefs.setBoolPref("browser.search.widget.inNavBar", true);
     Services.prefs.setBoolPref("browser.search.suggest.enabled", false);
     registerCleanupFunction(() => {
+      Services.prefs.clearUserPref("browser.search.widget.inNavBar");
       Services.prefs.clearUserPref("browser.search.suggest.enabled");
     });
 
+    let searchbar = document.getElementById("searchbar");
     ok(!searchbar.textbox.open, "Popup starts as closed");
     gContentAPI.openSearchPanel(() => {
       ok(searchbar.textbox.open, "Popup was opened");
       searchbar.textbox.closePopup();
       ok(!searchbar.textbox.open, "Popup was closed");
       done();
     });
   },
--- a/browser/modules/BrowserUITelemetry.jsm
+++ b/browser/modules/BrowserUITelemetry.jsm
@@ -50,17 +50,16 @@ const LEGACY_PANEL_PLACEMENTS = [
 XPCOMUtils.defineLazyGetter(this, "DEFAULT_AREA_PLACEMENTS", function() {
   let result = {
     "nav-bar": [
       "back-button",
       "forward-button",
       "stop-reload-button",
       "home-button",
       "urlbar-container",
-      "search-container",
       "downloads-button",
       "library-button",
       "sidebar-button",
     ],
     // It's true that toolbar-menubar is not visible
     // on OS X, but the XUL node is definitely present
     // in the document.
     "toolbar-menubar": [
@@ -83,16 +82,17 @@ XPCOMUtils.defineLazyGetter(this, "DEFAU
 
 XPCOMUtils.defineLazyGetter(this, "DEFAULT_AREAS", function() {
   return Object.keys(DEFAULT_AREA_PLACEMENTS);
 });
 
 XPCOMUtils.defineLazyGetter(this, "PALETTE_ITEMS", function() {
   let result = [
     "bookmarks-menu-button",
+    "search-container",
     "open-file-button",
     "developer-button",
     "feed-button",
     "email-link-button",
     "containers-panelmenu",
     ...LEGACY_PANEL_PLACEMENTS,
     "characterencoding-button",
   ];
--- a/browser/modules/test/browser/browser_UsageTelemetry_searchbar.js
+++ b/browser/modules/test/browser/browser_UsageTelemetry_searchbar.js
@@ -59,16 +59,20 @@ function clickSearchbarSuggestion(entryN
     // Simulate the click.
     EventUtils.synthesizeMouse(popup.tree.body, x, y, {},
                                popup.tree.ownerGlobal);
     break;
   }
 }
 
 add_task(async function setup() {
+  await SpecialPowers.pushPrefEnv({ set: [
+    ["browser.search.widget.inNavBar", true],
+  ]});
+
   // Create two new search engines. Mark one as the default engine, so
   // the test don't crash. We need to engines for this test as the searchbar
   // doesn't display the default search engine among the one-off engines.
   Services.search.addEngineWithDetails("MozSearch", "", "mozalias", "", "GET",
                                        "http://example.com/?q={searchTerms}");
 
   Services.search.addEngineWithDetails("MozSearch2", "", "mozalias2", "", "GET",
                                        "http://example.com/?q={searchTerms}");
--- a/layout/xul/test/browser_bug1163304.js
+++ b/layout/xul/test/browser_bug1163304.js
@@ -1,11 +1,12 @@
 function test() {
   waitForExplicitFinish();
 
+  Services.prefs.setBoolPref("browser.search.widget.inNavBar", true);
   let searchBar = BrowserSearch.searchBar;
   searchBar.focus();
 
   let DOMWindowUtils = EventUtils._getDOMWindowUtils();
   is(DOMWindowUtils.IMEStatus, DOMWindowUtils.IME_STATUS_ENABLED,
      "IME should be available when searchbar has focus");
 
   let searchPopup = document.getElementById("PopupSearchAutoComplete");
@@ -16,16 +17,17 @@ function test() {
       searchPopup.addEventListener("popuphidden", function (aEvent) {
         setTimeout(function () {
           is(DOMWindowUtils.IMEStatus, DOMWindowUtils.IME_STATUS_DISABLED,
              "IME should not be available when menubar is active");
           // Inactivate the menubar (and restore the focus to the searchbar
           EventUtils.synthesizeKey("VK_ESCAPE", {});
           is(DOMWindowUtils.IMEStatus, DOMWindowUtils.IME_STATUS_ENABLED,
              "IME should be available after focus is back to the searchbar");
+          Services.prefs.clearUserPref("browser.search.widget.inNavBar");
           finish();
         }, 0);
       }, {once: true});
       // Activate the menubar, then, the popup should be closed
       EventUtils.synthesizeKey("VK_ALT", {});
     }, 0);
   }, {once: true});
   // Open popup of the searchbar
--- a/toolkit/components/extensions/test/browser/browser_ext_themes_toolbar_fields.js
+++ b/toolkit/components/extensions/test/browser/browser_ext_themes_toolbar_fields.js
@@ -1,17 +1,18 @@
 "use strict";
 
 // This test checks whether applied WebExtension themes that attempt to change
 // the background color and the color of the navbar text fields are applied properly.
 
 add_task(async function setup() {
-  await SpecialPowers.pushPrefEnv({
-    set: [["extensions.webextensions.themes.enabled", true]],
-  });
+  await SpecialPowers.pushPrefEnv({set: [
+    ["extensions.webextensions.themes.enabled", true],
+    ["browser.search.widget.inNavBar", true],
+  ]});
 });
 
 add_task(async function test_support_toolbar_field_properties() {
   const TOOLBAR_FIELD_BACKGROUND = "#ff00ff";
   const TOOLBAR_FIELD_COLOR = "#00ff00";
   let extension = ExtensionTestUtils.loadExtension({
     manifest: {
       "theme": {