summaryrefslogtreecommitdiffstats
path: root/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_fenix_runtime_display.js
blob: 778b1bb9670b362b0f6ab21339190bf5caae1d71 (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const RUNTIME_ID = "1337id";
const DEVICE_NAME = "Fancy Phone";
const SERVER_RUNTIME_NAME = "Mozilla Firefox";
const ADB_RUNTIME_NAME = "Firefox Preview";
const SERVER_VERSION = "v7.3.31";
const ADB_VERSION = "v1.3.37";

const FENIX_RELEASE_ICON_SRC =
  "chrome://devtools/skin/images/aboutdebugging-fenix.svg";
const FENIX_NIGHTLY_ICON_SRC =
  "chrome://devtools/skin/images/aboutdebugging-fenix-nightly.svg";

/**
 * Check that Fenix runtime information is correctly displayed in about:debugging.
 */
add_task(async function () {
  const mocks = new Mocks();
  mocks.createUSBRuntime(RUNTIME_ID, {
    deviceName: DEVICE_NAME,
    isFenix: true,
    name: SERVER_RUNTIME_NAME,
    shortName: ADB_RUNTIME_NAME,
    versionName: ADB_VERSION,
    version: SERVER_VERSION,
  });

  // open a remote runtime page
  const { document, tab, window } = await openAboutDebugging();
  await selectThisFirefoxPage(document, window.AboutDebugging.store);

  mocks.emitUSBUpdate();
  await connectToRuntime(DEVICE_NAME, document);
  await selectRuntime(DEVICE_NAME, ADB_RUNTIME_NAME, document);

  info("Check that the runtime information is displayed as expected");
  const runtimeInfo = document.querySelector(".qa-runtime-name");
  ok(runtimeInfo, "Runtime info for the Fenix runtime is displayed");
  const runtimeInfoText = runtimeInfo.textContent;

  ok(runtimeInfoText.includes(ADB_RUNTIME_NAME), "Name is the ADB name");
  ok(
    !runtimeInfoText.includes(SERVER_RUNTIME_NAME),
    "Name does not include the server name"
  );

  ok(runtimeInfoText.includes(ADB_VERSION), "Version contains the ADB version");
  ok(
    !runtimeInfoText.includes(SERVER_VERSION),
    "Version does not contain the server version"
  );

  const runtimeIcon = document.querySelector(".qa-runtime-icon");
  is(
    runtimeIcon.src,
    FENIX_RELEASE_ICON_SRC,
    "The runtime icon is the Fenix icon"
  );

  info("Remove USB runtime");
  mocks.removeUSBRuntime(RUNTIME_ID);
  mocks.emitUSBUpdate();
  await waitUntilUsbDeviceIsUnplugged(DEVICE_NAME, document);

  await removeTab(tab);
});

/**
 * Check that Fenix runtime information is correctly displayed in about:devtools-toolbox.
 */
add_task(async function () {
  // We use a real local client combined with a mocked USB runtime to be able to open
  // about:devtools-toolbox on a real target.
  const clientWrapper = await createLocalClientWrapper();

  const mocks = new Mocks();
  mocks.createUSBRuntime(RUNTIME_ID, {
    channel: "nightly",
    clientWrapper,
    deviceName: DEVICE_NAME,
    isFenix: true,
    name: SERVER_RUNTIME_NAME,
    shortName: ADB_RUNTIME_NAME,
    versionName: ADB_VERSION,
    version: SERVER_VERSION,
  });

  // open a remote runtime page
  const { document, tab, window } = await openAboutDebugging();
  await selectThisFirefoxPage(document, window.AboutDebugging.store);

  mocks.emitUSBUpdate();
  info("Select the runtime page for the USB runtime");
  const onRequestSuccess = waitForRequestsSuccess(window.AboutDebugging.store);
  await connectToRuntime(DEVICE_NAME, document);
  await selectRuntime(DEVICE_NAME, ADB_RUNTIME_NAME, document);
  info(
    "Wait for requests to finish the USB runtime is backed by a real local client"
  );
  await onRequestSuccess;

  info("Wait for the about:debugging target to be available");
  await waitUntil(() => findDebugTargetByText("about:debugging", document));
  const { devtoolsDocument, devtoolsTab } = await openAboutDevtoolsToolbox(
    document,
    tab,
    window
  );

  const runtimeInfo = devtoolsDocument.querySelector(".qa-runtime-info");
  const runtimeInfoText = runtimeInfo.textContent;
  ok(
    runtimeInfoText.includes(ADB_RUNTIME_NAME),
    "Name is the ADB runtime name"
  );
  ok(runtimeInfoText.includes(ADB_VERSION), "Version is the ADB version");

  const runtimeIcon = devtoolsDocument.querySelector(".qa-runtime-icon");
  is(
    runtimeIcon.src,
    FENIX_NIGHTLY_ICON_SRC,
    "The runtime icon is the Fenix icon"
  );

  info("Wait for all pending requests to settle on the DevToolsClient");
  await clientWrapper.client.waitForRequestsToSettle();

  await closeAboutDevtoolsToolbox(document, devtoolsTab, window);

  info("Remove USB runtime");
  mocks.removeUSBRuntime(RUNTIME_ID);
  mocks.emitUSBUpdate();
  await waitUntilUsbDeviceIsUnplugged(DEVICE_NAME, document);

  await removeTab(tab);
  await clientWrapper.close();
});