browser_aboutdebugging_telemetry_runtime_updates_multi.js (2898B)
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 DEVICE_A = "Device A"; 13 const USB_RUNTIME_1 = { 14 id: "runtime-id-1", 15 deviceName: DEVICE_A, 16 name: "Runtime 1", 17 shortName: "R1", 18 }; 19 20 const USB_RUNTIME_2 = { 21 id: "runtime-id-2", 22 deviceName: DEVICE_A, 23 name: "Runtime 2", 24 shortName: "R2", 25 }; 26 27 const DEVICE_A_EXTRAS = { 28 connection_type: "usb", 29 device_name: DEVICE_A, 30 }; 31 32 const RUNTIME_1_EXTRAS = { 33 connection_type: "usb", 34 device_name: USB_RUNTIME_1.deviceName, 35 runtime_name: USB_RUNTIME_1.shortName, 36 }; 37 38 const RUNTIME_2_EXTRAS = { 39 connection_type: "usb", 40 device_name: USB_RUNTIME_2.deviceName, 41 runtime_name: USB_RUNTIME_2.shortName, 42 }; 43 44 /** 45 * Test runtime update events when a device is connected/disconnected with multiple 46 * runtimes available on the same device. 47 */ 48 add_task(async function () { 49 // enable USB devices mocks 50 const mocks = new Mocks(); 51 setupTelemetryTest(); 52 53 const { tab, document } = await openAboutDebugging(); 54 55 const sessionId = getOpenEventSessionId(); 56 ok(!isNaN(sessionId), "Open event has a valid session id"); 57 58 info("Add two runtimes on the same device at the same time"); 59 mocks.createUSBRuntime(USB_RUNTIME_1.id, { 60 deviceName: USB_RUNTIME_1.deviceName, 61 name: USB_RUNTIME_1.name, 62 shortName: USB_RUNTIME_1.shortName, 63 }); 64 mocks.createUSBRuntime(USB_RUNTIME_2.id, { 65 deviceName: USB_RUNTIME_2.deviceName, 66 name: USB_RUNTIME_2.name, 67 shortName: USB_RUNTIME_2.shortName, 68 }); 69 mocks.emitUSBUpdate(); 70 await waitUntil(() => 71 findSidebarItemByText(USB_RUNTIME_1.shortName, document) 72 ); 73 await waitUntil(() => 74 findSidebarItemByText(USB_RUNTIME_2.shortName, document) 75 ); 76 77 checkTelemetryEvents( 78 [ 79 { method: "device_added", extras: DEVICE_A_EXTRAS }, 80 { method: "runtime_added", extras: RUNTIME_1_EXTRAS }, 81 { method: "runtime_added", extras: RUNTIME_2_EXTRAS }, 82 ], 83 sessionId 84 ); 85 86 info("Remove both runtimes at once to simulate a device disconnection"); 87 mocks.removeRuntime(USB_RUNTIME_1.id); 88 mocks.removeRuntime(USB_RUNTIME_2.id); 89 mocks.emitUSBUpdate(); 90 await waitUntil( 91 () => 92 !findSidebarItemByText(USB_RUNTIME_1.name, document) && 93 !findSidebarItemByText(USB_RUNTIME_1.shortName, document) 94 ); 95 await waitUntil( 96 () => 97 !findSidebarItemByText(USB_RUNTIME_2.name, document) && 98 !findSidebarItemByText(USB_RUNTIME_2.shortName, document) 99 ); 100 101 checkTelemetryEvents( 102 [ 103 { method: "runtime_removed", extras: RUNTIME_1_EXTRAS }, 104 { method: "runtime_removed", extras: RUNTIME_2_EXTRAS }, 105 { method: "device_removed", extras: DEVICE_A_EXTRAS }, 106 ], 107 sessionId 108 ); 109 110 await removeTab(tab); 111 });