browser_aboutdebugging_persist_connection.js (2829B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const NETWORK_RUNTIME_HOST = "localhost:6080"; 7 const NETWORK_RUNTIME_APP_NAME = "TestNetworkApp"; 8 const USB_RUNTIME_ID = "test-runtime-id"; 9 const USB_DEVICE_NAME = "test device name"; 10 const USB_APP_NAME = "TestApp"; 11 12 // Test that remote runtime connections are persisted across about:debugging reloads. 13 add_task(async function () { 14 const mocks = new Mocks(); 15 16 info("Test with a USB runtime"); 17 const usbClient = mocks.createUSBRuntime(USB_RUNTIME_ID, { 18 name: USB_APP_NAME, 19 deviceName: USB_DEVICE_NAME, 20 }); 21 22 await testRemoteClientPersistConnection(mocks, { 23 client: usbClient, 24 id: USB_RUNTIME_ID, 25 runtimeName: USB_APP_NAME, 26 sidebarName: USB_DEVICE_NAME, 27 type: "usb", 28 }); 29 30 info("Test with a network runtime"); 31 const networkClient = mocks.createNetworkRuntime(NETWORK_RUNTIME_HOST, { 32 name: NETWORK_RUNTIME_APP_NAME, 33 }); 34 35 await testRemoteClientPersistConnection(mocks, { 36 client: networkClient, 37 id: NETWORK_RUNTIME_HOST, 38 runtimeName: NETWORK_RUNTIME_APP_NAME, 39 sidebarName: NETWORK_RUNTIME_HOST, 40 type: "network", 41 }); 42 }); 43 44 async function testRemoteClientPersistConnection( 45 mocks, 46 { client, id, runtimeName, sidebarName, type } 47 ) { 48 info("Open about:debugging and connect to the test runtime"); 49 let { document, tab, window } = await openAboutDebugging(); 50 await selectThisFirefoxPage(document, window.AboutDebugging.store); 51 52 await connectToRuntime(sidebarName, document); 53 await waitForRuntimePage(runtimeName, document); 54 55 info("Reload about:debugging"); 56 document = await reloadAboutDebugging(tab); 57 58 info("Wait until the remote runtime appears as connected"); 59 await waitUntil(() => { 60 const sidebarItem = findSidebarItemByText(sidebarName, document); 61 return sidebarItem && !sidebarItem.querySelector(".qa-connect-button"); 62 }); 63 64 info("Wait until the remote runtime page is selected"); 65 await waitUntil(() => { 66 const runtimeInfo = document.querySelector(".qa-runtime-name"); 67 return runtimeInfo && runtimeInfo.textContent.includes(runtimeName); 68 }); 69 70 // Remove the runtime without emitting an update. 71 // This is what happens today when we simply close Firefox for Android. 72 info("Remove the runtime from the list of remote runtimes"); 73 mocks.removeRuntime(id); 74 75 info( 76 "Emit 'closed' on the client and wait for the sidebar item to disappear" 77 ); 78 client._eventEmitter.emit("closed"); 79 if (type === "usb") { 80 await waitUntilUsbDeviceIsUnplugged(sidebarName, document); 81 } else { 82 await waitUntil( 83 () => 84 !findSidebarItemByText(sidebarName, document) && 85 !findSidebarItemByText(runtimeName, document) 86 ); 87 } 88 89 info("Remove the tab"); 90 await removeTab(tab); 91 }