Bug 1643687 - Resolve incompatibility between Search Tips and Paste & Go. r=mak, a=jcristau
authorHarry Twyford <htwyford@mozilla.com>
Fri, 12 Jun 2020 14:18:37 +0000
changeset 597143 04b57a2b3df5f8d457efd4cae3948ce1bca1f38f
parent 597142 6260a92051486b156100a4b5af9cf5db181ffa54
child 597144 28acb07b048322d370b6b27acb051ecd3a02dcde
push id13285
push userjcristau@mozilla.com
push dateMon, 15 Jun 2020 14:38:09 +0000
treeherdermozilla-beta@5edcb80711d0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak, jcristau
bugs1643687
milestone78.0
Bug 1643687 - Resolve incompatibility between Search Tips and Paste & Go. r=mak, a=jcristau 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",
@@ -526,16 +533,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);
   });