From fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:14:29 +0200 Subject: Merging upstream version 125.0.1. Signed-off-by: Daniel Baumann --- .../test/unit/test_ExperimentManager_unenroll.js | 112 +++++++++++++++++++++ 1 file changed, 112 insertions(+) (limited to 'toolkit/components/nimbus/test/unit/test_ExperimentManager_unenroll.js') diff --git a/toolkit/components/nimbus/test/unit/test_ExperimentManager_unenroll.js b/toolkit/components/nimbus/test/unit/test_ExperimentManager_unenroll.js index 3c53148c7a..a32de32cd6 100644 --- a/toolkit/components/nimbus/test/unit/test_ExperimentManager_unenroll.js +++ b/toolkit/components/nimbus/test/unit/test_ExperimentManager_unenroll.js @@ -6,6 +6,9 @@ const { TelemetryEvents } = ChromeUtils.importESModule( const { TelemetryEnvironment } = ChromeUtils.importESModule( "resource://gre/modules/TelemetryEnvironment.sys.mjs" ); +const { ExperimentAPI } = ChromeUtils.importESModule( + "resource://nimbus/ExperimentAPI.sys.mjs" +); const STUDIES_OPT_OUT_PREF = "app.shield.optoutstudies.enabled"; const UPLOAD_ENABLED_PREF = "datareporting.healthreport.uploadEnabled"; @@ -487,3 +490,112 @@ add_task(async function test_rollout_telemetry_events() { ); globalSandbox.restore(); }); + +add_task(async function test_check_unseen_enrollments_telemetry_events() { + globalSandbox.restore(); + const store = ExperimentFakes.store(); + const manager = ExperimentFakes.manager(store); + const sandbox = sinon.createSandbox(); + sandbox.stub(manager, "unenroll").returns(); + sandbox.stub(ExperimentAPI, "_store").get(() => manager.store); + sandbox.stub(ExperimentAPI, "_manager").get(() => manager); + + await manager.onStartup(); + await manager.store.ready(); + + const experiment = ExperimentFakes.recipe("foo", { + branches: [ + { + slug: "wsup", + ratio: 1, + features: [ + { + featureId: "nimbusTelemetry", + value: { + gleanMetricConfiguration: { + "nimbus_events.enrollment_status": true, + }, + }, + }, + ], + }, + ], + bucketConfig: { + ...ExperimentFakes.recipe.bucketConfig, + count: 1000, + }, + }); + + await manager.enroll(experiment, "aaa"); + + const source = "test"; + const slugs = [], + experiments = []; + for (let i = 0; i < 7; i++) { + slugs.push(`slug-${i}`); + experiments.push({ + slug: slugs[i], + source, + branch: { + slug: "control", + }, + }); + } + + manager.sessions.set(source, new Set([slugs[0]])); + + manager._checkUnseenEnrollments( + experiments, + source, + [slugs[1]], + [slugs[2]], + new Map([]), + new Map([[slugs[3], experiments[3]]]), + [slugs[4]], + new Map([[slugs[5], experiments[5]]]) + ); + + const events = Glean.nimbusEvents.enrollmentStatus.testGetValue(); + + Assert.equal(events?.length, 7); + + Assert.equal(events[0].extra.status, "Enrolled"); + Assert.equal(events[0].extra.reason, "Qualified"); + Assert.equal(events[0].extra.branch, "control"); + Assert.equal(events[0].extra.slug, slugs[0]); + + Assert.equal(events[1].extra.status, "Disqualified"); + Assert.equal(events[1].extra.reason, "NotTargeted"); + Assert.equal(events[1].extra.branch, "control"); + Assert.equal(events[1].extra.slug, slugs[1]); + + Assert.equal(events[2].extra.status, "Disqualified"); + Assert.equal(events[2].extra.reason, "Error"); + Assert.equal(events[2].extra.error_string, "invalid-recipe"); + Assert.equal(events[2].extra.branch, "control"); + Assert.equal(events[2].extra.slug, slugs[2]); + + Assert.equal(events[3].extra.status, "Disqualified"); + Assert.equal(events[3].extra.reason, "Error"); + Assert.equal(events[3].extra.error_string, "invalid-branch"); + Assert.equal(events[3].extra.branch, "control"); + Assert.equal(events[3].extra.slug, slugs[3]); + + Assert.equal(events[4].extra.status, "Disqualified"); + Assert.equal(events[4].extra.reason, "Error"); + Assert.equal(events[4].extra.error_string, "l10n-missing-locale"); + Assert.equal(events[4].extra.branch, "control"); + Assert.equal(events[4].extra.slug, slugs[4]); + + Assert.equal(events[5].extra.status, "Disqualified"); + Assert.equal(events[5].extra.reason, "Error"); + Assert.equal(events[5].extra.error_string, "l10n-missing-entry"); + Assert.equal(events[5].extra.branch, "control"); + Assert.equal(events[5].extra.slug, slugs[5]); + + Assert.equal(events[6].extra.status, "WasEnrolled"); + Assert.equal(events[6].extra.branch, "control"); + Assert.equal(events[6].extra.slug, slugs[6]); + + sandbox.restore(); +}); -- cgit v1.2.3