Bug 1643687 - Resolve incompatibility between Search Tips and Paste & Go. r=mak
authorHarry Twyford <htwyford@mozilla.com>
Fri, 12 Jun 2020 14:18:37 +0000
changeset 535501 89dc62c137a1aa73483bdf6af3d91425e00269cb
parent 535500 a7c49babc1a459731d59ba630c04ad30e54978e8
child 535502 f55dacce61a217fbf9ff3b54c85c4db2ed7d0032
push id118890
push userhtwyford@mozilla.com
push dateFri, 12 Jun 2020 14:50:23 +0000
treeherderautoland@89dc62c137a1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1643687
milestone79.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 1643687 - Resolve incompatibility between Search Tips and Paste & Go. r=mak Differential Revision: https://phabricator.services.mozilla.com/D79174
browser/components/urlbar/UrlbarInput.jsm
browser/components/urlbar/tests/browser-tips/browser_searchTips_interaction.js
--- a/browser/components/urlbar/UrlbarInput.jsm
+++ b/browser/components/urlbar/UrlbarInput.jsm
@@ -935,17 +935,20 @@ class UrlbarInput {
       this._autofillPlaceholder &&
       !firstResult.autofill &&
       // Avoid clobbering added spaces (for token aliases, for example).
       !this.value.endsWith(" ")
     ) {
       this._setValue(this.window.gBrowser.userTypedValue, false);
     }
 
-    if (firstResult.heuristic) {
+    // Heuristic tip results do not set the Urlbar value.
+    if (firstResult.type == UrlbarUtils.RESULT_TYPE.TIP) {
+      this._resultForCurrentValue = null;
+    } else if (firstResult.heuristic) {
       this._resultForCurrentValue = firstResult;
     }
   }
 
   /**
    * Starts a query based on the current input value.
    *
    * @param {boolean} [options.allowAutofill]
--- a/browser/components/urlbar/tests/browser-tips/browser_searchTips_interaction.js
+++ b/browser/components/urlbar/tests/browser-tips/browser_searchTips_interaction.js
@@ -13,16 +13,23 @@ XPCOMUtils.defineLazyModuleGetters(this,
   AppMenuNotifications: "resource://gre/modules/AppMenuNotifications.jsm",
   HttpServer: "resource://testing-common/httpd.js",
   ProfileAge: "resource://gre/modules/ProfileAge.jsm",
   UrlbarPrefs: "resource:///modules/UrlbarPrefs.jsm",
   UrlbarProviderSearchTips: "resource:///modules/UrlbarProviderSearchTips.jsm",
   UrlbarTestUtils: "resource://testing-common/UrlbarTestUtils.jsm",
 });
 
+XPCOMUtils.defineLazyServiceGetter(
+  this,
+  "clipboardHelper",
+  "@mozilla.org/widget/clipboardhelper;1",
+  "nsIClipboardHelper"
+);
+
 // These should match the same consts in UrlbarProviderSearchTips.jsm.
 const MAX_SHOWN_COUNT = 4;
 const LAST_UPDATE_THRESHOLD_MS = 24 * 60 * 60 * 1000;
 
 // We test some of the bigger Google domains.
 const GOOGLE_DOMAINS = [
   "www.google.com",
   "www.google.ca",
@@ -525,16 +532,51 @@ add_task(async function ignoreEndsEngage
           UrlbarProviderSearchTips.TIP_TYPE.NONE,
         "The engagement should have ended after the tip was ignored."
       );
     });
   });
   resetSearchTipsProvider();
 });
 
+add_task(async function pasteAndGo() {
+  UrlbarProviderSearchTips.disableTipsForCurrentSession = false;
+  let tab = await BrowserTestUtils.openNewForegroundTab({
+    gBrowser,
+    url: "about:newtab",
+    waitForLoad: false,
+  });
+  await checkTip(window, UrlbarProviderSearchTips.TIP_TYPE.ONBOARD, false);
+
+  const url = "http://example.com/";
+  await SimpleTest.promiseClipboardChange(url, () => {
+    clipboardHelper.copyString(url);
+  });
+
+  let textBox = gURLBar.querySelector("moz-input-box");
+  let cxmenu = textBox.menupopup;
+  let cxmenuPromise = BrowserTestUtils.waitForEvent(cxmenu, "popupshown");
+  EventUtils.synthesizeMouseAtCenter(gURLBar.inputField, {
+    type: "contextmenu",
+    button: 2,
+  });
+  await cxmenuPromise;
+  let menuitem = textBox.getMenuItem("paste-and-go");
+
+  let browserLoadedPromise = BrowserTestUtils.browserLoaded(
+    gBrowser.selectedBrowser,
+    false,
+    url
+  );
+  EventUtils.synthesizeMouseAtCenter(menuitem, {});
+  await browserLoadedPromise;
+  BrowserTestUtils.removeTab(tab);
+  resetSearchTipsProvider();
+});
+
 // Since we coupled the logic that decides whether to show the tip with our
 // gURLBar.search call, we should make sure search isn't called when
 // the conditions for a tip are met but the provider is disabled.
 add_task(async function noActionWhenDisabled() {
   await setDefaultEngine("Bing");
   await withDNSRedirect("www.bing.com", "/", async url => {
     await checkTab(window, url, UrlbarProviderSearchTips.TIP_TYPE.REDIRECT);
   });