browser_aboutdebugging_telemetry_runtime_actions.js (2718B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /* import-globals-from helper-telemetry.js */ 7 Services.scriptloader.loadSubScript( 8 CHROME_URL_ROOT + "helper-telemetry.js", 9 this 10 ); 11 12 const RUNTIME_ID = "test-runtime-id"; 13 const RUNTIME_NAME = "Test Runtime"; 14 const RUNTIME_DEVICE_NAME = "Test Device"; 15 16 /** 17 * Test that runtime specific actions are logged as telemetry events with the expected 18 * runtime id and action type. 19 */ 20 add_task(async function testUsbRuntimeUpdates() { 21 // enable USB devices mocks 22 const mocks = new Mocks(); 23 setupTelemetryTest(); 24 25 const { tab, document } = await openAboutDebugging(); 26 27 const sessionId = getOpenEventSessionId(); 28 ok(!isNaN(sessionId), "Open event has a valid session id"); 29 30 const usbClient = mocks.createUSBRuntime(RUNTIME_ID, { 31 deviceName: RUNTIME_DEVICE_NAME, 32 name: RUNTIME_NAME, 33 shortName: RUNTIME_NAME, 34 }); 35 mocks.emitUSBUpdate(); 36 37 info("Wait for the runtime to appear in the sidebar"); 38 await waitUntil(() => findSidebarItemByText(RUNTIME_NAME, document)); 39 await connectToRuntime(RUNTIME_DEVICE_NAME, document); 40 await waitForRuntimePage(RUNTIME_NAME, document); 41 42 info("Read telemetry events to flush unrelated events"); 43 const evts = readAboutDebuggingEvents(); 44 const runtimeAddedEvent = evts.filter(e => e.method === "runtime_added")[0]; 45 const telemetryRuntimeId = runtimeAddedEvent.extras.runtime_id; 46 47 info("Click on the toggle button and wait until the text is updated"); 48 const promptButton = document.querySelector( 49 ".qa-connection-prompt-toggle-button" 50 ); 51 promptButton.click(); 52 await waitUntil(() => promptButton.textContent.includes("Enable")); 53 54 checkTelemetryEvents( 55 [ 56 { 57 method: "update_conn_prompt", 58 extras: { prompt_enabled: "false", runtime_id: telemetryRuntimeId }, 59 }, 60 ], 61 sessionId 62 ); 63 64 info("Click on the toggle button again and check we log the correct value"); 65 promptButton.click(); 66 await waitUntil(() => promptButton.textContent.includes("Disable")); 67 68 checkTelemetryEvents( 69 [ 70 { 71 method: "update_conn_prompt", 72 extras: { prompt_enabled: "true", runtime_id: telemetryRuntimeId }, 73 }, 74 ], 75 sessionId 76 ); 77 78 info("Open the profiler dialog"); 79 await openProfilerDialog(usbClient, document); 80 81 checkTelemetryEvents( 82 [ 83 { 84 method: "show_profiler", 85 extras: { runtime_id: telemetryRuntimeId }, 86 }, 87 ], 88 sessionId 89 ); 90 91 info("Remove runtime"); 92 mocks.removeRuntime(RUNTIME_ID); 93 mocks.emitUSBUpdate(); 94 await waitUntil(() => !findSidebarItemByText(RUNTIME_NAME, document)); 95 96 await removeTab(tab); 97 });