summaryrefslogtreecommitdiffstats
path: root/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_unplugged_device.js
blob: 5074538a944c58b289ea8f7819d6051638d9ab88 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const RUNTIME_NAME = "RUNTIME_NAME_1";
const DEVICE_NAME = "DEVICE_NAME_1";
const DEVICE_ID = "DEVICE_ID_1";
const RUNTIME_ID = "RUNTIME_ID_1";

const RUNTIME_NAME_2 = "RUNTIME_NAME_2";
const DEVICE_NAME_2 = "DEVICE_NAME_2";
const DEVICE_ID_2 = "DEVICE_ID_2";
const RUNTIME_ID_2 = "RUNTIME_ID_2";

// Test that removed USB devices are still visible as "Unplugged devices", until
// about:debugging is reloaded.
add_task(async function () {
  const mocks = new Mocks();
  let { document, tab } = await openAboutDebugging();

  info("Create a mocked USB runtime");
  mocks.createUSBRuntime(RUNTIME_ID, {
    deviceId: DEVICE_ID,
    deviceName: DEVICE_NAME,
    shortName: RUNTIME_NAME,
  });
  mocks.emitUSBUpdate();

  info("Wait until the USB sidebar item appears");
  await waitUntil(() => findSidebarItemByText(DEVICE_NAME, document));
  const sidebarItem = findSidebarItemByText(DEVICE_NAME, document);
  ok(
    sidebarItem.textContent.includes(RUNTIME_NAME),
    "Sidebar item shows the runtime name"
  );

  mocks.removeUSBRuntime(RUNTIME_ID);
  mocks.emitUSBUpdate();
  await waitUntilUsbDeviceIsUnplugged(DEVICE_NAME, document);

  const unpluggedItem = findSidebarItemByText(DEVICE_NAME, document);
  ok(
    unpluggedItem.querySelector(".qa-runtime-item-unplugged"),
    "Sidebar item is shown as `Unplugged…`"
  );

  info("Reload about:debugging");
  document = await reloadAboutDebugging(tab);

  info(
    "Add another mocked USB runtime, to make sure the sidebar items are rendered."
  );
  mocks.createUSBRuntime(RUNTIME_ID_2, {
    deviceId: DEVICE_ID_2,
    deviceName: DEVICE_NAME_2,
    shortName: RUNTIME_NAME_2,
  });
  mocks.emitUSBUpdate();

  info("Wait until the other USB sidebar item appears");
  await waitUntil(() => findSidebarItemByText(DEVICE_NAME_2, document));
  ok(
    !findSidebarItemByText(DEVICE_NAME, document),
    "Unplugged device is no longer displayed after reloading aboutdebugging"
  );

  await removeTab(tab);
});