Bug 1416305 - Copying a search suggestion from the address bar gives back an http url. r=adw
MozReview-Commit-ID: DBfZvVOxmzE
--- 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 {