Bug 1359056 - Don't open the search panel when entering customization mode. r=Gijs draft
authorPanos Astithas <past@mozilla.com>
Fri, 12 May 2017 21:40:54 -0400
changeset 579560 2bc5ea1a434305f8a627f325467265c730ad3760
parent 579463 6e3ca5b38f7173b214b10de49e58cb01890bf39d
child 629043 ed22bf817dce927f64c3b22a622af79a4de6a076
push id59292
push userbmo:past@mozilla.com
push dateWed, 17 May 2017 12:35:57 +0000
reviewersGijs
bugs1359056
milestone55.0a1
Bug 1359056 - Don't open the search panel when entering customization mode. r=Gijs 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
@@ -697,16 +697,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(aEle
 
     aElement.addEventListener("mouseup", eventOccurred, true);
 
     utils.sendNativeMouseEvent(x * scale, y * scale, mouseDown, 0, null);
     utils.sendNativeMouseEvent(x * scale, y * scale, mouseUp, 0, null);
   });
 }
 
+async function endCustomizing(aWindow = window) {
+  if (aWindow.document.documentElement.getAttribute("customizing") != "true") {
+    return true;
+  }
+  await SpecialPowers.pushPrefEnv({set: [["browser.uiCustomization.disableAnimation", true]]});
+  let eventPromise = BrowserTestUtils.waitForEvent(aWindow.gNavToolbox, "aftercustomization");
+  aWindow.gCustomizeMode.exit();
+  return eventPromise;
+}
+
+async function startCustomizing(aWindow = window) {
+  if (aWindow.document.documentElement.getAttribute("customizing") == "true") {
+    return true;
+  }
+  await SpecialPowers.pushPrefEnv({set: [["browser.uiCustomization.disableAnimation", true]]});
+  let eventPromise = BrowserTestUtils.waitForEvent(aWindow.gNavToolbox, "customizationready");
+  aWindow.gCustomizeMode.enter();
+  return eventPromise;
+}
+
 add_task(async function init() {
   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,
@@ -515,8 +535,36 @@ add_task(async function dont_rollup_onca
 
   // Close the popup again
   promise = promiseEvent(searchPopup, "popuphidden");
   EventUtils.synthesizeKey("VK_ESCAPE", {});
   await 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 = "";
+});