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

"use strict";

const USB_RUNTIME_ID = "1337id";
const USB_DEVICE_NAME = "Fancy Phone";
const USB_APP_NAME = "Lorem ipsum";

const DEFAULT_PAGE = "#/runtime/this-firefox";

/**
 * Check if the disconnect button disconnects the remote runtime
 * and redirects to the default page.
 */
add_task(async function () {
  // Create a real local client and use it as the remote USB client for this
  // test.
  const clientWrapper = await createLocalClientWrapper();

  // enable USB devices mocks
  const mocks = new Mocks();
  mocks.createUSBRuntime(USB_RUNTIME_ID, {
    clientWrapper,
    deviceName: USB_DEVICE_NAME,
    name: USB_APP_NAME,
  });

  const { document, tab, window } = await openAboutDebugging();
  await selectThisFirefoxPage(document, window.AboutDebugging.store);

  mocks.emitUSBUpdate();

  const onRequestSuccess = waitForRequestsSuccess(window.AboutDebugging.store);
  await connectToRuntime(USB_DEVICE_NAME, document);
  await selectRuntime(USB_DEVICE_NAME, USB_APP_NAME, document);
  await onRequestSuccess;

  const disconnectRemoteRuntimeButton = document.querySelector(
    ".qa-runtime-info__action"
  );

  info("Check whether disconnect remote runtime button exists");
  ok(!!disconnectRemoteRuntimeButton, "Runtime contains the disconnect button");

  info("Click on the disconnect button");
  disconnectRemoteRuntimeButton.click();

  info("Wait until the runtime is disconnected");
  await waitUntil(() => document.querySelector(".qa-connect-button"));

  is(
    document.location.hash,
    DEFAULT_PAGE,
    "Redirection to the default page (this-firefox)"
  );

  info("Wait until the Runtime name is displayed");
  await waitUntil(() => {
    const runtimeInfo = document.querySelector(".qa-runtime-name");
    return runtimeInfo && runtimeInfo.textContent.includes("Firefox");
  });

  await removeTab(tab);
});