diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /toolkit/mozapps/extensions/test/xpcshell/test_amo_stats_telemetry.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/mozapps/extensions/test/xpcshell/test_amo_stats_telemetry.js')
-rw-r--r-- | toolkit/mozapps/extensions/test/xpcshell/test_amo_stats_telemetry.js | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_amo_stats_telemetry.js b/toolkit/mozapps/extensions/test/xpcshell/test_amo_stats_telemetry.js new file mode 100644 index 0000000000..8176c5881a --- /dev/null +++ b/toolkit/mozapps/extensions/test/xpcshell/test_amo_stats_telemetry.js @@ -0,0 +1,102 @@ +/* Any copyright is dedicated to the Public Domain. +http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { TelemetryController } = ChromeUtils.importESModule( + "resource://gre/modules/TelemetryController.sys.mjs" +); + +AddonTestUtils.init(this); +AddonTestUtils.overrideCertDB(); +AddonTestUtils.createAppInfo( + "xpcshell@tests.mozilla.org", + "XPCShell", + "1", + "42" +); + +add_task(async function setup() { + // We need to set this pref to `true` in order to collect add-ons Telemetry + // data (which is considered extended data and disabled in CI). + const overridePreReleasePref = "toolkit.telemetry.testing.overridePreRelease"; + let oldOverrideValue = Services.prefs.getBoolPref( + overridePreReleasePref, + false + ); + Services.prefs.setBoolPref(overridePreReleasePref, true); + registerCleanupFunction(() => { + Services.prefs.setBoolPref(overridePreReleasePref, oldOverrideValue); + }); + + await TelemetryController.testSetup(); + await AddonTestUtils.promiseStartupManager(); +}); + +add_task(async function test_ping_payload_and_environment() { + const extensions = [ + { + id: "addons-telemetry@test-extension-1", + name: "some extension 1", + version: "1.2.3", + }, + { + id: "addons-telemetry@test-extension-2", + name: "some extension 2", + version: "0.1", + }, + ]; + + // Install some extensions. + const installedExtensions = []; + for (const { id, name, version } of extensions) { + const extension = ExtensionTestUtils.loadExtension({ + manifest: { + name, + version, + browser_specific_settings: { gecko: { id } }, + }, + useAddonManager: "permanent", + }); + installedExtensions.push(extension); + + await extension.startup(); + } + + const { payload, environment } = TelemetryController.getCurrentPingData(); + + // Important: `payload.info.addons` is being used for AMO usage stats. + Assert.ok("addons" in payload.info, "payload.info.addons is defined"); + Assert.equal( + payload.info.addons, + extensions + .map(({ id, version }) => `${encodeURIComponent(id)}:${version}`) + .join(",") + ); + Assert.ok( + "XPI" in payload.addonDetails, + "payload.addonDetails.XPI is defined" + ); + for (const { id, name } of extensions) { + Assert.ok(id in payload.addonDetails.XPI); + Assert.equal(payload.addonDetails.XPI[id].name, name); + } + + const { addons } = environment; + Assert.ok( + "activeAddons" in addons, + "environment.addons.activeAddons is defined" + ); + Assert.ok("theme" in addons, "environment.addons.theme is defined"); + for (const { id } of extensions) { + Assert.ok(id in environment.addons.activeAddons); + } + + for (const extension of installedExtensions) { + await extension.unload(); + } +}); + +add_task(async function cleanup() { + await TelemetryController.testShutdown(); +}); |