From 5a64fcf173d1db9ec4fedc0cce87cf12dd7b362e Mon Sep 17 00:00:00 2001 From: Mark Banner Date: Wed, 10 Oct 2018 07:21:23 +0000 Subject: [PATCH] Bug 1496743 - Stop logging telemetry when pressing enter on the one-off search settings button in the urlbar. r=adw Also add tests for the search settings button in the urlbar. Differential Revision: https://phabricator.services.mozilla.com/D8146 --HG-- extra : moz-landing-system : lando --- browser/base/content/test/urlbar/browser.ini | 4 + .../urlbar/browser_urlbarOneOffs_settings.js | 78 +++++++++++++++++++ browser/base/content/urlbarBindings.xml | 6 +- 3 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 browser/base/content/test/urlbar/browser_urlbarOneOffs_settings.js diff --git a/browser/base/content/test/urlbar/browser.ini b/browser/base/content/test/urlbar/browser.ini index 9ecd3c15c7c0..4166c66650ee 100644 --- a/browser/base/content/test/urlbar/browser.ini +++ b/browser/base/content/test/urlbar/browser.ini @@ -96,6 +96,10 @@ support-files = searchSuggestionEngine.xml searchSuggestionEngine.sjs [browser_urlbarOneOffs_searchSuggestions.js] +support-files = + searchSuggestionEngine.xml + searchSuggestionEngine.sjs +[browser_urlbarOneOffs_settings.js] support-files = searchSuggestionEngine.xml searchSuggestionEngine.sjs diff --git a/browser/base/content/test/urlbar/browser_urlbarOneOffs_settings.js b/browser/base/content/test/urlbar/browser_urlbarOneOffs_settings.js new file mode 100644 index 000000000000..2c168b85bcc8 --- /dev/null +++ b/browser/base/content/test/urlbar/browser_urlbarOneOffs_settings.js @@ -0,0 +1,78 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +const TEST_ENGINE_BASENAME = "searchSuggestionEngine.xml"; + +let gMaxResults; + +add_task(async function init() { + Services.prefs.setBoolPref("browser.urlbar.oneOffSearches", true); + gMaxResults = Services.prefs.getIntPref("browser.urlbar.maxRichResults"); + + // Add a search suggestion engine and move it to the front so that it appears + // as the first one-off. + let engine = await SearchTestUtils.promiseNewSearchEngine( + getRootDirectory(gTestPath) + TEST_ENGINE_BASENAME); + Services.search.moveEngine(engine, 0); + + registerCleanupFunction(async function() { + await hidePopup(); + await PlacesUtils.history.clear(); + }); + + await PlacesUtils.history.clear(); + + let visits = []; + for (let i = 0; i < gMaxResults; i++) { + visits.push({ + uri: makeURI("http://example.com/browser_urlbarOneOffs.js/?" + i), + // TYPED so that the visit shows up when the urlbar's drop-down arrow is + // pressed. + transition: Ci.nsINavHistoryService.TRANSITION_TYPED, + }); + } + await PlacesTestUtils.addVisits(visits); +}); + + +async function selectSettings(activateFn) { + await BrowserTestUtils.withNewTab({gBrowser, url: "about:blank"}, async browser => { + gURLBar.focus(); + EventUtils.synthesizeKey("KEY_ArrowDown"); + await promisePopupShown(gURLBar.popup); + await waitForAutocompleteResultAt(gMaxResults - 1); + + let promiseHidden = promisePopupHidden(gURLBar.popup); + let prefPaneLoaded = TestUtils.topicObserved("sync-pane-loaded", () => true); + + activateFn(); + + await prefPaneLoaded; + await promiseHidden; + + Assert.equal(gBrowser.contentWindow.history.state, "paneSearch", + "Should have opened the search preferences pane"); + }); +} + +add_task(async function test_open_settings_with_enter() { + await selectSettings(() => { + EventUtils.synthesizeKey("KEY_ArrowUp"); + + Assert.equal(gURLBar.popup.oneOffSearchButtons.selectedButton.getAttribute("anonid"), + "search-settings-compact", "Should have selected the settings button"); + + EventUtils.synthesizeKey("KEY_Enter"); + }); +}); + +add_task(async function test_open_settings_with_click() { + await selectSettings(() => { + gURLBar.popup.oneOffSearchButtons.settingsButton.click(); + }); +}); + +async function hidePopup() { + EventUtils.synthesizeKey("KEY_Escape"); + await promisePopupHidden(gURLBar.popup); +} diff --git a/browser/base/content/urlbarBindings.xml b/browser/base/content/urlbarBindings.xml index 869b6d685e98..8f386104f26d 100644 --- a/browser/base/content/urlbarBindings.xml +++ b/browser/base/content/urlbarBindings.xml @@ -652,9 +652,6 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. return; } - BrowserUsageTelemetry.recordUrlbarSelectedResultMethod( - event, this.userSelectionBehavior); - // Determine whether to use the selected one-off search button. In // one-off search buttons parlance, "selected" means that the button // has been navigated to via the keyboard. So we want to use it if @@ -673,6 +670,9 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. return; } + BrowserUsageTelemetry.recordUrlbarSelectedResultMethod( + event, this.userSelectionBehavior); + let where = openUILinkWhere || this._whereToOpen(event); let url = this.value;