1
0
Fork 0
firefox/browser/components/aboutwelcome/tests/xpcshell/test_AboutWelcomeTelemetry_exposure.js
Daniel Baumann 5e9a113729
Adding upstream version 140.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
2025-06-25 09:37:52 +02:00

79 lines
2.3 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
https://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const { NetUtil } = ChromeUtils.importESModule(
"resource://gre/modules/NetUtil.sys.mjs"
);
const { NimbusTestUtils } = ChromeUtils.importESModule(
"resource://testing-common/NimbusTestUtils.sys.mjs"
);
NimbusTestUtils.init(this);
/**
* Tests that a visit to about:welcome results in an exposure recorded via
* Nimbus / Glean.
*/
add_task(async function test_exposure() {
do_get_profile();
Services.fog.initializeFOG();
NimbusTestUtils.cleanupStorePrefCache();
// Simulate a visit by requesting the about:welcome nsIAboutModule, and
// requesting a channel for about:welcome.
let module = Cc[
"@mozilla.org/network/protocol/about;1?what=welcome"
].getService(Ci.nsIAboutModule);
Assert.ok(module, "Found the nsIAboutModule.");
Services.fog.testResetFOG();
Assert.ok(
!Glean.normandy.exposeNimbusExperiment.testGetValue(),
"No exposure events recorded yet."
);
const { manager, cleanup } = await NimbusTestUtils.setupTest();
await manager.enroll(
NimbusTestUtils.factories.recipe.withFeatureConfig("foo", {
featureId: "aboutwelcome",
}),
"test"
);
const ABOUT_WELCOME_URI = Services.io.newURI("about:welcome");
// create a dummy loadinfo which we can hand to newChannel.
let dummyChannel = NetUtil.newChannel({
uri: Services.io.newURI("http://localhost"),
loadUsingSystemPrincipal: true,
});
let dummyLoadInfo = dummyChannel.loadInfo;
module.newChannel(ABOUT_WELCOME_URI, dummyLoadInfo);
let exposureEvents = Glean.normandy.exposeNimbusExperiment.testGetValue();
Assert.ok(exposureEvents, "Found exposure events.");
let result = exposureEvents.filter(exposureEvent => {
return (
exposureEvent.category === "normandy" &&
exposureEvent.extra.featureId === "aboutwelcome"
);
});
Assert.equal(result.length, 1, "Found the single exposure");
// Ensure there we only record this once.
module.newChannel(ABOUT_WELCOME_URI, dummyLoadInfo);
result = exposureEvents.filter(exposureEvent => {
return (
exposureEvent.category === "normandy" &&
exposureEvent.extra.featureId === "aboutwelcome"
);
});
Assert.equal(result.length, 1, "Only a single exposure still.");
await manager.unenroll("foo");
await cleanup();
});