diff --git a/browser/components/nsBrowserGlue.js b/browser/components/nsBrowserGlue.js index e06357185aac..433510e30360 100644 --- a/browser/components/nsBrowserGlue.js +++ b/browser/components/nsBrowserGlue.js @@ -363,6 +363,9 @@ BrowserGlue.prototype = { } }); break; + case "autocomplete-did-enter-text": + this._handleURLBarTelemetry(subject.QueryInterface(Ci.nsIAutoCompleteInput)); + break; case "test-initialize-sanitizer": this._sanitizer.onStartup(); break; @@ -372,6 +375,64 @@ BrowserGlue.prototype = { } }, + _handleURLBarTelemetry(input) { + if (!input || + input.id != "urlbar" || + input.inPrivateContext || + input.popup.selectedIndex < 0) { + return; + } + let controller = + input.popup.view.QueryInterface(Ci.nsIAutoCompleteController); + let idx = input.popup.selectedIndex; + let value = controller.getValueAt(idx); + let action = input._parseActionUrl(value); + let actionType; + if (action) { + actionType = + action.type == "searchengine" && action.params.searchSuggestion ? + "searchsuggestion" : + action.type; + } + if (!actionType) { + let styles = new Set(controller.getStyleAt(idx).split(/\s+/)); + let style = ["autofill", "tag", "bookmark"].find(s => styles.has(s)); + actionType = style || "history"; + } + + Services.telemetry + .getHistogramById("FX_URLBAR_SELECTED_RESULT_INDEX") + .add(idx); + + // Ideally this would be a keyed histogram and we'd just add(actionType), + // but keyed histograms aren't currently shown on the telemetry dashboard + // (bug 1151756). + // + // You can add values but don't change any of the existing values. + // Otherwise you'll break our data. + let buckets = { + autofill: 0, + bookmark: 1, + history: 2, + keyword: 3, + searchengine: 4, + searchsuggestion: 5, + switchtab: 6, + tag: 7, + visiturl: 8, + remotetab: 9, + extension: 10, + }; + if (actionType in buckets) { + Services.telemetry + .getHistogramById("FX_URLBAR_SELECTED_RESULT_TYPE") + .add(buckets[actionType]); + } else { + Cu.reportError("Unknown FX_URLBAR_SELECTED_RESULT_TYPE type: " + + actionType); + } + }, + // initialization (called on application startup) _init: function BG__init() { let os = Services.obs; @@ -408,6 +469,7 @@ BrowserGlue.prototype = { os.addObserver(this, "restart-in-safe-mode", false); os.addObserver(this, "flash-plugin-hang", false); os.addObserver(this, "xpi-signature-changed", false); + os.addObserver(this, "autocomplete-did-enter-text", false); if (AppConstants.NIGHTLY_BUILD) { os.addObserver(this, AddonWatcher.TOPIC_SLOW_ADDON_DETECTED, false); @@ -462,6 +524,7 @@ BrowserGlue.prototype = { os.removeObserver(this, "browser-search-engine-modified"); os.removeObserver(this, "flash-plugin-hang"); os.removeObserver(this, "xpi-signature-changed"); + os.removeObserver(this, "autocomplete-did-enter-text"); }, _onAppDefaults: function BG__onAppDefaults() { diff --git a/browser/modules/BrowserUsageTelemetry.jsm b/browser/modules/BrowserUsageTelemetry.jsm index fc8b1c2b1824..cc1745a6b08c 100644 --- a/browser/modules/BrowserUsageTelemetry.jsm +++ b/browser/modules/BrowserUsageTelemetry.jsm @@ -5,7 +5,7 @@ "use strict"; -this.EXPORTED_SYMBOLS = ["BrowserUsageTelemetry", "URLBAR_SELECTED_RESULT_TYPES"]; +this.EXPORTED_SYMBOLS = ["BrowserUsageTelemetry"]; const {classes: Cc, interfaces: Ci, utils: Cu} = Components; @@ -23,7 +23,6 @@ const WINDOWS_RESTORED_TOPIC = "sessionstore-windows-restored"; const TAB_RESTORING_TOPIC = "SSTabRestoring"; const TELEMETRY_SUBSESSIONSPLIT_TOPIC = "internal-telemetry-after-subsession-split"; const DOMWINDOW_OPENED_TOPIC = "domwindowopened"; -const AUTOCOMPLETE_ENTER_TEXT_TOPIC = "autocomplete-did-enter-text"; // Probe names. const MAX_TAB_COUNT_SCALAR_NAME = "browser.engagement.max_concurrent_tab_count"; @@ -49,24 +48,6 @@ const KNOWN_ONEOFF_SOURCES = [ "unknown", // Edge case: this is the searchbar (see bug 1195733 comment 7). ]; -/** - * The buckets used for logging telemetry to the FX_URLBAR_SELECTED_RESULT_TYPE - * histogram. - */ -const URLBAR_SELECTED_RESULT_TYPES = { - autofill: 0, - bookmark: 1, - history: 2, - keyword: 3, - searchengine: 4, - searchsuggestion: 5, - switchtab: 6, - tag: 7, - visiturl: 8, - remotetab: 9, - extension: 10, -}; - function getOpenTabsAndWinsCounts() { let tabCount = 0; let winCount = 0; @@ -206,82 +187,9 @@ let URICountListener = { Ci.nsISupportsWeakReference]), }; -let urlbarListener = { - init() { - Services.obs.addObserver(this, AUTOCOMPLETE_ENTER_TEXT_TOPIC, true); - }, - - uninit() { - Services.obs.removeObserver(this, AUTOCOMPLETE_ENTER_TEXT_TOPIC, true); - }, - - observe(subject, topic, data) { - switch (topic) { - case AUTOCOMPLETE_ENTER_TEXT_TOPIC: - this._handleURLBarTelemetry(subject.QueryInterface(Ci.nsIAutoCompleteInput)); - break; - } - }, - - /** - * Used to log telemetry when the user enters text in the urlbar. - * - * @param {nsIAutoCompleteInput} input The autocomplete element where the - * text was entered. - */ - _handleURLBarTelemetry(input) { - if (!input || - input.id != "urlbar" || - input.inPrivateContext || - input.popup.selectedIndex < 0) { - return; - } - let controller = - input.popup.view.QueryInterface(Ci.nsIAutoCompleteController); - let idx = input.popup.selectedIndex; - let value = controller.getValueAt(idx); - let action = input._parseActionUrl(value); - let actionType; - if (action) { - actionType = - action.type == "searchengine" && action.params.searchSuggestion ? - "searchsuggestion" : - action.type; - } - if (!actionType) { - let styles = new Set(controller.getStyleAt(idx).split(/\s+/)); - let style = ["autofill", "tag", "bookmark"].find(s => styles.has(s)); - actionType = style || "history"; - } - - Services.telemetry - .getHistogramById("FX_URLBAR_SELECTED_RESULT_INDEX") - .add(idx); - - // Ideally this would be a keyed histogram and we'd just add(actionType), - // but keyed histograms aren't currently shown on the telemetry dashboard - // (bug 1151756). - // - // You can add values but don't change any of the existing values. - // Otherwise you'll break our data. - if (actionType in URLBAR_SELECTED_RESULT_TYPES) { - Services.telemetry - .getHistogramById("FX_URLBAR_SELECTED_RESULT_TYPE") - .add(URLBAR_SELECTED_RESULT_TYPES[actionType]); - } else { - Cu.reportError("Unknown FX_URLBAR_SELECTED_RESULT_TYPE type: " + - actionType); - } - }, - - QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, - Ci.nsISupportsWeakReference]), -}; - let BrowserUsageTelemetry = { init() { Services.obs.addObserver(this, WINDOWS_RESTORED_TOPIC, false); - urlbarListener.init(); }, /** @@ -303,7 +211,6 @@ let BrowserUsageTelemetry = { Services.obs.removeObserver(this, DOMWINDOW_OPENED_TOPIC, false); Services.obs.removeObserver(this, TELEMETRY_SUBSESSIONSPLIT_TOPIC, false); Services.obs.removeObserver(this, WINDOWS_RESTORED_TOPIC, false); - urlbarListener.uninit(); }, observe(subject, topic, data) { diff --git a/browser/modules/test/browser_UsageTelemetry_content.js b/browser/modules/test/browser_UsageTelemetry_content.js index 8ba285706be6..35c6b5a6dd54 100644 --- a/browser/modules/test/browser_UsageTelemetry_content.js +++ b/browser/modules/test/browser_UsageTelemetry_content.js @@ -33,7 +33,6 @@ add_task(function* setup() { Services.search.currentEngine = originalEngine; Services.search.removeEngine(engineDefault); Services.search.removeEngine(engineOneOff); - yield PlacesTestUtils.clearHistory(); }); }); diff --git a/browser/modules/test/browser_UsageTelemetry_content_aboutHome.js b/browser/modules/test/browser_UsageTelemetry_content_aboutHome.js index a98df386f29e..1818ae5fd95c 100644 --- a/browser/modules/test/browser_UsageTelemetry_content_aboutHome.js +++ b/browser/modules/test/browser_UsageTelemetry_content_aboutHome.js @@ -35,7 +35,6 @@ add_task(function* setup() { Services.search.currentEngine = originalEngine; Services.search.removeEngine(engineDefault); Services.search.removeEngine(engineOneOff); - yield PlacesTestUtils.clearHistory(); }); }); diff --git a/browser/modules/test/browser_UsageTelemetry_urlbar.js b/browser/modules/test/browser_UsageTelemetry_urlbar.js index 98a0148e15cf..f0de0b0ab78d 100644 --- a/browser/modules/test/browser_UsageTelemetry_urlbar.js +++ b/browser/modules/test/browser_UsageTelemetry_urlbar.js @@ -8,21 +8,6 @@ const SUGGEST_URLBAR_PREF = "browser.urlbar.suggest.searches"; const SUGGESTION_ENGINE_NAME = "browser_UsageTelemetry usageTelemetrySearchSuggestions.xml"; const ONEOFF_URLBAR_PREF = "browser.urlbar.oneOffSearches"; -XPCOMUtils.defineLazyModuleGetter(this, "URLBAR_SELECTED_RESULT_TYPES", - "resource:///modules/BrowserUsageTelemetry.jsm"); - -function checkHistogramResults(resultIndexes, expected, histogram) { - for (let i = 0; i < resultIndexes.counts.length; i++) { - if (i == expected) { - Assert.equal(resultIndexes.counts[i], 1, - `expected counts should match for ${histogram} index ${i}`); - } else { - Assert.equal(resultIndexes.counts[i], 0, - `unexpected counts should be zero for ${histogram} index ${i}`); - } - } -} - let searchInAwesomebar = Task.async(function* (inputText, win = window) { yield new Promise(r => waitForFocus(r, win)); // Write the search query in the urlbar. @@ -83,7 +68,6 @@ add_task(function* setup() { Services.search.removeEngine(engine); Services.prefs.clearUserPref(SUGGEST_URLBAR_PREF, true); Services.prefs.clearUserPref(ONEOFF_URLBAR_PREF); - yield PlacesTestUtils.clearHistory(); }); }); @@ -91,11 +75,6 @@ add_task(function* test_simpleQuery() { // Let's reset the counts. Services.telemetry.clearScalars(); Services.telemetry.clearEvents(); - let resultIndexHist = Services.telemetry.getHistogramById("FX_URLBAR_SELECTED_RESULT_INDEX"); - let resultTypeHist = Services.telemetry.getHistogramById("FX_URLBAR_SELECTED_RESULT_TYPE"); - resultIndexHist.clear(); - resultTypeHist.clear(); - let search_hist = getSearchCountsHistogram(); let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank"); @@ -121,15 +100,6 @@ add_task(function* test_simpleQuery() { events = events.filter(e => e[1] == "navigation" && e[2] == "search"); checkEvents(events, [["navigation", "search", "urlbar", "enter", {engine: "other-MozSearch"}]]); - // Check the histograms as well. - let resultIndexes = resultIndexHist.snapshot(); - checkHistogramResults(resultIndexes, 0, "FX_URLBAR_SELECTED_RESULT_INDEX"); - - let resultTypes = resultTypeHist.snapshot(); - checkHistogramResults(resultTypes, - URLBAR_SELECTED_RESULT_TYPES.searchengine, - "FX_URLBAR_SELECTED_RESULT_TYPE"); - yield BrowserTestUtils.removeTab(tab); }); @@ -137,11 +107,6 @@ add_task(function* test_searchAlias() { // Let's reset the counts. Services.telemetry.clearScalars(); Services.telemetry.clearEvents(); - let resultIndexHist = Services.telemetry.getHistogramById("FX_URLBAR_SELECTED_RESULT_INDEX"); - let resultTypeHist = Services.telemetry.getHistogramById("FX_URLBAR_SELECTED_RESULT_TYPE"); - resultIndexHist.clear(); - resultTypeHist.clear(); - let search_hist = getSearchCountsHistogram(); let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank"); @@ -167,15 +132,6 @@ add_task(function* test_searchAlias() { events = events.filter(e => e[1] == "navigation" && e[2] == "search"); checkEvents(events, [["navigation", "search", "urlbar", "alias", {engine: "other-MozSearch"}]]); - // Check the histograms as well. - let resultIndexes = resultIndexHist.snapshot(); - checkHistogramResults(resultIndexes, 0, "FX_URLBAR_SELECTED_RESULT_INDEX"); - - let resultTypes = resultTypeHist.snapshot(); - checkHistogramResults(resultTypes, - URLBAR_SELECTED_RESULT_TYPES.searchengine, - "FX_URLBAR_SELECTED_RESULT_TYPE"); - yield BrowserTestUtils.removeTab(tab); }); @@ -183,11 +139,6 @@ add_task(function* test_oneOff() { // Let's reset the counts. Services.telemetry.clearScalars(); Services.telemetry.clearEvents(); - let resultIndexHist = Services.telemetry.getHistogramById("FX_URLBAR_SELECTED_RESULT_INDEX"); - let resultTypeHist = Services.telemetry.getHistogramById("FX_URLBAR_SELECTED_RESULT_TYPE"); - resultIndexHist.clear(); - resultTypeHist.clear(); - let search_hist = getSearchCountsHistogram(); let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank"); @@ -216,15 +167,6 @@ add_task(function* test_oneOff() { events = events.filter(e => e[1] == "navigation" && e[2] == "search"); checkEvents(events, [["navigation", "search", "urlbar", "oneoff", {engine: "other-MozSearch"}]]); - // Check the histograms as well. - let resultIndexes = resultIndexHist.snapshot(); - checkHistogramResults(resultIndexes, 0, "FX_URLBAR_SELECTED_RESULT_INDEX"); - - let resultTypes = resultTypeHist.snapshot(); - checkHistogramResults(resultTypes, - URLBAR_SELECTED_RESULT_TYPES.searchengine, - "FX_URLBAR_SELECTED_RESULT_TYPE"); - yield BrowserTestUtils.removeTab(tab); }); @@ -232,11 +174,6 @@ add_task(function* test_suggestion() { // Let's reset the counts. Services.telemetry.clearScalars(); Services.telemetry.clearEvents(); - let resultIndexHist = Services.telemetry.getHistogramById("FX_URLBAR_SELECTED_RESULT_INDEX"); - let resultTypeHist = Services.telemetry.getHistogramById("FX_URLBAR_SELECTED_RESULT_TYPE"); - resultIndexHist.clear(); - resultTypeHist.clear(); - let search_hist = getSearchCountsHistogram(); // Create an engine to generate search suggestions and add it as default @@ -277,15 +214,6 @@ add_task(function* test_suggestion() { events = events.filter(e => e[1] == "navigation" && e[2] == "search"); checkEvents(events, [["navigation", "search", "urlbar", "suggestion", {engine: searchEngineId}]]); - // Check the histograms as well. - let resultIndexes = resultIndexHist.snapshot(); - checkHistogramResults(resultIndexes, 3, "FX_URLBAR_SELECTED_RESULT_INDEX"); - - let resultTypes = resultTypeHist.snapshot(); - checkHistogramResults(resultTypes, - URLBAR_SELECTED_RESULT_TYPES.searchsuggestion, - "FX_URLBAR_SELECTED_RESULT_TYPE"); - Services.search.currentEngine = previousEngine; Services.search.removeEngine(suggestionEngine); yield BrowserTestUtils.removeTab(tab); diff --git a/browser/modules/test/head.js b/browser/modules/test/head.js index cd76859e5e33..24fc136b175c 100644 --- a/browser/modules/test/head.js +++ b/browser/modules/test/head.js @@ -1,8 +1,5 @@ Cu.import("resource://gre/modules/Promise.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "PlacesTestUtils", - "resource://testing-common/PlacesTestUtils.jsm"); - const SINGLE_TRY_TIMEOUT = 100; const NUMBER_OF_TRIES = 30; diff --git a/toolkit/components/telemetry/Histograms.json b/toolkit/components/telemetry/Histograms.json index 2ff299316fc3..c0639b2c3e2f 100644 --- a/toolkit/components/telemetry/Histograms.json +++ b/toolkit/components/telemetry/Histograms.json @@ -5471,7 +5471,7 @@ "kind": "enumerated", "n_values": 14, "bug_numbers": [775825], - "description": "Firefox: The type of the selected result in the URL bar popup. See BrowserUsageTelemetry.jsm:URLBAR_SELECTED_RESULT_TYPES for the result types." + "description": "Firefox: The type of the selected result in the URL bar popup. See nsBrowserGlue.js::_handleURLBarTelemetry for the result types." }, "INNERWINDOWS_WITH_MUTATION_LISTENERS": { "expires_in_version": "never",