From 49f3772d40c3a2b622b2b3ee2e14a3a185d5f9a9 Mon Sep 17 00:00:00 2001 From: Sean Feng Date: Wed, 17 Jul 2019 14:04:31 +0000 Subject: [PATCH] Bug 1551965 - Add telemetry for page reload key combinations r=bdekoz,Gijs,chutten Differential Revision: https://phabricator.services.mozilla.com/D35035 --HG-- extra : moz-landing-system : lando --- browser/base/content/browser-sets.inc | 2 +- browser/base/content/browser.js | 53 +++++- browser/modules/test/browser/browser.ini | 1 + ...r_UsageTelemetry_reload_key_combination.js | 160 ++++++++++++++++++ toolkit/components/telemetry/Histograms.json | 11 ++ 5 files changed, 224 insertions(+), 3 deletions(-) create mode 100644 browser/modules/test/browser/browser_UsageTelemetry_reload_key_combination.js diff --git a/browser/base/content/browser-sets.inc b/browser/base/content/browser-sets.inc index 11464065b03f..528e7fd15308 100644 --- a/browser/base/content/browser-sets.inc +++ b/browser/base/content/browser-sets.inc @@ -211,7 +211,7 @@ #endif - + #ifdef XP_MACOSX diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 341cc1b09389..78ca2848e4cb 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -1852,6 +1852,55 @@ var gBrowserInit = { } this._loadHandled = true; + let reloadHistogram = Services.telemetry.getHistogramById( + "FX_PAGE_RELOAD_KEY_COMBO" + ); + let reloadCommand = document.getElementById("Browser:Reload"); + reloadCommand.addEventListener("command", function(event) { + let { target } = event.sourceEvent || {}; + if (target.getAttribute("keycode") == "VK_F5") { + reloadHistogram.add("only_f5", 1); + } else if (target.id == "key_reload") { + reloadHistogram.add("accel_reloadKey", 1); + } + }); + + let reloadSkipCacheCommand = document.getElementById( + "Browser:ReloadSkipCache" + ); + reloadSkipCacheCommand.addEventListener("command", function(event) { + let { target } = event.sourceEvent || {}; + if (target.getAttribute("keycode") == "VK_F5") { + reloadHistogram.add("ctrl_f5", 1); + } else if (target.id == "key_reload_skip_cache") { + reloadHistogram.add("accel_shift_reload", 1); + } + }); + + let reloadOrDuplicateCommand = document.getElementById( + "Browser:ReloadOrDuplicate" + ); + reloadOrDuplicateCommand.addEventListener("command", function(event) { + let { target } = event.sourceEvent || {}; + if (target.id == "reload-button") { + let accelKeyPressed = + AppConstants.platform == "macosx" ? event.metaKey : event.ctrlKey; + let auxiliaryPressed = false; + let { sourceEvent } = event.sourceEvent || {}; + if (sourceEvent) { + auxiliaryPressed = sourceEvent.button == 1; + } + if (auxiliaryPressed) { + reloadHistogram.add("auxiliary_toolbar", 1); + } else if (accelKeyPressed) { + reloadHistogram.add("accel_toolbar", 1); + } else if (event.shiftKey) { + reloadHistogram.add("shift_toolbar", 1); + } else { + reloadHistogram.add("toolbar", 1); + } + } + }); }, _cancelDelayedStartup() { @@ -2617,9 +2666,9 @@ function BrowserStop() { function BrowserReloadOrDuplicate(aEvent) { aEvent = getRootEvent(aEvent); - let metaKeyPressed = + let accelKeyPressed = AppConstants.platform == "macosx" ? aEvent.metaKey : aEvent.ctrlKey; - var backgroundTabModifier = aEvent.button == 1 || metaKeyPressed; + var backgroundTabModifier = aEvent.button == 1 || accelKeyPressed; if (aEvent.shiftKey && !backgroundTabModifier) { BrowserReloadSkipCache(); diff --git a/browser/modules/test/browser/browser.ini b/browser/modules/test/browser/browser.ini index f4fb6ef55aca..91dd90058ad8 100644 --- a/browser/modules/test/browser/browser.ini +++ b/browser/modules/test/browser/browser.ini @@ -55,3 +55,4 @@ support-files = [browser_UsageTelemetry_content.js] [browser_UsageTelemetry_content_aboutHome.js] [browser_UsageTelemetry_content_aboutRestartRequired.js] +[browser_UsageTelemetry_reload_key_combination.js] diff --git a/browser/modules/test/browser/browser_UsageTelemetry_reload_key_combination.js b/browser/modules/test/browser/browser_UsageTelemetry_reload_key_combination.js new file mode 100644 index 000000000000..2c028208bc6f --- /dev/null +++ b/browser/modules/test/browser/browser_UsageTelemetry_reload_key_combination.js @@ -0,0 +1,160 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +/** + * This file tests page reload key combination telemetry + */ + +"use strict"; + +const TAB_URL = "https://example.com"; + +var accelKey = "ctrlKey"; +if (AppConstants.platform == "macosx") { + accelKey = "metaKey"; +} + +add_task(async function setup() { + await SpecialPowers.pushPrefEnv({ + set: [["toolkit.cosmeticAnimations.enabled", false]], + }); +}); + +add_task(async function test_pageReloadOnlyF5() { + let histogram = TelemetryTestUtils.getAndClearHistogram( + "FX_PAGE_RELOAD_KEY_COMBO" + ); + + await BrowserTestUtils.withNewTab(TAB_URL, async browser => { + let p = BrowserTestUtils.browserLoaded(browser); + EventUtils.synthesizeKey("VK_F5"); + await p; + + TelemetryTestUtils.assertHistogram(histogram, 0, 1); + }); +}); + +if (AppConstants.platform != "macosx") { + add_task(async function test_pageReloadAccelF5() { + let histogram = TelemetryTestUtils.getAndClearHistogram( + "FX_PAGE_RELOAD_KEY_COMBO" + ); + + await BrowserTestUtils.withNewTab(TAB_URL, async browser => { + let p = BrowserTestUtils.browserLoaded(browser); + EventUtils.synthesizeKey("VK_F5", { accelKey: true }); + await p; + + TelemetryTestUtils.assertHistogram(histogram, 1, 1); + }); + }); +} + +add_task(async function test_pageReloadAccelR() { + let histogram = TelemetryTestUtils.getAndClearHistogram( + "FX_PAGE_RELOAD_KEY_COMBO" + ); + + await BrowserTestUtils.withNewTab(TAB_URL, async browser => { + let p = BrowserTestUtils.browserLoaded(browser); + EventUtils.synthesizeKey("r", { accelKey: true }); + await p; + + TelemetryTestUtils.assertHistogram(histogram, 2, 1); + }); +}); + +add_task(async function test_pageReloadAccelShiftR() { + let histogram = TelemetryTestUtils.getAndClearHistogram( + "FX_PAGE_RELOAD_KEY_COMBO" + ); + + await BrowserTestUtils.withNewTab(TAB_URL, async browser => { + let p = BrowserTestUtils.browserLoaded(browser); + EventUtils.synthesizeKey("r", { accelKey: true, shiftKey: true }); + await p; + + TelemetryTestUtils.assertHistogram(histogram, 3, 1); + }); +}); + +add_task(async function test_pageReloadToolbar() { + let histogram = TelemetryTestUtils.getAndClearHistogram( + "FX_PAGE_RELOAD_KEY_COMBO" + ); + + await BrowserTestUtils.withNewTab(TAB_URL, async browser => { + let reloadButton = document.getElementById("reload-button"); + let p = BrowserTestUtils.browserLoaded(browser); + + await BrowserTestUtils.waitForCondition(() => { + return !reloadButton.disabled; + }); + + EventUtils.synthesizeMouseAtCenter(reloadButton, {}); + await p; + + TelemetryTestUtils.assertHistogram(histogram, 4, 1); + }); +}); + +add_task(async function test_pageReloadShiftToolbar() { + let histogram = TelemetryTestUtils.getAndClearHistogram( + "FX_PAGE_RELOAD_KEY_COMBO" + ); + + await BrowserTestUtils.withNewTab(TAB_URL, async browser => { + let reloadButton = document.getElementById("reload-button"); + let p = BrowserTestUtils.browserLoaded(browser); + + await BrowserTestUtils.waitForCondition(() => { + return !reloadButton.disabled; + }); + + EventUtils.synthesizeMouseAtCenter(reloadButton, { shiftKey: true }); + await p; + + TelemetryTestUtils.assertHistogram(histogram, 5, 1); + }); +}); + +add_task(async function test_pageReloadAccelToolbar() { + let histogram = TelemetryTestUtils.getAndClearHistogram( + "FX_PAGE_RELOAD_KEY_COMBO" + ); + + await BrowserTestUtils.withNewTab(TAB_URL, async browser => { + let reloadButton = document.getElementById("reload-button"); + + await BrowserTestUtils.waitForCondition(() => { + return !reloadButton.disabled; + }); + + EventUtils.synthesizeMouseAtCenter(reloadButton, { accelKey: true }); + + TelemetryTestUtils.assertHistogram(histogram, 6, 1); + // Accel + Toolbar would open an extra tab, so we need to call removeTab twice + BrowserTestUtils.removeTab(gBrowser.selectedTab); + }); +}); + +add_task(async function test_pageReloadAuxiliaryToobar() { + let histogram = TelemetryTestUtils.getAndClearHistogram( + "FX_PAGE_RELOAD_KEY_COMBO" + ); + + await BrowserTestUtils.withNewTab(TAB_URL, async browser => { + let reloadButton = document.getElementById("reload-button"); + + await BrowserTestUtils.waitForCondition(() => { + return !reloadButton.disabled; + }); + + EventUtils.synthesizeMouseAtCenter(reloadButton, { button: 1 }); + + TelemetryTestUtils.assertHistogram(histogram, 7, 1); + // Auxiliary + Toolbar would open an extra tab, so we need to call removeTab twice + BrowserTestUtils.removeTab(gBrowser.selectedTab); + }); +}); diff --git a/toolkit/components/telemetry/Histograms.json b/toolkit/components/telemetry/Histograms.json index 36dc94e9ef9f..2e41ce0dc7f2 100644 --- a/toolkit/components/telemetry/Histograms.json +++ b/toolkit/components/telemetry/Histograms.json @@ -7104,6 +7104,17 @@ "alert_emails": ["sefeng@mozilla.com", "perfteam@mozilla.com", "product-metrics-telemetry-alerts@mozilla.com"], "releaseChannelCollection": "opt-out" }, + "FX_PAGE_RELOAD_KEY_COMBO": { + "record_in_processes": ["main"], + "products": ["firefox"], + "expires_in_version": "72", + "kind": "categorical", + "description": "Record the frequency for common key combinations that users can use to trigger a page reload", + "labels": ["only_f5", "ctrl_f5", "accel_reloadKey", "accel_shift_reload", "toolbar", "shift_toolbar", "accel_toolbar", "auxiliary_toolbar"], + "bug_numbers": [1551965], + "alert_emails": ["sefeng@mozilla.com", "perfteam@mozilla.com", "product-metrics-telemetry-alerts@mozilla.com"], + "releaseChannelCollection": "opt-out" + }, "FX_SCHEDULE_PRESSURE_IDLE_SAMPLE_MS": { "record_in_processes": ["main"], "products": ["firefox", "fennec", "geckoview"],