diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_persist_connection.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_persist_connection.js')
-rw-r--r-- | devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_persist_connection.js | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_persist_connection.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_persist_connection.js new file mode 100644 index 0000000000..5ac1c2e188 --- /dev/null +++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_persist_connection.js @@ -0,0 +1,91 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const NETWORK_RUNTIME_HOST = "localhost:6080"; +const NETWORK_RUNTIME_APP_NAME = "TestNetworkApp"; +const USB_RUNTIME_ID = "test-runtime-id"; +const USB_DEVICE_NAME = "test device name"; +const USB_APP_NAME = "TestApp"; + +// Test that remote runtime connections are persisted across about:debugging reloads. +add_task(async function () { + const mocks = new Mocks(); + + info("Test with a USB runtime"); + const usbClient = mocks.createUSBRuntime(USB_RUNTIME_ID, { + name: USB_APP_NAME, + deviceName: USB_DEVICE_NAME, + }); + + await testRemoteClientPersistConnection(mocks, { + client: usbClient, + id: USB_RUNTIME_ID, + runtimeName: USB_APP_NAME, + sidebarName: USB_DEVICE_NAME, + type: "usb", + }); + + info("Test with a network runtime"); + const networkClient = mocks.createNetworkRuntime(NETWORK_RUNTIME_HOST, { + name: NETWORK_RUNTIME_APP_NAME, + }); + + await testRemoteClientPersistConnection(mocks, { + client: networkClient, + id: NETWORK_RUNTIME_HOST, + runtimeName: NETWORK_RUNTIME_APP_NAME, + sidebarName: NETWORK_RUNTIME_HOST, + type: "network", + }); +}); + +async function testRemoteClientPersistConnection( + mocks, + { client, id, runtimeName, sidebarName, type } +) { + info("Open about:debugging and connect to the test runtime"); + let { document, tab, window } = await openAboutDebugging(); + await selectThisFirefoxPage(document, window.AboutDebugging.store); + + await connectToRuntime(sidebarName, document); + await selectRuntime(sidebarName, runtimeName, document); + + info("Reload about:debugging"); + document = await reloadAboutDebugging(tab); + + info("Wait until the remote runtime appears as connected"); + await waitUntil(() => { + const sidebarItem = findSidebarItemByText(sidebarName, document); + return sidebarItem && !sidebarItem.querySelector(".qa-connect-button"); + }); + + info("Wait until the remote runtime page is selected"); + await waitUntil(() => { + const runtimeInfo = document.querySelector(".qa-runtime-name"); + return runtimeInfo && runtimeInfo.textContent.includes(runtimeName); + }); + + // Remove the runtime without emitting an update. + // This is what happens today when we simply close Firefox for Android. + info("Remove the runtime from the list of remote runtimes"); + mocks.removeRuntime(id); + + info( + "Emit 'closed' on the client and wait for the sidebar item to disappear" + ); + client._eventEmitter.emit("closed"); + if (type === "usb") { + await waitUntilUsbDeviceIsUnplugged(sidebarName, document); + } else { + await waitUntil( + () => + !findSidebarItemByText(sidebarName, document) && + !findSidebarItemByText(runtimeName, document) + ); + } + + info("Remove the tab"); + await removeTab(tab); +} |