Bug 1353831 - OneOff block in search bar doesn't update text if Customize was opened at least once. r?florian draft
authorDrew Willcoxon <adw@mozilla.com>
Fri, 14 Apr 2017 16:34:41 -0700
changeset 563092 0a4e93fb9637a7d66dda59817aeb4ef28bb3a10c
parent 562868 1a1069b27f40edbfbcf1aa81a5e7dfb39845a5fe
child 624387 f6952ce76192f2e01aba295363cf6a441398f978
push id54203
push userdwillcoxon@mozilla.com
push dateFri, 14 Apr 2017 23:34:59 +0000
reviewersflorian
bugs1353831
milestone55.0a1
Bug 1353831 - OneOff block in search bar doesn't update text if Customize was opened at least once. r?florian MozReview-Commit-ID: Iu7xhCbCh6B
browser/components/search/content/search.xml
--- a/browser/components/search/content/search.xml
+++ b/browser/components/search/content/search.xml
@@ -67,18 +67,16 @@
         </xul:hbox>
       </xul:textbox>
     </content>
 
     <implementation implements="nsIObserver">
       <constructor><![CDATA[
         if (this.parentNode.parentNode.localName == "toolbarpaletteitem")
           return;
-        // Make sure we rebuild the popup in onpopupshowing
-        this._needToBuildPopup = true;
 
         Services.obs.addObserver(this, "browser-search-engine-modified", false);
 
         this._initialized = true;
 
         Services.search.init((function search_init_cb(aStatus) {
           // Bail out if the binding's been destroyed
           if (!this._initialized)
@@ -87,16 +85,24 @@
           if (Components.isSuccessCode(aStatus)) {
             // Refresh the display (updating icon, etc)
             this.updateDisplay();
             BrowserSearch.updateOpenSearchBadge();
           } else {
             Components.utils.reportError("Cannot initialize search service, bailing out: " + aStatus);
           }
         }).bind(this));
+
+        // Some accessibility tests create their own <searchbar> that doesn't
+        // use the popup binding below, so null-check oneOffButtons.
+        if (this.textbox.popup.oneOffButtons) {
+          this.textbox.popup.oneOffButtons.telemetryOrigin = "searchbar";
+          this.textbox.popup.oneOffButtons.popup = this.textbox.popup;
+          this.textbox.popup.oneOffButtons.textbox = this.textbox;
+        }
       ]]></constructor>
 
       <destructor><![CDATA[
         this.destroy();
       ]]></destructor>
 
       <method name="destroy">
         <body><![CDATA[
@@ -1061,36 +1067,31 @@
           let searchbar = document.getElementById("searchbar");
           searchbar.handleSearchCommandWhere(event, engine, where, params);
         ]]></body>
       </method>
     </implementation>
 
     <handlers>
       <handler event="popupshowing"><![CDATA[
-        if (!this.oneOffButtons.popup) {
+        if (!this._computedMinWidth) {
           // The panel width only spans to the textbox size, but we also want it
           // to include the magnifier icon's width.
           let ltr = getComputedStyle(this).direction == "ltr";
           let magnifierWidth = parseInt(getComputedStyle(this)[
                                  ltr ? "marginLeft" : "marginRight"
                                ]) * -1;
           // Ensure the panel is wide enough to fit at least 3 engines.
           let minWidth = Math.max(
             parseInt(this.width) + magnifierWidth,
             this.oneOffButtons.buttonWidth * 3
           );
           this.style.minWidth = minWidth + "px";
 
-          // Set the origin before assigning the popup, as the assignment does
-          // a rebuild and would miss the origin.
-          this.oneOffButtons.telemetryOrigin = "searchbar";
-          // Set popup after setting the minWidth since it builds the buttons.
-          this.oneOffButtons.popup = this;
-          this.oneOffButtons.textbox = this.input;
+          this._computedMinWidth = true;
         }
 
         // First handle deciding if we are showing the reduced version of the
         // popup containing only the preferences button. We do this if the
         // glass icon has been clicked if the text field is empty.
         let searchbar = document.getElementById("searchbar");
         let tree = document.getAnonymousElementByAttribute(this, "anonid",
                                                            "tree")