Bug 1359056 - Don't open the search panel when entering customization mode. r=Gijs, a=gchang
☠☠ backed out by 64096bfc5a89 ☠ ☠
authorPanos Astithas <past@mozilla.com>
Fri, 12 May 2017 21:40:54 -0400
changeset 396364 0511fcd323f3a43ffbdae0e41353b9af776cfc37
parent 396363 82fcc3b1242af487f8faa04da0f0abebf479755a
child 396365 1099d84ea9bd94c452b4bbba7b6cbcab6daf23c6
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs, gchang
bugs1359056
milestone54.0
Bug 1359056 - Don't open the search panel when entering customization mode. r=Gijs, a=gchang MozReview-Commit-ID: XmNZMrizET
browser/components/search/content/search.xml
browser/components/search/test/browser_searchbar_openpopup.js
--- a/browser/components/search/content/search.xml
+++ b/browser/components/search/content/search.xml
@@ -692,16 +692,23 @@
       <!--
         This method overrides the autocomplete binding's openPopup (essentially
         duplicating the logic from the autocomplete popup binding's
         openAutocompletePopup method), modifying it so that the popup is aligned with
         the inner textbox, but sized to not extend beyond the search bar border.
       -->
       <method name="openPopup">
         <body><![CDATA[
+          // Entering customization mode after the search bar had focus causes
+          // the popup to appear again, due to focus returning after the
+          // hamburger panel closes. Don't open in that spurious event.
+          if (document.documentElement.getAttribute("customizing") == "true") {
+            return;
+          }
+
           var popup = this.popup;
           if (!popup.mPopupOpen) {
             // Initially the panel used for the searchbar (PopupSearchAutoComplete
             // in browser.xul) is hidden to avoid impacting startup / new
             // window performance. The base binding's openPopup would normally
             // call the overriden openAutocompletePopup in
             // browser-search-autocomplete-result-popup binding to unhide the popup,
             // but since we're overriding openPopup we need to unhide the panel
--- a/browser/components/search/test/browser_searchbar_openpopup.js
+++ b/browser/components/search/test/browser_searchbar_openpopup.js
@@ -37,16 +37,36 @@ function* synthesizeNativeMouseClick(aEl
 
     aElement.addEventListener("mouseup", eventOccurred, true);
 
     utils.sendNativeMouseEvent(x * scale, y * scale, mouseDown, 0, null);
     utils.sendNativeMouseEvent(x * scale, y * scale, mouseUp, 0, null);
   });
 }
 
+function* endCustomizing(aWindow = window) {
+  if (aWindow.document.documentElement.getAttribute("customizing") != "true") {
+    return true;
+  }
+  yield SpecialPowers.pushPrefEnv({set: [["browser.uiCustomization.disableAnimation", true]]});
+  let eventPromise = BrowserTestUtils.waitForEvent(aWindow.gNavToolbox, "aftercustomization");
+  aWindow.gCustomizeMode.exit();
+  return eventPromise;
+}
+
+function* startCustomizing(aWindow = window) {
+  if (aWindow.document.documentElement.getAttribute("customizing") == "true") {
+    return true;
+  }
+  yield SpecialPowers.pushPrefEnv({set: [["browser.uiCustomization.disableAnimation", true]]});
+  let eventPromise = BrowserTestUtils.waitForEvent(aWindow.gNavToolbox, "customizationready");
+  aWindow.gCustomizeMode.enter();
+  return eventPromise;
+}
+
 add_task(function* init() {
   yield promiseNewEngine("testEngine.xml");
 
   // First cleanup the form history in case other tests left things there.
   yield new Promise((resolve, reject) => {
     info("cleanup the search history");
     searchbar.FormHistory.update({op: "remove", fieldname: "searchbar-history"},
                                  {handleCompletion: resolve,
@@ -515,8 +535,36 @@ add_task(function* dont_rollup_oncaretmo
 
   // Close the popup again
   promise = promiseEvent(searchPopup, "popuphidden");
   EventUtils.synthesizeKey("VK_ESCAPE", {});
   yield promise;
 
   textbox.value = "";
 });
+
+// Entering customization mode shouldn't open the popup.
+add_task(async function dont_open_in_customization() {
+  gURLBar.focus();
+  textbox.value = "foo";
+
+  let promise = promiseEvent(searchPopup, "popupshown");
+  EventUtils.synthesizeKey("VK_TAB", {});
+  await promise;
+  isnot(searchPopup.getAttribute("showonlysettings"), "true", "Should show the full popup");
+
+  info("Entering customization mode");
+  let sawPopup = false;
+  function listener() {
+    sawPopup = true;
+  }
+  searchPopup.addEventListener("popupshowing", listener);
+  await PanelUI.show();
+  promise =  promiseEvent(searchPopup, "popuphidden");
+  await startCustomizing();
+  await promise;
+
+  searchPopup.removeEventListener("popupshowing", listener);
+  ok(!sawPopup, "Shouldn't have seen the suggestions popup");
+
+  await endCustomizing();
+  textbox.value = "";
+});