test_AboutWelcomeTelemetry_exposure.js (2387B)
1 /* Any copyright is dedicated to the Public Domain. 2 https://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const { NetUtil } = ChromeUtils.importESModule( 7 "resource://gre/modules/NetUtil.sys.mjs" 8 ); 9 const { NimbusTestUtils } = ChromeUtils.importESModule( 10 "resource://testing-common/NimbusTestUtils.sys.mjs" 11 ); 12 13 NimbusTestUtils.init(this); 14 15 /** 16 * Tests that a visit to about:welcome results in an exposure recorded via 17 * Nimbus / Glean. 18 */ 19 20 add_task(async function test_exposure() { 21 do_get_profile(); 22 Services.fog.initializeFOG(); 23 NimbusTestUtils.cleanupStorePrefCache(); 24 25 // Simulate a visit by requesting the about:welcome nsIAboutModule, and 26 // requesting a channel for about:welcome. 27 let module = Cc[ 28 "@mozilla.org/network/protocol/about;1?what=welcome" 29 ].getService(Ci.nsIAboutModule); 30 Assert.ok(module, "Found the nsIAboutModule."); 31 32 Services.fog.testResetFOG(); 33 Assert.ok( 34 !Glean.normandy.exposeNimbusExperiment.testGetValue(), 35 "No exposure events recorded yet." 36 ); 37 38 const { manager, cleanup } = await NimbusTestUtils.setupTest(); 39 await manager.enroll( 40 NimbusTestUtils.factories.recipe.withFeatureConfig("foo", { 41 featureId: "aboutwelcome", 42 }), 43 "test" 44 ); 45 46 const ABOUT_WELCOME_URI = Services.io.newURI("about:welcome"); 47 48 // create a dummy loadinfo which we can hand to newChannel. 49 let dummyChannel = NetUtil.newChannel({ 50 uri: Services.io.newURI("http://localhost"), 51 loadUsingSystemPrincipal: true, 52 }); 53 let dummyLoadInfo = dummyChannel.loadInfo; 54 module.newChannel(ABOUT_WELCOME_URI, dummyLoadInfo); 55 56 let exposureEvents = Glean.normandy.exposeNimbusExperiment.testGetValue(); 57 Assert.ok(exposureEvents, "Found exposure events."); 58 let result = exposureEvents.filter(exposureEvent => { 59 return ( 60 exposureEvent.category === "normandy" && 61 exposureEvent.extra.featureId === "aboutwelcome" 62 ); 63 }); 64 Assert.equal(result.length, 1, "Found the single exposure"); 65 66 // Ensure there we only record this once. 67 module.newChannel(ABOUT_WELCOME_URI, dummyLoadInfo); 68 69 result = exposureEvents.filter(exposureEvent => { 70 return ( 71 exposureEvent.category === "normandy" && 72 exposureEvent.extra.featureId === "aboutwelcome" 73 ); 74 }); 75 Assert.equal(result.length, 1, "Only a single exposure still."); 76 77 await manager.unenroll("foo"); 78 await cleanup(); 79 });