Bug 1416305 - Copying a search suggestion from the address bar gives back an http url. r=adw
authorMarco Bonardo <mbonardo@mozilla.com>
Tue, 16 Jan 2018 12:23:09 +0100
changeset 453908 f49f83a6971acb892e5272a4fa84d07af4133bc3
parent 453907 990bb647f2184da05a5d5a9304da66a00d20b51b
child 453909 2028080562ac6e5594f4900ca9bb554e7b404421
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw
bugs1416305
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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 {