Bug 1416305 - Copying a search suggestion from the address bar gives back an http url. r=adw draft
authorMarco Bonardo <mbonardo@mozilla.com>
Tue, 16 Jan 2018 12:23:09 +0100
changeset 721536 2b88998435efee64957850ee6baeb400499c88ef
parent 720380 b7d66e4e60ef177ec9ae687daa29443ae4a2acfc
child 746354 7bf586debe85311e2c8a5d202bfb3e252db3fa87
push id95858
push usermak77@bonardo.net
push dateWed, 17 Jan 2018 11:05:45 +0000
reviewersadw
bugs1416305
milestone59.0a1
Bug 1416305 - Copying a search suggestion from the address bar gives back an http url. r=adw MozReview-Commit-ID: DBfZvVOxmzE
browser/base/content/test/urlbar/browser_urlbarSearchSuggestions.js
browser/base/content/urlbarBindings.xml
--- a/browser/base/content/test/urlbar/browser_urlbarSearchSuggestions.js
+++ b/browser/base/content/test/urlbar/browser_urlbarSearchSuggestions.js
@@ -70,16 +70,31 @@ add_task(async function plainEnterOnSugg
 
 add_task(async function ctrlEnterOnSuggestion() {
   await testPressEnterOnSuggestion("http://www.foofoo.com/",
                                    AppConstants.platform === "macosx" ?
                                      { metaKey: true } :
                                      { ctrlKey: true });
 });
 
+add_task(async function copySuggestionText() {
+  gURLBar.focus();
+  await promiseAutocompleteResultPopup("foo");
+  let [idx, suggestion] = await promiseFirstSuggestion();
+  for (let i = 0; i < idx; ++i) {
+    EventUtils.synthesizeKey("VK_DOWN", {});
+  }
+  gURLBar.select();
+  await new Promise((resolve, reject) => waitForClipboard(suggestion, function() {
+    goDoCommand("cmd_copy");
+  }, resolve, reject));
+  EventUtils.synthesizeKey("VK_ESCAPE", {});
+  await promisePopupHidden(gURLBar.popup);
+});
+
 function getFirstSuggestion() {
   let controller = gURLBar.popup.input.controller;
   let matchCount = controller.matchCount;
   for (let i = 0; i < matchCount; i++) {
     let url = controller.getValueAt(i);
     let mozActionMatch = url.match(/^moz-action:([^,]+),(.*)$/);
     if (mozActionMatch) {
       let [, type, paramStr] = mozActionMatch;
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -974,41 +974,48 @@ file, You can obtain one at http://mozil
             }
             return aURI;
           ]]>
         </body>
       </method>
 
       <method name="_getSelectedValueForClipboard">
         <body><![CDATA[
-          // Grab the actual input field's value, not our value, which could include moz-action:
+          // Grab the actual input field's value, not our value, which could
+          // include "moz-action:".
           var inputVal = this.inputField.value;
           let selection = this.editor.selection;
           const flags = Ci.nsIDocumentEncoder.OutputPreformatted |
                         Ci.nsIDocumentEncoder.OutputRaw;
           let selectedVal = selection.QueryInterface(Ci.nsISelectionPrivate)
                                      .toStringWithFormat("text/plain", flags, 0);
 
           // Handle multiple-range selection as a string for simplicity.
           if (selection.rangeCount > 1) {
              return selectedVal;
           }
 
-          // If the selection doesn't start at the beginning or doesn't span the full domain or
-          // the URL bar is modified or there is no text at all, nothing else to do here.
+          // If the selection doesn't start at the beginning or doesn't span the
+          // full domain or the URL bar is modified or there is no text at all,
+          // nothing else to do here.
           if (this.selectionStart > 0 || this.valueIsTyped || selectedVal == "")
             return selectedVal;
           // The selection doesn't span the full domain if it doesn't contain a slash and is
           // followed by some character other than a slash.
           if (!selectedVal.includes("/")) {
             let remainder = inputVal.replace(selectedVal, "");
             if (remainder != "" && remainder[0] != "/")
               return selectedVal;
           }
 
+          // If the value was filled by a search suggestion, just return it.
+          let action = this._parseActionUrl(this.value);
+          if (action && action.type == "searchengine")
+            return selectedVal;
+
           let uriFixup = Cc["@mozilla.org/docshell/urifixup;1"].getService(Ci.nsIURIFixup);
 
           let uri;
           if (this.getAttribute("pageproxystate") == "valid") {
             uri = gBrowser.currentURI;
           } else {
             // We're dealing with an autocompleted value, create a new URI from that.
             try {