test_uptake_telemetry.js (1645B)
1 const { TelemetryTestUtils } = ChromeUtils.importESModule( 2 "resource://testing-common/TelemetryTestUtils.sys.mjs" 3 ); 4 const { UptakeTelemetry } = ChromeUtils.importESModule( 5 "resource://services-common/uptake-telemetry.sys.mjs" 6 ); 7 8 const COMPONENT = "remotesettings"; 9 const GLEAN_COMPONENT = "Remotesettings"; 10 11 add_task(async function test_unknown_status_is_not_reported() { 12 const source = "update-source"; 13 const startSnapshot = getUptakeTelemetrySnapshot(COMPONENT, source); 14 15 try { 16 await UptakeTelemetry.report(GLEAN_COMPONENT, "unknown-status", { source }); 17 } catch (e) {} 18 19 const endSnapshot = getUptakeTelemetrySnapshot(COMPONENT, source); 20 Assert.deepEqual(startSnapshot, endSnapshot); 21 }); 22 23 add_task(async function test_age_is_converted_to_string_and_reported() { 24 const status = UptakeTelemetry.STATUS.SUCCESS; 25 const age = 42; 26 27 await UptakeTelemetry.report(GLEAN_COMPONENT, status, { source: "s", age }); 28 29 TelemetryTestUtils.assertEvents([ 30 [ 31 "uptake.remotecontent.result", 32 "uptake", 33 COMPONENT, 34 status, 35 { source: "s", age: `${age}` }, 36 ], 37 ]); 38 }); 39 40 add_task(async function test_each_status_can_be_caught_in_snapshot() { 41 const source = "some-source"; 42 const startSnapshot = getUptakeTelemetrySnapshot(COMPONENT, source); 43 44 const expectedIncrements = {}; 45 for (const status of Object.values(UptakeTelemetry.STATUS)) { 46 expectedIncrements[status] = 1; 47 await UptakeTelemetry.report(GLEAN_COMPONENT, status, { source }); 48 } 49 50 const endSnapshot = getUptakeTelemetrySnapshot(COMPONENT, source); 51 checkUptakeTelemetry(startSnapshot, endSnapshot, expectedIncrements); 52 });