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

"use strict";

/* import-globals-from helper-adb.js */
Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-adb.js", this);

async function getExpectedRuntime() {
  const runtimes = await getExpectedRuntimeAll();
  return runtimes[0];
}
/* exported getExpectedRuntime */

async function getExpectedRuntimeAll() {
  const runtimesPath = _getExpectedRuntimesPath();
  const currentPath = Services.env.get("PWD");
  const path = `${currentPath}/${runtimesPath}`;
  info(`Load ${path}`);
  const buffer = await IOUtils.read(path);
  const data = new TextDecoder().decode(buffer);
  return JSON.parse(data);
}
/* exported getExpectedRuntimeAll */

function isAvailable() {
  return !!_getExpectedRuntimesPath();
}
/* exported isAvailable */

async function openAboutDebuggingWithADB() {
  const { document, tab, window } = await openAboutDebugging();

  await pushPref(
    "devtools.remote.adb.extensionURL",
    CHROME_URL_ROOT + "resources/test-adb-extension/adb-extension-#OS#.xpi"
  );
  await checkAdbNotRunning();

  const {
    adbAddon,
  } = require("resource://devtools/client/shared/remote-debugging/adb/adb-addon.js");
  adbAddon.install("internal");
  const usbStatusElement = document.querySelector(".qa-sidebar-usb-status");
  await waitUntil(() => usbStatusElement.textContent.includes("USB enabled"));
  await waitForAdbStart();

  return { document, tab, window };
}
/* exported openAboutDebuggingWithADB */

function _getExpectedRuntimesPath() {
  return Services.env.get("USB_RUNTIMES");
}