diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /toolkit/components/telemetry/tests/unit/test_TelemetryControllerBuildID.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/telemetry/tests/unit/test_TelemetryControllerBuildID.js')
-rw-r--r-- | toolkit/components/telemetry/tests/unit/test_TelemetryControllerBuildID.js | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/toolkit/components/telemetry/tests/unit/test_TelemetryControllerBuildID.js b/toolkit/components/telemetry/tests/unit/test_TelemetryControllerBuildID.js new file mode 100644 index 0000000000..126684fe82 --- /dev/null +++ b/toolkit/components/telemetry/tests/unit/test_TelemetryControllerBuildID.js @@ -0,0 +1,74 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ +*/ +/* Test inclusion of previous build ID in telemetry pings when build ID changes. + * bug 841028 + * + * Cases to cover: + * 1) Run with no "previousBuildID" stored in prefs: + * -> no previousBuildID in telemetry system info, new value set in prefs. + * 2) previousBuildID in prefs, equal to current build ID: + * -> no previousBuildID in telemetry, prefs not updated. + * 3) previousBuildID in prefs, not equal to current build ID: + * -> previousBuildID in telemetry, new value set in prefs. + */ + +"use strict"; + +const { TelemetryController } = ChromeUtils.importESModule( + "resource://gre/modules/TelemetryController.sys.mjs" +); +const { TelemetrySession } = ChromeUtils.importESModule( + "resource://gre/modules/TelemetrySession.sys.mjs" +); + +// Set up our dummy AppInfo object so we can control the appBuildID. +const { getAppInfo, updateAppInfo } = ChromeUtils.importESModule( + "resource://testing-common/AppInfo.sys.mjs" +); +updateAppInfo(); + +// Check that when run with no previous build ID stored, we update the pref but do not +// put anything into the metadata. +add_task(async function test_firstRun() { + await TelemetryController.testReset(); + let metadata = TelemetrySession.getMetadata(); + Assert.equal(false, "previousBuildID" in metadata); + let appBuildID = getAppInfo().appBuildID; + let buildIDPref = Services.prefs.getCharPref( + TelemetryUtils.Preferences.PreviousBuildID + ); + Assert.equal(appBuildID, buildIDPref); +}); + +// Check that a subsequent run with the same build ID does not put prev build ID in +// metadata. Assumes testFirstRun() has already been called to set the previousBuildID pref. +add_task(async function test_secondRun() { + await TelemetryController.testReset(); + let metadata = TelemetrySession.getMetadata(); + Assert.equal(false, "previousBuildID" in metadata); +}); + +// Set up telemetry with a different app build ID and check that the old build ID +// is returned in the metadata and the pref is updated to the new build ID. +// Assumes testFirstRun() has been called to set the previousBuildID pref. +const NEW_BUILD_ID = "20130314"; +add_task(async function test_newBuild() { + let info = getAppInfo(); + let oldBuildID = info.appBuildID; + info.appBuildID = NEW_BUILD_ID; + await TelemetryController.testReset(); + let metadata = TelemetrySession.getMetadata(); + Assert.equal(metadata.previousBuildId, oldBuildID); + let buildIDPref = Services.prefs.getCharPref( + TelemetryUtils.Preferences.PreviousBuildID + ); + Assert.equal(NEW_BUILD_ID, buildIDPref); +}); + +function run_test() { + // Make sure we have a profile directory. + do_get_profile(); + + run_next_test(); +} |