browser_aboutdebugging_sidebar_usb_unplugged_device.js (2091B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const RUNTIME_NAME = "RUNTIME_NAME_1"; 7 const DEVICE_NAME = "DEVICE_NAME_1"; 8 const DEVICE_ID = "DEVICE_ID_1"; 9 const RUNTIME_ID = "RUNTIME_ID_1"; 10 11 const RUNTIME_NAME_2 = "RUNTIME_NAME_2"; 12 const DEVICE_NAME_2 = "DEVICE_NAME_2"; 13 const DEVICE_ID_2 = "DEVICE_ID_2"; 14 const RUNTIME_ID_2 = "RUNTIME_ID_2"; 15 16 // Test that removed USB devices are still visible as "Unplugged devices", until 17 // about:debugging is reloaded. 18 add_task(async function () { 19 const mocks = new Mocks(); 20 let { document, tab } = await openAboutDebugging(); 21 22 info("Create a mocked USB runtime"); 23 mocks.createUSBRuntime(RUNTIME_ID, { 24 deviceId: DEVICE_ID, 25 deviceName: DEVICE_NAME, 26 shortName: RUNTIME_NAME, 27 }); 28 mocks.emitUSBUpdate(); 29 30 info("Wait until the USB sidebar item appears"); 31 await waitUntil(() => findSidebarItemByText(DEVICE_NAME, document)); 32 const sidebarItem = findSidebarItemByText(DEVICE_NAME, document); 33 ok( 34 sidebarItem.textContent.includes(RUNTIME_NAME), 35 "Sidebar item shows the runtime name" 36 ); 37 38 mocks.removeUSBRuntime(RUNTIME_ID); 39 mocks.emitUSBUpdate(); 40 await waitUntilUsbDeviceIsUnplugged(DEVICE_NAME, document); 41 42 const unpluggedItem = findSidebarItemByText(DEVICE_NAME, document); 43 ok( 44 unpluggedItem.querySelector(".qa-runtime-item-unplugged"), 45 "Sidebar item is shown as `Unplugged…`" 46 ); 47 48 info("Reload about:debugging"); 49 document = await reloadAboutDebugging(tab); 50 51 info( 52 "Add another mocked USB runtime, to make sure the sidebar items are rendered." 53 ); 54 mocks.createUSBRuntime(RUNTIME_ID_2, { 55 deviceId: DEVICE_ID_2, 56 deviceName: DEVICE_NAME_2, 57 shortName: RUNTIME_NAME_2, 58 }); 59 mocks.emitUSBUpdate(); 60 61 info("Wait until the other USB sidebar item appears"); 62 await waitUntil(() => findSidebarItemByText(DEVICE_NAME_2, document)); 63 ok( 64 !findSidebarItemByText(DEVICE_NAME, document), 65 "Unplugged device is no longer displayed after reloading aboutdebugging" 66 ); 67 68 await removeTab(tab); 69 });