1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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);
}
|