summaryrefslogtreecommitdiffstats
path: root/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_runtime_usbclient_closed.js
blob: 9e9715a46b16c095652587237ad1e482355abe5d (plain)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* 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 about:debugging navigates back to the default page when a USB device is
// unplugged.
add_task(async function testUsbDeviceUnplugged() {
  const mocks = new Mocks();
  const { document, tab, window } = await openAboutDebugging();
  await selectThisFirefoxPage(document, window.AboutDebugging.store);

  mocks.createUSBRuntime(USB_RUNTIME_ID, {
    deviceName: USB_DEVICE_NAME,
    name: USB_APP_NAME,
  });
  mocks.emitUSBUpdate();

  info("Connect to and select the USB device");
  await connectToRuntime(USB_DEVICE_NAME, document);
  await selectRuntime(USB_DEVICE_NAME, USB_APP_NAME, document);

  info("Simulate a device unplugged");
  mocks.removeUSBRuntime(USB_RUNTIME_ID);
  mocks.emitUSBUpdate();
  await waitUntilUsbDeviceIsUnplugged(USB_DEVICE_NAME, document);

  is(
    document.location.hash,
    `#/runtime/this-firefox`,
    "Redirection to the default page (this-firefox)"
  );

  await removeTab(tab);
});

// Test that about:debugging navigates back to the default page when the server for the
// current USB runtime is closed.
add_task(async function testUsbClientDisconnected() {
  const mocks = new Mocks();
  const { document, tab, window } = await openAboutDebugging();
  await selectThisFirefoxPage(document, window.AboutDebugging.store);

  const usbClient = mocks.createUSBRuntime(USB_RUNTIME_ID, {
    deviceName: USB_DEVICE_NAME,
    name: USB_APP_NAME,
  });
  mocks.emitUSBUpdate();

  info("Connect to and select the USB device");
  await connectToRuntime(USB_DEVICE_NAME, document);
  await selectRuntime(USB_DEVICE_NAME, USB_APP_NAME, document);

  info("Simulate a client disconnection");
  usbClient.isClosed = () => true;
  usbClient._eventEmitter.emit("closed");

  info("Wait until the connect button for this runtime appears");
  await waitUntil(() => {
    const item = findSidebarItemByText(USB_DEVICE_NAME, document);
    return item && item.querySelector(".qa-connect-button");
  });

  is(
    document.location.hash,
    `#/runtime/this-firefox`,
    "Redirection to the default page (this-firefox)"
  );
  await removeTab(tab);
});

// Test that about:debugging navigates back to the default page when the server for the
// current network runtime is closed.
add_task(async function testNetworkClientDisconnected() {
  const mocks = new Mocks();
  const { document, tab, window } = await openAboutDebugging();
  await selectThisFirefoxPage(document, window.AboutDebugging.store);

  const networkClient = mocks.createNetworkRuntime(NETWORK_RUNTIME_HOST, {
    name: NETWORK_RUNTIME_APP_NAME,
  });

  info("Connect to and select the network runtime");
  await connectToRuntime(NETWORK_RUNTIME_HOST, document);
  await selectRuntime(NETWORK_RUNTIME_HOST, NETWORK_RUNTIME_APP_NAME, document);

  info("Simulate a client disconnection");
  networkClient.isClosed = () => true;
  networkClient._eventEmitter.emit("closed");

  info("Wait until the connect button for this runtime appears");
  await waitUntil(() => {
    const item = findSidebarItemByText(NETWORK_RUNTIME_HOST, document);
    return item && item.querySelector(".qa-connect-button");
  });

  is(
    document.location.hash,
    `#/runtime/this-firefox`,
    "Redirection to the default page (this-firefox)"
  );
  await removeTab(tab);
});